@clearproof/contracts 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/README.md +1 -1
  2. package/artifacts/contracts/ComplianceRegistry.sol/ComplianceRegistry.json +220 -3
  3. package/artifacts/contracts/MockVerifier.sol/MockVerifier.json +2 -2
  4. package/artifacts/contracts/PilotCurrentRegistry.sol/PilotCurrentRegistry.json +363 -4
  5. package/artifacts/contracts/PilotGroth16Verifier.sol/PilotGroth16Verifier.json +2 -2
  6. package/artifacts/contracts/PilotRootCheckpoint.sol/PilotRootCheckpoint.json +380 -3
  7. package/artifacts/contracts/SanctionsOracle.sol/SanctionsOracle.json +2 -2
  8. package/artifacts/contracts/SanctionsRootRelay.sol/SanctionsRootRelay.json +2 -2
  9. package/artifacts/contracts/VASPRegistry.sol/VASPRegistry.json +2 -2
  10. package/artifacts/contracts/VerifierRouter.sol/VerifierRouter.json +178 -3
  11. package/artifacts/contracts/generated/PilotSignalConstants.sol/PilotSignalConstants.json +10 -0
  12. package/artifacts/contracts/test/MockPilotVerifier.sol/MockPilotVerifier.json +95 -0
  13. package/contracts/ComplianceRegistry.sol +87 -7
  14. package/contracts/ISanctionsRootReceiver.sol +4 -0
  15. package/contracts/MockVerifier.sol +4 -0
  16. package/contracts/PilotCurrentRegistry.sol +52 -25
  17. package/contracts/PilotGroth16Verifier.sol +7 -5
  18. package/contracts/PilotRootCheckpoint.sol +50 -12
  19. package/contracts/SanctionsOracle.sol +4 -0
  20. package/contracts/SanctionsRootRelay.sol +4 -0
  21. package/contracts/VASPRegistry.sol +4 -0
  22. package/contracts/VerifierRouter.sol +111 -127
  23. package/contracts/generated/PilotSignalConstants.sol +33 -0
  24. package/contracts/test/MockPilotVerifier.sol +27 -0
  25. package/package.json +4 -3
@@ -0,0 +1,95 @@
1
+ {
2
+ "_format": "hh-sol-artifact-1",
3
+ "contractName": "MockPilotVerifier",
4
+ "sourceName": "contracts/test/MockPilotVerifier.sol",
5
+ "abi": [
6
+ {
7
+ "inputs": [
8
+ {
9
+ "internalType": "bytes32",
10
+ "name": "manifestDigest",
11
+ "type": "bytes32"
12
+ }
13
+ ],
14
+ "stateMutability": "nonpayable",
15
+ "type": "constructor"
16
+ },
17
+ {
18
+ "inputs": [],
19
+ "name": "artifactManifestDigest",
20
+ "outputs": [
21
+ {
22
+ "internalType": "bytes32",
23
+ "name": "",
24
+ "type": "bytes32"
25
+ }
26
+ ],
27
+ "stateMutability": "view",
28
+ "type": "function"
29
+ },
30
+ {
31
+ "inputs": [],
32
+ "name": "result",
33
+ "outputs": [
34
+ {
35
+ "internalType": "bool",
36
+ "name": "",
37
+ "type": "bool"
38
+ }
39
+ ],
40
+ "stateMutability": "view",
41
+ "type": "function"
42
+ },
43
+ {
44
+ "inputs": [
45
+ {
46
+ "internalType": "bool",
47
+ "name": "value",
48
+ "type": "bool"
49
+ }
50
+ ],
51
+ "name": "setResult",
52
+ "outputs": [],
53
+ "stateMutability": "nonpayable",
54
+ "type": "function"
55
+ },
56
+ {
57
+ "inputs": [
58
+ {
59
+ "internalType": "uint256[2]",
60
+ "name": "",
61
+ "type": "uint256[2]"
62
+ },
63
+ {
64
+ "internalType": "uint256[2][2]",
65
+ "name": "",
66
+ "type": "uint256[2][2]"
67
+ },
68
+ {
69
+ "internalType": "uint256[2]",
70
+ "name": "",
71
+ "type": "uint256[2]"
72
+ },
73
+ {
74
+ "internalType": "uint256[8]",
75
+ "name": "",
76
+ "type": "uint256[8]"
77
+ }
78
+ ],
79
+ "name": "verifyProof",
80
+ "outputs": [
81
+ {
82
+ "internalType": "bool",
83
+ "name": "",
84
+ "type": "bool"
85
+ }
86
+ ],
87
+ "stateMutability": "view",
88
+ "type": "function"
89
+ }
90
+ ],
91
+ "bytecode": "0x60a06040526000805460ff1916600117905534801561001d57600080fd5b5060405161023a38038061023a83398101604081905261003c91610044565b60805261005d565b60006020828403121561005657600080fd5b5051919050565b6080516101c36100776000396000607801526101c36000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80636537214714610051578063940a72ec14610073578063c9219a7a146100a8578063f4b4dc2e146100c4575b600080fd5b60005461005e9060ff1681565b60405190151581526020015b60405180910390f35b61009a7f000000000000000000000000000000000000000000000000000000000000000081565b60405190815260200161006a565b61005e6100b63660046100fe565b60005460ff16949350505050565b6100e56100d2366004610164565b6000805460ff1916911515919091179055565b005b80604081018310156100f857600080fd5b92915050565b60008060008061020080868803121561011657600080fd5b61012087876100e7565b945060c086018781111561013357600080fd5b60408701945061014388826100e7565b93505086818701111561015557600080fd5b50929591945092610100019150565b60006020828403121561017657600080fd5b8135801515811461018657600080fd5b939250505056fea26469706673582212200aaef75e0f4eabc71ff71d7151298a29c24b399ade598fbcc4c68ab62377293464736f6c63430008180033",
92
+ "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80636537214714610051578063940a72ec14610073578063c9219a7a146100a8578063f4b4dc2e146100c4575b600080fd5b60005461005e9060ff1681565b60405190151581526020015b60405180910390f35b61009a7f000000000000000000000000000000000000000000000000000000000000000081565b60405190815260200161006a565b61005e6100b63660046100fe565b60005460ff16949350505050565b6100e56100d2366004610164565b6000805460ff1916911515919091179055565b005b80604081018310156100f857600080fd5b92915050565b60008060008061020080868803121561011657600080fd5b61012087876100e7565b945060c086018781111561013357600080fd5b60408701945061014388826100e7565b93505086818701111561015557600080fd5b50929591945092610100019150565b60006020828403121561017657600080fd5b8135801515811461018657600080fd5b939250505056fea26469706673582212200aaef75e0f4eabc71ff71d7151298a29c24b399ade598fbcc4c68ab62377293464736f6c63430008180033",
93
+ "linkReferences": {},
94
+ "deployedLinkReferences": {}
95
+ }
@@ -1,6 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // clearproof — ZK-proven compliance without transmitting PII
3
3
  // https://clearproof.world | https://docs.clearproof.world
4
+ // LEGACY: 16-signal `compliance.circom` demo/parity path, not pilot-transfer-v3.
5
+ // Never treat proofs, roots or records accepted here as current pilot authorization.
6
+ // Kept at this path for the published @clearproof/contracts artifact layout; see
7
+ // packages/contracts/AGENTS.md ("Legacy contracts") and docs/internal/CIRCUIT_SIGNALS.md.
4
8
  pragma solidity ^0.8.24;
5
9
 
6
10
  import "@openzeppelin/contracts/access/AccessControl.sol";
@@ -35,6 +39,10 @@ contract ComplianceRegistry is AccessControl, Pausable {
35
39
  error ThresholdMismatch();
36
40
  error ThresholdsNotOrdered();
37
41
  error VerifierSelectorNotSet();
42
+ error VerifierUnavailable();
43
+ error SelectionAlreadyPending();
44
+ error SelectionNotReady();
45
+ error SelectorGraceExpired();
38
46
 
39
47
  bytes32 public constant REVOKER_ROLE = keccak256("REVOKER_ROLE");
40
48
  bytes32 public constant THRESHOLD_ADMIN_ROLE = keccak256("THRESHOLD_ADMIN_ROLE");
@@ -59,7 +67,15 @@ contract ComplianceRegistry is AccessControl, Pausable {
59
67
  event JurisdictionThresholdsSet(uint16 indexed jurisdictionCode, uint64 tier2, uint64 tier3, uint64 tier4);
60
68
  event JurisdictionCodeMismatch(bytes32 indexed transferId, uint256 claimedJurisdictionCode, uint256 expectedJurisdictionCode);
61
69
 
62
- VerifierRouter public verifierRouter;
70
+ VerifierRouter public immutable verifierRouter;
71
+ uint256 public immutable verifierSelectionDelay;
72
+ bytes32 public pendingVerifierSelector;
73
+ uint256 public verifierSelectionAfter;
74
+ mapping(bytes32 => uint256) public previousSelectorUntil;
75
+ mapping(bytes32 => uint256) public previousSelectorCutoff;
76
+ event VerifierSelectionScheduled(bytes32 indexed selector, uint256 executeAfter);
77
+ event VerifierSelectionCancelled(bytes32 indexed selector);
78
+ event VerifierSelectionActivated(bytes32 indexed previousSelector, bytes32 indexed selector, uint256 previousUntil);
63
79
  bytes32 public verifierSelector;
64
80
  VASPRegistry public immutable vaspRegistry;
65
81
  SanctionsOracle public immutable sanctionsOracle;
@@ -102,6 +118,7 @@ contract ComplianceRegistry is AccessControl, Pausable {
102
118
  if (_sanctionsOracle == address(0)) revert ZeroOracle();
103
119
 
104
120
  verifierRouter = VerifierRouter(_verifierRouter);
121
+ verifierSelectionDelay = verifierRouter.minTimelock();
105
122
  verifierSelector = _verifierSelector;
106
123
  vaspRegistry = VASPRegistry(_vaspRegistry);
107
124
  sanctionsOracle = SanctionsOracle(_sanctionsOracle);
@@ -115,10 +132,39 @@ contract ComplianceRegistry is AccessControl, Pausable {
115
132
  _setJurisdictionThresholds(DEFAULT_JURISDICTION_KEY, defaultTier2, defaultTier3, defaultTier4);
116
133
  }
117
134
 
118
- /// @notice Set the verifier selector to use
119
- /// @param _verifierSelector The selector for the verifier to use
120
- function setVerifierSelector(bytes32 _verifierSelector) external onlyRole(DEFAULT_ADMIN_ROLE) {
121
- verifierSelector = _verifierSelector;
135
+ /// @notice Schedule a new default. Existing callers must separately activate it.
136
+ function setVerifierSelector(bytes32 selector) external onlyRole(DEFAULT_ADMIN_ROLE) {
137
+ if (pendingVerifierSelector != bytes32(0)) revert SelectionAlreadyPending();
138
+ if (selector == bytes32(0)) revert VerifierSelectorNotSet();
139
+ if (selector == verifierSelector || !verifierRouter.isVerifierActive(selector)) revert VerifierUnavailable();
140
+ pendingVerifierSelector = selector;
141
+ // Capture the greater of the reviewed deployment delay and current delay.
142
+ uint256 delay = verifierRouter.minTimelock();
143
+ if (delay < verifierSelectionDelay) delay = verifierSelectionDelay;
144
+ verifierSelectionAfter = block.timestamp + delay;
145
+ emit VerifierSelectionScheduled(selector, verifierSelectionAfter);
146
+ }
147
+
148
+ function cancelVerifierSelection() external onlyRole(DEFAULT_ADMIN_ROLE) {
149
+ if (pendingVerifierSelector == bytes32(0)) revert VerifierSelectorNotSet();
150
+ emit VerifierSelectionCancelled(pendingVerifierSelector);
151
+ delete pendingVerifierSelector;
152
+ delete verifierSelectionAfter;
153
+ }
154
+
155
+ function activateVerifierSelector() external onlyRole(DEFAULT_ADMIN_ROLE) {
156
+ bytes32 selector = pendingVerifierSelector;
157
+ if (selector == bytes32(0)) revert VerifierSelectorNotSet();
158
+ if (block.timestamp < verifierSelectionAfter) revert SelectionNotReady();
159
+ if (!verifierRouter.isVerifierActive(selector)) revert VerifierUnavailable();
160
+ bytes32 previous = verifierSelector;
161
+ uint256 until = block.timestamp + verifierRouter.RETIREMENT_GRACE();
162
+ previousSelectorUntil[previous] = until;
163
+ previousSelectorCutoff[previous] = block.timestamp;
164
+ verifierSelector = selector;
165
+ delete pendingVerifierSelector;
166
+ delete verifierSelectionAfter;
167
+ emit VerifierSelectionActivated(previous, selector, until);
122
168
  }
123
169
 
124
170
  /// @notice Register or update the thresholds accepted for a jurisdiction.
@@ -185,6 +231,38 @@ contract ComplianceRegistry is AccessControl, Pausable {
185
231
  uint[16] calldata _pubSignals,
186
232
  bytes32 vaspDidHash
187
233
  ) external whenNotPaused returns (bool) {
234
+ return _verifyAndRecord(verifierSelector, transferId, _pA, _pB, _pC, _pubSignals, vaspDidHash);
235
+ }
236
+
237
+ /// @notice Submit an in-flight proof against a former default within grace.
238
+ /// Domain, roots, thresholds, sender, revocation and nullifiers stay identical.
239
+ function verifyAndRecordWithSelector(
240
+ bytes32 selector,
241
+ bytes32 transferId,
242
+ uint[2] calldata _pA,
243
+ uint[2][2] calldata _pB,
244
+ uint[2] calldata _pC,
245
+ uint[16] calldata _pubSignals,
246
+ bytes32 vaspDidHash
247
+ ) external whenNotPaused returns (bool) {
248
+ if (selector != verifierSelector) {
249
+ uint256 until = previousSelectorUntil[selector];
250
+ if (until == 0 || block.timestamp > until || _pubSignals[5] > previousSelectorCutoff[selector]) {
251
+ revert SelectorGraceExpired();
252
+ }
253
+ }
254
+ return _verifyAndRecord(selector, transferId, _pA, _pB, _pC, _pubSignals, vaspDidHash);
255
+ }
256
+
257
+ function _verifyAndRecord(
258
+ bytes32 selector,
259
+ bytes32 transferId,
260
+ uint[2] calldata _pA,
261
+ uint[2][2] calldata _pB,
262
+ uint[2] calldata _pC,
263
+ uint[16] calldata _pubSignals,
264
+ bytes32 vaspDidHash
265
+ ) internal returns (bool) {
188
266
  // Replay prevention
189
267
  if (proofs[transferId].timestamp != 0) revert TransferAlreadyRecorded();
190
268
 
@@ -232,9 +310,11 @@ contract ComplianceRegistry is AccessControl, Pausable {
232
310
  if (usedNullifiers[nullifier]) revert ProofAlreadyUsed();
233
311
 
234
312
  // C-1: Cryptographic verification — revert on invalid proof
235
- if (verifierSelector == bytes32(0)) revert VerifierSelectorNotSet();
313
+ if (selector == bytes32(0)) revert VerifierSelectorNotSet();
314
+ // A retired verifier is never accepted as the default.
315
+ if (selector == verifierSelector && !verifierRouter.isVerifierActive(selector)) revert VerifierUnavailable();
236
316
 
237
- bool valid = verifierRouter.verifyProof(verifierSelector, _pA, _pB, _pC, _pubSignals);
317
+ bool valid = verifierRouter.verifyProof(selector, _pA, _pB, _pC, _pubSignals);
238
318
  if (!valid) revert ProofVerificationFailed();
239
319
 
240
320
  // Record
@@ -1,6 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // clearproof — ZK-proven compliance without transmitting PII
3
3
  // https://clearproof.world | https://docs.clearproof.world
4
+ // LEGACY: 16-signal `compliance.circom` demo/parity path, not pilot-transfer-v3.
5
+ // Never treat proofs, roots or records accepted here as current pilot authorization.
6
+ // Kept at this path for the published @clearproof/contracts artifact layout; see
7
+ // packages/contracts/AGENTS.md ("Legacy contracts") and docs/internal/CIRCUIT_SIGNALS.md.
4
8
  pragma solidity ^0.8.24;
5
9
 
6
10
  /**
@@ -1,4 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
+ // LEGACY: 16-signal `compliance.circom` demo/parity path, not pilot-transfer-v3.
3
+ // Never treat proofs, roots or records accepted here as current pilot authorization.
4
+ // Kept at this path for the published @clearproof/contracts artifact layout; see
5
+ // packages/contracts/AGENTS.md ("Legacy contracts") and docs/internal/CIRCUIT_SIGNALS.md.
2
6
  pragma solidity ^0.8.24;
3
7
 
4
8
  /// @dev Mock verifier that always returns true, for testing event emission.
@@ -1,13 +1,23 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.24;
3
3
 
4
- import "@openzeppelin/contracts/access/AccessControl.sol";
4
+ import {PilotSignalConstants as P, PILOT_SIGNAL_COUNT} from "./generated/PilotSignalConstants.sol";
5
+
6
+ import {AccessControlDefaultAdminRules} from
7
+ "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
8
+ import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
5
9
  import {PilotGroth16Verifier} from "./PilotGroth16Verifier.sol";
6
10
 
7
11
  /// @notice Development current-state checkpoints and mirrors of consumed PostgreSQL receipts.
8
12
  /// @dev Publishers authenticate private source records off-chain (ADR 0006).
9
13
  /// This contract verifies their versioned bindings, not JSON/Ed25519 source signatures.
10
- contract PilotCurrentRegistry is AccessControl {
14
+ /// Administration uses two-step default-admin transfer with a delay. PAUSER_ROLE can halt
15
+ /// every state-changing publication and mirror path; views, including `inspect`, stay readable.
16
+ contract PilotCurrentRegistry is AccessControlDefaultAdminRules, Pausable {
17
+ /// @notice Role allowed to pause publication and mirroring. Only the default admin unpauses.
18
+ bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
19
+ /// @notice Initial delay before an accepted default-admin transfer can complete.
20
+ uint48 public constant INITIAL_ADMIN_DELAY = 2 days;
11
21
  uint256 private constant R =
12
22
  21888242871839275222246405745257275088548364400416034343698204186575808495617;
13
23
  uint64 private constant MAX_SAFE = 9007199254740991;
@@ -63,20 +73,36 @@ contract PilotCurrentRegistry is AccessControl {
63
73
  error AlreadyMirrored();
64
74
  error InvalidProof();
65
75
 
66
- event PublisherChanged(bytes32 indexed tenant, address publisher, uint64 epoch);
67
- event HeadPublished(bytes32 indexed tenant, Kind indexed kind, bytes32 indexed scope, uint64 revision, bytes32 digest);
68
- event StatementPublished(bytes32 indexed tenant, bytes32 indexed statementId, bytes32 contextDigest);
76
+ event PublisherChanged(bytes32 indexed tenant, address indexed publisher, uint64 epoch);
77
+ event HeadPublished(
78
+ bytes32 indexed tenant, Kind indexed kind, bytes32 indexed scope, uint64 revision, bytes32 digest,
79
+ uint256 value, uint64 validFrom, uint64 validUntil, bool enabled, uint64 publisherEpoch
80
+ );
81
+ event StatementPublished(
82
+ bytes32 indexed tenant, bytes32 indexed statementId, bytes32 contextDigest, address consumer,
83
+ uint256 projectionCommitment
84
+ );
69
85
  event AuthorizationMirrored(bytes32 indexed tenant, bytes32 statementId, bytes32 indexed receiptId, uint256 indexed nullifier);
70
86
 
71
- constructor(address admin, PilotGroth16Verifier pairing) {
72
- if (admin == address(0) || address(pairing).code.length == 0) revert InvalidScope();
73
- _grantRole(DEFAULT_ADMIN_ROLE, admin);
87
+ /// @dev A zero admin reverts in AccessControlDefaultAdminRules before this body runs.
88
+ constructor(address admin, PilotGroth16Verifier pairing) AccessControlDefaultAdminRules(INITIAL_ADMIN_DELAY, admin) {
89
+ if (address(pairing).code.length == 0) revert InvalidScope();
90
+ _grantRole(PAUSER_ROLE, admin);
74
91
  verifier = pairing;
75
92
  verifierCodeHash = address(pairing).codehash;
76
93
  artifactManifestDigest = pairing.artifactManifestDigest();
77
94
  if (artifactManifestDigest == bytes32(0)) revert InvalidScope();
78
95
  }
79
96
 
97
+ function pause() external onlyRole(PAUSER_ROLE) {
98
+ _pause();
99
+ }
100
+
101
+ function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
102
+ _unpause();
103
+ }
104
+
105
+ /// @dev Deliberately not pausable, so an admin can disable a compromised publisher during a pause.
80
106
  function setPublisher(bytes32 tenant, address publisher) external onlyRole(DEFAULT_ADMIN_ROLE) {
81
107
  if (tenant == bytes32(0)) revert InvalidScope();
82
108
  publishers[tenant] = publisher;
@@ -93,7 +119,7 @@ contract PilotCurrentRegistry is AccessControl {
93
119
  }
94
120
 
95
121
  function publishHead(bytes32 tenant, Kind kind, bytes32 scope, bytes32 digest, uint256 value,
96
- uint64 expectedRevision, uint64 validFrom, uint64 validUntil, bool enabled) public {
122
+ uint64 expectedRevision, uint64 validFrom, uint64 validUntil, bool enabled) public whenNotPaused {
97
123
  if (msg.sender != publishers[tenant]) revert UnauthorizedPublisher();
98
124
  // These time bounds imply validUntil > validFrom, making subtraction safe.
99
125
  if (scope == bytes32(0) || digest == bytes32(0) || validFrom > block.timestamp ||
@@ -107,8 +133,9 @@ contract PilotCurrentRegistry is AccessControl {
107
133
  if (expectedRevision >= MAX_SAFE || previous.revision != expectedRevision || validFrom < previous.validFrom) {
108
134
  revert InvalidState();
109
135
  }
110
- _heads[key] = Head(digest, value, expectedRevision + 1, validFrom, validUntil, publisherEpochs[tenant], enabled);
111
- emit HeadPublished(tenant, kind, scope, expectedRevision + 1, digest);
136
+ uint64 epoch = publisherEpochs[tenant];
137
+ _heads[key] = Head(digest, value, expectedRevision + 1, validFrom, validUntil, epoch, enabled);
138
+ emit HeadPublished(tenant, kind, scope, expectedRevision + 1, digest, value, validFrom, validUntil, enabled, epoch);
112
139
  }
113
140
 
114
141
  function statementId(bytes32 tenant, Statement calldata statement) public pure returns (bytes32) {
@@ -125,13 +152,13 @@ contract PilotCurrentRegistry is AccessControl {
125
152
  block.timestamp >= current.validUntil) revert InvalidState();
126
153
  }
127
154
 
128
- function publishStatement(bytes32 tenant, Statement calldata statement) public returns (bytes32 id) {
155
+ function publishStatement(bytes32 tenant, Statement calldata statement) public whenNotPaused returns (bytes32 id) {
129
156
  if (msg.sender != publishers[tenant]) revert UnauthorizedPublisher();
130
157
  if (statement.contextDigest == bytes32(0) || statement.transferDigest == bytes32(0) ||
131
158
  statement.projectionCommitment == 0 || statement.projectionCommitment >= R ||
132
159
  statement.consumer == address(0) || statement.evaluatedAt > block.timestamp ||
133
160
  statement.validUntil <= block.timestamp || statement.validUntil > MAX_SAFE ||
134
- statement.validUntil > uint256(statement.evaluatedAt) + 300 ||
161
+ statement.validUntil > uint256(statement.evaluatedAt) + P.PROOF_LIFETIME_SECONDS ||
135
162
  statement.pins[7].scope != statement.contextDigest) revert InvalidStatement();
136
163
  for (uint8 i; i < 7; ++i) _currentHead(tenant, Kind(i), statement.pins[i], statement.evaluatedAt);
137
164
  id = statementId(tenant, statement);
@@ -146,13 +173,13 @@ contract PilotCurrentRegistry is AccessControl {
146
173
  approved.statement.validUntil = statement.validUntil;
147
174
  approved.statement.consumer = statement.consumer;
148
175
  for (uint8 i; i < 8; ++i) approved.statement.pins[i] = statement.pins[i];
149
- emit StatementPublished(tenant, id, statement.contextDigest);
176
+ emit StatementPublished(tenant, id, statement.contextDigest, statement.consumer, statement.projectionCommitment);
150
177
  }
151
178
 
152
179
  /// @notice Publish a coherent checkpoint set and statement in one transaction.
153
180
  /// @dev Exact epochs and revisions reject stale preparation, including reused heads.
154
181
  function publishBatch(bytes32 tenant, uint64 expectedEpoch, HeadUpdate[8] calldata updates,
155
- Statement calldata statement) external returns (bytes32 id) {
182
+ Statement calldata statement) external whenNotPaused returns (bytes32 id) {
156
183
  if (msg.sender != publishers[tenant]) revert UnauthorizedPublisher();
157
184
  if (expectedEpoch != publisherEpochs[tenant]) revert InvalidState();
158
185
  for (uint8 i; i < 8; ++i) {
@@ -178,39 +205,39 @@ contract PilotCurrentRegistry is AccessControl {
178
205
  }
179
206
 
180
207
  function _inspect(bytes32 tenant, bytes32 id, uint256[2] calldata a, uint256[2][2] calldata b,
181
- uint256[2] calldata c, uint256[8] calldata signals) private view returns (bool) {
208
+ uint256[2] calldata c, uint256[PILOT_SIGNAL_COUNT] calldata signals) private view returns (bool) {
182
209
  Approval storage approved = _statements[id];
183
210
  if (!approved.exists || publishers[tenant] == address(0) || approved.publisherEpoch != publisherEpochs[tenant] ||
184
211
  address(verifier).codehash != verifierCodeHash) revert InvalidStatement();
185
212
  Statement memory statement = approved.statement;
186
213
  // Publication checked evaluatedAt; approvals are immutable and chain time is monotonic.
187
214
  if (keccak256(abi.encode(tenant, statement)) != id ||
188
- signals[0] != statement.projectionCommitment || signals[3] == 0 ||
189
- signals[4] != statement.evaluatedAt || signals[5] <= block.timestamp ||
190
- signals[5] > statement.validUntil || signals[6] != block.chainid || signals[7] != uint160(address(this))) {
215
+ signals[P.PROJECTION_COMMITMENT_INDEX] != statement.projectionCommitment || signals[P.AUTHORIZATION_NULLIFIER_INDEX] == 0 ||
216
+ signals[P.EVALUATED_AT_INDEX] != statement.evaluatedAt || signals[P.PROOF_EXPIRES_AT_INDEX] <= block.timestamp ||
217
+ signals[P.PROOF_EXPIRES_AT_INDEX] > statement.validUntil || signals[P.DOMAIN_CHAIN_ID_INDEX] != block.chainid || signals[P.DOMAIN_REGISTRY_INDEX] != uint160(address(this))) {
191
218
  revert InvalidStatement();
192
219
  }
193
220
  for (uint8 i; i < 7; ++i) {
194
221
  Head memory current = _currentHead(tenant, Kind(i), statement.pins[i], statement.evaluatedAt);
195
- if ((i == 1 && signals[1] != current.value) || (i == 2 && signals[2] != current.value)) revert InvalidStatement();
222
+ if ((i == 1 && signals[P.AUTHORIZED_ISSUER_ROOT_INDEX] != current.value) || (i == 2 && signals[P.SANCTIONS_ROOT_INDEX] != current.value)) revert InvalidStatement();
196
223
  }
197
224
  return verifier.verifyProof(a, b, c, signals);
198
225
  }
199
226
 
200
227
  function inspect(bytes32 tenant, bytes32 id, uint256[2] calldata a, uint256[2][2] calldata b,
201
- uint256[2] calldata c, uint256[8] calldata signals) external view returns (bool) {
228
+ uint256[2] calldata c, uint256[PILOT_SIGNAL_COUNT] calldata signals) external view returns (bool) {
202
229
  return _inspect(tenant, id, a, b, c, signals);
203
230
  }
204
231
 
205
232
  function mirror(bytes32 tenant, bytes32 id, bytes32 receiptId, uint256[2] calldata a, uint256[2][2] calldata b,
206
- uint256[2] calldata c, uint256[8] calldata signals) external {
233
+ uint256[2] calldata c, uint256[PILOT_SIGNAL_COUNT] calldata signals) external whenNotPaused {
207
234
  Approval storage approved = _statements[id];
208
235
  if (!approved.exists || msg.sender != approved.statement.consumer) revert UnauthorizedConsumer();
209
- if (mirroredReceipts[tenant][signals[3]] != bytes32(0)) revert AlreadyMirrored();
236
+ if (mirroredReceipts[tenant][signals[P.AUTHORIZATION_NULLIFIER_INDEX]] != bytes32(0)) revert AlreadyMirrored();
210
237
  if (!_inspect(tenant, id, a, b, c, signals)) revert InvalidProof();
211
238
  Head memory decision = _currentHead(tenant, Kind.Authorization, approved.statement.pins[7], approved.statement.evaluatedAt);
212
239
  if (decision.value != 1 || decision.digest != receiptId) revert AuthorizationUnavailable();
213
- mirroredReceipts[tenant][signals[3]] = receiptId;
214
- emit AuthorizationMirrored(tenant, id, receiptId, signals[3]);
240
+ mirroredReceipts[tenant][signals[P.AUTHORIZATION_NULLIFIER_INDEX]] = receiptId;
241
+ emit AuthorizationMirrored(tenant, id, receiptId, signals[P.AUTHORIZATION_NULLIFIER_INDEX]);
215
242
  }
216
243
  }
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.24;
3
3
 
4
+ import {PilotSignalConstants as P, PILOT_SIGNAL_COUNT} from "./generated/PilotSignalConstants.sol";
5
+
4
6
  import {Pairing} from "./Pairing.sol";
5
7
 
6
8
  /// @notice Fixed eight-signal Groth16 pairing for the development pilot profile.
@@ -17,13 +19,13 @@ contract PilotGroth16Verifier {
17
19
  uint256[2][2] beta;
18
20
  uint256[2][2] gamma;
19
21
  uint256[2][2] delta;
20
- uint256[2][9] ic;
22
+ uint256[2][PILOT_SIGNAL_COUNT + 1] ic;
21
23
  }
22
24
 
23
25
  VerificationKey private _key;
24
26
  bytes32 public immutable verificationKeyCommitment;
25
27
  bytes32 public immutable artifactManifestDigest;
26
- string public constant proofProfile = "pilot-transfer-v3";
28
+ string public constant proofProfile = P.PROFILE;
27
29
  string public constant assurance = "development-unapproved";
28
30
 
29
31
  error InvalidCoordinate();
@@ -33,7 +35,7 @@ contract PilotGroth16Verifier {
33
35
  constructor(VerificationKey memory key, bytes32 manifestDigest) {
34
36
  if (manifestDigest == bytes32(0)) revert InvalidKey();
35
37
  _validateG1(key.alpha);
36
- for (uint256 i; i < 9; ++i) _validateG1(key.ic[i]);
38
+ for (uint256 i; i < P.PILOT_PUBLIC_SIGNAL_COUNT + 1; ++i) _validateG1(key.ic[i]);
37
39
  _validateG2(key.beta);
38
40
  _validateG2(key.gamma);
39
41
  _validateG2(key.delta);
@@ -74,14 +76,14 @@ contract PilotGroth16Verifier {
74
76
  /// Invalid encodings may revert; false means a well-encoded failed pairing.
75
77
  function verifyProof(
76
78
  uint256[2] calldata a, uint256[2][2] calldata b, uint256[2] calldata c,
77
- uint256[8] calldata signals
79
+ uint256[PILOT_SIGNAL_COUNT] calldata signals
78
80
  ) external view returns (bool) {
79
81
  // Check before negation so noncanonical y + Q cannot be silently reduced.
80
82
  Pairing.G1Point memory pointA = _g1(a);
81
83
  Pairing.G2Point memory pointB = _g2(b);
82
84
  Pairing.G1Point memory pointC = _g1(c);
83
85
  Pairing.G1Point memory accumulator = _g1(_key.ic[0]);
84
- for (uint256 i; i < 8; ++i) {
86
+ for (uint256 i; i < P.PILOT_PUBLIC_SIGNAL_COUNT; ++i) {
85
87
  if (signals[i] >= R) revert NoncanonicalSignal();
86
88
  accumulator = Pairing.add(accumulator, Pairing.scalar_mul(_g1(_key.ic[i + 1]), signals[i]));
87
89
  }
@@ -1,15 +1,25 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.24;
3
3
 
4
- import "@openzeppelin/contracts/access/AccessControl.sol";
4
+ import {AccessControlDefaultAdminRules} from
5
+ "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
6
+ import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
5
7
 
6
8
  /// @notice Current root approval checkpoints independent of the credential DB.
7
9
  /// @dev Scoped publishers authenticate registrar JSON/Ed25519 approvals off-chain.
8
10
  /// This contract neither parses those approvals nor verifies ZK proofs.
9
- contract PilotRootCheckpoint is AccessControl {
11
+ /// Every `setPublisher` call increments the tenant's publisher epoch. A head is current
12
+ /// only while its recorded epoch equals the tenant epoch and the publisher is nonzero;
13
+ /// readers must check both (see `isCurrent`). Administration uses two-step default-admin
14
+ /// transfer with a delay; PAUSER_ROLE halts publication while views stay readable.
15
+ contract PilotRootCheckpoint is AccessControlDefaultAdminRules, Pausable {
10
16
  uint256 private constant SCALAR_FIELD =
11
17
  21888242871839275222246405745257275088548364400416034343698204186575808495617;
12
18
  uint64 private constant MAX_SAFE_INTEGER = 9007199254740991;
19
+ /// @notice Role allowed to pause publication. Only the default admin unpauses.
20
+ bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
21
+ /// @notice Initial delay before an accepted default-admin transfer can complete.
22
+ uint48 public constant INITIAL_ADMIN_DELAY = 2 days;
13
23
  error InvalidScope();
14
24
  error UnauthorizedPublisher();
15
25
  error StaleRevision();
@@ -22,35 +32,58 @@ contract PilotRootCheckpoint is AccessControl {
22
32
  uint64 validFrom;
23
33
  uint64 validUntil;
24
34
  uint64 publishedAt;
35
+ uint64 publisherEpoch;
25
36
  }
26
37
  mapping(bytes32 tenantHash => address) public publishers;
38
+ mapping(bytes32 tenantHash => uint64) public publisherEpochs;
27
39
  mapping(bytes32 key => Checkpoint) private _heads;
28
- event PublisherChanged(bytes32 indexed tenantHash, address indexed publisher);
40
+ event PublisherChanged(bytes32 indexed tenantHash, address indexed publisher, uint64 epoch);
29
41
  event RootCheckpointPublished(
30
42
  bytes32 indexed tenantHash, bytes32 indexed rootScope, bytes32 indexed snapshotDigest,
31
- uint256 root, uint64 revision, uint64 validFrom, uint64 validUntil
43
+ uint256 root, uint64 revision, uint64 validFrom, uint64 validUntil, uint64 publisherEpoch
32
44
  );
33
45
 
34
- constructor(address admin) {
35
- if (admin == address(0)) revert InvalidScope();
36
- _grantRole(DEFAULT_ADMIN_ROLE, admin);
46
+ /// @dev A zero admin reverts in AccessControlDefaultAdminRules before this body runs.
47
+ constructor(address admin) AccessControlDefaultAdminRules(INITIAL_ADMIN_DELAY, admin) {
48
+ _grantRole(PAUSER_ROLE, admin);
37
49
  }
38
50
 
51
+ function pause() external onlyRole(PAUSER_ROLE) {
52
+ _pause();
53
+ }
54
+
55
+ function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
56
+ _unpause();
57
+ }
58
+
59
+ /// @dev Deliberately not pausable, so an admin can disable a compromised publisher during a pause.
39
60
  function setPublisher(bytes32 tenantHash, address publisher) external onlyRole(DEFAULT_ADMIN_ROLE) {
40
61
  if (tenantHash == bytes32(0)) revert InvalidScope();
41
- // Zero address deliberately disables publication for this tenant.
62
+ // Zero address deliberately disables publication for this tenant. Any call,
63
+ // including reassigning the same address, supersedes every existing head.
42
64
  publishers[tenantHash] = publisher;
43
- emit PublisherChanged(tenantHash, publisher);
65
+ publisherEpochs[tenantHash] += 1;
66
+ emit PublisherChanged(tenantHash, publisher, publisherEpochs[tenantHash]);
44
67
  }
45
68
 
46
69
  function head(bytes32 tenantHash, bytes32 rootScope) external view returns (Checkpoint memory) {
47
70
  return _heads[keccak256(abi.encode(tenantHash, rootScope))];
48
71
  }
49
72
 
73
+ /// @notice Whether a published head exists under the tenant's current, enabled publisher epoch.
74
+ /// @dev Does not check validity times; readers compare them with their own trusted clock.
75
+ function isCurrent(bytes32 tenantHash, bytes32 rootScope) external view returns (bool) {
76
+ Checkpoint storage current = _heads[keccak256(abi.encode(tenantHash, rootScope))];
77
+ return current.revision != 0 && publishers[tenantHash] != address(0) &&
78
+ current.publisherEpoch == publisherEpochs[tenantHash];
79
+ }
80
+
81
+ /// @dev Revisions stay monotonic across epochs: after a publisher change, a superseded
82
+ /// approval cannot be republished; the registrar must sign a newer approval revision.
50
83
  function publish(
51
84
  bytes32 tenantHash, bytes32 rootScope, bytes32 snapshotDigest, uint256 root,
52
85
  uint64 expectedRevision, uint64 approvalRevision, uint64 validFrom, uint64 validUntil
53
- ) external {
86
+ ) external whenNotPaused {
54
87
  if (tenantHash == bytes32(0) || rootScope == bytes32(0)) revert InvalidScope();
55
88
  if (msg.sender != publishers[tenantHash]) revert UnauthorizedPublisher();
56
89
  bytes32 key = keccak256(abi.encode(tenantHash, rootScope));
@@ -62,7 +95,12 @@ contract PilotRootCheckpoint is AccessControl {
62
95
  validFrom > block.timestamp || validFrom < previous.validFrom || validUntil <= block.timestamp ||
63
96
  validUntil - validFrom > 1 days || validUntil > MAX_SAFE_INTEGER
64
97
  ) revert InvalidApproval();
65
- _heads[key] = Checkpoint(snapshotDigest, root, approvalRevision, validFrom, validUntil, uint64(block.timestamp));
66
- emit RootCheckpointPublished(tenantHash, rootScope, snapshotDigest, root, approvalRevision, validFrom, validUntil);
98
+ uint64 epoch = publisherEpochs[tenantHash];
99
+ _heads[key] = Checkpoint(
100
+ snapshotDigest, root, approvalRevision, validFrom, validUntil, uint64(block.timestamp), epoch
101
+ );
102
+ emit RootCheckpointPublished(
103
+ tenantHash, rootScope, snapshotDigest, root, approvalRevision, validFrom, validUntil, epoch
104
+ );
67
105
  }
68
106
  }
@@ -1,6 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // clearproof — ZK-proven compliance without transmitting PII
3
3
  // https://clearproof.world | https://docs.clearproof.world
4
+ // LEGACY: 16-signal `compliance.circom` demo/parity path, not pilot-transfer-v3.
5
+ // Never treat proofs, roots or records accepted here as current pilot authorization.
6
+ // Kept at this path for the published @clearproof/contracts artifact layout; see
7
+ // packages/contracts/AGENTS.md ("Legacy contracts") and docs/internal/CIRCUIT_SIGNALS.md.
4
8
  pragma solidity ^0.8.24;
5
9
 
6
10
  import "@openzeppelin/contracts/access/AccessControl.sol";
@@ -1,6 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // clearproof — ZK-proven compliance without transmitting PII
3
3
  // https://clearproof.world | https://docs.clearproof.world
4
+ // LEGACY: 16-signal `compliance.circom` demo/parity path, not pilot-transfer-v3.
5
+ // Never treat proofs, roots or records accepted here as current pilot authorization.
6
+ // Kept at this path for the published @clearproof/contracts artifact layout; see
7
+ // packages/contracts/AGENTS.md ("Legacy contracts") and docs/internal/CIRCUIT_SIGNALS.md.
4
8
  pragma solidity ^0.8.24;
5
9
 
6
10
  import "@openzeppelin/contracts/access/AccessControl.sol";
@@ -1,6 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // clearproof — ZK-proven compliance without transmitting PII
3
3
  // https://clearproof.world | https://docs.clearproof.world
4
+ // LEGACY: 16-signal `compliance.circom` demo/parity path, not pilot-transfer-v3.
5
+ // Never treat proofs, roots or records accepted here as current pilot authorization.
6
+ // Kept at this path for the published @clearproof/contracts artifact layout; see
7
+ // packages/contracts/AGENTS.md ("Legacy contracts") and docs/internal/CIRCUIT_SIGNALS.md.
4
8
  pragma solidity ^0.8.24;
5
9
 
6
10
  import "@openzeppelin/contracts/access/AccessControl.sol";