@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
@@ -1,14 +1,13 @@
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.
4
6
  pragma solidity ^0.8.24;
5
7
 
6
8
  import "@openzeppelin/contracts/access/AccessControl.sol";
7
9
  import "@openzeppelin/contracts/utils/Pausable.sol";
8
- import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
9
10
 
10
- /// @dev Interface for the Groth16 verifier with 16 public signals.
11
- /// The concrete Groth16Verifier.sol will be regenerated after circuit recompilation.
12
11
  interface IGroth16Verifier {
13
12
  function verifyProof(
14
13
  uint[2] calldata _pA,
@@ -18,145 +17,127 @@ interface IGroth16Verifier {
18
17
  ) external view returns (bool);
19
18
  }
20
19
 
21
- contract VerifierRouter is AccessControl, Pausable, ReentrancyGuard {
22
- // Custom errors
20
+ /// @notice Permanent scheme/version bindings for the legacy Groth16 interface.
21
+ /// A different proof-system ABI requires a separately reviewed adapter/router.
22
+ contract VerifierRouter is AccessControl, Pausable {
23
23
  error ZeroAddress();
24
+ error InvalidSelector();
25
+ error InvalidTimelock();
26
+ error VerifierNotContract();
27
+ error VerifierCodeChanged();
28
+ error SelectorAlreadyReserved();
24
29
  error VerifierNotFound();
25
30
  error VerifierAlreadyDisabled();
31
+ error VerifierAlreadyRetiring();
26
32
  error Unauthorized();
27
-
33
+
28
34
  bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
29
35
  bytes32 public constant EMERGENCY_ROLE = keccak256("EMERGENCY_ROLE");
30
-
31
- // Minimum timelock period (in seconds)
36
+ uint256 public constant RETIREMENT_GRACE = 1 days;
37
+ uint256 public immutable timelockFloor;
32
38
  uint256 public minTimelock;
33
-
39
+ uint256 public pendingTimelock;
40
+ uint256 public timelockUpdateAfter;
41
+
34
42
  struct VerifierInfo {
35
- address verifier; // Address of the verifier contract
36
- uint256 registeredAt; // Timestamp when verifier was registered
37
- uint256 disabledAt; // Timestamp when verifier was disabled (0 if active)
38
- bool active; // Whether the verifier is currently active
39
- string name; // Human-readable name for the verifier
43
+ address verifier;
44
+ uint256 registeredAt;
45
+ uint256 disabledAt; // Emergency disable only; never grants a grace period.
46
+ bool active; // Eligible for a new default selection.
47
+ string name;
48
+ bytes32 codeHash;
49
+ uint256 retiredAt;
50
+ uint256 graceEndsAt;
40
51
  }
41
-
42
- // Mapping from selector to verifier info
52
+
43
53
  mapping(bytes32 => VerifierInfo) public verifiers;
44
-
45
- // Timelock for verifier registration and retirement
54
+ // Registration and retirement cannot overlap: selectors are reserved once.
46
55
  mapping(bytes32 => uint256) public timelocks;
47
56
  mapping(bytes32 => address) public pendingRegistrations;
48
57
  mapping(bytes32 => bool) public pendingRetirements;
49
-
50
- // Event declarations
58
+ mapping(bytes32 => bytes32) public pendingCodeHashes;
59
+
51
60
  event VerifierRegistered(bytes32 indexed selector, address verifier, string name, uint256 timelock);
52
61
  event VerifierActivated(bytes32 indexed selector, address verifier);
53
62
  event VerifierDisabled(bytes32 indexed selector, address verifier);
54
63
  event VerifierRetired(bytes32 indexed selector, address verifier);
64
+ event RetirementCompleted(bytes32 indexed selector, uint256 graceEndsAt);
65
+ event TimelockUpdateScheduled(uint256 newTimelock, uint256 executeAfter);
55
66
  event TimelockUpdated(uint256 newTimelock);
56
-
67
+
57
68
  constructor(uint256 _minTimelock) {
69
+ if (_minTimelock == 0) revert InvalidTimelock();
58
70
  _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
59
71
  _grantRole(ADMIN_ROLE, msg.sender);
60
72
  _grantRole(EMERGENCY_ROLE, msg.sender);
73
+ timelockFloor = _minTimelock;
61
74
  minTimelock = _minTimelock;
62
75
  }
63
-
64
- /// @notice Register a new verifier with a selector
65
- /// @param selector Unique identifier for the verifier (e.g., keccak256("groth16-bn254-v1"))
66
- /// @param verifier Address of the verifier contract
67
- /// @param name Human-readable name for the verifier
68
- function registerVerifier(bytes32 selector, address verifier, string memory name)
69
- external
70
- onlyRole(ADMIN_ROLE)
71
- {
76
+
77
+ /// @notice Reserve a scheme/version selector, e.g. keccak256("groth16-bn254-v2").
78
+ /// Neither pending nor activated bindings can ever be overwritten or reused.
79
+ function registerVerifier(bytes32 selector, address verifier, string memory name) external onlyRole(ADMIN_ROLE) {
80
+ if (selector == bytes32(0)) revert InvalidSelector();
72
81
  if (verifier == address(0)) revert ZeroAddress();
73
-
74
- // Set timelock for the registration
82
+ if (verifier.code.length == 0) revert VerifierNotContract();
83
+ if (verifiers[selector].verifier != address(0) || pendingRegistrations[selector] != address(0)) {
84
+ revert SelectorAlreadyReserved();
85
+ }
75
86
  timelocks[selector] = block.timestamp + minTimelock;
76
87
  pendingRegistrations[selector] = verifier;
77
-
88
+ pendingCodeHashes[selector] = verifier.codehash;
78
89
  emit VerifierRegistered(selector, verifier, name, timelocks[selector]);
79
90
  }
80
-
81
- /// @notice Activate a verifier after the timelock period
82
- /// @param selector Unique identifier for the verifier
83
- function activateVerifier(bytes32 selector, string memory name)
84
- external
85
- onlyRole(ADMIN_ROLE)
86
- {
87
- if (block.timestamp < timelocks[selector]) revert Unauthorized();
88
- if (pendingRegistrations[selector] == address(0)) revert VerifierNotFound();
89
-
91
+
92
+ function activateVerifier(bytes32 selector, string memory name) external onlyRole(ADMIN_ROLE) {
90
93
  address verifier = pendingRegistrations[selector];
91
-
94
+ if (verifier == address(0)) revert VerifierNotFound();
95
+ if (block.timestamp < timelocks[selector]) revert Unauthorized();
96
+ bytes32 codeHash = pendingCodeHashes[selector];
97
+ if (verifier.codehash != codeHash) revert VerifierCodeChanged();
92
98
  verifiers[selector] = VerifierInfo({
93
- verifier: verifier,
94
- registeredAt: block.timestamp,
95
- disabledAt: 0,
96
- active: true,
97
- name: name
99
+ verifier: verifier, registeredAt: block.timestamp, disabledAt: 0,
100
+ active: true, name: name, codeHash: codeHash, retiredAt: 0, graceEndsAt: 0
98
101
  });
99
-
100
102
  delete pendingRegistrations[selector];
103
+ delete pendingCodeHashes[selector];
101
104
  delete timelocks[selector];
102
-
103
105
  emit VerifierActivated(selector, verifier);
104
106
  }
105
-
106
- /// @notice Disable a verifier immediately (emergency kill switch)
107
- /// @param selector Unique identifier for the verifier
108
- function disableVerifier(bytes32 selector)
109
- external
110
- onlyRole(EMERGENCY_ROLE)
111
- {
112
- if (verifiers[selector].verifier == address(0)) revert VerifierNotFound();
113
- if (!verifiers[selector].active) revert VerifierAlreadyDisabled();
114
-
115
- verifiers[selector].active = false;
116
- verifiers[selector].disabledAt = block.timestamp;
117
-
118
- emit VerifierDisabled(selector, verifiers[selector].verifier);
107
+
108
+ /// @notice Immediately reject all proofs, including those within retirement grace.
109
+ function disableVerifier(bytes32 selector) external onlyRole(EMERGENCY_ROLE) {
110
+ VerifierInfo storage info = verifiers[selector];
111
+ if (info.verifier == address(0)) revert VerifierNotFound();
112
+ if (info.disabledAt != 0) revert VerifierAlreadyDisabled();
113
+ info.active = false;
114
+ info.disabledAt = block.timestamp;
115
+ emit VerifierDisabled(selector, info.verifier);
119
116
  }
120
-
121
- /// @notice Schedule retirement of a verifier with timelock
122
- /// @param selector Unique identifier for the verifier
123
- function scheduleRetirement(bytes32 selector)
124
- external
125
- onlyRole(ADMIN_ROLE)
126
- {
127
- if (verifiers[selector].verifier == address(0)) revert VerifierNotFound();
128
-
129
- // Set timelock for retirement
117
+
118
+ function scheduleRetirement(bytes32 selector) external onlyRole(ADMIN_ROLE) {
119
+ VerifierInfo storage info = verifiers[selector];
120
+ if (info.verifier == address(0)) revert VerifierNotFound();
121
+ if (!info.active) revert VerifierAlreadyDisabled();
122
+ if (pendingRetirements[selector]) revert VerifierAlreadyRetiring();
130
123
  timelocks[selector] = block.timestamp + minTimelock;
131
124
  pendingRetirements[selector] = true;
132
-
133
- emit VerifierRetired(selector, verifiers[selector].verifier);
125
+ emit VerifierRetired(selector, info.verifier);
134
126
  }
135
-
136
- /// @notice Complete retirement of a verifier after timelock
137
- /// @param selector Unique identifier for the verifier
138
- function completeRetirement(bytes32 selector)
139
- external
140
- onlyRole(ADMIN_ROLE)
141
- {
142
- if (block.timestamp < timelocks[selector]) revert Unauthorized();
127
+
128
+ function completeRetirement(bytes32 selector) external onlyRole(ADMIN_ROLE) {
143
129
  if (!pendingRetirements[selector]) revert VerifierNotFound();
144
-
145
- // Disable the verifier
146
- verifiers[selector].active = false;
147
- verifiers[selector].disabledAt = block.timestamp;
148
-
130
+ if (block.timestamp < timelocks[selector]) revert Unauthorized();
131
+ VerifierInfo storage info = verifiers[selector];
132
+ if (info.disabledAt != 0) revert VerifierAlreadyDisabled();
133
+ info.active = false;
134
+ info.retiredAt = block.timestamp;
135
+ info.graceEndsAt = block.timestamp + RETIREMENT_GRACE;
149
136
  delete pendingRetirements[selector];
150
137
  delete timelocks[selector];
138
+ emit RetirementCompleted(selector, info.graceEndsAt);
151
139
  }
152
-
153
- /// @notice Verify a proof using the specified verifier
154
- /// @param selector Unique identifier for the verifier
155
- /// @param _pA First parameter for proof verification
156
- /// @param _pB Second parameter for proof verification
157
- /// @param _pC Third parameter for proof verification
158
- /// @param _pubSignals Array of public signals
159
- /// @return Whether the proof is valid
140
+
160
141
  function verifyProof(
161
142
  bytes32 selector,
162
143
  uint[2] calldata _pA,
@@ -164,44 +145,47 @@ contract VerifierRouter is AccessControl, Pausable, ReentrancyGuard {
164
145
  uint[2] calldata _pC,
165
146
  uint[16] calldata _pubSignals
166
147
  ) external view whenNotPaused returns (bool) {
167
- VerifierInfo memory info = verifiers[selector];
148
+ VerifierInfo storage info = verifiers[selector];
168
149
  if (info.verifier == address(0)) revert VerifierNotFound();
169
- if (!info.active) revert VerifierAlreadyDisabled();
170
-
150
+ if (!isVerifierResolvable(selector)) revert VerifierAlreadyDisabled();
151
+ if (info.verifier.codehash != info.codeHash) revert VerifierCodeChanged();
152
+ // Grace accepts the old declared transfer-time cutoff, not new transfers.
153
+ // This does not independently attest the wall-clock time of proof creation.
154
+ if (!info.active && _pubSignals[5] > info.retiredAt) revert VerifierAlreadyDisabled();
171
155
  return IGroth16Verifier(info.verifier).verifyProof(_pA, _pB, _pC, _pubSignals);
172
156
  }
173
-
174
- /// @notice Get the address of a verifier
175
- /// @param selector Unique identifier for the verifier
176
- /// @return Address of the verifier contract
157
+
158
+ /// @notice Historical addresses remain discoverable after all acceptance ends.
177
159
  function getVerifier(bytes32 selector) external view returns (address) {
178
160
  return verifiers[selector].verifier;
179
161
  }
180
-
181
- /// @notice Check if a verifier is active
182
- /// @param selector Unique identifier for the verifier
183
- /// @return Whether the verifier is active
162
+
184
163
  function isVerifierActive(bytes32 selector) external view returns (bool) {
185
164
  return verifiers[selector].active;
186
165
  }
187
-
188
- /// @notice Update the timelock period
189
- /// @param newTimelock New timelock period in seconds
190
- function updateTimelock(uint256 newTimelock)
191
- external
192
- onlyRole(ADMIN_ROLE)
193
- {
194
- minTimelock = newTimelock;
195
- emit TimelockUpdated(newTimelock);
166
+
167
+ function isVerifierResolvable(bytes32 selector) public view returns (bool) {
168
+ VerifierInfo storage info = verifiers[selector];
169
+ return info.verifier != address(0) && info.disabledAt == 0 &&
170
+ (info.active || (info.graceEndsAt != 0 && block.timestamp <= info.graceEndsAt));
196
171
  }
197
-
198
- /// @notice Pause the router (emergency stop)
199
- function pause() external onlyRole(EMERGENCY_ROLE) {
200
- _pause();
172
+
173
+ /// @notice Schedule a delay change; the constructor floor can never be lowered.
174
+ function updateTimelock(uint256 newTimelock) external onlyRole(ADMIN_ROLE) {
175
+ if (newTimelock < timelockFloor) revert InvalidTimelock();
176
+ pendingTimelock = newTimelock;
177
+ timelockUpdateAfter = block.timestamp + minTimelock;
178
+ emit TimelockUpdateScheduled(newTimelock, timelockUpdateAfter);
201
179
  }
202
-
203
- /// @notice Unpause the router
204
- function unpause() external onlyRole(ADMIN_ROLE) {
205
- _unpause();
180
+
181
+ function completeTimelockUpdate() external onlyRole(ADMIN_ROLE) {
182
+ if (timelockUpdateAfter == 0 || block.timestamp < timelockUpdateAfter) revert Unauthorized();
183
+ minTimelock = pendingTimelock;
184
+ delete pendingTimelock;
185
+ delete timelockUpdateAfter;
186
+ emit TimelockUpdated(minTimelock);
206
187
  }
207
- }
188
+
189
+ function pause() external onlyRole(EMERGENCY_ROLE) { _pause(); }
190
+ function unpause() external onlyRole(ADMIN_ROLE) { _unpause(); }
191
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Generated: specs/pilot-signals-v3.json; SHA256 4932f8bc2948340926aeb23c7ed202bb47615ba9c570c2731daea64366206948.
3
+ pragma solidity ^0.8.24;
4
+
5
+ uint256 constant PILOT_SIGNAL_COUNT = 8;
6
+
7
+ library PilotSignalConstants {
8
+ string internal constant PROFILE = "pilot-transfer-v3";
9
+ uint256 internal constant PILOT_PUBLIC_SIGNAL_COUNT = 8;
10
+ uint256 internal constant PROJECTION_FIELD_COUNT = 48;
11
+ uint256 internal constant PROJECTION_COMMITMENT_INDEX = 0;
12
+ uint256 internal constant AUTHORIZED_ISSUER_ROOT_INDEX = 1;
13
+ uint256 internal constant SANCTIONS_ROOT_INDEX = 2;
14
+ uint256 internal constant AUTHORIZATION_NULLIFIER_INDEX = 3;
15
+ uint256 internal constant EVALUATED_AT_INDEX = 4;
16
+ uint256 internal constant PROOF_EXPIRES_AT_INDEX = 5;
17
+ uint256 internal constant DOMAIN_CHAIN_ID_INDEX = 6;
18
+ uint256 internal constant DOMAIN_REGISTRY_INDEX = 7;
19
+ uint256 internal constant ISSUANCE_TREE_DEPTH = 32;
20
+ uint256 internal constant ISSUER_TREE_DEPTH = 20;
21
+ uint256 internal constant SANCTIONS_TREE_DEPTH = 20;
22
+ uint256 internal constant HOLDER_DOMAIN_TAG = 101;
23
+ uint256 internal constant CREDENTIAL_DOMAIN_TAG = 102;
24
+ uint256 internal constant ISSUER_LEAF_DOMAIN_TAG = 103;
25
+ uint256 internal constant PROJECTION_DOMAIN_TAG = 201;
26
+ uint256 internal constant AUTHORIZATION_SCOPE_DOMAIN_TAG = 202;
27
+ uint256 internal constant AUTHORIZATION_NULLIFIER_DOMAIN_TAG = 203;
28
+ uint256 internal constant BOUND_PROJECTION_DOMAIN_TAG = 204;
29
+ uint256 internal constant SANCTIONS_LEAF_DOMAIN_TAG = 301;
30
+ uint256 internal constant PROOF_LIFETIME_SECONDS = 300;
31
+ uint256 internal constant MAX_TRANSFER_AGE_SECONDS = 86400;
32
+ uint256 internal constant MAX_ASSET_DECIMALS = 18;
33
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.24;
3
+
4
+ /// @dev TEST ONLY. ABI-compatible stand-in for PilotGroth16Verifier so registry logic
5
+ /// (pause, epochs, events, domain binding) runs without circuit artifacts. It performs
6
+ /// no pairing check and must never be deployed outside a local test network.
7
+ contract MockPilotVerifier {
8
+ bytes32 public immutable artifactManifestDigest;
9
+ bool public result = true;
10
+
11
+ constructor(bytes32 manifestDigest) {
12
+ artifactManifestDigest = manifestDigest;
13
+ }
14
+
15
+ function setResult(bool value) external {
16
+ result = value;
17
+ }
18
+
19
+ function verifyProof(
20
+ uint256[2] calldata,
21
+ uint256[2][2] calldata,
22
+ uint256[2] calldata,
23
+ uint256[8] calldata
24
+ ) external view returns (bool) {
25
+ return result;
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearproof/contracts",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "On-chain Groth16 verifier for clearproof compliance proofs",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
@@ -37,9 +37,10 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@nomicfoundation/hardhat-toolbox": "^5.0",
40
- "dotenv": "^17.4.2",
40
+ "dotenv": "^18.0.5",
41
41
  "hardhat": "^2.22",
42
- "typescript": "^5.4"
42
+ "ts-node": "^10.9.2",
43
+ "typescript": "^5.9.3"
43
44
  },
44
45
  "dependencies": {
45
46
  "@openzeppelin/contracts": "^5.6.1"