Repository navigation
fix: strict balance-delta check on ERC-3009 escrow collections - #189
Conversation
The single-input fast path in _openForWithAuthorization performed a raw call to receiveWithAuthorization and trusted its success flag. Tokens with a permissive fallback (e.g. WETH9, whose fallback treats unknown calldata as a deposit) make that call "succeed" without transferring anything, letting an order be marked Deposited while the escrow received no funds. The multi-signature loop similarly trusted the token to revert without any evidence tokens moved. Both ERC-3009 call sites now snapshot the escrow's token balance before collecting and revert with InvalidBalanceDelta unless the balance increased by exactly the input amount. This also rejects under-transfers such as fee-on-transfer tokens on this path. Adds MockERC20Fallback (a WETH-style fallback-swallowing mock) and regression tests for both the single-input raw-call path and the multi-signature array path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Note
|
| Layer / File(s) | Summary |
|---|---|
Implement exact balance validation src/input/escrow/InputSettlerEscrow.sol |
ERC-3009 single- and multi-input collection now requires the token balance to increase by the requested amount. InvalidBalanceDelta handles mismatches and overflow. |
Test failed transfer handling test/mocks/MockERC20Fallback.sol, test/input/escrow/InputSettlerEscrow.t.sol, snapshots/*.json |
Fallback-token tests verify reverts and unchanged order status for single- and multi-input calls. Snapshot values are updated. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Mergeability Score: ⚪ Minimal · up to 94743
The change adds exact balance-delta validation to ERC-3009 escrow collection and covers the previously vulnerable paths with regression tests; no actionable merge-blocking risk remains beyond normal checks and review.
Sequence Diagram(s)
sequenceDiagram
participant InputSettlerEscrow
participant ERC3009Token
participant OrderStatus
InputSettlerEscrow->>ERC3009Token: Read pre-transfer balance
InputSettlerEscrow->>ERC3009Token: Execute authorized transfer
InputSettlerEscrow->>ERC3009Token: Read post-transfer balance
InputSettlerEscrow->>InputSettlerEscrow: Validate exact balance increase
InputSettlerEscrow->>OrderStatus: Continue only after validation
Possibly related PRs
- openintentsframework/oif-contracts#186: Adds an overridable payout transfer hook related to token-transfer behavior in
InputSettlerEscrow.sol.
Suggested reviewers: luiz-lvj
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and concisely describes the strict balance-delta validation added to ERC-3009 escrow collections. |
| Description check | ✅ Passed | The description clearly explains the problem, fix, unsupported token behavior, regression tests, and gas impact, but does not use the template headings. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
fix/erc3009-balance-delta-check
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 @coderabbitai help to get the list of available commands.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Hey @reednaa is this ready to merge? |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Problem
InputSettlerEscrow._openForWithAuthorizationcollects order inputs via ERC-3009receiveWithAuthorization. The single-input fast path performed a rawtoken.call(...)and trusted the success flag (if (success) return;). Tokens with a permissive fallback — notably WETH9, whose fallback treats unknown calldata as a deposit — make that call "succeed" without transferring anything. An order could therefore be markedDepositedwhile the escrow received no funds. The multi-signature loop similarly trusted the token to revert, with no evidence tokens actually moved.Fix
Both ERC-3009 call sites now snapshot
balanceOf(address(this))before collecting and revert with a newInvalidBalanceDelta(expectedBalance, actualBalance)error unless the balance increased by exactly the input amount (checked arithmetic, since the amount is attacker-controlled).Note: exact-delta enforcement makes under-transferring tokens (e.g. fee-on-transfer) explicitly unsupported on the ERC-3009 path, which is the intended escrow-solvency behavior.
Tests
MockERC20Fallback: a WETH-style mock whosefallback()swallows any call whilebalanceOfnever changes.test_open_for_3009_single_fallback_reverts: the previously vulnerable single-input raw-call path now reverts withInvalidBalanceDeltaand the order stays unopened.test_open_for_3009_two_fallback_as_array_reverts: same for the multi-signature array branch (two inputs, since a single input hits the fast path first).balanceOfcalls).🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests