Skip to content

Consolidate repeated circuits - #612

Merged
0xisk merged 3 commits into
OpenZeppelin:mainfrom
andrew-fleming:consolidate-repeated-circuits
Jun 18, 2026
Merged

Consolidate repeated circuits#612
0xisk merged 3 commits into
OpenZeppelin:mainfrom
andrew-fleming:consolidate-repeated-circuits

Conversation

@andrew-fleming

@andrew-fleming andrew-fleming commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The tracked issues for this are not really clean bc we'd be putting in the same circuits into Utils for each PR if they were separate. Bundling into one PR seems appropriate

Summary by CodeRabbit

  • Refactor

    • Consolidated account identifier computation and zero-value validation into centralized utility module.
    • Removed duplicate ZERO() and computeAccountId() implementations from individual token and access control modules.
    • Updated internal references to use shared utility functions across all modules.
  • Tests

    • Removed test coverage for previously consolidated utility functions from individual module test suites.
    • Added comprehensive test coverage for new centralized utility functions.

@andrew-fleming
andrew-fleming requested review from a team as code owners June 18, 2026 05:12
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 373b898d-c96c-448a-a4f6-8f14408d3a45

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Three shared utility circuits (zeroAccount, isTargetZero, computeAccountId) are added to Utils.compact. All five contract modules (AccessControl, Ownable, FungibleToken, MultiToken, NonFungibleToken) are updated to call these shared helpers, removing their duplicated local implementations and the previously exported ZERO() and computeAccountId circuits. Mocks, simulators, and tests are updated to match.

Changes

Utility Centralization and Callsite Migration

Layer / File(s) Summary
New shared Utils circuits and tests
contracts/src/utils/Utils.compact, contracts/src/utils/test/mocks/MockUtils.compact, contracts/src/utils/test/simulators/UtilsSimulator.ts, contracts/src/utils/test/utils.test.ts
Utils.compact gains zeroAccount(), isTargetZero(), and computeAccountId(). MockUtils and UtilsSimulator expose them for test use. utils.test.ts adds persistentHash-based assertions for all three circuits.
Access module migration
contracts/src/access/AccessControl.compact, contracts/src/access/Ownable.compact, contracts/src/access/test/mocks/Mock*.compact, contracts/src/access/test/simulators/*Simulator.ts, contracts/src/access/test/*.test.ts
_computeAccountId in AccessControl and Ownable delegates to Utils_computeAccountId; initialize and _unsafeTransferOwnership in Ownable use Utils_isTargetZero. Per-contract computeAccountId exported circuits removed from mocks and simulators; matching test suites deleted.
Token module migration
contracts/src/token/FungibleToken.compact, contracts/src/token/MultiToken.compact, contracts/src/token/NonFungibleToken.compact, contracts/src/token/test/mocks/Mock*.compact, contracts/src/token/test/simulators/*Simulator.ts, contracts/src/token/test/*.test.ts
ZERO() exported circuit removed from all three token modules; all _isTargetZero, ZERO(), and computeAccountId call sites replaced with Utils_isTargetZero, Utils_zeroAccount, and Utils_computeAccountId across transfer/mint/burn/approve paths. ZERO() and computeAccountId wrappers removed from mocks and simulators; corresponding test suites deleted and comments updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • OpenZeppelin/compact-contracts#444: Introduced the witness-derived computeAccountId scheme in AccessControl that this PR now redirects to Utils_computeAccountId.
  • OpenZeppelin/compact-contracts#466: Introduced wit_OwnableSK-based account-id computation in Ownable that this PR now delegates to the shared Utils_computeAccountId.
  • OpenZeppelin/compact-contracts#468: Introduced wit_FungibleTokenSK-based computeAccountId and zero helpers in FungibleToken that this PR consolidates into the shared Utils_ namespace.

Suggested labels

enhancement

🐇 Hop, hop, hooray, the helpers are one!
No more copy-paste under each token's sun.
zeroAccount, isTargetZero — now shared with care,
computeAccountId lives in Utils, so fair.
The warren is tidy, the burrows aligned,
One source of truth for all rabbits to find! 🌿

🚥 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 PR title 'Consolidate repeated circuits' accurately summarizes the main objective: moving duplicated circuits (computeAccountId, ZERO/zeroAccount, isTargetZero) from individual modules into a shared Utils module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@0xisk 0xisk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@0xisk
0xisk merged commit 8d00d0e into OpenZeppelin:main Jun 18, 2026
7 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.

2 participants