@clearproof/contracts 0.3.0 → 0.6.0

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 (29) hide show
  1. package/README.md +33 -5
  2. package/artifacts/contracts/ComplianceRegistry.sol/ComplianceRegistry.json +356 -5
  3. package/artifacts/contracts/Groth16Verifier.sol/Groth16Verifier.json +7 -2
  4. package/artifacts/contracts/MockVerifier.sol/MockVerifier.json +45 -0
  5. package/artifacts/contracts/Pairing.sol/Pairing.json +10 -0
  6. package/artifacts/contracts/PairingHarness.sol/PairingHarness.json +252 -0
  7. package/artifacts/contracts/PilotCurrentRegistry.sol/PilotCurrentRegistry.json +1063 -0
  8. package/artifacts/contracts/PilotGroth16Verifier.sol/PilotGroth16Verifier.json +155 -0
  9. package/artifacts/contracts/PilotRootCheckpoint.sol/PilotRootCheckpoint.json +476 -0
  10. package/artifacts/contracts/SanctionsOracle.sol/SanctionsOracle.json +27 -2
  11. package/artifacts/contracts/SanctionsRootRelay.sol/SanctionsRootRelay.json +12 -2
  12. package/artifacts/contracts/VASPRegistry.sol/VASPRegistry.json +27 -2
  13. package/artifacts/contracts/{ComplianceRegistry.sol → VerifierRouter.sol}/IGroth16Verifier.json +1 -1
  14. package/artifacts/contracts/VerifierRouter.sol/VerifierRouter.json +741 -0
  15. package/artifacts/contracts/bench/Groth16VerifierBLS.sol/Groth16VerifierBLS.json +35 -0
  16. package/contracts/ComplianceRegistry.sol +186 -35
  17. package/contracts/Groth16Verifier.sol +135 -267
  18. package/contracts/MockVerifier.sol +14 -0
  19. package/contracts/Pairing.sol +147 -0
  20. package/contracts/PairingHarness.sol +27 -0
  21. package/contracts/PilotCurrentRegistry.sol +216 -0
  22. package/contracts/PilotGroth16Verifier.sol +95 -0
  23. package/contracts/PilotRootCheckpoint.sol +68 -0
  24. package/contracts/SanctionsOracle.sol +12 -5
  25. package/contracts/SanctionsRootRelay.sol +6 -2
  26. package/contracts/VASPRegistry.sol +13 -6
  27. package/contracts/VerifierRouter.sol +207 -0
  28. package/contracts/bench/Groth16VerifierBLS.sol +127 -0
  29. package/package.json +6 -2
@@ -0,0 +1,216 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.24;
3
+
4
+ import "@openzeppelin/contracts/access/AccessControl.sol";
5
+ import {PilotGroth16Verifier} from "./PilotGroth16Verifier.sol";
6
+
7
+ /// @notice Development current-state checkpoints and mirrors of consumed PostgreSQL receipts.
8
+ /// @dev Publishers authenticate private source records off-chain (ADR 0006).
9
+ /// This contract verifies their versioned bindings, not JSON/Ed25519 source signatures.
10
+ contract PilotCurrentRegistry is AccessControl {
11
+ uint256 private constant R =
12
+ 21888242871839275222246405745257275088548364400416034343698204186575808495617;
13
+ uint64 private constant MAX_SAFE = 9007199254740991;
14
+ enum Kind { Issuance, Issuers, Sanctions, Credential, Policy, Valuation, Participants, Authorization }
15
+ struct Head {
16
+ bytes32 digest;
17
+ uint256 value;
18
+ uint64 revision;
19
+ uint64 validFrom;
20
+ uint64 validUntil;
21
+ uint64 publisherEpoch;
22
+ bool enabled;
23
+ }
24
+ struct HeadUpdate {
25
+ bytes32 scope;
26
+ bytes32 digest;
27
+ uint256 value;
28
+ uint64 expectedRevision;
29
+ uint64 validFrom;
30
+ uint64 validUntil;
31
+ bool enabled;
32
+ bool replace;
33
+ }
34
+ struct Pin { bytes32 scope; bytes32 digest; uint64 revision; }
35
+ struct Statement {
36
+ bytes32 contextDigest;
37
+ bytes32 transferDigest;
38
+ uint256 projectionCommitment;
39
+ uint64 evaluatedAt;
40
+ uint64 validUntil;
41
+ address consumer;
42
+ Pin[8] pins;
43
+ }
44
+ struct Approval { Statement statement; uint64 publisherEpoch; bool exists; }
45
+
46
+ PilotGroth16Verifier public immutable verifier;
47
+ bytes32 public immutable verifierCodeHash;
48
+ bytes32 public immutable artifactManifestDigest;
49
+ mapping(bytes32 => address) public publishers;
50
+ mapping(bytes32 => uint64) public publisherEpochs;
51
+ mapping(bytes32 => Head) private _heads;
52
+ mapping(bytes32 => Approval) private _statements;
53
+ string public constant consumptionOwner = "postgresql";
54
+ mapping(bytes32 => mapping(uint256 => bytes32)) public mirroredReceipts;
55
+
56
+ error InvalidScope();
57
+ error InvalidState();
58
+ error UnauthorizedPublisher();
59
+ error InvalidStatement();
60
+ error StatementExists();
61
+ error UnauthorizedConsumer();
62
+ error AuthorizationUnavailable();
63
+ error AlreadyMirrored();
64
+ error InvalidProof();
65
+
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);
69
+ event AuthorizationMirrored(bytes32 indexed tenant, bytes32 statementId, bytes32 indexed receiptId, uint256 indexed nullifier);
70
+
71
+ constructor(address admin, PilotGroth16Verifier pairing) {
72
+ if (admin == address(0) || address(pairing).code.length == 0) revert InvalidScope();
73
+ _grantRole(DEFAULT_ADMIN_ROLE, admin);
74
+ verifier = pairing;
75
+ verifierCodeHash = address(pairing).codehash;
76
+ artifactManifestDigest = pairing.artifactManifestDigest();
77
+ if (artifactManifestDigest == bytes32(0)) revert InvalidScope();
78
+ }
79
+
80
+ function setPublisher(bytes32 tenant, address publisher) external onlyRole(DEFAULT_ADMIN_ROLE) {
81
+ if (tenant == bytes32(0)) revert InvalidScope();
82
+ publishers[tenant] = publisher;
83
+ publisherEpochs[tenant] += 1;
84
+ emit PublisherChanged(tenant, publisher, publisherEpochs[tenant]);
85
+ }
86
+
87
+ function _headKey(bytes32 tenant, Kind kind, bytes32 scope) private pure returns (bytes32) {
88
+ return keccak256(abi.encode(tenant, kind, scope));
89
+ }
90
+
91
+ function head(bytes32 tenant, Kind kind, bytes32 scope) external view returns (Head memory) {
92
+ return _heads[_headKey(tenant, kind, scope)];
93
+ }
94
+
95
+ function publishHead(bytes32 tenant, Kind kind, bytes32 scope, bytes32 digest, uint256 value,
96
+ uint64 expectedRevision, uint64 validFrom, uint64 validUntil, bool enabled) public {
97
+ if (msg.sender != publishers[tenant]) revert UnauthorizedPublisher();
98
+ // These time bounds imply validUntil > validFrom, making subtraction safe.
99
+ if (scope == bytes32(0) || digest == bytes32(0) || validFrom > block.timestamp ||
100
+ validUntil <= block.timestamp || validUntil > MAX_SAFE ||
101
+ validUntil - validFrom > 1 days || value >= R ||
102
+ (uint8(kind) >= 3 && kind != Kind.Authorization && value != 0) ||
103
+ (kind == Kind.Authorization && value > 1)) revert InvalidState();
104
+ bytes32 key = _headKey(tenant, kind, scope);
105
+ Head storage previous = _heads[key];
106
+ // Validate caller-supplied revision bounds before comparing the stored head.
107
+ if (expectedRevision >= MAX_SAFE || previous.revision != expectedRevision || validFrom < previous.validFrom) {
108
+ revert InvalidState();
109
+ }
110
+ _heads[key] = Head(digest, value, expectedRevision + 1, validFrom, validUntil, publisherEpochs[tenant], enabled);
111
+ emit HeadPublished(tenant, kind, scope, expectedRevision + 1, digest);
112
+ }
113
+
114
+ function statementId(bytes32 tenant, Statement calldata statement) public pure returns (bytes32) {
115
+ return keccak256(abi.encode(tenant, statement));
116
+ }
117
+
118
+ function _currentHead(bytes32 tenant, Kind kind, Pin memory pin, uint64 evaluatedAt)
119
+ private view returns (Head memory current) {
120
+ current = _heads[_headKey(tenant, kind, pin.scope)];
121
+ uint256 validAt = uint8(kind) >= 6 ? block.timestamp : evaluatedAt;
122
+ if (pin.scope == bytes32(0) || pin.digest == bytes32(0) || pin.revision == 0 || !current.enabled ||
123
+ current.digest != pin.digest || current.revision != pin.revision ||
124
+ current.publisherEpoch != publisherEpochs[tenant] || current.validFrom > validAt ||
125
+ block.timestamp >= current.validUntil) revert InvalidState();
126
+ }
127
+
128
+ function publishStatement(bytes32 tenant, Statement calldata statement) public returns (bytes32 id) {
129
+ if (msg.sender != publishers[tenant]) revert UnauthorizedPublisher();
130
+ if (statement.contextDigest == bytes32(0) || statement.transferDigest == bytes32(0) ||
131
+ statement.projectionCommitment == 0 || statement.projectionCommitment >= R ||
132
+ statement.consumer == address(0) || statement.evaluatedAt > block.timestamp ||
133
+ statement.validUntil <= block.timestamp || statement.validUntil > MAX_SAFE ||
134
+ statement.validUntil > uint256(statement.evaluatedAt) + 300 ||
135
+ statement.pins[7].scope != statement.contextDigest) revert InvalidStatement();
136
+ for (uint8 i; i < 7; ++i) _currentHead(tenant, Kind(i), statement.pins[i], statement.evaluatedAt);
137
+ id = statementId(tenant, statement);
138
+ if (_statements[id].exists) revert StatementExists();
139
+ Approval storage approved = _statements[id];
140
+ approved.publisherEpoch = publisherEpochs[tenant];
141
+ approved.exists = true;
142
+ approved.statement.contextDigest = statement.contextDigest;
143
+ approved.statement.transferDigest = statement.transferDigest;
144
+ approved.statement.projectionCommitment = statement.projectionCommitment;
145
+ approved.statement.evaluatedAt = statement.evaluatedAt;
146
+ approved.statement.validUntil = statement.validUntil;
147
+ approved.statement.consumer = statement.consumer;
148
+ for (uint8 i; i < 8; ++i) approved.statement.pins[i] = statement.pins[i];
149
+ emit StatementPublished(tenant, id, statement.contextDigest);
150
+ }
151
+
152
+ /// @notice Publish a coherent checkpoint set and statement in one transaction.
153
+ /// @dev Exact epochs and revisions reject stale preparation, including reused heads.
154
+ function publishBatch(bytes32 tenant, uint64 expectedEpoch, HeadUpdate[8] calldata updates,
155
+ Statement calldata statement) external returns (bytes32 id) {
156
+ if (msg.sender != publishers[tenant]) revert UnauthorizedPublisher();
157
+ if (expectedEpoch != publisherEpochs[tenant]) revert InvalidState();
158
+ for (uint8 i; i < 8; ++i) {
159
+ HeadUpdate calldata update = updates[i];
160
+ Head memory previous = _heads[_headKey(tenant, Kind(i), update.scope)];
161
+ if (previous.revision != update.expectedRevision || statement.pins[i].scope != update.scope ||
162
+ statement.pins[i].digest != update.digest) revert InvalidState();
163
+ if (update.replace) {
164
+ publishHead(tenant, Kind(i), update.scope, update.digest, update.value,
165
+ update.expectedRevision, update.validFrom, update.validUntil, update.enabled);
166
+ } else if (previous.digest != update.digest || previous.value != update.value ||
167
+ previous.validFrom != update.validFrom || previous.validUntil != update.validUntil ||
168
+ previous.enabled != update.enabled) revert InvalidState();
169
+ _currentHead(tenant, Kind(i), statement.pins[i], statement.evaluatedAt);
170
+ }
171
+ id = publishStatement(tenant, statement);
172
+ }
173
+
174
+ /// @notice Reconcile an uncertain publication by its deterministic statement ID.
175
+ function statementPublication(bytes32 id) external view returns (bool exists, uint64 epoch) {
176
+ Approval storage approved = _statements[id];
177
+ return (approved.exists, approved.publisherEpoch);
178
+ }
179
+
180
+ 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) {
182
+ Approval storage approved = _statements[id];
183
+ if (!approved.exists || publishers[tenant] == address(0) || approved.publisherEpoch != publisherEpochs[tenant] ||
184
+ address(verifier).codehash != verifierCodeHash) revert InvalidStatement();
185
+ Statement memory statement = approved.statement;
186
+ // Publication checked evaluatedAt; approvals are immutable and chain time is monotonic.
187
+ 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))) {
191
+ revert InvalidStatement();
192
+ }
193
+ for (uint8 i; i < 7; ++i) {
194
+ 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();
196
+ }
197
+ return verifier.verifyProof(a, b, c, signals);
198
+ }
199
+
200
+ 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) {
202
+ return _inspect(tenant, id, a, b, c, signals);
203
+ }
204
+
205
+ 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 {
207
+ Approval storage approved = _statements[id];
208
+ if (!approved.exists || msg.sender != approved.statement.consumer) revert UnauthorizedConsumer();
209
+ if (mirroredReceipts[tenant][signals[3]] != bytes32(0)) revert AlreadyMirrored();
210
+ if (!_inspect(tenant, id, a, b, c, signals)) revert InvalidProof();
211
+ Head memory decision = _currentHead(tenant, Kind.Authorization, approved.statement.pins[7], approved.statement.evaluatedAt);
212
+ if (decision.value != 1 || decision.digest != receiptId) revert AuthorizationUnavailable();
213
+ mirroredReceipts[tenant][signals[3]] = receiptId;
214
+ emit AuthorizationMirrored(tenant, id, receiptId, signals[3]);
215
+ }
216
+ }
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.24;
3
+
4
+ import {Pairing} from "./Pairing.sol";
5
+
6
+ /// @notice Fixed eight-signal Groth16 pairing for the development pilot profile.
7
+ /// @dev Key material is immutable after deployment. This does not approve that key,
8
+ /// reconstruct current statements, authenticate policy facts or consume nullifiers.
9
+ contract PilotGroth16Verifier {
10
+ uint256 private constant Q =
11
+ 21888242871839275222246405745257275088696311157297823662689037894645226208583;
12
+ uint256 private constant R =
13
+ 21888242871839275222246405745257275088548364400416034343698204186575808495617;
14
+
15
+ struct VerificationKey {
16
+ uint256[2] alpha;
17
+ uint256[2][2] beta;
18
+ uint256[2][2] gamma;
19
+ uint256[2][2] delta;
20
+ uint256[2][9] ic;
21
+ }
22
+
23
+ VerificationKey private _key;
24
+ bytes32 public immutable verificationKeyCommitment;
25
+ bytes32 public immutable artifactManifestDigest;
26
+ string public constant proofProfile = "pilot-transfer-v3";
27
+ string public constant assurance = "development-unapproved";
28
+
29
+ error InvalidCoordinate();
30
+ error InvalidKey();
31
+ error NoncanonicalSignal();
32
+
33
+ constructor(VerificationKey memory key, bytes32 manifestDigest) {
34
+ if (manifestDigest == bytes32(0)) revert InvalidKey();
35
+ _validateG1(key.alpha);
36
+ for (uint256 i; i < 9; ++i) _validateG1(key.ic[i]);
37
+ _validateG2(key.beta);
38
+ _validateG2(key.gamma);
39
+ _validateG2(key.delta);
40
+ _key = key;
41
+ verificationKeyCommitment = keccak256(abi.encode(key));
42
+ artifactManifestDigest = manifestDigest;
43
+ }
44
+
45
+ function _g1(uint256[2] memory p) private pure returns (Pairing.G1Point memory) {
46
+ if (p[0] >= Q || p[1] >= Q) revert InvalidCoordinate();
47
+ return Pairing.G1Point(p[0], p[1]);
48
+ }
49
+
50
+ function _g2(uint256[2][2] memory p) private pure returns (Pairing.G2Point memory) {
51
+ for (uint256 i; i < 2; ++i) {
52
+ for (uint256 j; j < 2; ++j) if (p[i][j] >= Q) revert InvalidCoordinate();
53
+ }
54
+ return Pairing.G2Point(p[0], p[1]);
55
+ }
56
+
57
+ function _validateG1(uint256[2] memory p) private view {
58
+ if (p[0] == 0 && p[1] == 0) revert InvalidKey();
59
+ Pairing.scalar_mul(_g1(p), 1); // Precompile validates curve membership.
60
+ }
61
+
62
+ function _validateG2(uint256[2][2] memory p) private view {
63
+ if (p[0][0] == 0 && p[0][1] == 0 && p[1][0] == 0 && p[1][1] == 0) revert InvalidKey();
64
+ Pairing.G1Point[] memory left = new Pairing.G1Point[](2);
65
+ Pairing.G2Point[] memory right = new Pairing.G2Point[](2);
66
+ left[0] = Pairing.P1();
67
+ left[1] = Pairing.negate(Pairing.P1());
68
+ right[0] = _g2(p);
69
+ right[1] = right[0];
70
+ if (!Pairing.pairing(left, right)) revert InvalidKey();
71
+ }
72
+
73
+ /// @dev G2 coordinates use EVM precompile order, the reverse of snarkjs JSON pairs.
74
+ /// Invalid encodings may revert; false means a well-encoded failed pairing.
75
+ function verifyProof(
76
+ uint256[2] calldata a, uint256[2][2] calldata b, uint256[2] calldata c,
77
+ uint256[8] calldata signals
78
+ ) external view returns (bool) {
79
+ // Check before negation so noncanonical y + Q cannot be silently reduced.
80
+ Pairing.G1Point memory pointA = _g1(a);
81
+ Pairing.G2Point memory pointB = _g2(b);
82
+ Pairing.G1Point memory pointC = _g1(c);
83
+ Pairing.G1Point memory accumulator = _g1(_key.ic[0]);
84
+ for (uint256 i; i < 8; ++i) {
85
+ if (signals[i] >= R) revert NoncanonicalSignal();
86
+ accumulator = Pairing.add(accumulator, Pairing.scalar_mul(_g1(_key.ic[i + 1]), signals[i]));
87
+ }
88
+ return Pairing.pairingProd4(
89
+ Pairing.negate(pointA), pointB,
90
+ _g1(_key.alpha), _g2(_key.beta),
91
+ accumulator, _g2(_key.gamma),
92
+ pointC, _g2(_key.delta)
93
+ );
94
+ }
95
+ }
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.24;
3
+
4
+ import "@openzeppelin/contracts/access/AccessControl.sol";
5
+
6
+ /// @notice Current root approval checkpoints independent of the credential DB.
7
+ /// @dev Scoped publishers authenticate registrar JSON/Ed25519 approvals off-chain.
8
+ /// This contract neither parses those approvals nor verifies ZK proofs.
9
+ contract PilotRootCheckpoint is AccessControl {
10
+ uint256 private constant SCALAR_FIELD =
11
+ 21888242871839275222246405745257275088548364400416034343698204186575808495617;
12
+ uint64 private constant MAX_SAFE_INTEGER = 9007199254740991;
13
+ error InvalidScope();
14
+ error UnauthorizedPublisher();
15
+ error StaleRevision();
16
+ error InvalidApproval();
17
+
18
+ struct Checkpoint {
19
+ bytes32 snapshotDigest;
20
+ uint256 root;
21
+ uint64 revision;
22
+ uint64 validFrom;
23
+ uint64 validUntil;
24
+ uint64 publishedAt;
25
+ }
26
+ mapping(bytes32 tenantHash => address) public publishers;
27
+ mapping(bytes32 key => Checkpoint) private _heads;
28
+ event PublisherChanged(bytes32 indexed tenantHash, address indexed publisher);
29
+ event RootCheckpointPublished(
30
+ bytes32 indexed tenantHash, bytes32 indexed rootScope, bytes32 indexed snapshotDigest,
31
+ uint256 root, uint64 revision, uint64 validFrom, uint64 validUntil
32
+ );
33
+
34
+ constructor(address admin) {
35
+ if (admin == address(0)) revert InvalidScope();
36
+ _grantRole(DEFAULT_ADMIN_ROLE, admin);
37
+ }
38
+
39
+ function setPublisher(bytes32 tenantHash, address publisher) external onlyRole(DEFAULT_ADMIN_ROLE) {
40
+ if (tenantHash == bytes32(0)) revert InvalidScope();
41
+ // Zero address deliberately disables publication for this tenant.
42
+ publishers[tenantHash] = publisher;
43
+ emit PublisherChanged(tenantHash, publisher);
44
+ }
45
+
46
+ function head(bytes32 tenantHash, bytes32 rootScope) external view returns (Checkpoint memory) {
47
+ return _heads[keccak256(abi.encode(tenantHash, rootScope))];
48
+ }
49
+
50
+ function publish(
51
+ bytes32 tenantHash, bytes32 rootScope, bytes32 snapshotDigest, uint256 root,
52
+ uint64 expectedRevision, uint64 approvalRevision, uint64 validFrom, uint64 validUntil
53
+ ) external {
54
+ if (tenantHash == bytes32(0) || rootScope == bytes32(0)) revert InvalidScope();
55
+ if (msg.sender != publishers[tenantHash]) revert UnauthorizedPublisher();
56
+ bytes32 key = keccak256(abi.encode(tenantHash, rootScope));
57
+ Checkpoint storage previous = _heads[key];
58
+ if (expectedRevision != previous.revision || approvalRevision <= previous.revision) revert StaleRevision();
59
+ // The clock bounds imply validUntil > validFrom before subtraction.
60
+ if (
61
+ snapshotDigest == bytes32(0) || root >= SCALAR_FIELD || approvalRevision > MAX_SAFE_INTEGER ||
62
+ validFrom > block.timestamp || validFrom < previous.validFrom || validUntil <= block.timestamp ||
63
+ validUntil - validFrom > 1 days || validUntil > MAX_SAFE_INTEGER
64
+ ) revert InvalidApproval();
65
+ _heads[key] = Checkpoint(snapshotDigest, root, approvalRevision, validFrom, validUntil, uint64(block.timestamp));
66
+ emit RootCheckpointPublished(tenantHash, rootScope, snapshotDigest, root, approvalRevision, validFrom, validUntil);
67
+ }
68
+ }
@@ -7,6 +7,13 @@ import "@openzeppelin/contracts/access/AccessControl.sol";
7
7
  import "@openzeppelin/contracts/utils/Pausable.sol";
8
8
 
9
9
  contract SanctionsOracle is AccessControl, Pausable {
10
+ // Custom errors
11
+ error ZeroAdmin();
12
+ error ZeroRoot();
13
+ error CooldownActive();
14
+ error LeafCountDecreasedTooMuch();
15
+ error PeriodOutOfBounds();
16
+
10
17
  bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");
11
18
 
12
19
  bytes32 public currentRoot;
@@ -36,7 +43,7 @@ contract SanctionsOracle is AccessControl, Pausable {
36
43
 
37
44
  constructor(address admin, bytes32 initialRoot, uint32 initialLeafCount) {
38
45
  // M-7: Zero-address validation
39
- require(admin != address(0), "Zero admin");
46
+ if (admin == address(0)) revert ZeroAdmin();
40
47
  _grantRole(DEFAULT_ADMIN_ROLE, admin);
41
48
  _grantRole(ORACLE_ROLE, admin);
42
49
  currentRoot = initialRoot;
@@ -46,11 +53,11 @@ contract SanctionsOracle is AccessControl, Pausable {
46
53
  }
47
54
 
48
55
  function updateRoot(bytes32 newRoot, uint32 _leafCount) external onlyRole(ORACLE_ROLE) whenNotPaused {
49
- require(newRoot != bytes32(0), "Zero root");
50
- require(block.timestamp >= lastUpdated + UPDATE_COOLDOWN, "Cooldown active");
56
+ if (newRoot == bytes32(0)) revert ZeroRoot();
57
+ if (block.timestamp < lastUpdated + UPDATE_COOLDOWN) revert CooldownActive();
51
58
 
52
59
  // H-3: Leaf count floor — prevent silently clearing the sanctions list
53
- require(_leafCount >= leafCount / 2, "Leaf count decreased too much");
60
+ if (_leafCount < leafCount / 2) revert LeafCountDecreasedTooMuch();
54
61
 
55
62
  bytes32 old = currentRoot;
56
63
  currentRoot = newRoot;
@@ -71,7 +78,7 @@ contract SanctionsOracle is AccessControl, Pausable {
71
78
 
72
79
  // M-2: Allow admin to configure grace period within bounds
73
80
  function setGracePeriod(uint256 newPeriod) external onlyRole(DEFAULT_ADMIN_ROLE) {
74
- require(newPeriod >= 6 hours && newPeriod <= 168 hours, "Period out of bounds");
81
+ if (newPeriod < 6 hours || newPeriod > 168 hours) revert PeriodOutOfBounds();
75
82
  uint256 oldPeriod = gracePeriod;
76
83
  gracePeriod = newPeriod;
77
84
  emit GracePeriodUpdated(oldPeriod, newPeriod);
@@ -23,6 +23,10 @@ import "./ISanctionsRootReceiver.sol";
23
23
  * 4. No oracle redeployment needed
24
24
  */
25
25
  contract SanctionsRootRelay is ISanctionsRootReceiver, AccessControl {
26
+ // Custom errors
27
+ error ZeroAdmin();
28
+ error ZeroOracle();
29
+
26
30
  bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE");
27
31
 
28
32
  SanctionsOracle public immutable oracle;
@@ -30,8 +34,8 @@ contract SanctionsRootRelay is ISanctionsRootReceiver, AccessControl {
30
34
  event RootRelayed(bytes32 indexed root, uint32 leafCount, address indexed relayer);
31
35
 
32
36
  constructor(address admin, address oracleAddress) {
33
- require(admin != address(0), "Zero admin");
34
- require(oracleAddress != address(0), "Zero oracle");
37
+ if (admin == address(0)) revert ZeroAdmin();
38
+ if (oracleAddress == address(0)) revert ZeroOracle();
35
39
  _grantRole(DEFAULT_ADMIN_ROLE, admin);
36
40
  _grantRole(RELAYER_ROLE, admin);
37
41
  oracle = SanctionsOracle(oracleAddress);
@@ -7,6 +7,13 @@ import "@openzeppelin/contracts/access/AccessControl.sol";
7
7
  import "@openzeppelin/contracts/utils/Pausable.sol";
8
8
 
9
9
  contract VASPRegistry is AccessControl, Pausable {
10
+ // Custom errors
11
+ error ZeroAdmin();
12
+ error AlreadyRegistered();
13
+ error NotActive();
14
+ error NotRegistered();
15
+ error AlreadyActive();
16
+
10
17
  bytes32 public constant REGISTRAR_ROLE = keccak256("REGISTRAR_ROLE");
11
18
 
12
19
  struct VASP {
@@ -31,7 +38,7 @@ contract VASPRegistry is AccessControl, Pausable {
31
38
 
32
39
  constructor(address admin) {
33
40
  // M-7: Zero-address validation
34
- require(admin != address(0), "Zero admin");
41
+ if (admin == address(0)) revert ZeroAdmin();
35
42
  _grantRole(DEFAULT_ADMIN_ROLE, admin);
36
43
  _grantRole(REGISTRAR_ROLE, admin);
37
44
  }
@@ -42,7 +49,7 @@ contract VASPRegistry is AccessControl, Pausable {
42
49
  string calldata jurisdiction,
43
50
  string calldata discoveryEndpoint
44
51
  ) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
45
- require(vasps[didHash].registeredAt == 0, "Already registered");
52
+ if (vasps[didHash].registeredAt != 0) revert AlreadyRegistered();
46
53
  vasps[didHash] = VASP(wallet, jurisdiction, discoveryEndpoint, true, uint64(block.timestamp));
47
54
  vaspIds.push(didHash);
48
55
  activeVaspCount++; // M-6
@@ -53,7 +60,7 @@ contract VASPRegistry is AccessControl, Pausable {
53
60
  bytes32 didHash,
54
61
  string calldata newEndpoint
55
62
  ) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
56
- require(vasps[didHash].active, "Not active");
63
+ if (!vasps[didHash].active) revert NotActive();
57
64
  vasps[didHash].discoveryEndpoint = newEndpoint;
58
65
  emit DiscoveryEndpointUpdated(didHash, newEndpoint);
59
66
  }
@@ -64,7 +71,7 @@ contract VASPRegistry is AccessControl, Pausable {
64
71
 
65
72
  // M-8: Added whenNotPaused — revocation requires explicit unpause for safety
66
73
  function revokeVASP(bytes32 didHash) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
67
- require(vasps[didHash].active, "Not active");
74
+ if (!vasps[didHash].active) revert NotActive();
68
75
  vasps[didHash].active = false;
69
76
  activeVaspCount--; // M-6
70
77
  emit VASPRevoked(didHash);
@@ -72,8 +79,8 @@ contract VASPRegistry is AccessControl, Pausable {
72
79
 
73
80
  // H-5: Reactivate a previously revoked VASP with a new wallet
74
81
  function reactivateVASP(bytes32 didHash, address newWallet) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
75
- require(vasps[didHash].registeredAt != 0, "Not registered");
76
- require(!vasps[didHash].active, "Already active");
82
+ if (vasps[didHash].registeredAt == 0) revert NotRegistered();
83
+ if (vasps[didHash].active) revert AlreadyActive();
77
84
  vasps[didHash].active = true;
78
85
  vasps[didHash].wallet = newWallet;
79
86
  activeVaspCount++; // M-6