Skip to content

Recover StreamCore bytecode headroom#116

Merged
punk6529 merged 4 commits into
mainfrom
codex/recover-streamcore-headroom
Jun 11, 2026
Merged

Recover StreamCore bytecode headroom#116
punk6529 merged 4 commits into
mainfrom
codex/recover-streamcore-headroom

Conversation

@punk6529

@punk6529 punk6529 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replaces selected legacy StreamCore string reverts with typed custom errors to recover production runtime bytecode headroom.
  • Adds focused selector regressions for function-admin authorization, artist signatures, metadata array length validation, final-supply timing, and missing collection data before final supply math.
  • Addresses CodeRabbit's setFinalSupply review finding by rejecting created collections with missing collection data via CollectionDataMissing(collectionId) before _finalizeCollectionSupply can underflow.
  • Documents the current StreamCore size policy: 384-byte minimum release floor and 512-byte warning threshold for future non-trivial Core work.
  • Regenerates release/deployment artifacts for the ABI and bytecode deltas.

Closes #115.

Validation

  • forge test --match-contract StreamCoreCustomErrorsTest -vvv
  • forge build --sizes --via-ir --skip test --skip script --force (StreamCore: 24,135 runtime bytes, 441 bytes EIP-170 headroom)
  • make release-checksums
  • make check
  • powershell -ExecutionPolicy Bypass -File scripts\check.ps1
  • forge fmt --check smart-contracts\StreamCore.sol test\StreamCoreCustomErrors.t.sol
  • git diff --check (only known Windows line-ending warning for release-artifacts/latest/SHA256SUMS)

Summary by CodeRabbit

  • New Features

    • Added typed failure handling to improve validation and reduce runtime size.
  • Bug Fixes

    • Prevented final-supply operations when collection data is missing to avoid underflow.
  • Documentation

    • Updated status, roadmap, and gates with runtime size/headroom figures and size-policy guidance.
  • Tests

    • Added tests covering authorization, signature validation, metadata input, and supply-timing failures.
  • Chores

    • Updated release manifests, checksums, and deployment metadata to reflect regenerated artifacts.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

StreamCore replaces several string reverts with four typed custom errors, refactors collection-data access, adds regression tests for the new errors, updates changelog/docs/ops size-headroom policy, and regenerates release and deployment artifact checksums due to ABI/bytecode changes.

Changes

StreamCore Bytecode Headroom Recovery via Custom Errors

Layer / File(s) Summary
Custom error declarations and StreamCore logic updates
smart-contracts/StreamCore.sol
Adds FunctionAdminUnauthorized, ArtistSignatureUnauthorized, InvalidTokenMetadataInput, FinalSupplyTimeNotPassed; replaces string require checks in FunctionAdminRequired, artistSignature, updateImagesAndAttributes, and setFinalSupply with typed reverts; refactors setCollectionData storage access and enforces collection-data presence before final-supply math.
StreamCore custom error regression test suite
test/StreamCoreCustomErrors.t.sol
Adds StreamCoreCustomErrorsTest with expectRevert tests covering unauthorized admin, wrong/duplicate artist signature, mismatched metadata array lengths, premature final-supply timing, and missing collection-data rejection.
Headroom metrics, policy, and release notes
CHANGELOG.md, docs/status.md, ops/ROADMAP.md
Documents custom-error regression coverage and reports updated StreamCore runtime/headroom figures; updates Gate A size-gate text and establishes a 512-byte warning threshold with a 384-byte minimum release floor.
Autonomous run state and decision log updates
ops/AUTONOMOUS_RUN.md
Refreshes active branch to codex/recover-streamcore-headroom, records queue status (PR #114 merged, PR #116 active), and appends decision-log entries describing local validation and interim size-policy thresholds.
Release and deployment artifact regeneration
deployments/address-books/*, deployments/examples/*, release-artifacts/latest/*
Regenerates manifest and checksum metadata (SHA256SUMS, abi-checksums.json, release-artifact-manifest.json, release-checksums.json, release-manifest.json, source-verification-inputs.json, and address-book/example manifests) to reflect updated StreamCore ABI/bytecode hashes and library-linking position changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I swapped old strings for tidy errors,
Tiny hops saved precious bytes,
Tests thump paws to prove selectors,
Docs sing headroom through the nights,
StreamCore naps with room to grow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Recover StreamCore bytecode headroom' directly matches the primary objective and main change in the PR: replacing string reverts with custom errors to recover bytecode headroom.
Linked Issues check ✅ Passed The PR fulfills all acceptance criteria from issue #115: custom errors recover bytecode headroom (24,143 bytes with 433 bytes remaining vs. prior 24,515 with 61 bytes), size policy is documented in ROADMAP.md and status.md, ABI compatibility is preserved, custom-error regressions prove enforcement, and artifacts are regenerated.
Out of Scope Changes check ✅ Passed All changes are scoped to bytecode headroom recovery: custom errors in StreamCore.sol, new regression tests, documentation updates, and artifact regeneration—all directly supporting issue #115 objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/recover-streamcore-headroom

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

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
smart-contracts/StreamCore.sol (1)

652-664: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard setFinalSupply against unset collection data to avoid panic reverts.

Line 656 onward can still hit an arithmetic panic path when _collectionID is not fully initialized (reservedMinTokensIndex == 0 and zero circulation), because _finalizeCollectionSupply computes reservedMin - 1. Add explicit mutable-collection and data-initialized checks before the time-window check.

💡 Suggested patch
 function setFinalSupply(uint256 _collectionID)
     public
     FunctionAdminRequired(this.setFinalSupply.selector)
 {
-    _requireCollectionNotFrozen(_collectionID);
+    _requireExistingMutableCollection(_collectionID);
+    if (!wereDataAdded[_collectionID]) {
+        revert CollectionDataMissing(_collectionID);
+    }
     if (
         block.timestamp
             <= IStreamMinter(minterContract).getEndTime(_collectionID)
                 + collectionAdditionalData[_collectionID].setFinalSupplyTimeAfterMint
     ) {
         revert FinalSupplyTimeNotPassed();
     }
     _finalizeCollectionSupply(_collectionID);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@smart-contracts/StreamCore.sol` around lines 652 - 664, The setFinalSupply
function can underflow in _finalizeCollectionSupply when collection data isn't
initialized (e.g., reservedMinTokensIndex == 0 and zero circulation); add an
explicit guard at the top of setFinalSupply that ensures the collection's
mutable/data-initialized state before doing the time-window check and calling
_finalizeCollectionSupply. Specifically, check
collectionAdditionalData[_collectionID].reservedMinTokensIndex != 0 (or
otherwise verify collectionCirculation[_collectionID] > 0 / a "data initialized"
flag) and revert with a descriptive error (e.g., CollectionNotInitialized or
InvalidCollectionData) if not initialized; keep the existing calls to
_requireCollectionNotFrozen, IStreamMinter(minterContract).getEndTime, and
collectionAdditionalData for locating the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@smart-contracts/StreamCore.sol`:
- Around line 652-664: The setFinalSupply function can underflow in
_finalizeCollectionSupply when collection data isn't initialized (e.g.,
reservedMinTokensIndex == 0 and zero circulation); add an explicit guard at the
top of setFinalSupply that ensures the collection's mutable/data-initialized
state before doing the time-window check and calling _finalizeCollectionSupply.
Specifically, check
collectionAdditionalData[_collectionID].reservedMinTokensIndex != 0 (or
otherwise verify collectionCirculation[_collectionID] > 0 / a "data initialized"
flag) and revert with a descriptive error (e.g., CollectionNotInitialized or
InvalidCollectionData) if not initialized; keep the existing calls to
_requireCollectionNotFrozen, IStreamMinter(minterContract).getEndTime, and
collectionAdditionalData for locating the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f4d94ae-711c-420e-9bb6-6de24b002ff8

📥 Commits

Reviewing files that changed from the base of the PR and between ef5dcba and 613ddf6.

📒 Files selected for processing (16)
  • CHANGELOG.md
  • deployments/address-books/anvil-6529stream-v0.1.0-001-broadcast.json
  • deployments/address-books/anvil-6529stream-v0.1.0-001.json
  • deployments/examples/anvil-6529stream-v0.1.0-001-broadcast.json
  • deployments/examples/anvil-6529stream-v0.1.0-001.json
  • docs/status.md
  • ops/AUTONOMOUS_RUN.md
  • ops/ROADMAP.md
  • release-artifacts/latest/SHA256SUMS
  • release-artifacts/latest/abi-checksums.json
  • release-artifacts/latest/release-artifact-manifest.json
  • release-artifacts/latest/release-checksums.json
  • release-artifacts/latest/release-manifest.json
  • release-artifacts/latest/source-verification-inputs.json
  • smart-contracts/StreamCore.sol
  • test/StreamCoreCustomErrors.t.sol

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ops/AUTONOMOUS_RUN.md`:
- Around line 121-125: The status line under the "PR candidate: Recover
`StreamCore` bytecode headroom (Queue Item 61)" heading is out of date; edit the
Status text in ops/AUTONOMOUS_RUN.md for that section (the block that currently
reads "Status: CodeRabbit review fix validated locally; ready to push PR
update.") to reflect that PR `#116` (branch `codex/recover-streamcore-headroom`,
PR URL https://github.com/6529-Collections/6529Stream/pull/116) has been opened
and the follow-up validation is complete (e.g., "Status: PR `#116` opened and
validated; ready to merge" or equivalent), so the durable state matches the
recorded PR and validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c04e6873-98ae-4900-9e84-c7b2b2a41ae6

📥 Commits

Reviewing files that changed from the base of the PR and between 613ddf6 and 31dc396.

📒 Files selected for processing (16)
  • CHANGELOG.md
  • deployments/address-books/anvil-6529stream-v0.1.0-001-broadcast.json
  • deployments/address-books/anvil-6529stream-v0.1.0-001.json
  • deployments/examples/anvil-6529stream-v0.1.0-001-broadcast.json
  • deployments/examples/anvil-6529stream-v0.1.0-001.json
  • docs/status.md
  • ops/AUTONOMOUS_RUN.md
  • ops/ROADMAP.md
  • release-artifacts/latest/SHA256SUMS
  • release-artifacts/latest/abi-checksums.json
  • release-artifacts/latest/release-artifact-manifest.json
  • release-artifacts/latest/release-checksums.json
  • release-artifacts/latest/release-manifest.json
  • release-artifacts/latest/source-verification-inputs.json
  • smart-contracts/StreamCore.sol
  • test/StreamCoreCustomErrors.t.sol
✅ Files skipped from review due to trivial changes (8)
  • release-artifacts/latest/release-artifact-manifest.json
  • release-artifacts/latest/release-checksums.json
  • release-artifacts/latest/SHA256SUMS
  • deployments/examples/anvil-6529stream-v0.1.0-001-broadcast.json
  • deployments/examples/anvil-6529stream-v0.1.0-001.json
  • release-artifacts/latest/abi-checksums.json
  • CHANGELOG.md
  • release-artifacts/latest/source-verification-inputs.json
🚧 Files skipped from review as they are similar to previous changes (6)
  • deployments/address-books/anvil-6529stream-v0.1.0-001-broadcast.json
  • docs/status.md
  • deployments/address-books/anvil-6529stream-v0.1.0-001.json
  • test/StreamCoreCustomErrors.t.sol
  • release-artifacts/latest/release-manifest.json
  • smart-contracts/StreamCore.sol

Comment thread ops/AUTONOMOUS_RUN.md
@punk6529 punk6529 merged commit a6d9271 into main Jun 11, 2026
1 check 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.

Recover StreamCore bytecode headroom before further feature work

1 participant