-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Remove unreachable return value checks in ERC1363 #6206
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,9 +65,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363 { | |
| * no specified format. | ||
| */ | ||
| function transferAndCall(address to, uint256 value, bytes memory data) public virtual returns (bool) { | ||
| if (!transfer(to, value)) { | ||
| revert ERC1363TransferFailed(to, value); | ||
| } | ||
| transfer(to, value); | ||
| ERC1363Utils.checkOnERC1363TransferReceived(_msgSender(), _msgSender(), to, value, data); | ||
| return true; | ||
| } | ||
|
|
@@ -98,9 +96,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363 { | |
| uint256 value, | ||
| bytes memory data | ||
| ) public virtual returns (bool) { | ||
| if (!transferFrom(from, to, value)) { | ||
| revert ERC1363TransferFromFailed(from, to, value); | ||
| } | ||
| transferFrom(from, to, value); | ||
| ERC1363Utils.checkOnERC1363TransferReceived(_msgSender(), from, to, value, data); | ||
| return true; | ||
| } | ||
|
|
@@ -126,9 +122,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363 { | |
| * no specified format. | ||
| */ | ||
| function approveAndCall(address spender, uint256 value, bytes memory data) public virtual returns (bool) { | ||
| if (!approve(spender, value)) { | ||
| revert ERC1363ApproveFailed(spender, value); | ||
| } | ||
| approve(spender, value); | ||
| ERC1363Utils.checkOnERC1363ApprovalReceived(_msgSender(), spender, value, data); | ||
| return true; | ||
| } | ||
|
Comment on lines
124
to
128
Contributor
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. 🧩 Analysis chain🏁 Script executed: # First, let's find and examine the ERC1363.sol file and surrounding context
cd contracts && find . -name "ERC1363.sol" -type fRepository: OpenZeppelin/openzeppelin-contracts Length of output: 115 🏁 Script executed: # Let's also check the OpenZeppelin ERC20 implementation to understand approve() behavior
find . -name "ERC20.sol" -type f | head -5Repository: OpenZeppelin/openzeppelin-contracts Length of output: 112 🏁 Script executed: # Search for any documentation about ERC1363 and the semantics of approveAndCall
rg -A 10 -B 5 "function approveAndCall" contracts/Repository: OpenZeppelin/openzeppelin-contracts Length of output: 7351 🏁 Script executed: # Check the ERC1363Utils to understand what checkOnERC1363ApprovalReceived does
rg -A 15 "function checkOnERC1363ApprovalReceived" contracts/Repository: OpenZeppelin/openzeppelin-contracts Length of output: 1387 🏁 Script executed: # Let's examine OpenZeppelin's ERC20.approve to understand its return value semantics
rg -A 10 "function approve" contracts/ -B 2 | head -50Repository: OpenZeppelin/openzeppelin-contracts Length of output: 3572 🏁 Script executed: # Check if ERC20.approve is marked final
rg -A 5 "function approve" contracts/token/ERC20/ERC20.sol | head -20Repository: OpenZeppelin/openzeppelin-contracts Length of output: 270 🏁 Script executed: # Let's read the full ERC1363.sol file to understand all context
wc -l contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 127 🏁 Script executed: # Read the relevant section with context
sed -n '110,135p' contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 929 🏁 Script executed: # Check the documentation comment more carefully
sed -n '100,135p' contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 1315 🏁 Script executed: # Search for tests related to approveAndCall to see what behavior is tested
find . -name "*.test.ts" -o -name "*.test.js" -o -name "*.test.sol" | xargs grep -l "approveAndCall" 2>/dev/null | head -3Repository: OpenZeppelin/openzeppelin-contracts Length of output: 167 🏁 Script executed: # Check if there are any test files that test custom approve() behavior
fd -e "test.ts" -e "test.js" | xargs grep -l "ERC1363" 2>/dev/null | head -3Repository: OpenZeppelin/openzeppelin-contracts Length of output: 163 🏁 Script executed: # Look for ERC1363 test files specifically
find . -path "*/test/*" -name "*ERC1363*" -type f 2>/dev/nullRepository: OpenZeppelin/openzeppelin-contracts Length of output: 124 🏁 Script executed: # Search for any comments about the approve() return value handling in the codebase
rg "approve.*return" contracts/token/ERC20/extensions/ERC1363.sol -B 5 -A 5Repository: OpenZeppelin/openzeppelin-contracts Length of output: 950 🏁 Script executed: # Check what the transferAndCall function does for comparison (does it check return value?)
sed -n '80,110p' contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 1282 🏁 Script executed: # Check the test file size first
wc -l test/token/ERC20/extensions/ERC1363.test.jsRepository: OpenZeppelin/openzeppelin-contracts Length of output: 126 🏁 Script executed: # Search for tests related to approve or custom implementations in the test file
rg -A 10 "describe.*approve|test.*approve" test/token/ERC20/extensions/ERC1363.test.js | head -40Repository: OpenZeppelin/openzeppelin-contracts Length of output: 443 🏁 Script executed: # Look for mock usage in tests
rg "Mock|mock" test/token/ERC20/extensions/ERC1363.test.js | head -20Repository: OpenZeppelin/openzeppelin-contracts Length of output: 403 🏁 Script executed: # Check if the test file tests the return value handling
rg "return.*false|ReturnFalse" test/token/ERC20/extensions/ERC1363.test.jsRepository: OpenZeppelin/openzeppelin-contracts Length of output: 61 🏁 Script executed: # Read the full ERC1363.sol file to see the class declaration and documentation
head -50 contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 2300 🏁 Script executed: # Check the IERC1363 interface documentation
head -60 contracts/interfaces/IERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 3037 🏁 Script executed: # Look at the context around the issue - is this related to a specific change or bug report?
git log --oneline -n 20 -- contracts/token/ERC20/extensions/ERC1363.sol 2>/dev/null | head -10Repository: OpenZeppelin/openzeppelin-contracts Length of output: 106 🏁 Script executed: # Check if ERC1363ApproveFailed is defined but truly never used
rg "ERC1363ApproveFailed" contracts/Repository: OpenZeppelin/openzeppelin-contracts Length of output: 187 🏁 Script executed: # Check the git history for when this error was added
git log -p -- contracts/token/ERC20/extensions/ERC1363.sol 2>/dev/null | grep -A 5 -B 5 "ERC1363ApproveFailed" | head -40Repository: OpenZeppelin/openzeppelin-contracts Length of output: 61 🏁 Script executed: # Check if there are any similar errors that ARE being used
rg "ERC1363TransferFailed|ERC1363TransferFromFailed" contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 230 🏁 Script executed: # Let's check when these errors were added and look at recent changes to the file
git log --oneline --all -- contracts/token/ERC20/extensions/ERC1363.sol 2>/dev/nullRepository: OpenZeppelin/openzeppelin-contracts Length of output: 624 🏁 Script executed: # Let's see the actual implementation to confirm none of the errors are used
grep -n "ERC1363ApproveFailed\|ERC1363TransferFailed\|ERC1363TransferFromFailed" contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 303 🏁 Script executed: # Check if checkOnERC1363ApprovalReceived could throw and would that be sufficient
rg -A 20 "function checkOnERC1363ApprovalReceived" contracts/token/ERC20/utils/ERC1363Utils.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 865 🏁 Script executed: # Look for any comments or documentation about why these errors exist but aren't used
rg -B 10 -A 2 "error ERC1363ApproveFailed" contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts Length of output: 605 🏁 Script executed: # Check if there's any documentation about supported ERC20 implementations
rg -i "erc20|override|compatible" contracts/token/ERC20/extensions/ERC1363.sol | head -20Repository: OpenZeppelin/openzeppelin-contracts Length of output: 471 Check the The 🤖 Prompt for AI Agents |
||
|
|
||
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.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the full ERC1363.sol file to understand context and NatSpec cat -n contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts
Length of output: 6388
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 3330
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 238
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 2610
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 2357
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 111
🏁 Script executed:
# Check git history to see if these error types were recently added/removed git log --oneline -20 -- contracts/token/ERC20/extensions/ERC1363.solRepository: OpenZeppelin/openzeppelin-contracts
Length of output: 106
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 783
🏁 Script executed:
# Check the recent commit that updated ERC1363.sol git show d473269d --statRepository: OpenZeppelin/openzeppelin-contracts
Length of output: 50391
🏁 Script executed:
# Check the ERC1363 test file to see what behavior is tested head -100 test/token/ERC20/extensions/ERC1363.test.jsRepository: OpenZeppelin/openzeppelin-contracts
Length of output: 3539
🏁 Script executed:
Repository: OpenZeppelin/openzeppelin-contracts
Length of output: 61
🏁 Script executed:
# Check ERC1363Utils to understand callback validation cat contracts/token/ERC20/utils/ERC1363Utils.solRepository: OpenZeppelin/openzeppelin-contracts
Length of output: 3375
Document expected behavior for
transfer/transferFrom/approveoverrides, or add assertions.If a derived contract overrides
transfer()(line 68),transferFrom()(line 99), orapprove()(line 125) to returnfalsewithout reverting, the ERC1363 functions will still execute the callback and returntrue, misleading the caller. The NatSpec says "must succeed (returnedtrue)" but the code no longer checks return values. Either document that only revert-on-failure overrides are supported, or add assertions/requires to enforce this expectation.🤖 Prompt for AI Agents