Skip to content

[#44] CEI pattern reorder in createStoryline#49

Merged
realproject7 merged 1 commit intomainfrom
task/44-cei-reorder
Mar 20, 2026
Merged

[#44] CEI pattern reorder in createStoryline#49
realproject7 merged 1 commit intomainfrom
task/44-cei-reorder

Conversation

@realproject7
Copy link
Owner

Summary

  • Reorder createStoryline() to follow Checks-Effects-Interactions pattern
  • State writes (storylineCount++, storylines[id]) now happen before external calls (BOND.createToken, BOND.updateBondCreator)
  • Token address stored as address(0) placeholder, updated after interaction completes
  • No behavioral change — pure reorder for security best practice

Test plan

  • All 45 existing tests pass unchanged (no behavioral change)
  • forge fmt --check clean

Fixes #44

🤖 Generated with Claude Code

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>
Copy link
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T2b Review — APPROVED

Clean CEI reorder:

  1. Checks — title, CID, hash validation at top (unchanged)
  2. EffectsstorylineCount++ and full struct write (with token: address(0) placeholder) before any external call
  3. InteractionsBOND.createToken and BOND.updateBondCreator after state writes
  4. Post-interactionstorylines[storylineId].token = tokenAddress updates 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.

@realproject7 realproject7 merged commit 229dec9 into main Mar 20, 2026
2 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.

[Contract] CEI pattern reorder in createStoryline (#38 Group D)

2 participants