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:
pinosu
2022-11-17 14:19:57 +01:00
committed by GitHub
parent 48ef13db42
commit ab4ffa51e6
7 changed files with 14 additions and 10 deletions

View File

@@ -209,6 +209,7 @@ file of your custom chain.
* `wasmtypes.MaxLabelSize = 64` to set the maximum label size on instantiation (default 128)
* `wasmtypes.MaxWasmSize=777000` to set the max size of compiled wasm to be accepted (default 819200)
* `wasmtypes.MaxProposalWasmSize=888000` to set the max size of gov proposal compiled wasm to be accepted (default 3145728)
## Genesis Configuration
We strongly suggest **to limit the max block gas in the genesis** and not use the default value (`-1` for infinite).

View File

@@ -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

View File

@@ -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,
},

View File

@@ -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())
}

View File

@@ -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,
},

View File

@@ -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())
}

View File

@@ -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
}