From d5d9860facb28f129823ac07fe82c1f69320c09b Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 30 Apr 2025 16:50:13 +0200 Subject: [PATCH 1/3] Update wasmvm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1d252dfd6a..d80fdd2944 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd go 1.23.6 require ( - github.com/CosmWasm/wasmvm/v2 v2.2.1 + github.com/CosmWasm/wasmvm/v2 v2.2.4 github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/cosmos-sdk v0.50.12 github.com/cosmos/gogogateway v1.2.0 // indirect diff --git a/go.sum b/go.sum index d7303cf7ac..6e88f9a5b0 100644 --- a/go.sum +++ b/go.sum @@ -227,8 +227,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/CosmWasm/wasmvm/v2 v2.2.1 h1:cmOnM+TDfUl2VRugeo1eJBw4U/Lw0WLviuQHKSo9DVQ= -github.com/CosmWasm/wasmvm/v2 v2.2.1/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg= +github.com/CosmWasm/wasmvm/v2 v2.2.4 h1:V3UwXJMA8TNOuQETppDQkaXAevF7gOWLYpKvrThPv7o= +github.com/CosmWasm/wasmvm/v2 v2.2.4/go.mod h1:Aj/rB2KMRM8nAdbWxkO23rnQYb5KsoPuH9ZizSi0sVg= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q= github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= From 8404057183b0e9b9d30f8dfdaabcb5176ab66993 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 30 Apr 2025 15:20:35 +0200 Subject: [PATCH 2/3] Fix tests --- x/wasm/keeper/keeper_test.go | 4 ++-- x/wasm/keeper/recurse_test.go | 30 +++++++++++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index a16be5de9b..d0f9edd357 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -423,7 +423,7 @@ func TestInstantiate(t *testing.T) { gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { - require.Equal(t, uint64(0x1bca5), gasAfter-gasBefore) + require.Equal(t, uint64(0x1bcb0), gasAfter-gasBefore) } // ensure it is stored properly @@ -960,7 +960,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(0x1acdb), gasAfter-gasBefore) + require.Equal(t, uint64(0x1ace0), gasAfter-gasBefore) } // ensure bob now exists and got both payments released bobAcct = accKeeper.GetAccount(ctx, bob) diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index 58f88a4666..dcb4735e2e 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -56,14 +56,14 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, ctx sdk.Context func TestGasCostOnQuery(t *testing.T) { const ( - GasNoWork uint64 = 63_987 - GasNoWorkDiscounted uint64 = 5_968 - // Note: about 100 SDK gas (10k CosmWasm gas) for each round of sha256 - GasWork50 uint64 = 64_234 // this is a little shy of 50k gas - to keep an eye on the limit - GasWork50Discounted uint64 = 6_207 - - GasReturnUnhashed uint64 = 89 - GasReturnHashed uint64 = 86 + GasNoWork uint64 = 63_988 + GasWork50 uint64 = 64_236 + // should be discounted exactly by the difference between normal instance cost and discounted instance cost + GasNoWorkDiscounted uint64 = GasNoWork - (types.DefaultInstanceCost - types.DefaultInstanceCostDiscount) + GasWork50Discounted uint64 = GasWork50 - (types.DefaultInstanceCost - types.DefaultInstanceCostDiscount) + + GasReturnUnhashed uint64 = 72 + GasReturnHashed uint64 = 60 ) cases := map[string]struct { @@ -214,12 +214,16 @@ func TestLimitRecursiveQueryGas(t *testing.T) { const ( // Note: about 100 SDK gas (10k CosmWasm gas) for each round of sha256 - GasWork2k uint64 = 76_817 // = SetupContractCost + x // we have 6x gas used in cpu than in the instance + GasWork2k uint64 = 76818 // = SetupContractCost + x // we have 6x gas used in cpu than in the instance - GasWork2kDiscounted uint64 = 18_264 + 432 + // should be discounted exactly by the difference between normal instance cost and discounted instance cost + GasWork2kDiscounted uint64 = GasWork2k - (types.DefaultInstanceCost - types.DefaultInstanceCostDiscount) // This is overhead for calling into a sub-contract - GasReturnHashed uint64 = 48 + 132 + GasReturnHashed uint64 = 62 + + // lots of additional gas for long error message + GasError uint64 = 3396 ) cases := map[string]struct { @@ -268,8 +272,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) { }, expectQueriesFromContract: 10, expectOutOfGas: false, - expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd - expectedGas: GasWork2k + GasReturnHashed + 9*(GasWork2kDiscounted+GasReturnHashed) + 3279, // lots of additional gas for long error message + expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd + expectedGas: GasWork2k + GasReturnHashed + 9*(GasWork2kDiscounted+GasReturnHashed) + GasError, }, } From c51b4e453ce9dcfdeb0b2beedf9edf19fce27368 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 30 Apr 2025 17:23:24 +0200 Subject: [PATCH 3/3] Update dockerfile --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index af7d3a4821..e8de647fed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,10 +15,10 @@ RUN apk add git WORKDIR /code COPY . /code/ # See https://github.com/CosmWasm/wasmvm/releases -ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.2.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a -ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.2.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a -RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep ba6cb5db6b14a265c8556326c045880908db9b1d2ffb5d4aa9f09ac09b24cecc -RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep b3bd755efac0ff39c01b59b8110f961c48aa3eb93588071d7a628270cc1f2326 +ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.2.4/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a +ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.2.4/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 27fb13821dbc519119f4f98c30a42cb32429b111b0fdc883686c34a41777488f +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 70c989684d2b48ca17bbd55bb694bbb136d75c393c067ef3bdbca31d2b23b578 # force it to use static lib (from above) not standard libgo_cosmwasm.so file RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build