Skip to content

Commit

Permalink
fix(evm): check bech32 addr length in precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Feb 12, 2025
1 parent 65d212e commit 41a2456
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion precompiles/bech32/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

exocmn "github.com/ExocoreNetwork/exocore/precompiles/common"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -83,11 +84,16 @@ func (p Precompile) Bech32ToHex(
return nil, err
}

// validate the address bytes
// validate the address bytes: call the verifier if set and check length is range-bound
if err := sdk.VerifyAddressFormat(addressBz); err != nil {
return nil, err
}

// check the bytes length, since BytesToAddress silently crops
if len(addressBz) != common.AddressLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(addressBz), common.AddressLength)
}

// pack the address bytes
return method.Outputs.Pack(common.BytesToAddress(addressBz))
}

0 comments on commit 41a2456

Please sign in to comment.