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:
@@ -209,6 +209,7 @@ file of your custom chain.
|
|||||||
|
|
||||||
* `wasmtypes.MaxLabelSize = 64` to set the maximum label size on instantiation (default 128)
|
* `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.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
|
## Genesis Configuration
|
||||||
We strongly suggest **to limit the max block gas in the genesis** and not use the default value (`-1` for infinite).
|
We strongly suggest **to limit the max block gas in the genesis** and not use the default value (`-1` for infinite).
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (c Code) ValidateBasic() error {
|
|||||||
if err := c.CodeInfo.ValidateBasic(); err != nil {
|
if err := c.CodeInfo.ValidateBasic(); err != nil {
|
||||||
return sdkerrors.Wrap(err, "code info")
|
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 sdkerrors.Wrap(err, "code bytes")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func TestCodeValidateBasic(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"codeBytes greater limit": {
|
"codeBytes greater limit": {
|
||||||
srcMutator: func(c *Code) {
|
srcMutator: func(c *Code) {
|
||||||
c.CodeBytes = bytes.Repeat([]byte{0x1}, MaxWasmSize+1)
|
c.CodeBytes = bytes.Repeat([]byte{0x1}, MaxProposalWasmSize+1)
|
||||||
},
|
},
|
||||||
expError: true,
|
expError: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func (p StoreCodeProposal) ValidateBasic() error {
|
|||||||
return sdkerrors.Wrap(err, "run as")
|
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())
|
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")
|
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())
|
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "code bytes %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ func TestValidateStoreCodeProposal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"wasm code invalid": {
|
"wasm code invalid": {
|
||||||
src: StoreCodeProposalFixture(func(p *StoreCodeProposal) {
|
src: StoreCodeProposalFixture(func(p *StoreCodeProposal) {
|
||||||
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxWasmSize+1)
|
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxProposalWasmSize+1)
|
||||||
}),
|
}),
|
||||||
expErr: true,
|
expErr: true,
|
||||||
},
|
},
|
||||||
@@ -299,7 +299,7 @@ func TestValidateStoreAndInstantiateContractProposal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"wasm code invalid": {
|
"wasm code invalid": {
|
||||||
src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) {
|
src: StoreAndInstantiateContractProposalFixture(func(p *StoreAndInstantiateContractProposal) {
|
||||||
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxWasmSize+1)
|
p.WASMByteCode = bytes.Repeat([]byte{0x0}, MaxProposalWasmSize+1)
|
||||||
}),
|
}),
|
||||||
expErr: true,
|
expErr: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func (msg MsgStoreCode) ValidateBasic() error {
|
|||||||
return err
|
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())
|
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 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.
|
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 {
|
if len(s) == 0 {
|
||||||
return sdkerrors.Wrap(ErrEmpty, "is required")
|
return sdkerrors.Wrap(ErrEmpty, "is required")
|
||||||
}
|
}
|
||||||
if len(s) > MaxWasmSize {
|
if len(s) > maxSize {
|
||||||
return sdkerrors.Wrapf(ErrLimit, "cannot be longer than %d bytes", MaxWasmSize)
|
return sdkerrors.Wrapf(ErrLimit, "cannot be longer than %d bytes", maxSize)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user