Skip to content

test reentrancy guard on store + ERC721/ERC1155 recipient paths#471

Merged
thedavidmeister merged 4 commits into
mainfrom
2026-05-07-issue-309-reentrancy-per-path-tests
Jun 13, 2026
Merged

test reentrancy guard on store + ERC721/ERC1155 recipient paths#471
thedavidmeister merged 4 commits into
mainfrom
2026-05-07-issue-309-reentrancy-per-path-tests

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Summary

Flow.flow carries nonReentrant and the LibFlow.flow NatSpec names four reentrancy entry points. PR #446 covers ERC20/ERC777-style reentrancy via a malicious token. This adds tests for the remaining three:

  1. Malicious interpreter store: MaliciousReenteringStore.set re-enters flow.flow. Etched at the framework's STORE address. Storage slots from the deployed contract are copied across so the etched code retains its evaluable.
  2. Malicious ERC721 recipient: MaliciousReenteringRecipient.onERC721Received re-enters. The framework's TOKEN_B is etched with StubERC721WithReceiverHook so the underlying safeTransferFrom call propagates into the recipient hook (the standard mock token does not call the hook).
  3. Malicious ERC1155 recipient: same shape via StubERC1155WithReceiverHook at TOKEN_C and onERC1155Received.

Mutation verified: dropping nonReentrant from Flow.flow makes all three new tests fail; reverting passes.

Replaces the closed PR #440 (NatSpec-only enumeration). Closes #309.

Test plan

  • all 3 tests pass under current code
  • mutation: drop nonReentrant → all 3 fail

🤖 Generated with Claude Code

The `Flow.flow` `nonReentrant` guard has four documented entry points
(LibFlow.sol:142). PR #446 covers ERC20/ERC777-style reentrancy via a
malicious token. This adds tests for the remaining three:

1. Malicious interpreter store: `MaliciousReenteringStore.set` re-enters
   `flow.flow`. Etched at the framework's STORE address.
2. Malicious ERC721 recipient: `MaliciousReenteringRecipient
   .onERC721Received` re-enters. The framework's TOKEN_B is etched
   with `StubERC721WithReceiverHook` so the underlying
   `safeTransferFrom` call propagates into the recipient hook.
3. Malicious ERC1155 recipient: same shape via
   `StubERC1155WithReceiverHook` at TOKEN_C and `onERC1155Received`.

Mutation verified: dropping `nonReentrant` from `Flow.flow` makes all
three new tests fail; reverting passes.

Closes #309.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 54 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e985311f-b74e-4469-bc26-cadf2d0c085c

📥 Commits

Reviewing files that changed from the base of the PR and between 0af4624 and dc29a94.

📒 Files selected for processing (5)
  • test/concrete/MaliciousReenteringRecipient.sol
  • test/concrete/MaliciousReenteringStore.sol
  • test/concrete/StubERC1155WithReceiverHook.sol
  • test/concrete/StubERC721WithReceiverHook.sol
  • test/src/concrete/Flow.transfer.t.sol
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-05-07-issue-309-reentrancy-per-path-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thedavidmeister thedavidmeister self-assigned this May 9, 2026
thedavidmeister and others added 3 commits May 9, 2026 18:53
`generateFlowStack` / `findEvent` / `findEvents` were thin wrappers in `FlowUtilsAbstractTest`. The wrappers exist only because Solidity's `using X for T` clauses don't inherit, so child contracts of `FlowTest` couldn't otherwise call the library forms directly.

Replace each callsite with the explicit static form:
- `generateFlowStack(t)` -> `LibStackGeneration.generateFlowStack(Sentinel.unwrap(RAIN_FLOW_SENTINEL), t)`
- `findEvent(logs, sig)` -> `LibLogHelper.findEvent(logs, sig)`

`FlowTest` now inherits `FlowTransferOperation` directly. `FlowUtilsAbstractTest.sol` is removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Resolve the single conflict in test/src/concrete/Flow.transfer.t.sol as the
union of both sides' additions: both branches appended disjoint new test
functions and a new import after testFlowProcessesERC721BeforeERC1155. Keep
this branch's three reentrancy-guard tests
(testFlowReentrancyGuardFiresOn{StoreCallback,ERC721Recipient,ERC1155Recipient})
plus their four stub/recipient imports, and main's six tests
(testFlowERC{20,721,1155}TokenRevertBubblesUp, testFlowAtomicRollbackOnLaterTransferFailure,
testFlowRevertsOn{Empty,OneSentinelOnly}EvaluatedStack) plus its MissingSentinel
import. No money-path or contract logic touched; test fixtures only. All 21
tests in the merged contract pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister

Copy link
Copy Markdown
Contributor Author

Reviewed dc29a94: rebased onto main (Flow.transfer.t.sol union — this PR 3 reentrancy-guard tests coexist with main 6 revert tests) and the forge fmt --check failure in the new tests fixed. 21 tests pass, build + fmt green. Test-only. LGTM.

@thedavidmeister thedavidmeister merged commit ec7a7f7 into main Jun 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[A23-6] [LOW] LibFlow.flow reentrancy surface needs per-path tests

1 participant