diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index c169c043df..9524bd8c03 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -168,9 +168,8 @@ func (k Keeper) create(ctx context.Context, creator sdk.AccAddress, wasmCode []b } } - sdkCtx.GasMeter().ConsumeGas(k.gasRegister.CompileCosts(len(wasmCode)), "Compiling wasm bytecode") - gas := k.runtimeGasForContract(sdkCtx) - checksum, gasUsed, err := k.wasmVM.StoreCode(wasmCode, gas) + gasLeft := k.runtimeGasForContract(sdkCtx) + checksum, gasUsed, err := k.wasmVM.StoreCode(wasmCode, gasLeft) k.consumeRuntimeGas(sdkCtx, gasUsed) if err != nil { return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error()) diff --git a/x/wasm/keeper/wasmtesting/gas_register.go b/x/wasm/keeper/wasmtesting/gas_register.go index 77c176e4ea..a16de3b32d 100644 --- a/x/wasm/keeper/wasmtesting/gas_register.go +++ b/x/wasm/keeper/wasmtesting/gas_register.go @@ -8,7 +8,6 @@ import ( // MockGasRegister mock that implements keeper.GasRegister type MockGasRegister struct { - CompileCostFn func(byteLength int) storetypes.Gas SetupContractCostFn func(discount bool, msgLen int) storetypes.Gas ReplyCostFn func(discount bool, reply wasmvmtypes.Reply) storetypes.Gas EventCostsFn func(evts []wasmvmtypes.EventAttribute) storetypes.Gas @@ -17,13 +16,6 @@ type MockGasRegister struct { UncompressCostsFn func(byteLength int) storetypes.Gas } -func (m MockGasRegister) CompileCosts(byteLength int) storetypes.Gas { - if m.CompileCostFn == nil { - panic("not expected to be called") - } - return m.CompileCostFn(byteLength) -} - func (m MockGasRegister) UncompressCosts(byteLength int) storetypes.Gas { if m.UncompressCostsFn == nil { panic("not expected to be called") diff --git a/x/wasm/keeper/wasmtesting/mock_engine.go b/x/wasm/keeper/wasmtesting/mock_engine.go index 1b3465bfae..9ef1c583a2 100644 --- a/x/wasm/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/keeper/wasmtesting/mock_engine.go @@ -348,8 +348,8 @@ func NoOpInstantiateFn(wasmvm.Checksum, wasmvmtypes.Env, wasmvmtypes.MessageInfo return &wasmvmtypes.ContractResult{Ok: &wasmvmtypes.Response{}}, 0, nil } -func NoOpStoreCodeFn(_ wasmvm.WasmCode) (wasmvm.Checksum, error) { - return rand.Bytes(32), nil +func NoOpStoreCodeFn(wasm wasmvm.WasmCode, gasLimit uint64) (wasmvm.Checksum, uint64, error) { + return rand.Bytes(32), uint64(MockStoreCodeCostPerByte * len(wasm)), nil } func HasIBCAnalyzeFn(wasmvm.Checksum) (*wasmvmtypes.AnalysisReport, error) { diff --git a/x/wasm/types/gas_register.go b/x/wasm/types/gas_register.go index 15e9058b1e..c7617b6557 100644 --- a/x/wasm/types/gas_register.go +++ b/x/wasm/types/gas_register.go @@ -74,8 +74,6 @@ func DefaultPerByteUncompressCost() wasmvmtypes.UFraction { // GasRegister abstract source for gas costs type GasRegister interface { - // CompileCosts costs to persist and "compile" a new wasm contract - CompileCosts(byteLength int) storetypes.Gas // UncompressCosts costs to unpack a new wasm contract UncompressCosts(byteLength int) storetypes.Gas // SetupContractCost are charged when interacting with a Wasm contract, i.e. every time @@ -165,14 +163,6 @@ func NewWasmGasRegister(c WasmGasRegisterConfig) WasmGasRegister { } } -// CompileCosts costs to persist and "compile" a new wasm contract -func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas { - if byteLength < 0 { - panic(errorsmod.Wrap(ErrInvalid, "negative length")) - } - return g.c.CompileCost * uint64(byteLength) -} - // UncompressCosts costs to unpack a new wasm contract func (g WasmGasRegister) UncompressCosts(byteLength int) storetypes.Gas { if byteLength < 0 { diff --git a/x/wasm/types/gas_register_test.go b/x/wasm/types/gas_register_test.go index d530fa02ec..45e9719cbf 100644 --- a/x/wasm/types/gas_register_test.go +++ b/x/wasm/types/gas_register_test.go @@ -11,43 +11,6 @@ import ( storetypes "cosmossdk.io/store/types" ) -func TestCompileCosts(t *testing.T) { - specs := map[string]struct { - srcLen int - srcConfig WasmGasRegisterConfig - exp storetypes.Gas - expPanic bool - }{ - "one byte": { - srcLen: 1, - srcConfig: DefaultGasRegisterConfig(), - exp: storetypes.Gas(3), // DefaultCompileCost - }, - "zero byte": { - srcLen: 0, - srcConfig: DefaultGasRegisterConfig(), - exp: storetypes.Gas(0), - }, - "negative len": { - srcLen: -1, - srcConfig: DefaultGasRegisterConfig(), - expPanic: true, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - if spec.expPanic { - assert.Panics(t, func() { - NewWasmGasRegister(spec.srcConfig).CompileCosts(spec.srcLen) - }) - return - } - gotGas := NewWasmGasRegister(spec.srcConfig).CompileCosts(spec.srcLen) - assert.Equal(t, spec.exp, gotGas) - }) - } -} - func TestSetupContractCost(t *testing.T) { specs := map[string]struct { srcLen int