@@ -59,12 +59,12 @@ type InboundQueueRecord struct {
5959}
6060
6161const (
62- // bundleUncompressedSizeLimit is the (exclusive) limit on uncompressed bundle size.
62+ // BundleUncompressedSizeLimit is the (exclusive) limit on uncompressed bundle size.
6363 // We must ensure there is an exclusive int64 limit in order to detect an underflow.
64- bundleUncompressedSizeLimit uint64 = 10 * 1024 * 1024 // 10MB
65- chunkSizeLimit uint64 = 512 * 1024 // 512KB
66- chunkIndexLimit uint64 = (bundleUncompressedSizeLimit + chunkSizeLimit - 1 ) / chunkSizeLimit
67- hashLimit int = 128
64+ BundleUncompressedSizeLimit uint64 = 10 * 1024 * 1024 // 10MB
65+ ChunkSizeLimit uint64 = 512 * 1024 // 512KB
66+ ChunkIndexLimit uint64 = (BundleUncompressedSizeLimit + ChunkSizeLimit - 1 ) / ChunkSizeLimit
67+ HashSize int = 256 / 8 * 2
6868)
6969
7070// Charge an account address for the beans associated with given messages and storage.
@@ -441,7 +441,7 @@ func (msg MsgInstallBundle) ValidateBasic() error {
441441 return sdkioerrors .Wrap (sdkerrors .ErrUnknownRequest , "Uncompressed size must be set with a compressed bundle" )
442442 case msg .UncompressedSize != 0 && hasBundle :
443443 return sdkioerrors .Wrap (sdkerrors .ErrUnknownRequest , "Uncompressed size cannot be set with a legacy bundle" )
444- case uint64 (msg .UncompressedSize ) >= bundleUncompressedSizeLimit :
444+ case uint64 (msg .UncompressedSize ) >= BundleUncompressedSizeLimit :
445445 // must enforce a limit to avoid overflow when computing its successor in Uncompress()
446446 return sdkioerrors .Wrap (sdkerrors .ErrUnknownRequest , "Uncompressed size out of range" )
447447 }
@@ -523,26 +523,26 @@ func (bc BundleChunks) ValidateBasic() error {
523523 if len (bc .Chunks ) == 0 {
524524 return sdkioerrors .Wrap (sdkerrors .ErrUnknownRequest , "Bundle chunks cannot be empty" )
525525 }
526- if uint64 (len (bc .Chunks )) >= chunkIndexLimit {
527- return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Number of bundle chunks must be less than %d" , chunkIndexLimit )
526+ if uint64 (len (bc .Chunks )) >= ChunkIndexLimit {
527+ return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Number of bundle chunks must be less than %d" , ChunkIndexLimit )
528528 }
529- if len (bc .BundleHash ) > hashLimit {
530- return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Bundle hash must not exceed %d characters" , hashLimit )
529+ if len (bc .BundleHash ) != HashSize {
530+ return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Bundle hash must be %d characters" , HashSize )
531531 }
532532 if ! IsHexBytes (bc .BundleHash ) {
533533 return sdkioerrors .Wrap (sdkerrors .ErrUnknownRequest , "Bundle hash must be a hex byte string" )
534534 }
535- if bc .BundleSize <= 0 || bc .BundleSize >= bundleUncompressedSizeLimit {
535+ if bc .BundleSize <= 0 || bc .BundleSize >= BundleUncompressedSizeLimit {
536536 return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Bundle size out of range" )
537537 }
538538 totalChunkSize := uint64 (0 )
539539 for i , chunk := range bc .Chunks {
540- if chunk .ChunkSize <= 0 || chunk .ChunkSize >= chunkSizeLimit {
540+ if chunk .ChunkSize <= 0 || chunk .ChunkSize >= ChunkSizeLimit {
541541 return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk %d size out of range" , i )
542542 }
543543 totalChunkSize += chunk .ChunkSize
544- if len (chunk .Hash ) > hashLimit {
545- return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk %d hash must not exceed %d characters" , i , hashLimit )
544+ if len (chunk .Hash ) != HashSize {
545+ return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk %d hash must be %d characters" , i , HashSize )
546546 }
547547 if ! IsHexBytes (chunk .Hash ) {
548548 return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk %d hash must be a hex byte string" , i )
@@ -610,11 +610,11 @@ func (msg MsgSendChunk) ValidateBasic() error {
610610 if len (msg .ChunkData ) == 0 {
611611 return sdkioerrors .Wrap (sdkerrors .ErrUnknownRequest , "Chunk data cannot be empty" )
612612 }
613- if uint64 (len (msg .ChunkData )) >= chunkSizeLimit {
614- return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk size must be less than than %d" , chunkSizeLimit )
613+ if uint64 (len (msg .ChunkData )) >= ChunkSizeLimit {
614+ return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk size must be less than than %d" , ChunkSizeLimit )
615615 }
616- if msg .ChunkIndex >= chunkIndexLimit {
617- return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk index must be less than %d" , chunkIndexLimit )
616+ if msg .ChunkIndex >= ChunkIndexLimit {
617+ return sdkioerrors .Wrapf (sdkerrors .ErrUnknownRequest , "Chunk index must be less than %d" , ChunkIndexLimit )
618618 }
619619 return nil
620620}
0 commit comments