fix(erc20): add zero-address validation in transfer (#975)#1197
fix(erc20): add zero-address validation in transfer (#975)#1197aglichandrap wants to merge 3 commits into
Conversation
Per ERC-20 standard (EIP-20), transfers to address(0) should revert. Currently the precompile allows transfers to the zero address, causing permanent token loss. Added validation in the common transfer() function to reject transfers where the recipient is the zero address. Fixes cosmos#975
|
PR author is not in the allowed authors list. |
|
no test coverage for the new zero-address guard. the pr description lists three cases — please add them:
also worth adding a |
aljo242
left a comment
There was a problem hiding this comment.
missing tests for the new zero-address guard and missing from == address(0) check in transferFrom.
…ferFrom Add test cases requested by reviewer: - transfer to zero address should fail - transferFrom to zero address should fail - transferFrom from zero address should fail Refs: cosmos#975
Addresses review feedback from aljo242 on PR cosmos#1197. - Add from == address(0) check in TransferFrom to prevent transfers from the zero address - Update test expectation to match new error message The transfer() function already validates to == address(0). This commit adds the complementary from == address(0) check in TransferFrom, which is called before delegation to transfer().
|
Thanks for the review @aljo242! I've addressed both points: 1. Tests for zero-address guardTests were already added in commit
2.
|
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs. |
Problem
The ERC-20 precompile's
transfer()andtransferFrom()functions do not validate that the recipient address is non-zero. Per ERC-20 standard (EIP-20), transfers toaddress(0)should revert, but currently they succeed, causing permanent token loss.Fix
Added zero-address validation in the common
transfer()function:This check covers both
TransferandTransferFromsince they both calltransfer().Testing
Transfer(to=0x0, amount=100)→ should revertTransfer(to=validAddr, amount=100)→ should succeedTransferFrom(from=validAddr, to=0x0, amount=100)→ should revertFixes #975