Skip to content

Add ERC1155Supply extension #1632

Merged
ericnordelo merged 4 commits intomainfrom
feat/add-erc1155-supply-extension-#1574
Jan 16, 2026
Merged

Add ERC1155Supply extension #1632
ericnordelo merged 4 commits intomainfrom
feat/add-erc1155-supply-extension-#1574

Conversation

@ericnordelo
Copy link
Copy Markdown
Member

@ericnordelo ericnordelo commented Jan 14, 2026

Fixes #1574

PR Checklist

  • Tests
  • Documentation
  • Added entry to CHANGELOG.md
  • Tried the feature on a public network

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ERC1155Supply extension for ERC1155 tokens to query token supplies and check existence.
  • Chores

    • Updated Cairo to v2.15.0 and Scarb to v2.15.1. Bumped related dependencies including snforge and starknet.

✏️ Tip: You can customize this high-level summary in your review settings.

@ericnordelo ericnordelo requested a review from immrsd January 14, 2026 14:47
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 14, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces an ERC-1155 Supply Extension component that tracks token supplies across the ERC-1155 token standard. The implementation includes new interface definitions, a component with storage and hooks, macro support for component integration, mock implementations for testing, and comprehensive test coverage. Dependency versions are also updated.

Changes

Cohort / File(s) Summary
Version Updates
Scarb.toml, CHANGELOG.md
Cairo bumped to 2.15.0, Scarb to 2.15.1; workspace dependencies (assert_macros, starknet, snforge_std) also updated. Changelog entry added documenting the bump.
Interface Definitions
packages/interfaces/src/token/erc1155.cairo
New IERC1155Supply trait with three methods: total_supply(token_id), total_supply_all(), and exists(token_id).
Macro Component Registry
packages/macros/src/attribute/with_components/components.rs
Added ERC1155Supply variant to AllowedComponents enum; extended from_str() and get_info() to recognize and configure the new component.
Component Implementation
packages/token/src/erc1155/extensions.cairo, packages/token/src/erc1155/extensions/erc1155_supply.cairo
New extensions module with ERC1155SupplyComponent that manages per-token and aggregate supply via Storage maps; InternalImpl hooks into ERC1155 after_update to increment/decrement supplies on mint/burn operations.
Module Exports
packages/token/src/erc1155.cairo
Added public extensions module and re-export of ERC1155SupplyComponent.
Test Infrastructure
packages/test_common/src/mocks/erc1155.cairo, packages/testing/CHANGELOG.md
ERC1155SupplyMock contract added with ERC1155HooksImpl routing after_update calls to the ERC1155Supply component; testing CHANGELOG updated.
Test Suite
packages/token/src/tests/erc1155.cairo, packages/token/src/tests/erc1155/test_erc1155_supply.cairo
Test module declaration added; comprehensive test file covering mint, burn, transfer, and supply tracking scenarios across single and batch operations.

Sequence Diagram(s)

sequenceDiagram
    participant Contract
    participant ERC1155Component
    participant ERC1155SupplyComponent
    participant Storage

    Contract->>ERC1155Component: transfer/mint/burn
    activate ERC1155Component
    ERC1155Component->>ERC1155Component: execute operation
    ERC1155Component->>Contract: invoke after_update hook
    deactivate ERC1155Component
    
    activate Contract
    Contract->>ERC1155SupplyComponent: after_update(from, to, token_ids, values)
    deactivate Contract
    
    activate ERC1155SupplyComponent
    ERC1155SupplyComponent->>Storage: update total_supply[token_id]
    ERC1155SupplyComponent->>Storage: update total_supply_all
    deactivate ERC1155SupplyComponent
    
    Contract->>ERC1155SupplyComponent: total_supply(token_id)
    activate ERC1155SupplyComponent
    ERC1155SupplyComponent->>Storage: read total_supply[token_id]
    ERC1155SupplyComponent-->>Contract: u256 value
    deactivate ERC1155SupplyComponent
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • immrsd
  • bidzyyys

Poem

🐰 A supply component hops into place,
Tracking tokens with speed and grace,
Hooks that measure each mint and burn,
ERC-1155 now counts its turn! 📦✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add ERC1155Supply extension' directly describes the main change in the pull request, which adds a new ERC1155Supply component for supply tracking.
Linked Issues check ✅ Passed The PR implements the ERC1155Supply extension for Cairo following the Solidity reference, with storage tracking, supply methods, and hooks integration as required by issue #1574.
Out of Scope Changes check ✅ Passed All changes directly support the ERC1155Supply extension implementation: interface definitions, component implementation, macros registration, tests, mocks, and version/changelog updates.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-erc1155-supply-extension-#1574

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

@ericnordelo ericnordelo requested a review from bidzyyys January 14, 2026 14:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 14, 2026

🧪 Cairo Contract Size Benchmark Diff

BYTECODE SIZE (felts) (limit: 81,920 felts)

Contract Old New Δ Note
ERC1155SupplyMock 10435 +10435 ✅ NEW

SIERRA CONTRACT CLASS SIZE (bytes) (limit: 4,089,446 bytes)

Contract Old New Δ Note
ERC1155SupplyMock 235154 +235154 ✅ NEW

This comment was generated automatically from benchmark diffs.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Around line 19-21: Add a new entry under the "Added" section of the changelog
to document the ERC1155 supply extension: mention the new ERC1155SupplyComponent
and the IERC1155Supply interface (and optionally a short note about their
purpose, e.g., supply tracking for ERC‑1155 tokens) so users see these API
additions; ensure the entry follows existing changelog style and placement
conventions.
🧹 Nitpick comments (1)
packages/interfaces/src/token/erc1155.cairo (1)

45-50: Interface definition looks good.

The IERC1155Supply interface correctly mirrors the OpenZeppelin Solidity ERC1155Supply extension with appropriate snake_case naming.

Consider defining an interface ID constant (e.g., IERC1155_SUPPLY_ID) similar to other interfaces in this file if consumers need to check for supply extension support via SRC5.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a6d204 and 9043414.

⛔ Files ignored due to path filters (1)
  • Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • CHANGELOG.md
  • Scarb.toml
  • packages/interfaces/src/token/erc1155.cairo
  • packages/macros/src/attribute/with_components/components.rs
  • packages/test_common/src/mocks/erc1155.cairo
  • packages/testing/CHANGELOG.md
  • packages/token/src/erc1155.cairo
  • packages/token/src/erc1155/extensions.cairo
  • packages/token/src/erc1155/extensions/erc1155_supply.cairo
  • packages/token/src/tests/erc1155.cairo
  • packages/token/src/tests/erc1155/test_erc1155_supply.cairo
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: ericnordelo
Repo: OpenZeppelin/cairo-contracts PR: 1630
File: packages/test_common/src/mocks/erc721.cairo:363-409
Timestamp: 2026-01-13T11:48:56.063Z
Learning: In Cairo contracts using the ERC721ConsecutiveComponent with the component! macro, the ERC721OwnerOfDefaultImpl import is not needed because ConsecutiveExtensionERC721OwnerOfTraitImpl is automatically used to provide custom owner_of logic for consecutive/batched tokens. This is different from regular ERC721 mocks that require the explicit ERC721OwnerOfDefaultImpl import.
📚 Learning: 2026-01-13T11:50:05.718Z
Learnt from: ericnordelo
Repo: OpenZeppelin/cairo-contracts PR: 1630
File: packages/token/src/erc721/erc721.cairo:25-26
Timestamp: 2026-01-13T11:50:05.718Z
Learning: In Cairo contracts, trait implementation imports must be brought into scope using an import like `use Component::InternalImpl as Alias` to enable method resolution, even if the alias name is not textually used in the code. Ensure such trait imports (e.g., for ERC721ConsecutiveComponent::InternalImpl and similar component trait imports) exist so component method calls on instances (e.g., via get_dep_component()) resolve correctly. In reviews, verify that relevant Cairo files include the necessary trait import aliases to bring implementations into scope, not just the concrete types or module paths.

Applied to files:

  • packages/interfaces/src/token/erc1155.cairo
  • packages/token/src/erc1155/extensions/erc1155_supply.cairo
  • packages/token/src/erc1155/extensions.cairo
  • packages/test_common/src/mocks/erc1155.cairo
  • packages/token/src/tests/erc1155/test_erc1155_supply.cairo
  • packages/token/src/tests/erc1155.cairo
  • packages/token/src/erc1155.cairo
📚 Learning: 2026-01-13T11:54:54.301Z
Learnt from: ericnordelo
Repo: OpenZeppelin/cairo-contracts PR: 1630
File: packages/token/src/erc721/extensions/erc721_consecutive.cairo:118-129
Timestamp: 2026-01-13T11:54:54.301Z
Learning: In Cairo 1.0 and later, all integer types (u8, u16, u32, u64, u128, u256, i8–i128) have built-in overflow and underflow protection. Arithmetic operations on these types automatically panic (revert) if they overflow or underflow, rather than wrapping. This means explicit overflow guards are not necessary for standard integer arithmetic in Cairo. Apply this broadly to Cairo code (including files like packages/token/src/erc721/extensions/erc721_consecutive.cairo); rely on language-provided overflow checks. If you need non-wrapping behavior, consider alternative logic or explicit checks only for exceptional cases, but generally avoid manual overflow guards for normal operations.

Applied to files:

  • packages/interfaces/src/token/erc1155.cairo
  • packages/token/src/erc1155/extensions/erc1155_supply.cairo
  • packages/token/src/erc1155/extensions.cairo
  • packages/test_common/src/mocks/erc1155.cairo
  • packages/token/src/tests/erc1155/test_erc1155_supply.cairo
  • packages/token/src/tests/erc1155.cairo
  • packages/token/src/erc1155.cairo
📚 Learning: 2026-01-13T11:48:56.063Z
Learnt from: ericnordelo
Repo: OpenZeppelin/cairo-contracts PR: 1630
File: packages/test_common/src/mocks/erc721.cairo:363-409
Timestamp: 2026-01-13T11:48:56.063Z
Learning: In Cairo contracts using the ERC721ConsecutiveComponent with the component! macro, the ERC721OwnerOfDefaultImpl import is not needed because ConsecutiveExtensionERC721OwnerOfTraitImpl is automatically used to provide custom owner_of logic for consecutive/batched tokens. This is different from regular ERC721 mocks that require the explicit ERC721OwnerOfDefaultImpl import.

Applied to files:

  • packages/token/src/erc1155/extensions/erc1155_supply.cairo
  • packages/token/src/erc1155.cairo
📚 Learning: 2026-01-13T11:48:47.957Z
Learnt from: ericnordelo
Repo: OpenZeppelin/cairo-contracts PR: 1630
File: packages/test_common/src/mocks/erc721.cairo:363-409
Timestamp: 2026-01-13T11:48:47.957Z
Learning: When using ERC721ConsecutiveComponent with the component! macro in Cairo contracts, you do not need to import ERC721OwnerOfDefaultImpl in mocks under packages/test_common/src/mocks. The ConsecutiveExtensionERC721OwnerOfTraitImpl automatically provides the custom owner_of logic for consecutive/batched tokens, unlike regular ERC721 mocks that require the explicit ERC721OwnerOfDefaultImpl import. Apply this guidance to all Cairo mocks in the mocks directory that utilize ERC721ConsecutiveComponent.

Applied to files:

  • packages/test_common/src/mocks/erc1155.cairo
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: comment-benchmark-diff
  • GitHub Check: Lint and test macros
  • GitHub Check: Lint and test Cairo
🔇 Additional comments (17)
packages/testing/CHANGELOG.md (1)

10-12: LGTM!

The changelog entry follows the established format and correctly documents the snforge version bump.

packages/token/src/erc1155/extensions.cairo (1)

1-2: LGTM!

The module declaration and re-export follow the established pattern for extension components in this codebase.

Scarb.toml (1)

30-31: Version numbers appear to exceed officially released versions and require clarification.

The Scarb.toml specifies Cairo 2.15.0 and Scarb 2.15.1, which are ahead of the latest officially released versions (Cairo 2.13.2 and Scarb 2.13.1 as of January 2026). Verify whether these are:

  • Pre-release/development versions intentionally targeted
  • Versions with documented compatibility guarantees
  • Or if versions should be aligned with official releases

This needs to be confirmed before merging, as using non-standard versions could introduce stability or compatibility risks.

Likely an incorrect or invalid review comment.

packages/token/src/tests/erc1155.cairo (1)

3-3: LGTM!

Test module declaration follows the existing pattern.

packages/token/src/erc1155.cairo (1)

3-3: LGTM!

The extensions module and ERC1155SupplyComponent re-export follow the established pattern for token extensions (similar to ERC721 extensions structure).

Also applies to: 7-7

packages/token/src/tests/erc1155/test_erc1155_supply.cairo (3)

1-12: LGTM!

Imports are correctly structured. The ERC1155InternalImpl alias import (line 11) follows the Cairo pattern where trait imports enable method resolution even if the alias isn't textually used. Based on learnings.


18-32: LGTM!

Setup function correctly initializes the contract state and batch mints tokens, which properly triggers the after_update hook for supply tracking.


38-272: Excellent test coverage!

The tests comprehensively cover all supply-tracking scenarios:

  • Zero state verification
  • Single and batch mint/burn operations
  • Transfer operations (verifying supply unchanged)
  • Partial burns
  • Mixed operations
  • exists() semantics for never-minted and fully-burned tokens

The test logic aligns with the expected behavior of the ERC1155Supply extension per the Solidity reference implementation.

packages/macros/src/attribute/with_components/components.rs (3)

22-22: LGTM!

Enum variant correctly placed in alphabetical order after ERC1155.


61-61: LGTM!

String parsing for the new component variant is correctly implemented.


227-235: LGTM!

The ComponentInfo configuration is correct:

  • has_initializer: false is appropriate since supply tracking doesn't require initialization
  • internal_impls: vec!["InternalImpl"] correctly exposes the after_update hook
  • Path aligns with the actual module structure in openzeppelin_token::erc1155::extensions
packages/test_common/src/mocks/erc1155.cairo (1)

152-200: LGTM! Well-structured mock for ERC1155Supply extension.

The mock correctly wires the after_update hook to the ERC1155SupplyComponent for supply tracking. The pattern of only implementing the needed hook (after_update) while relying on defaults for before_update follows the extension pattern seen throughout the codebase, consistent with how other hooks are implemented (e.g., ERC20VotesHooksImpl, ERC721VotesHooksImpl).

packages/token/src/erc1155/extensions/erc1155_supply.cairo (5)

5-16: Clear and appropriate documentation.

The warnings about upgrade constraints and hook requirements are well-articulated, which is essential for ensuring correct integration of this extension.


17-28: Imports are appropriate and necessary.

All imported items are utilized in the implementation.


29-33: Storage structure is well-designed.

The dual tracking approach (per-token and aggregate) aligns with the Solidity reference implementation and provides efficient access patterns for both query types.


35-57: Public interface implementation is correct.

The read-only functions are straightforward and correctly implemented. The generic constraints properly enforce that this component can only be used with contracts implementing ERC1155Component.


75-105: Supply tracking logic is correctly implemented.

The implementation properly handles:

  • Mints (from=zero): Increases per-token and aggregate supply
  • Burns (to=zero): Decreases per-token and aggregate supply
  • Transfers (both non-zero): No supply change (neither block executes)

The optimization of accumulating values before a single aggregate write is a good pattern. Based on learnings, Cairo's built-in overflow/underflow protection will correctly revert if attempting to burn more tokens than exist.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread CHANGELOG.md
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.74%. Comparing base (6364709) to head (f2ca473).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../token/src/erc1155/extensions/erc1155_supply.cairo 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1632      +/-   ##
==========================================
+ Coverage   93.10%   93.74%   +0.63%     
==========================================
  Files          87       88       +1     
  Lines        2364     2190     -174     
==========================================
- Hits         2201     2053     -148     
+ Misses        163      137      -26     
Files with missing lines Coverage Δ
packages/interfaces/src/token/erc1155.cairo 100.00% <ø> (ø)
.../token/src/erc1155/extensions/erc1155_supply.cairo 94.44% <94.44%> (ø)

... and 28 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6364709...f2ca473. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@immrsd immrsd left a comment

Choose a reason for hiding this comment

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

LGTM

has_initializer: false,
has_immutable_config: false,
internal_impls: vec!["InternalImpl"],
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may want to add an additional check in case ERC1155Supply is used (or any other component that has internal function that must be called in hooks), a check that ensures that the calls to these internal functions do exist in the implementing contract

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are right. I'm going to address that in a separate PR where I also plan to enable the other components in macros (like the wrappers). I haven't gone deep into that because there's also an issue with the span matching to address in the macro implementation,

@ericnordelo ericnordelo merged commit f8fd771 into main Jan 16, 2026
13 checks passed
@ericnordelo ericnordelo deleted the feat/add-erc1155-supply-extension-#1574 branch January 16, 2026 11:48
This was referenced Jan 26, 2026
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.

[Feature]: Add ERC-1155 Supply Extension

2 participants