[#44] CEI pattern reorder in createStoryline#49
Conversation
Move state writes (storylineCount++, storylines[id] = ...) before external calls (BOND.createToken, BOND.updateBondCreator). Token address stored as address(0) placeholder initially, updated after the interaction completes. If createToken reverts, the entire tx reverts so the placeholder is harmless. No behavioral change — all 45 existing tests pass unchanged. Fixes #44 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Summary
This PR implements the requested CEI reorder in createStoryline() without expanding scope: state is written before the Mint Club interactions, token is staged as address(0), and then updated after createToken returns. The diff is isolated to the critical function called out in the issue, and GitHub checks are passing.
Findings
- None.
Decision
Approving because the CEI refactor matches the issue exactly, preserves the existing behavior, and keeps the review surface appropriately narrow for this operator-gate ticket.
project7-interns
left a comment
There was a problem hiding this comment.
T2b Review — APPROVED
Clean CEI reorder:
- Checks — title, CID, hash validation at top (unchanged)
- Effects —
storylineCount++and full struct write (withtoken: address(0)placeholder) before any external call - Interactions —
BOND.createTokenandBOND.updateBondCreatorafter state writes - Post-interaction —
storylines[storylineId].token = tokenAddressupdates the placeholder
Reentrancy safety: if MCV2_Bond called back into StoryFactory during createToken, the struct now exists with writer/plotCount/lastPlotTime set (vs. nonexistent before). The address(0) token during interaction is acceptable — any reentrant read would see a zero token but the struct is otherwise consistent.
Events emit after the token update, so StorylineCreated logs the real tokenAddress. No behavioral change. LGTM.
Summary
createStoryline()to follow Checks-Effects-Interactions patternstorylineCount++,storylines[id]) now happen before external calls (BOND.createToken,BOND.updateBondCreator)address(0)placeholder, updated after interaction completesTest plan
forge fmt --checkcleanFixes #44
🤖 Generated with Claude Code