Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(axelarnet)!: add/trim 0x prefix when checking contract address min deposit #1974

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/axelarnet/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h Hooks) AfterProposalDeposit(ctx sdk.Context, proposalID uint64, _ sdk.Ac

switch c := proposal.GetContent().(type) {
case *types.CallContractsProposal:
minDepositsMap := h.k.GetParams(ctx).CallContractsProposalMinDeposits.ToMap()
minDepositsMap := h.k.GetParams(ctx).CallContractsProposalMinDeposits.ToMap(ctx, h.nexus)

for _, contractCall := range c.ContractCalls {
minDeposit := minDepositsMap.Get(contractCall.Chain, contractCall.ContractAddress)
Expand Down
4 changes: 4 additions & 0 deletions x/axelarnet/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func TestAfterProposalDeposit(t *testing.T) {
keeper := keeper.NewKeeper(encCfg.Codec, sdk.NewKVStoreKey("nexus"), subspace, &mock.ChannelKeeperMock{}, &mock.FeegrantKeeperMock{})
keeper.SetParams(ctx, types.DefaultParams())

nexusK.GetChainFunc = func(ctx sdk.Context, chain nexus.ChainName) (nexus.Chain, bool) {
return evm.Ethereum, true
}

Given("a proposal is created", func() {
govK.GetProposalFunc = func(ctx sdk.Context, proposalID uint64) (govtypes.Proposal, bool) {
return proposal, proposalID == proposal.ProposalId
Expand Down
18 changes: 17 additions & 1 deletion x/axelarnet/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/axelarnetwork/axelar-core/utils"
"github.com/axelarnetwork/axelar-core/x/axelarnet/exported"
evmtypes "github.com/axelarnetwork/axelar-core/x/evm/types"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
)

Expand All @@ -30,6 +31,8 @@ const (
DefaultRateLimitWindow = 6 * time.Hour
)

const ZERO_X_PREFIX = "0x"

// NewLinkedAddress creates a new address to make a deposit which can be transferred to another blockchain
func NewLinkedAddress(ctx sdk.Context, chain nexus.ChainName, symbol, recipientAddr string) sdk.AccAddress {
nonce := utils.GetNonce(ctx.HeaderHash(), ctx.BlockGasMeter())
Expand Down Expand Up @@ -313,7 +316,7 @@ func (minDeposits CallContractProposalMinDeposits) ValidateBasic() error {
}

// ToMap returns a map of chain name to contract address to min deposit
func (minDeposits CallContractProposalMinDeposits) ToMap() callContractProposalMinDepositsMap {
func (minDeposits CallContractProposalMinDeposits) ToMap(ctx sdk.Context, nexus Nexus) callContractProposalMinDepositsMap {
minDepositsMap := make(callContractProposalMinDepositsMap)

for _, minDeposit := range minDeposits {
Expand All @@ -325,6 +328,19 @@ func (minDeposits CallContractProposalMinDeposits) ToMap() callContractProposalM
}

minDepositsMap[chain][contractAddress] = minDeposit.MinDeposits

// TODO: eventually, this is confusing and bad cuz cosmos addresses will also
// show up here and be prefixed with 0x. Like the address validator, we should
// also implement chain-specific address deserializer so that we just use the
// actual bytes as map keys for this check instead of a string representation.
if chain, ok := nexus.GetChain(ctx, minDeposit.Chain); !ok || !chain.IsFrom(evmtypes.ModuleName) {
continue
}
if strings.HasPrefix(contractAddress, ZERO_X_PREFIX) {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
minDepositsMap[chain][strings.TrimPrefix(contractAddress, ZERO_X_PREFIX)] = minDeposit.MinDeposits
} else {
minDepositsMap[chain][fmt.Sprintf("%s%s", ZERO_X_PREFIX, contractAddress)] = minDeposit.MinDeposits
}
}

return minDepositsMap
Expand Down
Loading