Repository navigation
Conversation
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
|
Important Review skippedToo 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.
|
andrew-fleming
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
| # 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. |
There was a problem hiding this comment.
Same thing here. "Sum of the per-target caps..." works just as well, no?
There was a problem hiding this comment.
Ditto with the rest of this file. I think the amount of diffs below bolster my point in this file
| 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 |
There was a problem hiding this comment.
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
| * `Caller`, which the composing contract gets from an authenticator and | ||
| * passes to every module it drives. How the caller is authenticated is the |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Ditto with the same docblocks in the other mods if you agree
| @@ -71,7 +71,7 @@ export const MultiTokenWitnesses = <L>(): IMultiTokenWitnesses< | |||
| L, | |||
| MultiTokenPrivateState | |||
| > => ({ | |||
| wit_MultiTokenSK( | |||
| wit_AuthPrfAddrSK( | |||
There was a problem hiding this comment.
Not a now thing, but we can abstract a lot of the witness files away since the logic + wit is identical
| 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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| export circuit isAllowed(account: Account): Boolean { | ||
| const canonAcct = Utils_canonicalize<Bytes<32>, ContractAddress>(account); | ||
| return _allowed.member(disclose(canonAcct)); |
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
Types of changes
What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an
xin the boxes that applyFixes #801
Fixes #1233
The contract authenticates the caller once per circuit and passes the same
Callerto 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, thenaccess/Ownable.compact. The other six modules follow the same pattern.Not visible in the diff:
@constraintson a circuit that takes aCallerexcludes authentication, which carries its own line onAuthPrfAddr.authenticate.README.mdstates the rule.accountis a new live target with its own job pair. It needs alive-tests:accountlabel.PR Checklist
## Unreleased, or asked a maintainer to add theskip-changeloglabel because nothing user-facing changed. See CONTRIBUTING.md.Further comments