@clearproof/contracts 0.1.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.
- package/artifacts/contracts/ComplianceRegistry.sol/ComplianceRegistry.json +584 -0
- package/artifacts/contracts/ComplianceRegistry.sol/IGroth16Verifier.json +45 -0
- package/artifacts/contracts/Groth16Verifier.sol/Groth16Verifier.json +45 -0
- package/artifacts/contracts/SanctionsOracle.sol/SanctionsOracle.json +560 -0
- package/artifacts/contracts/VASPRegistry.sol/VASPRegistry.json +596 -0
- package/contracts/ComplianceRegistry.sol +130 -0
- package/contracts/Groth16Verifier.sol +266 -0
- package/contracts/SanctionsOracle.sol +93 -0
- package/contracts/VASPRegistry.sol +87 -0
- package/package.json +39 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.24;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/access/AccessControl.sol";
|
|
5
|
+
import "@openzeppelin/contracts/utils/Pausable.sol";
|
|
6
|
+
import "./VASPRegistry.sol";
|
|
7
|
+
import "./SanctionsOracle.sol";
|
|
8
|
+
|
|
9
|
+
/// @dev Interface for the Groth16 verifier with 15 public signals.
|
|
10
|
+
/// The concrete Groth16Verifier.sol will be regenerated after circuit recompilation.
|
|
11
|
+
interface IGroth16Verifier {
|
|
12
|
+
function verifyProof(
|
|
13
|
+
uint[2] calldata _pA,
|
|
14
|
+
uint[2][2] calldata _pB,
|
|
15
|
+
uint[2] calldata _pC,
|
|
16
|
+
uint[15] calldata _pubSignals
|
|
17
|
+
) external view returns (bool);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
contract ComplianceRegistry is AccessControl, Pausable {
|
|
21
|
+
bytes32 public constant REVOKER_ROLE = keccak256("REVOKER_ROLE");
|
|
22
|
+
|
|
23
|
+
IGroth16Verifier public immutable verifier;
|
|
24
|
+
VASPRegistry public immutable vaspRegistry;
|
|
25
|
+
SanctionsOracle public immutable sanctionsOracle;
|
|
26
|
+
|
|
27
|
+
struct ProofRecord {
|
|
28
|
+
bytes32 proofHash;
|
|
29
|
+
uint256 timestamp;
|
|
30
|
+
bool verified;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
mapping(bytes32 => ProofRecord) public proofs;
|
|
34
|
+
mapping(bytes32 => bool) public revokedCredentials;
|
|
35
|
+
mapping(bytes32 => bool) public usedNullifiers;
|
|
36
|
+
|
|
37
|
+
event ProofVerified(bytes32 indexed transferId, bytes32 indexed nullifier, bool isCompliant, bool sarFlag);
|
|
38
|
+
event CredentialRevoked(bytes32 indexed commitment, address revoker);
|
|
39
|
+
|
|
40
|
+
constructor(address _verifier, address _vaspRegistry, address _sanctionsOracle) {
|
|
41
|
+
// M-7: Zero-address validation
|
|
42
|
+
require(_verifier != address(0), "Zero verifier");
|
|
43
|
+
require(_vaspRegistry != address(0), "Zero registry");
|
|
44
|
+
require(_sanctionsOracle != address(0), "Zero oracle");
|
|
45
|
+
|
|
46
|
+
verifier = IGroth16Verifier(_verifier);
|
|
47
|
+
vaspRegistry = VASPRegistry(_vaspRegistry);
|
|
48
|
+
sanctionsOracle = SanctionsOracle(_sanctionsOracle);
|
|
49
|
+
|
|
50
|
+
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
|
51
|
+
_grantRole(REVOKER_ROLE, msg.sender);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function verifyAndRecord(
|
|
55
|
+
bytes32 transferId,
|
|
56
|
+
uint[2] calldata _pA,
|
|
57
|
+
uint[2][2] calldata _pB,
|
|
58
|
+
uint[2] calldata _pC,
|
|
59
|
+
uint[15] calldata _pubSignals,
|
|
60
|
+
bytes32 vaspDidHash
|
|
61
|
+
) external whenNotPaused returns (bool) {
|
|
62
|
+
// Replay prevention
|
|
63
|
+
require(proofs[transferId].timestamp == 0, "Transfer already recorded");
|
|
64
|
+
|
|
65
|
+
// H-6: Dependency health checks
|
|
66
|
+
require(!sanctionsOracle.paused(), "Sanctions oracle paused");
|
|
67
|
+
require(!vaspRegistry.paused(), "VASP registry paused");
|
|
68
|
+
require(!sanctionsOracle.isStale(), "Sanctions oracle stale");
|
|
69
|
+
require(vaspRegistry.isActive(vaspDidHash), "VASP not active");
|
|
70
|
+
|
|
71
|
+
// Sender binding
|
|
72
|
+
(address vaspWallet,,, ) = vaspRegistry.vasps(vaspDidHash);
|
|
73
|
+
require(msg.sender == vaspWallet, "Not registered VASP wallet");
|
|
74
|
+
|
|
75
|
+
// C-3: Domain binding (cross-chain replay protection)
|
|
76
|
+
require(_pubSignals[11] == block.chainid, "Wrong chain");
|
|
77
|
+
require(uint256(keccak256(abi.encodePacked(address(this)))) == _pubSignals[12], "Wrong contract");
|
|
78
|
+
|
|
79
|
+
// C-4: State binding (proof matches current on-chain roots)
|
|
80
|
+
require(bytes32(_pubSignals[2]) == sanctionsOracle.currentRoot(), "Sanctions root mismatch");
|
|
81
|
+
require(bytes32(_pubSignals[3]) == vaspRegistry.issuerMerkleRoot(), "Issuer root mismatch");
|
|
82
|
+
|
|
83
|
+
// M-1: Transfer binding (proof bound to this transfer)
|
|
84
|
+
require(uint256(keccak256(abi.encodePacked(transferId))) == _pubSignals[13], "Transfer ID mismatch");
|
|
85
|
+
|
|
86
|
+
// C-5: Credential revocation check
|
|
87
|
+
require(!revokedCredentials[bytes32(_pubSignals[7])], "Credential revoked");
|
|
88
|
+
|
|
89
|
+
// M-3: Nullifier — one-time proof use (prevents same proof on different transferIds)
|
|
90
|
+
bytes32 nullifier = bytes32(_pubSignals[14]);
|
|
91
|
+
require(!usedNullifiers[nullifier], "Proof already used");
|
|
92
|
+
|
|
93
|
+
// C-1: Cryptographic verification — revert on invalid proof
|
|
94
|
+
bool valid = verifier.verifyProof(_pA, _pB, _pC, _pubSignals);
|
|
95
|
+
require(valid, "Proof verification failed");
|
|
96
|
+
|
|
97
|
+
// Record
|
|
98
|
+
usedNullifiers[nullifier] = true;
|
|
99
|
+
proofs[transferId] = ProofRecord({
|
|
100
|
+
proofHash: keccak256(abi.encode(_pA, _pB, _pC, _pubSignals)), // H-1: includes pubSignals
|
|
101
|
+
timestamp: block.timestamp,
|
|
102
|
+
verified: true // Always true now (we revert on invalid)
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
emit ProofVerified(transferId, nullifier, _pubSignals[0] == 1, _pubSignals[1] == 1);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function revokeCredential(bytes32 commitment) external onlyRole(REVOKER_ROLE) {
|
|
110
|
+
require(!revokedCredentials[commitment], "Already revoked");
|
|
111
|
+
revokedCredentials[commitment] = true;
|
|
112
|
+
emit CredentialRevoked(commitment, msg.sender);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isRevoked(bytes32 commitment) external view returns (bool) {
|
|
116
|
+
return revokedCredentials[commitment];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isVerified(bytes32 transferId) external view returns (bool) {
|
|
120
|
+
return proofs[transferId].verified;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
124
|
+
_pause();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
128
|
+
_unpause();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2021 0KIMS association.
|
|
4
|
+
|
|
5
|
+
This file is generated with [snarkJS](https://github.com/iden3/snarkjs).
|
|
6
|
+
|
|
7
|
+
snarkJS is a free software: you can redistribute it and/or modify it
|
|
8
|
+
under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
snarkJS is distributed in the hope that it will be useful, but WITHOUT
|
|
13
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
14
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
15
|
+
License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with snarkJS. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
pragma solidity >=0.7.0 <0.9.0;
|
|
22
|
+
|
|
23
|
+
contract Groth16Verifier {
|
|
24
|
+
// Scalar field size
|
|
25
|
+
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
|
26
|
+
// Base field size
|
|
27
|
+
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
|
28
|
+
|
|
29
|
+
// Verification Key data
|
|
30
|
+
uint256 constant alphax = 14520529041790456786995074540012157593114958168944110579383159897030270421683;
|
|
31
|
+
uint256 constant alphay = 12190044747698844131408403166438846980657017889827211487113361059707207182672;
|
|
32
|
+
uint256 constant betax1 = 3099300253378967695622319524995410925435112289546553940785697138041984453350;
|
|
33
|
+
uint256 constant betax2 = 8591562137143704349741918814436587940548574783735952328854272429056062986345;
|
|
34
|
+
uint256 constant betay1 = 19732336449763641045562402464710747257728246716611257381901316297113485311837;
|
|
35
|
+
uint256 constant betay2 = 17725255565992761070677663510410141440524977079751397615130866129662422673787;
|
|
36
|
+
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
|
37
|
+
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
|
38
|
+
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
|
39
|
+
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
40
|
+
uint256 constant deltax1 = 11208820528355933937509114257038767265250708247101889906384837742638040921911;
|
|
41
|
+
uint256 constant deltax2 = 2351724291376613172494929879166749577904947733878282329485300734950500675429;
|
|
42
|
+
uint256 constant deltay1 = 10071807493466688233648885001460033354886249407194332712779982294125684050067;
|
|
43
|
+
uint256 constant deltay2 = 10186720019104201576680755920258602838799608381365293611527506022359293309127;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
uint256 constant IC0x = 12101374489738417303840181572580069764732363057515680683745090219107645090682;
|
|
47
|
+
uint256 constant IC0y = 6622868140565385066376227039427993681099925034474371659030596024890146904163;
|
|
48
|
+
|
|
49
|
+
uint256 constant IC1x = 3669173732190367513652034287079810078449694464897815690603816498785194709298;
|
|
50
|
+
uint256 constant IC1y = 12787552409465063176671040388968071843096720382928171325958634655937745904306;
|
|
51
|
+
|
|
52
|
+
uint256 constant IC2x = 10170489719246253671314687317213013791640770166137501428884495801025758736797;
|
|
53
|
+
uint256 constant IC2y = 6252395882627424781706364969531995749933564822768034059098225707092062892276;
|
|
54
|
+
|
|
55
|
+
uint256 constant IC3x = 10687481240706766603557091601215731928279126584360618324726499550379950672384;
|
|
56
|
+
uint256 constant IC3y = 18232245990332373208670193454828315865982081800651657649905394892430114319137;
|
|
57
|
+
|
|
58
|
+
uint256 constant IC4x = 21479520805308843176453350540312157689793392686894956217336144931222100248332;
|
|
59
|
+
uint256 constant IC4y = 20794240477273416707592605344748314870068446001913164610390302381834843364218;
|
|
60
|
+
|
|
61
|
+
uint256 constant IC5x = 1639431340488776769304709738824454095007661834601823301121609655140677204345;
|
|
62
|
+
uint256 constant IC5y = 20241100315007980443635026076756163052388871674389145654353231874849036162838;
|
|
63
|
+
|
|
64
|
+
uint256 constant IC6x = 121645431274525990360138477525109868662860092956168925828298462395321687784;
|
|
65
|
+
uint256 constant IC6y = 794747987098961918220870106626898804586360564216491869032162762989366388476;
|
|
66
|
+
|
|
67
|
+
uint256 constant IC7x = 2203372645692227215676899858833836590816324059236287726456820657448783477922;
|
|
68
|
+
uint256 constant IC7y = 2207309673745076358166732988325125705730197773311277805000897437308566547524;
|
|
69
|
+
|
|
70
|
+
uint256 constant IC8x = 7661536419049628598164594465666263178650205781527068355000772766824470727314;
|
|
71
|
+
uint256 constant IC8y = 8811196404119343314769069609010829337590521896699063939687119401222942408654;
|
|
72
|
+
|
|
73
|
+
uint256 constant IC9x = 21343499519323604545088998121814591820494318698260047386701341623495150952819;
|
|
74
|
+
uint256 constant IC9y = 6690944176613940177567986909847360918607057563241644423161570806785072607212;
|
|
75
|
+
|
|
76
|
+
uint256 constant IC10x = 15264014509141355058781275071990577551887158548257857606419165483731082471950;
|
|
77
|
+
uint256 constant IC10y = 15216600797471553468459707999770136646723171284081709084120301846088036216358;
|
|
78
|
+
|
|
79
|
+
uint256 constant IC11x = 12733780935417197072452063628052190220002459201228095695184676669312707904830;
|
|
80
|
+
uint256 constant IC11y = 16298108809776740697899759704974665278820323554206358196275176082801210672419;
|
|
81
|
+
|
|
82
|
+
uint256 constant IC12x = 6012479247763961858712330659591617235298186231561389312795940364358559647113;
|
|
83
|
+
uint256 constant IC12y = 14721923019704138783748153829207729465935088314626429943383893818959078617779;
|
|
84
|
+
|
|
85
|
+
uint256 constant IC13x = 13061379726279750555423847998978370480196471520457553871911806444367687353028;
|
|
86
|
+
uint256 constant IC13y = 2975548495951886948231673481109927887365893753862741621324254610502694261941;
|
|
87
|
+
|
|
88
|
+
uint256 constant IC14x = 17048825568529186912687446126032713752166726936647722462681262666976911028917;
|
|
89
|
+
uint256 constant IC14y = 4770007883853892820003356098186534463380640029144851943088490003586536185193;
|
|
90
|
+
|
|
91
|
+
uint256 constant IC15x = 13628101711350889888526860037192365772666344522220684297140938100564664858788;
|
|
92
|
+
uint256 constant IC15y = 4355821266360537693062567273491516561731162144993540609483109600550687891933;
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// Memory data
|
|
96
|
+
uint16 constant pVk = 0;
|
|
97
|
+
uint16 constant pPairing = 128;
|
|
98
|
+
|
|
99
|
+
uint16 constant pLastMem = 896;
|
|
100
|
+
|
|
101
|
+
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[15] calldata _pubSignals) public view returns (bool) {
|
|
102
|
+
assembly {
|
|
103
|
+
function checkField(v) {
|
|
104
|
+
if iszero(lt(v, r)) {
|
|
105
|
+
mstore(0, 0)
|
|
106
|
+
return(0, 0x20)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// G1 function to multiply a G1 value(x,y) to value in an address
|
|
111
|
+
function g1_mulAccC(pR, x, y, s) {
|
|
112
|
+
let success
|
|
113
|
+
let mIn := mload(0x40)
|
|
114
|
+
mstore(mIn, x)
|
|
115
|
+
mstore(add(mIn, 32), y)
|
|
116
|
+
mstore(add(mIn, 64), s)
|
|
117
|
+
|
|
118
|
+
success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
|
|
119
|
+
|
|
120
|
+
if iszero(success) {
|
|
121
|
+
mstore(0, 0)
|
|
122
|
+
return(0, 0x20)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
mstore(add(mIn, 64), mload(pR))
|
|
126
|
+
mstore(add(mIn, 96), mload(add(pR, 32)))
|
|
127
|
+
|
|
128
|
+
success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
|
|
129
|
+
|
|
130
|
+
if iszero(success) {
|
|
131
|
+
mstore(0, 0)
|
|
132
|
+
return(0, 0x20)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
|
|
137
|
+
let _pPairing := add(pMem, pPairing)
|
|
138
|
+
let _pVk := add(pMem, pVk)
|
|
139
|
+
|
|
140
|
+
mstore(_pVk, IC0x)
|
|
141
|
+
mstore(add(_pVk, 32), IC0y)
|
|
142
|
+
|
|
143
|
+
// Compute the linear combination vk_x
|
|
144
|
+
|
|
145
|
+
g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
|
|
146
|
+
|
|
147
|
+
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
|
|
148
|
+
|
|
149
|
+
g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
|
|
150
|
+
|
|
151
|
+
g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
|
|
152
|
+
|
|
153
|
+
g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
|
|
154
|
+
|
|
155
|
+
g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
|
|
156
|
+
|
|
157
|
+
g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
|
|
158
|
+
|
|
159
|
+
g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
|
|
160
|
+
|
|
161
|
+
g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
|
|
162
|
+
|
|
163
|
+
g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
|
|
164
|
+
|
|
165
|
+
g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
|
|
166
|
+
|
|
167
|
+
g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
|
|
168
|
+
|
|
169
|
+
g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384)))
|
|
170
|
+
|
|
171
|
+
g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416)))
|
|
172
|
+
|
|
173
|
+
g1_mulAccC(_pVk, IC15x, IC15y, calldataload(add(pubSignals, 448)))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
// -A
|
|
177
|
+
mstore(_pPairing, calldataload(pA))
|
|
178
|
+
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
|
179
|
+
|
|
180
|
+
// B
|
|
181
|
+
mstore(add(_pPairing, 64), calldataload(pB))
|
|
182
|
+
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
|
|
183
|
+
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
|
|
184
|
+
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
|
|
185
|
+
|
|
186
|
+
// alpha1
|
|
187
|
+
mstore(add(_pPairing, 192), alphax)
|
|
188
|
+
mstore(add(_pPairing, 224), alphay)
|
|
189
|
+
|
|
190
|
+
// beta2
|
|
191
|
+
mstore(add(_pPairing, 256), betax1)
|
|
192
|
+
mstore(add(_pPairing, 288), betax2)
|
|
193
|
+
mstore(add(_pPairing, 320), betay1)
|
|
194
|
+
mstore(add(_pPairing, 352), betay2)
|
|
195
|
+
|
|
196
|
+
// vk_x
|
|
197
|
+
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
|
198
|
+
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
// gamma2
|
|
202
|
+
mstore(add(_pPairing, 448), gammax1)
|
|
203
|
+
mstore(add(_pPairing, 480), gammax2)
|
|
204
|
+
mstore(add(_pPairing, 512), gammay1)
|
|
205
|
+
mstore(add(_pPairing, 544), gammay2)
|
|
206
|
+
|
|
207
|
+
// C
|
|
208
|
+
mstore(add(_pPairing, 576), calldataload(pC))
|
|
209
|
+
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
|
|
210
|
+
|
|
211
|
+
// delta2
|
|
212
|
+
mstore(add(_pPairing, 640), deltax1)
|
|
213
|
+
mstore(add(_pPairing, 672), deltax2)
|
|
214
|
+
mstore(add(_pPairing, 704), deltay1)
|
|
215
|
+
mstore(add(_pPairing, 736), deltay2)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
|
219
|
+
|
|
220
|
+
isOk := and(success, mload(_pPairing))
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let pMem := mload(0x40)
|
|
224
|
+
mstore(0x40, add(pMem, pLastMem))
|
|
225
|
+
|
|
226
|
+
// Validate that all evaluations ∈ F
|
|
227
|
+
|
|
228
|
+
checkField(calldataload(add(_pubSignals, 0)))
|
|
229
|
+
|
|
230
|
+
checkField(calldataload(add(_pubSignals, 32)))
|
|
231
|
+
|
|
232
|
+
checkField(calldataload(add(_pubSignals, 64)))
|
|
233
|
+
|
|
234
|
+
checkField(calldataload(add(_pubSignals, 96)))
|
|
235
|
+
|
|
236
|
+
checkField(calldataload(add(_pubSignals, 128)))
|
|
237
|
+
|
|
238
|
+
checkField(calldataload(add(_pubSignals, 160)))
|
|
239
|
+
|
|
240
|
+
checkField(calldataload(add(_pubSignals, 192)))
|
|
241
|
+
|
|
242
|
+
checkField(calldataload(add(_pubSignals, 224)))
|
|
243
|
+
|
|
244
|
+
checkField(calldataload(add(_pubSignals, 256)))
|
|
245
|
+
|
|
246
|
+
checkField(calldataload(add(_pubSignals, 288)))
|
|
247
|
+
|
|
248
|
+
checkField(calldataload(add(_pubSignals, 320)))
|
|
249
|
+
|
|
250
|
+
checkField(calldataload(add(_pubSignals, 352)))
|
|
251
|
+
|
|
252
|
+
checkField(calldataload(add(_pubSignals, 384)))
|
|
253
|
+
|
|
254
|
+
checkField(calldataload(add(_pubSignals, 416)))
|
|
255
|
+
|
|
256
|
+
checkField(calldataload(add(_pubSignals, 448)))
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
// Validate all evaluations
|
|
260
|
+
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
|
261
|
+
|
|
262
|
+
mstore(0, isValid)
|
|
263
|
+
return(0, 0x20)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.24;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/access/AccessControl.sol";
|
|
5
|
+
import "@openzeppelin/contracts/utils/Pausable.sol";
|
|
6
|
+
|
|
7
|
+
contract SanctionsOracle is AccessControl, Pausable {
|
|
8
|
+
bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");
|
|
9
|
+
|
|
10
|
+
bytes32 public currentRoot;
|
|
11
|
+
uint64 public lastUpdated;
|
|
12
|
+
uint32 public leafCount;
|
|
13
|
+
uint256 public gracePeriod = 24 hours; // M-2: Configurable (changed from 72h constant per audit)
|
|
14
|
+
uint256 public constant UPDATE_COOLDOWN = 1 hours;
|
|
15
|
+
|
|
16
|
+
// H-2: Ring buffer for root history
|
|
17
|
+
uint256 public constant MAX_HISTORY = 1000;
|
|
18
|
+
RootRecord[] public rootHistory;
|
|
19
|
+
uint256 public ringBufferStart; // Index of oldest entry when buffer is full
|
|
20
|
+
|
|
21
|
+
struct RootRecord {
|
|
22
|
+
bytes32 root;
|
|
23
|
+
uint64 timestamp;
|
|
24
|
+
uint32 leafCount;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
event SanctionsRootUpdated(
|
|
28
|
+
bytes32 indexed oldRoot,
|
|
29
|
+
bytes32 indexed newRoot,
|
|
30
|
+
uint32 leafCount,
|
|
31
|
+
uint64 timestamp
|
|
32
|
+
);
|
|
33
|
+
event GracePeriodUpdated(uint256 oldPeriod, uint256 newPeriod);
|
|
34
|
+
|
|
35
|
+
constructor(address admin, bytes32 initialRoot, uint32 initialLeafCount) {
|
|
36
|
+
// M-7: Zero-address validation
|
|
37
|
+
require(admin != address(0), "Zero admin");
|
|
38
|
+
_grantRole(DEFAULT_ADMIN_ROLE, admin);
|
|
39
|
+
_grantRole(ORACLE_ROLE, admin);
|
|
40
|
+
currentRoot = initialRoot;
|
|
41
|
+
lastUpdated = uint64(block.timestamp);
|
|
42
|
+
leafCount = initialLeafCount;
|
|
43
|
+
rootHistory.push(RootRecord(initialRoot, uint64(block.timestamp), initialLeafCount));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function updateRoot(bytes32 newRoot, uint32 _leafCount) external onlyRole(ORACLE_ROLE) whenNotPaused {
|
|
47
|
+
require(newRoot != bytes32(0), "Zero root");
|
|
48
|
+
require(block.timestamp >= lastUpdated + UPDATE_COOLDOWN, "Cooldown active");
|
|
49
|
+
|
|
50
|
+
// H-3: Leaf count floor — prevent silently clearing the sanctions list
|
|
51
|
+
require(_leafCount >= leafCount / 2, "Leaf count decreased too much");
|
|
52
|
+
|
|
53
|
+
bytes32 old = currentRoot;
|
|
54
|
+
currentRoot = newRoot;
|
|
55
|
+
lastUpdated = uint64(block.timestamp);
|
|
56
|
+
leafCount = _leafCount;
|
|
57
|
+
|
|
58
|
+
// H-2: Ring buffer — cap history at MAX_HISTORY
|
|
59
|
+
if (rootHistory.length < MAX_HISTORY) {
|
|
60
|
+
rootHistory.push(RootRecord(newRoot, uint64(block.timestamp), _leafCount));
|
|
61
|
+
} else {
|
|
62
|
+
uint256 idx = ringBufferStart % MAX_HISTORY;
|
|
63
|
+
rootHistory[idx] = RootRecord(newRoot, uint64(block.timestamp), _leafCount);
|
|
64
|
+
ringBufferStart++;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
emit SanctionsRootUpdated(old, newRoot, _leafCount, uint64(block.timestamp));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// M-2: Allow admin to configure grace period within bounds
|
|
71
|
+
function setGracePeriod(uint256 newPeriod) external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
72
|
+
require(newPeriod >= 6 hours && newPeriod <= 168 hours, "Period out of bounds");
|
|
73
|
+
uint256 oldPeriod = gracePeriod;
|
|
74
|
+
gracePeriod = newPeriod;
|
|
75
|
+
emit GracePeriodUpdated(oldPeriod, newPeriod);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isStale() public view returns (bool) {
|
|
79
|
+
return block.timestamp > lastUpdated + gracePeriod;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function historyLength() external view returns (uint256) {
|
|
83
|
+
return rootHistory.length;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
87
|
+
_pause();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
91
|
+
_unpause();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.24;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/access/AccessControl.sol";
|
|
5
|
+
import "@openzeppelin/contracts/utils/Pausable.sol";
|
|
6
|
+
|
|
7
|
+
contract VASPRegistry is AccessControl, Pausable {
|
|
8
|
+
bytes32 public constant REGISTRAR_ROLE = keccak256("REGISTRAR_ROLE");
|
|
9
|
+
|
|
10
|
+
struct VASP {
|
|
11
|
+
address wallet;
|
|
12
|
+
string jurisdiction;
|
|
13
|
+
bool active;
|
|
14
|
+
uint64 registeredAt;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
mapping(bytes32 => VASP) public vasps; // keccak256(did) => VASP
|
|
18
|
+
bytes32[] public vaspIds;
|
|
19
|
+
bytes32 public issuerMerkleRoot;
|
|
20
|
+
uint64 public issuerRootVersion;
|
|
21
|
+
uint256 public activeVaspCount; // M-6: Track active VASP count
|
|
22
|
+
|
|
23
|
+
event VASPRegistered(bytes32 indexed didHash, address wallet, string jurisdiction);
|
|
24
|
+
event VASPRevoked(bytes32 indexed didHash);
|
|
25
|
+
event VASPReactivated(bytes32 indexed didHash, address newWallet); // H-5
|
|
26
|
+
event IssuerRootUpdated(bytes32 oldRoot, bytes32 newRoot, uint64 version);
|
|
27
|
+
|
|
28
|
+
constructor(address admin) {
|
|
29
|
+
// M-7: Zero-address validation
|
|
30
|
+
require(admin != address(0), "Zero admin");
|
|
31
|
+
_grantRole(DEFAULT_ADMIN_ROLE, admin);
|
|
32
|
+
_grantRole(REGISTRAR_ROLE, admin);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function registerVASP(
|
|
36
|
+
bytes32 didHash,
|
|
37
|
+
address wallet,
|
|
38
|
+
string calldata jurisdiction
|
|
39
|
+
) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
|
|
40
|
+
require(vasps[didHash].registeredAt == 0, "Already registered");
|
|
41
|
+
vasps[didHash] = VASP(wallet, jurisdiction, true, uint64(block.timestamp));
|
|
42
|
+
vaspIds.push(didHash);
|
|
43
|
+
activeVaspCount++; // M-6
|
|
44
|
+
emit VASPRegistered(didHash, wallet, jurisdiction);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// M-8: Added whenNotPaused — revocation requires explicit unpause for safety
|
|
48
|
+
function revokeVASP(bytes32 didHash) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
|
|
49
|
+
require(vasps[didHash].active, "Not active");
|
|
50
|
+
vasps[didHash].active = false;
|
|
51
|
+
activeVaspCount--; // M-6
|
|
52
|
+
emit VASPRevoked(didHash);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// H-5: Reactivate a previously revoked VASP with a new wallet
|
|
56
|
+
function reactivateVASP(bytes32 didHash, address newWallet) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
|
|
57
|
+
require(vasps[didHash].registeredAt != 0, "Not registered");
|
|
58
|
+
require(!vasps[didHash].active, "Already active");
|
|
59
|
+
vasps[didHash].active = true;
|
|
60
|
+
vasps[didHash].wallet = newWallet;
|
|
61
|
+
activeVaspCount++; // M-6
|
|
62
|
+
emit VASPReactivated(didHash, newWallet);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function updateIssuerRoot(bytes32 newRoot) external onlyRole(REGISTRAR_ROLE) whenNotPaused {
|
|
66
|
+
bytes32 old = issuerMerkleRoot;
|
|
67
|
+
issuerMerkleRoot = newRoot;
|
|
68
|
+
issuerRootVersion++;
|
|
69
|
+
emit IssuerRootUpdated(old, newRoot, issuerRootVersion);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isActive(bytes32 didHash) external view returns (bool) {
|
|
73
|
+
return vasps[didHash].active;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function vaspCount() external view returns (uint256) {
|
|
77
|
+
return vaspIds.length;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
81
|
+
_pause();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
|
|
85
|
+
_unpause();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clearproof/contracts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "On-chain Groth16 verifier for clearproof compliance proofs",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"files": [
|
|
7
|
+
"contracts/",
|
|
8
|
+
"artifacts/contracts/**/*.json",
|
|
9
|
+
"!artifacts/contracts/**/*.dbg.json"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/clearproof/zk-travel-rule.git",
|
|
14
|
+
"directory": "packages/contracts"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"zk",
|
|
18
|
+
"zero-knowledge",
|
|
19
|
+
"groth16",
|
|
20
|
+
"solidity",
|
|
21
|
+
"verifier",
|
|
22
|
+
"compliance",
|
|
23
|
+
"travel-rule",
|
|
24
|
+
"ethereum"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"compile": "hardhat compile",
|
|
28
|
+
"test": "hardhat test",
|
|
29
|
+
"deploy": "hardhat run scripts/deploy.ts"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@nomicfoundation/hardhat-toolbox": "^5.0",
|
|
33
|
+
"hardhat": "^2.22",
|
|
34
|
+
"typescript": "^5.4"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@openzeppelin/contracts": "^5.6.1"
|
|
38
|
+
}
|
|
39
|
+
}
|