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(evm-precompile): use bank.MsgServer Send in precompile IFunToken.bankMsgSend #2160

Merged
merged 2 commits into from
Jan 10, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ JSON encoding for the `EIP55Addr` struct was not following the Go conventions an
needed to include double quotes around the hexadecimal string.
- [#2156](https://github.com/NibiruChain/nibiru/pull/2156) - test(evm-e2e): add E2E test using the Nibiru Oracle's ChainLink impl
- [#2157](https://github.com/NibiruChain/nibiru/pull/2157) - fix(evm): Fix unit inconsistency related to AuthInfo.Fee and txData.Fee using effective fee
- [#2160](https://github.com/NibiruChain/nibiru/pull/2160) - fix(evm-precompile): use bank.MsgServer Send in precompile IFunToken.bankMsgSend

#### Nibiru EVM | Before Audit 2 - 2024-12-06

Expand Down
21 changes: 16 additions & 5 deletions x/evm/precompile/funtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
gethabi "github.com/ethereum/go-ethereum/accounts/abi"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -125,6 +127,10 @@ type precompileFunToken struct {
// /// @param to the receiving Nibiru base account address as a string
// function sendToBank(address erc20, uint256 amount, string memory to) external;
// ```
//
// Because [sendToBank] uses "SendCoinsFromModuleToAccount" to send Bank Coins,
// this method correctly avoids sending funds to addresses blocked by the Bank
// module.
func (p precompileFunToken) sendToBank(
startResult OnRunStartResult,
caller gethcommon.Address,
Expand Down Expand Up @@ -701,9 +707,6 @@ func (p precompileFunToken) bankMsgSend(
if err != nil {
return nil, ErrInvalidArgs(err)
}
if amount.Sign() != 1 {
return nil, fmt.Errorf("msgSend amount must be positive")
}

// parse toStr (bech32 or hex)
toEthAddr, e := parseToAddr(toStr)
Expand All @@ -715,8 +718,16 @@ func (p precompileFunToken) bankMsgSend(

// do the bank send
coin := sdk.NewCoins(sdk.NewCoin(denom, math.NewIntFromBigInt(amount)))
if err := p.evmKeeper.Bank.SendCoins(
ctx, fromBech32, toBech32, coin,
bankMsg := &bank.MsgSend{
FromAddress: fromBech32.String(),
ToAddress: toBech32.String(),
Amount: coin,
}
if err := bankMsg.ValidateBasic(); err != nil {
return nil, err
}
if _, err := bankkeeper.NewMsgServerImpl(p.evmKeeper.Bank).Send(
sdk.WrapSDKContext(ctx), bankMsg,
Comment on lines +721 to +730
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the block address check to IFunToken.bankMsgSend

); err != nil {
return nil, fmt.Errorf("bankMsgSend: %w", err)
}
Expand Down
Loading