diff --git a/README.md b/README.md index c8fc9549f5..fe0f6e3e2d 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/x/wasm/types/genesis.go b/x/wasm/types/genesis.go index a82893bd90..4d6775d02e 100644 --- a/x/wasm/types/genesis.go +++ b/x/wasm/types/genesis.go @@ -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 diff --git a/x/wasm/types/genesis_test.go b/x/wasm/types/genesis_test.go index 5ddcb20885..f45d3f07f0 100644 --- a/x/wasm/types/genesis_test.go +++ b/x/wasm/types/genesis_test.go @@ -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, }, diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go index 0b8f943264..e56300a911 100644 --- a/x/wasm/types/proposal.go +++ b/x/wasm/types/proposal.go @@ -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()) } diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go index 6657d11412..245184752b 100644 --- a/x/wasm/types/proposal_test.go +++ b/x/wasm/types/proposal_test.go @@ -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, }, diff --git a/x/wasm/types/tx.go b/x/wasm/types/tx.go index dd6f6284cd..6742224df7 100644 --- a/x/wasm/types/tx.go +++ b/x/wasm/types/tx.go @@ -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()) } diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index 908c525524..cf6b1511b2 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -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 }