-
Notifications
You must be signed in to change notification settings - Fork 193
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): improve safety of ERC20 transfers, accounting for boolean success return values and recipient balance changes that don't match the ERC20 transfer amount. #2090
Changes from 6 commits
9d59336
a0afa5a
476ffbc
eb72b31
f356315
43ae3e1
80d5353
3ad846b
e4b932d
b2c863d
2235d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Unique-Divine marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ func (p precompileFunToken) bankSend( | |
|
||
// Caller transfers ERC20 to the EVM account | ||
transferTo := evm.EVM_MODULE_ADDRESS | ||
_, err = p.evmKeeper.ERC20().Transfer(erc20, caller, transferTo, amount, ctx) | ||
_, err, _ = p.evmKeeper.ERC20().Transfer(erc20, caller, transferTo, amount, ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle the Received Amount from At line 162: _, err, _ = p.evmKeeper.ERC20().Transfer(erc20, caller, transferTo, amount, ctx) The Consider capturing and utilizing the -receivedAmount, err, _ := p.evmKeeper.ERC20().Transfer(erc20, caller, transferTo, amount, ctx)
+receivedAmount, err, _ := p.evmKeeper.ERC20().Transfer(erc20, caller, transferTo, amount, ctx)
if err != nil {
return nil, fmt.Errorf("failed to send from caller to the EVM account: %w", err)
}
+// Update the amount to reflect the actual received amount
+amount = receivedAmount By handling |
||
if err != nil { | ||
return nil, fmt.Errorf("failed to send from caller to the EVM account: %w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update transfer result handling for fee-on-transfer tokens.
The test ignores the actual received amount (third return value) from
Transfer()
. For fee-on-transfer tokens, the received amount could be less than the sent amount, which this test wouldn't catch.Consider updating the test to handle fee-on-transfer scenarios:
Also applies to: 61-61