fix: resolve DoS for zero-intolerant tokens in approveAndBridge (Fixes #5)#6
Conversation
📝 WalkthroughWalkthroughModified ERC20 approval flow in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/mixin/ApproveAndBridge.sol`:
- Around line 41-49: The current low-level approve call only checks the call
success flag and can miss tokens that return false; change the logic to inspect
the returned data: after calling
address(token).call(abi.encodeWithSelector(IERC20.approve.selector, target,
balance)) capture (bool success, bytes memory returndata) and consider the
approve successful only if success is true AND (returndata.length == 0 ||
abi.decode(returndata, (bool)) == true); otherwise call
token.forceApprove(target, balance). Update the code paths referencing
IERC20.approve.selector, the local variables success/returndata, and
token.forceApprove to implement this check.
Summary
Resolved a vulnerability where
ApproveAndBridgecould enter a permanent Denial of Service (DoS) state when interacting with "Zero-Intolerant" tokens that revert onapprove(0).The Issue
When residual "dust" allowance exists,
SafeERC20.forceApproveattempts a reset-to-zero before updating. Zero-intolerant tokens revert on this reset, blocking all future bridge attempts for that token.The Solution
.callto update allowance , bypassing the revert.forceApproveonly if the direct call fails (e.g., for USDT).approve(0)via low-level call to ensure no settlement reverts even if the cleanup fails.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.