fix: consume allowance on transferFrom when caller == from#87
Merged
Conversation
MockB20.transferFrom and transferFromWithMemo gated _consumeAllowance behind `msg.sender != from`, silently skipping allowance burn when the owner was the caller. OZ ERC20 and the Rust precompile both carve no such exception. Lift _consumeAllowance to fire unconditionally outside the factory bootstrap window; keep the executor-policy check gated on `msg.sender != from` (sender-policy already covers `from`). Regression tests pin the corrected behavior on both transferFrom and transferFromWithMemo: self-caller now reverts InsufficientAllowance without a self-approval and consumes the slot when one exists. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
amiecorso
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MockB20.transferFrom(andtransferFromWithMemo) gated_consumeAllowancebehindmsg.sender != from, so an owner-as-callertransferFrom(self, to, amt)silently moved tokens without burning any approval. OZ ERC20 and the Rust precompile both carve no exception formsg.sender == from, so this is a real divergence — flagged by Andreas in #proj-b20.Fix
_consumeAllowancenow fires unconditionally outside the factory bootstrap window. The executor-policy check is still gated onmsg.sender != from, since the sender-policy already coversfrominside_transferand self-callers aren't a distinct executor — this is the one carve-out the mock intentionally keeps.Tests
Regression tests added to both
transferFrom.t.solandtransferFromWithMemo.t.sol(all fuzz, per repo convention):test_transferFrom_revert_selfCaller_insufficientAllowance— owner-as-caller with no self-approval revertsInsufficientAllowancetest_transferFrom_success_selfCaller_decreasesAllowance— owner-as-caller consumesallowances[from][from]slottest_transferFrom_success_selfCaller_skipsExecutorPolicy— pins the intentional carve-out: executor policy is still bypassed whenmsg.sender == fromtest_transferFromWithMemo_revert_selfCaller_insufficientAllowance/…_success_selfCaller_decreasesAllowance— same for the memo variantTest plan
forge test --match-path "test/unit/B20/erc20/transferFrom.t.sol"— 14/14 passingforge test --match-path "test/unit/B20/**/*.t.sol"— 191/191 passingforge test(full suite) — 504/504 passing