Skip to content

Commit

Permalink
Upgrade wasmvm-v1.0.0-soon2 (#628)
Browse files Browse the repository at this point in the history
* Upgrade wasmvm-v1.0.0-soon2

* Improve comment on DefaultGasMultiplier

Co-authored-by: Simon Warta <simon@warta.it>
  • Loading branch information
alpe and webmaster128 authored Oct 7, 2021
1 parent 2b7d28a commit 62e976a
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
24 changes: 18 additions & 6 deletions x/wasm/keeper/gas_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
// 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 the wasmer engine should have this multiplied
DefaultGasMultiplier uint64 = 100
// 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
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions x/wasm/keeper/recurse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Binary file modified x/wasm/keeper/testdata/burner.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/hackatom.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/hackatom.wasm.gzip
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/ibc_reflect.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/ibc_reflect_send.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/reflect.wasm
Binary file not shown.
Binary file modified x/wasm/keeper/testdata/staking.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion x/wasm/keeper/testdata/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.0-soon
v1.0.0-soon2

0 comments on commit 62e976a

Please sign in to comment.