Skip to content

feat!: authenticate the caller once and pass it to modules - #1243

Open
0xisk wants to merge 3 commits into
mainfrom
feat/caller-authentication
Open

0xisk wants to merge 3 commits into
mainfrom
feat/caller-authentication

Conversation

@0xisk

@0xisk 0xisk commented Nov 14, 2026

Copy link
Copy Markdown
Member

Types of changes

What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Fixes #801
Fixes #1233

The contract authenticates the caller once per circuit and passes the same Caller to every module it drives. Before, each module read its own key witness, so one circuit could pass an ownership check with one key and move funds for another.

Start with crypto/authentication/interfaces/IAuthenticator.compact, then access/Ownable.compact. The other six modules follow the same pattern.

Not visible in the diff:

  • Every stored account id changes: the authenticator hashes the key under a tag and a per-deployment salt. Fresh deploys only.
  • @constraints on a circuit that takes a Caller excludes authentication, which carries its own line on AuthPrfAddr.authenticate. README.md states the rule.
  • The note token's privacy spec gets a 60 s timeout on its generated-input cases, which time out at 5 s in a full parallel run.
  • account is a new live target with its own job pair. It needs a live-tests:account label.

PR Checklist

  • I have read the Contributing Guide
  • I have added tests that prove my fix is effective or that my feature works. See GUIDELINES.md#testing for more information.
  • I have added documentation for new methods or changes to existing method behavior. See GUIDELINES.md#documentation for more information.
  • I have added a CHANGELOG entry under ## Unreleased, or asked a maintainer to add the skip-changelog label because nothing user-facing changed. See CONTRIBUTING.md.
  • CI Workflows Are Passing

Further comments

Modules no longer derive the caller from a witness of their own. The
contract authenticates once per circuit and passes the same Caller to
every module it drives, so a gate and an effect act for one identity.

* New: account/Account, crypto/prf (PrfCore, PrfAddr) and
  crypto/authentication (IAuthenticator, AuthPrfAddr).
* Ownable, AccessControl, ShieldedAccessControl, FungibleToken,
  NonFungibleToken, MultiToken and ConfidentialFungibleToken take a
  Caller. Allowlist and Blocklist store an Account.
* Ownable.assertOnlyOwner rejects the zero account.

Refs: #801, #1233
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Too many files!

This PR contains 113 files, which is 13 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 45437a3 and 7fc8129.

Files selected for processing: 113

  • .github/workflows/live.yml
  • ARCHITECTURE.md
  • CHANGELOG.md
  • GUIDELINES.md
  • README.md
  • TESTING.md
  • compact.toml
  • contracts/package.json
  • contracts/src/access/AccessControl.compact
  • contracts/src/access/Ownable.compact
  • contracts/src/access/ShieldedAccessControl.compact
  • contracts/src/access/ZOwnablePK.compact
  • contracts/src/access/test/AccessControl.test.ts
  • contracts/src/access/test/Ownable.caller.test.ts
  • contracts/src/access/test/Ownable.test.ts
  • contracts/src/access/test/ShieldedAccessControl.test.ts
  • contracts/src/access/test/ZOwnablePK.test.ts
  • contracts/src/access/test/mocks/MockAccessControl.compact
  • contracts/src/access/test/mocks/MockOwnable.compact
  • contracts/src/access/test/mocks/MockOwnableCaller.compact
  • contracts/src/access/test/mocks/MockShieldedAccessControl.compact
  • contracts/src/access/test/simulators/OwnableCallerSimulator.ts
  • contracts/src/access/test/simulators/ShieldedAccessControlSimulator.ts
  • contracts/src/access/test/witnesses/AccessControlWitnesses.test.ts
  • contracts/src/access/test/witnesses/AccessControlWitnesses.ts
  • contracts/src/access/test/witnesses/OwnableWitnesses.test.ts
  • contracts/src/access/test/witnesses/OwnableWitnesses.ts
  • contracts/src/access/test/witnesses/ShieldedAccessControlWitnesses.ts
  • contracts/src/account/Account.compact
  • contracts/src/account/extensions/AccountCommitment.compact
  • contracts/src/account/extensions/test/AccountCommitment.compatibility.test.ts
  • contracts/src/account/extensions/test/AccountCommitment.unit.test.ts
  • contracts/src/account/extensions/test/mocks/MockAccountCommitment.compact
  • contracts/src/account/extensions/test/simulators/AccountCommitmentSimulator.ts
  • contracts/src/account/test/Account.property.test.ts
  • contracts/src/account/test/Account.unit.test.ts
  • contracts/src/account/test/mocks/MockAccount.compact
  • contracts/src/account/test/simulators/AccountSimulator.ts
  • contracts/src/crypto/ElGamal.compact
  • contracts/src/crypto/authentication/AuthPrfAddr.compact
  • contracts/src/crypto/authentication/interfaces/IAuthenticator.compact
  • contracts/src/crypto/authentication/test/AuthPrfAddr.compatibility.test.ts
  • contracts/src/crypto/authentication/test/AuthPrfAddr.property.test.ts
  • contracts/src/crypto/authentication/test/AuthPrfAddr.unit.test.ts
  • contracts/src/crypto/authentication/test/mocks/MockAuthPrfAddr.compact
  • contracts/src/crypto/authentication/test/simulators/AuthPrfAddrSimulator.ts
  • contracts/src/crypto/authentication/test/witnesses/AuthPrfAddrWitnesses.test.ts
  • contracts/src/crypto/authentication/test/witnesses/AuthPrfAddrWitnesses.ts
  • contracts/src/crypto/prf/PrfAddr.compact
  • contracts/src/crypto/prf/PrfCore.compact
  • contracts/src/crypto/prf/test/PrfAddr.compatibility.test.ts
  • contracts/src/crypto/prf/test/PrfAddr.property.test.ts
  • contracts/src/crypto/prf/test/PrfAddr.unit.test.ts
  • contracts/src/crypto/prf/test/PrfCore.compatibility.test.ts
  • contracts/src/crypto/prf/test/PrfCore.property.test.ts
  • contracts/src/crypto/prf/test/PrfCore.unit.test.ts
  • contracts/src/crypto/prf/test/mocks/MockPrfAddr.compact
  • contracts/src/crypto/prf/test/mocks/MockPrfCore.compact
  • contracts/src/crypto/prf/test/simulators/PrfAddrSimulator.ts
  • contracts/src/crypto/prf/test/simulators/PrfCoreSimulator.ts
  • contracts/src/crypto/randomness/RandBlinding.compact
  • contracts/src/crypto/randomness/test/RandBlinding.property.test.ts
  • contracts/src/crypto/randomness/test/RandBlinding.unit.test.ts
  • contracts/src/crypto/randomness/test/mocks/MockRandBlinding.compact
  • contracts/src/crypto/randomness/test/simulators/RandBlindingSimulator.ts
  • contracts/src/crypto/randomness/test/witnesses/RandBlindingWitnesses.test.ts
  • contracts/src/crypto/randomness/test/witnesses/RandBlindingWitnesses.ts
  • contracts/src/security/Allowlist.compact
  • contracts/src/security/Blocklist.compact
  • contracts/src/security/test/Allowlist.test.ts
  • contracts/src/security/test/Blocklist.test.ts
  • contracts/src/security/test/mocks/MockAllowlist.compact
  • contracts/src/security/test/mocks/MockBlocklist.compact
  • contracts/src/security/test/simulators/AllowlistSimulator.ts
  • contracts/src/security/test/simulators/BlocklistSimulator.ts
  • contracts/src/token/ConfidentialFungibleToken.compact
  • contracts/src/token/FungibleToken.compact
  • contracts/src/token/MultiToken.compact
  • contracts/src/token/NonFungibleToken.compact
  • contracts/src/token/test/ConfidentialFungibleToken.test.ts
  • contracts/src/token/test/ConfidentialNoteFungibleToken.privacy.test.ts
  • contracts/src/token/test/FungibleToken.test.ts
  • contracts/src/token/test/MultiToken.test.ts
  • contracts/src/token/test/mocks/MockConfidentialFungibleToken.compact
  • contracts/src/token/test/mocks/MockConfidentialFungibleTokenRegister.compact
  • contracts/src/token/test/mocks/MockFungibleToken.compact
  • contracts/src/token/test/mocks/MockMultiToken.compact
  • contracts/src/token/test/mocks/MockNonFungibleToken.compact
  • contracts/src/token/test/nonFungibleToken.test.ts
  • contracts/src/token/test/simulators/ConfidentialFungibleTokenSimulator.ts
  • contracts/src/token/test/witnesses/ConfidentialFungibleTokenWitnesses.test.ts
  • contracts/src/token/test/witnesses/ConfidentialFungibleTokenWitnesses.ts
  • contracts/src/token/test/witnesses/FungibleTokenWitnesses.test.ts
  • contracts/src/token/test/witnesses/FungibleTokenWitnesses.ts
  • contracts/src/token/test/witnesses/MultiTokenWitnesses.test.ts
  • contracts/src/token/test/witnesses/MultiTokenWitnesses.ts
  • contracts/src/token/test/witnesses/NonFungibleTokenWitnesses.test.ts
  • contracts/src/token/test/witnesses/NonFungibleTokenWitnesses.ts
  • 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
  • contracts/test-utils/fixtures/elgamal.ts
  • contracts/test/integration/_mocks/ComposedConfidentialFungibleTokenPublicSupply.compact
  • contracts/test/integration/_mocks/SharedCallerShieldedRoles.compact
  • contracts/test/integration/fixtures/confidentialFungibleTokenPublicSupply.ts
  • contracts/test/integration/fixtures/sharedCallerShieldedRoles.ts
  • contracts/test/integration/specs/confidentialFungibleToken.spec.ts
  • contracts/test/integration/specs/confidentialFungibleToken/metadata.spec.ts
  • contracts/test/integration/specs/shieldedRoleHolderPrivacy.spec.ts
  • llms.txt
  • package.json
  • turbo.json

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

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@0xisk 0xisk added the live-tests:all Run the full live suite on this PR label Nov 14, 2026
@0xisk
0xisk added this pull request to stack #1245 November 14, 2026 03:21
@0xisk
0xisk marked this pull request as ready for review November 14, 2026 21:08
@0xisk
0xisk requested review from a team as code owners November 14, 2026 21:08

@andrew-fleming andrew-fleming left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great initiative on this, @0xisk! Forgive the millions of comments, it's a big PR :)

# Two consequences of that literalness:
# - the steps live in reusable workflows (`live-compile.yml`, `live-suite.yml`)
# so the pairs below stay declarations rather than 16 copies of a job;
# so the pairs below stay declarations rather than 18 copies of a job;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Whether the real value is 18 or 180,000, what value does stating the number of copies provide? I'd suggest "...rather than multiple copies of a job"

# Deny by default, at the workflow level rather than per job.
#
# The 16 job pairs below are `uses:` declarations with no steps of their own, and
# The 18 job pairs below are `uses:` declarations with no steps of their own, and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment/suggestion here. Otherwise, whenever there's a change to the job pairs, we'll have to update this value for doc correctness

# a job without a `permissions:` block inherits whatever the repository's default
# GITHUB_TOKEN scope happens to be — which CodeQL flags, once per job. Setting the
# floor here covers all of them in one place instead of adding 16 identical blocks
# floor here covers all of them in one place instead of adding 18 identical blocks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

Comment on lines -206 to 208
# Sum of the 8 per-target caps bounds the fan-out; Actions has no global
# Sum of the 9 per-target caps bounds the fan-out; Actions has no global
# one. The org shares 60 concurrent jobs and an uncapped run peaked at 58.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing here. "Sum of the per-target caps..." works just as well, no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto with the rest of this file. I think the amount of diffs below bolster my point in this file

Comment on lines +221 to +243
compile-account:
name: compile-account
needs: plan
if: ${{ contains(fromJSON(needs.plan.outputs.targets), 'account') }}
uses: ./.github/workflows/live-compile.yml
with:
target: account

live-account:
# The matrix value is in the name on purpose: a caller job with a fixed name
# renders every leg identically, so the spec under test has to appear here.
name: live-account · ${{ matrix.name }}
needs: [plan, compile-account]
# The empty-legs guard is belt and braces: this target's compile is
# already skipped when the run's scope drops it, and an empty `include` is
# a hard matrix error rather than an empty job list.
if: >-
${{ !cancelled()
&& needs.compile-account.result == 'success'
&& needs.plan.outputs.legs-account != '[]' }}
strategy:
fail-fast: false # one spec file failing should not cancel the others
# Sum of the 9 per-target caps bounds the fan-out; Actions has no global

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, there's a ton of repeating logic in the yml. I imagine this could be greatly simplified with a script. Out of scope, just thinking out loud. This PR is big enough

Comment on lines +11 to +12
* `Caller`, which the composing contract gets from an authenticator and
* passes to every module it drives. How the caller is authenticated is the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is a bit too overview-y. I'd just make it about this module. We don't need to comment about what authenticator does to the other modules (if this were c/p, this could be dangerously interpreted)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto with the same docblocks in the other mods if you agree

Comment on lines 19 to +74
@@ -71,7 +71,7 @@ export const MultiTokenWitnesses = <L>(): IMultiTokenWitnesses<
L,
MultiTokenPrivateState
> => ({
wit_MultiTokenSK(
wit_AuthPrfAddrSK(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a now thing, but we can abstract a lot of the witness files away since the logic + wit is identical

Comment on lines -358 to +340
export circuit approve(to: Either<Bytes<32>, ContractAddress>, tokenId: Uint<128>): [] {
export circuit approve(
caller: Caller,
to: Account,
tokenId: Uint<128>
): [] {
assertInitialized();
const auth = left<Bytes<32>, ContractAddress>(_computeAccountId());
const auth = caller.account;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Soooo I think this introduces a potential vulnerability. Before this change, the auth was computed inside the mod and could not be zero. Now, we're passing caller.account unchecked so tokens can be moved or approved w/o the owner's consent

To do this, it would need a zero Caller and the proposed auth currently can't produce one if I understand correctly. I think we should reject zero in approve, transferFrom, and _unsafeTransferFrom to eliminate the risk

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As a side note from this, it might be a good idea to state in the Caller doc whether mods must validate or trust and apply it throughout for consistency. Fungible and MultiToken should get an explicit check as well so it looks intentional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we're calling this "Core", should we mention that it's not meant to be directly imported by users? Or is that not the intention? bc then we're conflicting with the "core" convention

Comment on lines +63 to +65
export circuit isAllowed(account: Account): Boolean {
const canonAcct = Utils_canonicalize<Bytes<32>, ContractAddress>(account);
return _allowed.member(disclose(canonAcct));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

ShieldedAccessControl used the caller's account as the holder id. A
contract that also drives a transparent module publishes that account,
so a role nullifier could be recomputed from public state. The module
now commits to the account under a secret blinding factor and uses the
commitment as the holder id. One Caller is still shared.

* access: every circuit that proves a role takes a Blinding after the
  caller. An admin grants by account commitment.
* New: account/extensions/AccountCommitment and
  crypto/randomness/RandBlinding.
* A role check costs about 3,840 more rows: assertOnlyRole and
  renounceRole move from k=14 to k=15.

Refs: #1243

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

live-tests:all Run the full live suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pseudorandom function modules (crypto/prf) L-03: Inefficient Module Composability Can Lead To Confused Deputy Behavior

2 participants