diff --git a/Dockerfile b/Dockerfile index 9249e452..7dc6c883 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,8 @@ WORKDIR /code COPY . /code/ # See https://github.com/CosmWasm/wasmvm/releases -ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-soon/libwasmvm_muslc.a /lib/libwasmvm_muslc.a -RUN sha256sum /lib/libwasmvm_muslc.a | grep 6e82693aa64e4373ae303e82988c2f3a7216e83ee0021e9be80acbf18676ca9b +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-soon2/libwasmvm_muslc.a /lib/libwasmvm_muslc.a +RUN sha256sum /lib/libwasmvm_muslc.a | grep ae3132ff947428499a94fc7005999440bd0b04c06322113bbb64bf33d726ed6f # force it to use static lib (from above) not standard libgo_cosmwasm.so file RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make build diff --git a/app/app.go b/app/app.go index 098a72e9..11829488 100644 --- a/app/app.go +++ b/app/app.go @@ -488,7 +488,7 @@ func NewWasmApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b app.SetAnteHandler( NewAnteHandler( app.accountKeeper, app.bankKeeper, ante.DefaultSigVerificationGasConsumer, - encodingConfig.TxConfig.SignModeHandler(), keys[wasm.StoreKey],app.ibcKeeper.ChannelKeeper, + encodingConfig.TxConfig.SignModeHandler(), keys[wasm.StoreKey], app.ibcKeeper.ChannelKeeper, ), ) app.SetEndBlocker(app.EndBlocker) diff --git a/go.mod b/go.mod index ec154b52..e15acbd8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd go 1.16 require ( - github.com/CosmWasm/wasmvm v1.0.0-soon + github.com/CosmWasm/wasmvm v1.0.0-soon2 github.com/cosmos/cosmos-sdk v0.42.10 github.com/cosmos/iavl v0.17.1 github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b diff --git a/go.sum b/go.sum index a73c79cd..808b6262 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= -github.com/CosmWasm/wasmvm v1.0.0-soon h1:AUN0RDNgJ85hAv8LClUuhmm9OZOWYw3JhINiLa9NEeQ= -github.com/CosmWasm/wasmvm v1.0.0-soon/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A= +github.com/CosmWasm/wasmvm v1.0.0-soon2 h1:lwaV55tM+LMWGM0pu18iESEcAQ/PABNsnVQhCng6xJ8= +github.com/CosmWasm/wasmvm v1.0.0-soon2/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= diff --git a/x/wasm/keeper/gas_register.go b/x/wasm/keeper/gas_register.go index 9d0ae790..5a09f8c3 100644 --- a/x/wasm/keeper/gas_register.go +++ b/x/wasm/keeper/gas_register.go @@ -9,13 +9,25 @@ import ( ) const ( - // DefaultGasMultiplier is how many cosmwasm gas points = 1 sdk gas point - // SDK reference costs can be found here: https://github.com/cosmos/cosmos-sdk/blob/02c6c9fafd58da88550ab4d7d494724a477c8a68/store/types/gas.go#L153-L164 - // A write at ~3000 gas and ~200us = 10 gas per us (microsecond) cpu/io - // Rough timing have 88k gas at 90us, which is equal to 1k sdk gas... (one read) + // DefaultGasMultiplier is how many CosmWasm gas points = 1 Cosmos SDK gas point. // - // Please note that all gas prices returned to the wasmer engine should have this multiplied - DefaultGasMultiplier uint64 = 100 + // CosmWasm gas strategy is documented in https://github.com/CosmWasm/cosmwasm/blob/v1.0.0-soon2/docs/GAS.md. + // Cosmos SDK reference costs can be found here: https://github.com/cosmos/cosmos-sdk/blob/v0.42.10/store/types/gas.go#L198-L209. + // + // The original multiplier of 100 up to CosmWasm 0.16 was based on + // "A write at ~3000 gas and ~200us = 10 gas per us (microsecond) cpu/io + // Rough timing have 88k gas at 90us, which is equal to 1k sdk gas... (one read)" + // as well as manual Wasmer benchmarks from 2019. This was then multiplied by 150_000 + // in the 0.16 -> 1.0 upgrade (https://github.com/CosmWasm/cosmwasm/pull/1120). + // + // The multiplier deserves more reproducible benchmarking and a strategy that allows easy adjustments. + // This is tracked in https://github.com/CosmWasm/wasmd/issues/566 and https://github.com/CosmWasm/wasmd/issues/631. + // Gas adjustments are consensus breaking but may happen in any release marked as consensus breaking. + // Do not make assumptions on how much gas an operation will consume in places that are hard to adjust, + // such as hardcoding them in contracts. + // + // Please note that all gas prices returned to wasmvm should have this multiplied. + DefaultGasMultiplier uint64 = 15_000_000 // DefaultInstanceCost is how much SDK gas we charge each time we load a WASM instance. // Creating a new instance is costly, and this helps put a recursion limit to contracts calling contracts. DefaultInstanceCost uint64 = 40_000 diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 0835a1bc..cf370bd3 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -541,7 +541,7 @@ func TestExecute(t *testing.T) { // make sure gas is properly deducted from ctx gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x12b01), gasAfter-gasBefore) + require.Equal(t, uint64(0x12b02), gasAfter-gasBefore) } // ensure bob now exists and got both payments released bobAcct = accKeeper.GetAccount(ctx, bob) @@ -1609,7 +1609,7 @@ func TestReply(t *testing.T) { Bank: &wasmvmtypes.BankQuery{ Balance: &wasmvmtypes.BalanceQuery{Address: env.Contract.Address, Denom: "stake"}, }, - }, 1_000_000) + }, 1000*DefaultGasMultiplier) require.NoError(t, err) var gotBankRsp wasmvmtypes.BalanceResponse require.NoError(t, json.Unmarshal(bzRsp, &gotBankRsp)) @@ -1673,7 +1673,7 @@ func TestQueryIsolation(t *testing.T) { mock.ReplyFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, reply wasmvmtypes.Reply, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { _, err := querier.Query(wasmvmtypes.QueryRequest{ Custom: []byte(`{}`), - }, 1_000_000) + }, 10000*DefaultGasMultiplier) require.NoError(t, err) return &wasmvmtypes.Response{}, 0, nil } diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index 8a339b7c..8f9bccb2 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -52,11 +52,11 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, creator sdk.Acc func TestGasCostOnQuery(t *testing.T) { const ( - GasNoWork uint64 = 44_170 + GasNoWork uint64 = 44_171 // Note: about 100 SDK gas (10k wasmer gas) for each round of sha256 - GasWork50 uint64 = 48_854 // this is a little shy of 50k gas - to keep an eye on the limit + GasWork50 uint64 = 48_855 // this is a little shy of 50k gas - to keep an eye on the limit - GasReturnUnhashed uint64 = 253 + GasReturnUnhashed uint64 = 252 GasReturnHashed uint64 = 228 ) @@ -75,7 +75,7 @@ func TestGasCostOnQuery(t *testing.T) { msg: Recurse{ Work: 50, // 50 rounds of sha256 inside the contract }, - expectedGas: GasWork50 + 1, + expectedGas: GasWork50, }, "recursion 1, no work": { gasLimit: 400_000, @@ -218,7 +218,7 @@ func TestLimitRecursiveQueryGas(t *testing.T) { // Note: about 100 SDK gas (10k wasmer gas) for each round of sha256 GasWork2k uint64 = 233_979 // = NewContractInstanceCosts + x // we have 6x gas used in cpu than in the instance // This is overhead for calling into a sub-contract - GasReturnHashed uint64 = 231 + GasReturnHashed uint64 = 232 ) cases := map[string]struct { @@ -244,8 +244,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) { Work: 2000, }, expectQueriesFromContract: 5, - // FIXME: why +2 ... confused a bit by calculations, seems like rounding issues - expectedGas: GasWork2k + 5*(GasWork2k+GasReturnHashed) + 2, + // FIXME: why +3 ... confused a bit by calculations, seems like rounding issues + expectedGas: GasWork2k + 5*(GasWork2k+GasReturnHashed) + 3, }, // this is where we expect an error... // it has enough gas to run 4 times and die on the 5th (4th time dispatching to sub-contract) diff --git a/x/wasm/keeper/testdata/burner.wasm b/x/wasm/keeper/testdata/burner.wasm index e3987ee2..4d4aa567 100644 Binary files a/x/wasm/keeper/testdata/burner.wasm and b/x/wasm/keeper/testdata/burner.wasm differ diff --git a/x/wasm/keeper/testdata/hackatom.wasm b/x/wasm/keeper/testdata/hackatom.wasm index 9ac2d2ee..496652c6 100644 Binary files a/x/wasm/keeper/testdata/hackatom.wasm and b/x/wasm/keeper/testdata/hackatom.wasm differ diff --git a/x/wasm/keeper/testdata/hackatom.wasm.gzip b/x/wasm/keeper/testdata/hackatom.wasm.gzip index 73a976d6..b4b1dfc4 100644 Binary files a/x/wasm/keeper/testdata/hackatom.wasm.gzip and b/x/wasm/keeper/testdata/hackatom.wasm.gzip differ diff --git a/x/wasm/keeper/testdata/ibc_reflect.wasm b/x/wasm/keeper/testdata/ibc_reflect.wasm index a9c2fb3a..dfc8dd99 100644 Binary files a/x/wasm/keeper/testdata/ibc_reflect.wasm and b/x/wasm/keeper/testdata/ibc_reflect.wasm differ diff --git a/x/wasm/keeper/testdata/ibc_reflect_send.wasm b/x/wasm/keeper/testdata/ibc_reflect_send.wasm index 4920b53a..f4882525 100644 Binary files a/x/wasm/keeper/testdata/ibc_reflect_send.wasm and b/x/wasm/keeper/testdata/ibc_reflect_send.wasm differ diff --git a/x/wasm/keeper/testdata/reflect.wasm b/x/wasm/keeper/testdata/reflect.wasm index bb072ba6..1c86fce0 100644 Binary files a/x/wasm/keeper/testdata/reflect.wasm and b/x/wasm/keeper/testdata/reflect.wasm differ diff --git a/x/wasm/keeper/testdata/staking.wasm b/x/wasm/keeper/testdata/staking.wasm index 675fb565..104d5af8 100644 Binary files a/x/wasm/keeper/testdata/staking.wasm and b/x/wasm/keeper/testdata/staking.wasm differ diff --git a/x/wasm/keeper/testdata/version.txt b/x/wasm/keeper/testdata/version.txt index f659ddde..09ea963b 100644 --- a/x/wasm/keeper/testdata/version.txt +++ b/x/wasm/keeper/testdata/version.txt @@ -1 +1 @@ -v1.0.0-soon +v1.0.0-soon2