Enable larger wasm bytecode upload for gov proposals (#1095)
* Enable larger wasm bytecode upload for gov proposals * Set max proposal wasm code size to 3MB
This commit is contained in:
@@ -47,7 +47,7 @@ func (c Code) ValidateBasic() error {
|
||||
if err := c.CodeInfo.ValidateBasic(); err != nil {
|
||||
return sdkerrors.Wrap(err, "code info")
|
||||
}
|
||||
if err := validateWasmCode(c.CodeBytes); err != nil {
|
||||
if err := validateWasmCode(c.CodeBytes, MaxProposalWasmSize); err != nil {
|
||||
return sdkerrors.Wrap(err, "code bytes")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -117,7 +117,7 @@ func TestCodeValidateBasic(t *testing.T) {
|
||||
},
|
||||
"codeBytes greater limit": {
|
||||
srcMutator: func(c *Code) {
|
||||
c.CodeBytes = bytes.Repeat([]byte{0x1}, MaxWasmSize+1)
|
||||
c.CodeBytes = bytes.Repeat([]byte{0x1}, MaxProposalWasmSize+1)
|
||||
},
|
||||
expError: true,
|
||||
},
|
||||
|
||||
@@ -119,7 +119,7 @@ func (p StoreCodeProposal) ValidateBasic() error {
|
||||
return sdkerrors.Wrap(err, "run as")
|
||||
}
|
||||
|
||||
if err := validateWasmCode(p.WASMByteCode); err != nil {
|
||||
if err := validateWasmCode(p.WASMByteCode, MaxProposalWasmSize); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error())
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ func (p StoreAndInstantiateContractProposal) ValidateBasic() error {
|
||||
return sdkerrors.Wrap(err, "run as")
|
||||
}
|
||||
|
||||
if err := validateWasmCode(p.WASMByteCode); err != nil {
|
||||
if err := validateWasmCode(p.WASMByteCode, MaxProposalWasmSize); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ func TestValidateStoreCodeProposal(t *testing.T) {
|
||||
},
|
||||
"wasm code invalid": {
|
||||
src: StoreCodeProposalFixture(func(p *StoreCodeProposal) {
|
||||
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxWasmSize+1)
|
||||
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxProposalWasmSize+1)
|
||||
}),
|
||||
expErr: true,
|
||||
},
|
||||
@@ -299,7 +299,7 @@ func TestValidateStoreAndInstantiateContractProposal(t *testing.T) {
|
||||
},
|
||||
"wasm code invalid": {
|
||||
src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) {
|
||||
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxWasmSize+1)
|
||||
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxProposalWasmSize+1)
|
||||
}),
|
||||
expErr: true,
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ func (msg MsgStoreCode) ValidateBasic() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateWasmCode(msg.WASMByteCode); err != nil {
|
||||
if err := validateWasmCode(msg.WASMByteCode, MaxWasmSize); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,17 @@ var (
|
||||
|
||||
// MaxWasmSize is the largest a compiled contract code can be when storing code on chain
|
||||
MaxWasmSize = 800 * 1024 // extension point for chains to customize via compile flag.
|
||||
|
||||
// MaxProposalWasmSize is the largest a gov proposal compiled contract code can be when storing code on chain
|
||||
MaxProposalWasmSize = 3 * 1024 * 1024 // extension point for chains to customize via compile flag.
|
||||
)
|
||||
|
||||
func validateWasmCode(s []byte) error {
|
||||
func validateWasmCode(s []byte, maxSize int) error {
|
||||
if len(s) == 0 {
|
||||
return sdkerrors.Wrap(ErrEmpty, "is required")
|
||||
}
|
||||
if len(s) > MaxWasmSize {
|
||||
return sdkerrors.Wrapf(ErrLimit, "cannot be longer than %d bytes", MaxWasmSize)
|
||||
if len(s) > maxSize {
|
||||
return sdkerrors.Wrapf(ErrLimit, "cannot be longer than %d bytes", maxSize)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user