Skip to content

Commit

Permalink
Use addresses for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Jul 4, 2024
1 parent c2113cf commit 22b479c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions x/wasm/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package wasm

import (
"math"
"strings"

wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
Expand Down Expand Up @@ -440,15 +439,19 @@ func (i IBCHandler) IBCReceivePacketCallback(
}

func validateSender(contractAddr, senderAddr string) (sdk.AccAddress, error) {
// We only allow the contract that sent the message to receive source chain callbacks for it.
if !strings.EqualFold(contractAddr, senderAddr) {
return nil, errorsmod.Wrapf(types.ErrExecuteFailed, "contract address %s does not match packet sender %s", contractAddr, senderAddr)
}

contractAddress, err := sdk.AccAddressFromBech32(contractAddr)
if err != nil {
return nil, errorsmod.Wrapf(err, "contract address")
}
senderAddress, err := sdk.AccAddressFromBech32(senderAddr)
if err != nil {
return nil, errorsmod.Wrapf(err, "packet sender address")
}

// We only allow the contract that sent the message to receive source chain callbacks for it.
if !contractAddress.Equals(senderAddress) {
return nil, errorsmod.Wrapf(types.ErrExecuteFailed, "contract address %s does not match packet sender %s", contractAddr, senderAddress)
}

return contractAddress, nil
}
Expand Down

0 comments on commit 22b479c

Please sign in to comment.