Skip to content

Commit

Permalink
Fix address validation
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Feb 8, 2024
1 parent 50a3f30 commit 52b583a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions x/wasm/keeper/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"errors"

wasmvm "github.com/CosmWasm/wasmvm/v2"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"

Expand All @@ -15,7 +17,7 @@ const (
// DefaultGasCostCanonicalAddress is how much SDK gas we charge to convert to a canonical address format
DefaultGasCostCanonicalAddress = 4
// DefaultGasCostValidateAddress is how much SDK gas we charge to validate an address
DefaultGasCostValidateAddress = 4
DefaultGasCostValidateAddress = 9

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

func validateAddress(human string) (uint64, error) {
_, err := sdk.AccAddressFromBech32(human)
canonicalized, err := sdk.AccAddressFromBech32(human)
if err != nil {
return costValidate, err
}
// AccAddressFromBech32 already calls VerifyAddressFormat, so we can just humanize and compare
if sdk.AccAddress(canonicalized).String() != human {
return costValidate, errors.New("address not normalized")
}
return costValidate, err
}

Expand Down

0 comments on commit 52b583a

Please sign in to comment.