Skip to content

Commit 52b583a

Browse files
committed
Fix address validation
1 parent 50a3f30 commit 52b583a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

x/wasm/keeper/api.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"errors"
5+
46
wasmvm "github.com/CosmWasm/wasmvm/v2"
57
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
68

@@ -15,7 +17,7 @@ const (
1517
// DefaultGasCostCanonicalAddress is how much SDK gas we charge to convert to a canonical address format
1618
DefaultGasCostCanonicalAddress = 4
1719
// DefaultGasCostValidateAddress is how much SDK gas we charge to validate an address
18-
DefaultGasCostValidateAddress = 4
20+
DefaultGasCostValidateAddress = 9
1921

2022
// DefaultDeserializationCostPerByte The formula should be `len(data) * deserializationCostPerByte`
2123
DefaultDeserializationCostPerByte = 1
@@ -44,7 +46,14 @@ func canonicalizeAddress(human string) ([]byte, uint64, error) {
4446
}
4547

4648
func validateAddress(human string) (uint64, error) {
47-
_, err := sdk.AccAddressFromBech32(human)
49+
canonicalized, err := sdk.AccAddressFromBech32(human)
50+
if err != nil {
51+
return costValidate, err
52+
}
53+
// AccAddressFromBech32 already calls VerifyAddressFormat, so we can just humanize and compare
54+
if sdk.AccAddress(canonicalized).String() != human {
55+
return costValidate, errors.New("address not normalized")
56+
}
4857
return costValidate, err
4958
}
5059

0 commit comments

Comments
 (0)