From 0cf7c018ffccaedde87901acd9eb23d2573e192a Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 31 Jan 2025 15:48:25 +0100 Subject: [PATCH 1/3] Make ContractAddrLen variable --- x/wasm/types/types.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/wasm/types/types.go b/x/wasm/types/types.go index e0f74e72b4..dcd8a9d549 100644 --- a/x/wasm/types/types.go +++ b/x/wasm/types/types.go @@ -20,12 +20,13 @@ const ( defaultSmartQueryGasLimit uint64 = 3_000_000 defaultContractDebugMode = false - // ContractAddrLen defines a valid address length for contracts - ContractAddrLen = 32 // SDKAddrLen defines a valid address length that was used in sdk address generation SDKAddrLen = 20 ) +// ContractAddrLen defines a valid address length for contracts +var ContractAddrLen = 32 + func (m Model) ValidateBasic() error { if len(m.Key) == 0 { return errorsmod.Wrap(ErrEmpty, "key") From c988a0b682589bcd66c9eebc0d7aebe6f3a356dd Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 31 Jan 2025 17:15:20 +0100 Subject: [PATCH 2/3] Add test for shorter addresses --- x/wasm/keeper/addresses_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/x/wasm/keeper/addresses_test.go b/x/wasm/keeper/addresses_test.go index c548f46787..f626cf3e5b 100644 --- a/x/wasm/keeper/addresses_test.go +++ b/x/wasm/keeper/addresses_test.go @@ -1,11 +1,14 @@ package keeper import ( + "encoding/hex" "encoding/json" "fmt" "testing" + "github.com/CosmWasm/wasmd/x/wasm/types" tmbytes "github.com/cometbft/cometbft/libs/bytes" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -69,6 +72,24 @@ func TestBuildContractAddressClassic(t *testing.T) { } } +func TestBuildContractAddressPredictableShort(t *testing.T) { + types.ContractAddrLen = 20 + // reset to default value after test completion + defer func() { types.ContractAddrLen = 32 }() + + checksum, err := hex.DecodeString("13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5") + require.NoError(t, err) + creator, err := sdk.AccAddressFromHexUnsafe("9999999999aaaaaaaaaabbbbbbbbbbcccccccccc") + require.NoError(t, err) + salt, err := hex.DecodeString("61") + require.NoError(t, err) + expAddr, err := sdk.AccAddressFromHexUnsafe("5e865d3e45ad3e961f77fd77d46543417ced44d9") + require.NoError(t, err) + + addr := BuildContractAddressPredictable(checksum, creator, salt, []byte{}) + assert.Equal(t, expAddr, addr) +} + func TestBuildContractAddressPredictable(t *testing.T) { // set cleanup function prepareCleanup(t) From b8568402883f2b77d2966ab84cb64e5b1547180e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 16:18:18 +0000 Subject: [PATCH 3/3] [autofix.ci] apply automated fixes --- x/wasm/keeper/addresses_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/wasm/keeper/addresses_test.go b/x/wasm/keeper/addresses_test.go index f626cf3e5b..bb2a9429fe 100644 --- a/x/wasm/keeper/addresses_test.go +++ b/x/wasm/keeper/addresses_test.go @@ -6,12 +6,13 @@ import ( "fmt" "testing" - "github.com/CosmWasm/wasmd/x/wasm/types" tmbytes "github.com/cometbft/cometbft/libs/bytes" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/CosmWasm/wasmd/x/wasm/types" ) func prepareCleanup(t *testing.T) {