Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate MaxWasmSize constraints into a single var #809

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased](https://github.com/CosmWasm/wasmd/tree/HEAD)

**Merged pull requests:**

- Consolidate MaxWasmSize constraints into a single var [\#809](https://github.com/CosmWasm/wasmd/pull/809)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.26.0...HEAD)

## [v0.26.0](https://github.com/CosmWasm/wasmd/tree/v0.26.0) (2022-04-21)
Expand Down
1 change: 0 additions & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (
TStoreKey = types.TStoreKey
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
MaxWasmSize = types.MaxWasmSize
MaxLabelSize = types.MaxLabelSize
WasmModuleEventType = types.WasmModuleEventType
AttributeKeyContractAddr = types.AttributeKeyContractAddr
Expand Down
10 changes: 2 additions & 8 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ func (k Keeper) getInstantiateAccessConfig(ctx sdk.Context) types.AccessType {
return a
}

func (k Keeper) GetMaxWasmCodeSize(ctx sdk.Context) uint64 {
var a uint64
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxWasmCodeSize, &a)
return a
}

// GetParams returns the total set of wasm parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
var params types.Params
Expand All @@ -164,7 +158,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte,
if !authZ.CanCreateCode(k.getUploadAccessConfig(ctx), creator) {
return 0, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not create code")
}
wasmCode, err = uncompress(wasmCode, k.GetMaxWasmCodeSize(ctx))
wasmCode, err = uncompress(wasmCode, uint64(types.MaxWasmSize))
if err != nil {
return 0, sdkerrors.Wrap(types.ErrCreateFailed, err.Error())
}
Expand Down Expand Up @@ -206,7 +200,7 @@ func (k Keeper) storeCodeInfo(ctx sdk.Context, codeID uint64, codeInfo types.Cod
}

func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeInfo, wasmCode []byte) error {
wasmCode, err := uncompress(wasmCode, k.GetMaxWasmCodeSize(ctx))
wasmCode, err := uncompress(wasmCode, uint64(types.MaxWasmSize))
if err != nil {
return sdkerrors.Wrap(types.ErrCreateFailed, err.Error())
}
Expand Down
5 changes: 0 additions & 5 deletions x/wasm/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ func ParamChanges(r *rand.Rand, cdc codec.Codec) []simtypes.ParamChange {
return fmt.Sprintf("%q", params.CodeUploadAccess.Permission.String())
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.ParamStoreKeyMaxWasmCodeSize),
func(r *rand.Rand) string {
return fmt.Sprintf(`"%d"`, params.MaxWasmCodeSize)
},
),
}
}

Expand Down
8 changes: 0 additions & 8 deletions x/wasm/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ import (
"gopkg.in/yaml.v2"
)

const (
// DefaultMaxWasmCodeSize limit max bytes read to prevent gzip bombs
DefaultMaxWasmCodeSize = 600 * 1024 * 2
)

var ParamStoreKeyUploadAccess = []byte("uploadAccess")
var ParamStoreKeyInstantiateAccess = []byte("instantiateAccess")
var ParamStoreKeyMaxWasmCodeSize = []byte("maxWasmCodeSize")

var AllAccessTypes = []AccessType{
AccessTypeNobody,
Expand Down Expand Up @@ -96,7 +90,6 @@ func DefaultParams() Params {
return Params{
CodeUploadAccess: AllowEverybody,
InstantiateDefaultPermission: AccessTypeEverybody,
MaxWasmCodeSize: DefaultMaxWasmCodeSize,
}
}

Expand All @@ -113,7 +106,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyUploadAccess, &p.CodeUploadAccess, validateAccessConfig),
paramtypes.NewParamSetPair(ParamStoreKeyInstantiateAccess, &p.InstantiateDefaultPermission, validateAccessType),
paramtypes.NewParamSetPair(ParamStoreKeyMaxWasmCodeSize, &p.MaxWasmCodeSize, validateMaxWasmCodeSize),
}
}

Expand Down
5 changes: 3 additions & 2 deletions x/wasm/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
)

const (
MaxWasmSize = 500 * 1024
bigs marked this conversation as resolved.
Show resolved Hide resolved

// MaxLabelSize is the longest label that can be used when Instantiating a contract
MaxLabelSize = 128
)

// MaxWasmSize is the largest a compiled contract code can be when storing code on chain
var MaxWasmSize int = 800 * 1024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why you increased the value to 800kb? Do you have a contract example with this size? We had some internal discussion for tgrade yesterday where I looked at some of our contracts and max was 555kb.

Suggested change
var MaxWasmSize int = 800 * 1024
var MaxWasmSize int = 777 * 1024

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, Ethan suggested 800kb. We should have coordinated better. 🤷 It would help with tgrade if you can make it 777kb

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

777kb is an odd number.
But tgrade can easily override this default, so maybe best to use 800 and verify we can change it in the imported one


func validateWasmCode(s []byte) error {
if len(s) == 0 {
return sdkerrors.Wrap(ErrEmpty, "is required")
Expand Down