mirror of
https://github.com/selfxyz/self.git
synced 2026-01-10 07:08:10 -05:00
ci: add prettier check for contract sdk (#602)
* Add Prettier check for code formatting in contracts workflow * Update contracts workflow: remove unused checkout action and fix build step name * Run formatter * Run lint fix
This commit is contained in:
@@ -22,17 +22,17 @@ pragma solidity >=0.7.0 <0.9.0;
|
||||
|
||||
contract Verifier_vc_and_disclose {
|
||||
// Scalar field size
|
||||
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
// Base field size
|
||||
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
|
||||
// Verification Key data
|
||||
uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042;
|
||||
uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958;
|
||||
uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132;
|
||||
uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731;
|
||||
uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679;
|
||||
uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856;
|
||||
uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042;
|
||||
uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958;
|
||||
uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132;
|
||||
uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731;
|
||||
uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679;
|
||||
uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856;
|
||||
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
||||
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
||||
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
||||
@@ -42,7 +42,6 @@ contract Verifier_vc_and_disclose {
|
||||
uint256 constant deltay1 = 12540010325641881371116121450209835663869183125485844650454127657458562657135;
|
||||
uint256 constant deltay2 = 5745831082153426833961839903205936221609761549734057076333858241059465478539;
|
||||
|
||||
|
||||
uint256 constant IC0x = 1327643666632315025512187418817023630780563184758021455663314119872437463145;
|
||||
uint256 constant IC0y = 2622893971724901828914047259052067392447274440848954417614321746778812751881;
|
||||
|
||||
@@ -109,14 +108,18 @@ contract Verifier_vc_and_disclose {
|
||||
uint256 constant IC21x = 6877461228082443111890464295830127588035564773913061145705260000890224419695;
|
||||
uint256 constant IC21y = 13729662662934324858332564018609296055385187918293000684588750857191114304504;
|
||||
|
||||
|
||||
// Memory data
|
||||
uint16 constant pVk = 0;
|
||||
uint16 constant pPairing = 128;
|
||||
|
||||
uint16 constant pLastMem = 896;
|
||||
|
||||
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[21] calldata _pubSignals) public view returns (bool) {
|
||||
function verifyProof(
|
||||
uint[2] calldata _pA,
|
||||
uint[2][2] calldata _pB,
|
||||
uint[2] calldata _pC,
|
||||
uint[21] calldata _pubSignals
|
||||
) public view returns (bool) {
|
||||
assembly {
|
||||
function checkField(v) {
|
||||
if iszero(lt(v, r)) {
|
||||
@@ -202,7 +205,6 @@ contract Verifier_vc_and_disclose {
|
||||
|
||||
g1_mulAccC(_pVk, IC21x, IC21y, calldataload(add(pubSignals, 640)))
|
||||
|
||||
|
||||
// -A
|
||||
mstore(_pPairing, calldataload(pA))
|
||||
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
||||
@@ -227,7 +229,6 @@ contract Verifier_vc_and_disclose {
|
||||
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
||||
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
||||
|
||||
|
||||
// gamma2
|
||||
mstore(add(_pPairing, 448), gammax1)
|
||||
mstore(add(_pPairing, 480), gammax2)
|
||||
@@ -244,7 +245,6 @@ contract Verifier_vc_and_disclose {
|
||||
mstore(add(_pPairing, 704), deltay1)
|
||||
mstore(add(_pPairing, 736), deltay2)
|
||||
|
||||
|
||||
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
||||
|
||||
isOk := and(success, mload(_pPairing))
|
||||
@@ -297,12 +297,11 @@ contract Verifier_vc_and_disclose {
|
||||
|
||||
checkField(calldataload(add(_pubSignals, 640)))
|
||||
|
||||
|
||||
// Validate all evaluations
|
||||
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
||||
|
||||
mstore(0, isValid)
|
||||
return(0, 0x20)
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0, 0x20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,17 @@ pragma solidity >=0.7.0 <0.9.0;
|
||||
|
||||
contract Verifier_vc_and_disclose_id {
|
||||
// Scalar field size
|
||||
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
||||
// Base field size
|
||||
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
||||
|
||||
// Verification Key data
|
||||
uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042;
|
||||
uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958;
|
||||
uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132;
|
||||
uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731;
|
||||
uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679;
|
||||
uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856;
|
||||
uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042;
|
||||
uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958;
|
||||
uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132;
|
||||
uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731;
|
||||
uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679;
|
||||
uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856;
|
||||
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
||||
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
||||
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
||||
@@ -42,7 +42,6 @@ contract Verifier_vc_and_disclose_id {
|
||||
uint256 constant deltay1 = 7435464704050078541040143210361029167943489190182457760833515213308787654134;
|
||||
uint256 constant deltay2 = 15408719086758721919659067176144873307399894070070928787991675000177094388646;
|
||||
|
||||
|
||||
uint256 constant IC0x = 5856920506801943179747940431507261587545690354191837904074746625856713057019;
|
||||
uint256 constant IC0y = 19124539120756340306225201952668471579555384876400327849356328019845881097562;
|
||||
|
||||
@@ -109,14 +108,18 @@ contract Verifier_vc_and_disclose_id {
|
||||
uint256 constant IC21x = 694085742582167480921564969992368553233272238548053666297768861621687596406;
|
||||
uint256 constant IC21y = 19146278969945936933324725088253247909700597465969498560427768702663925772917;
|
||||
|
||||
|
||||
// Memory data
|
||||
uint16 constant pVk = 0;
|
||||
uint16 constant pPairing = 128;
|
||||
|
||||
uint16 constant pLastMem = 896;
|
||||
|
||||
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[21] calldata _pubSignals) public view returns (bool) {
|
||||
function verifyProof(
|
||||
uint[2] calldata _pA,
|
||||
uint[2][2] calldata _pB,
|
||||
uint[2] calldata _pC,
|
||||
uint[21] calldata _pubSignals
|
||||
) public view returns (bool) {
|
||||
assembly {
|
||||
function checkField(v) {
|
||||
if iszero(lt(v, r)) {
|
||||
@@ -202,7 +205,6 @@ contract Verifier_vc_and_disclose_id {
|
||||
|
||||
g1_mulAccC(_pVk, IC21x, IC21y, calldataload(add(pubSignals, 640)))
|
||||
|
||||
|
||||
// -A
|
||||
mstore(_pPairing, calldataload(pA))
|
||||
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
||||
@@ -227,7 +229,6 @@ contract Verifier_vc_and_disclose_id {
|
||||
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
||||
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
||||
|
||||
|
||||
// gamma2
|
||||
mstore(add(_pPairing, 448), gammax1)
|
||||
mstore(add(_pPairing, 480), gammax2)
|
||||
@@ -244,7 +245,6 @@ contract Verifier_vc_and_disclose_id {
|
||||
mstore(add(_pPairing, 704), deltay1)
|
||||
mstore(add(_pPairing, 736), deltay2)
|
||||
|
||||
|
||||
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
||||
|
||||
isOk := and(success, mload(_pPairing))
|
||||
@@ -297,12 +297,11 @@ contract Verifier_vc_and_disclose_id {
|
||||
|
||||
checkField(calldataload(add(_pubSignals, 640)))
|
||||
|
||||
|
||||
// Validate all evaluations
|
||||
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
||||
|
||||
mstore(0, isValid)
|
||||
return(0, 0x20)
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0, 0x20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ export default buildModule("DeployRegistryModule", (m) => {
|
||||
// Get the interface and encode the initialize function call
|
||||
const registryInterface = getRegistryInitializeData();
|
||||
|
||||
const registryInitData = registryInterface.encodeFunctionData("initialize", [
|
||||
ethers.ZeroAddress,
|
||||
]);
|
||||
const registryInitData = registryInterface.encodeFunctionData("initialize", [ethers.ZeroAddress]);
|
||||
console.log(" Init data:", registryInitData);
|
||||
|
||||
console.log("🚀 Deploying IdentityRegistry proxy...");
|
||||
|
||||
@@ -15,7 +15,10 @@ module.exports = buildModule("UpdateRegistryHubV2", (m) => {
|
||||
|
||||
try {
|
||||
const registryAddress = getContractAddress("DeployRegistryModule#IdentityRegistry", deployedAddresses);
|
||||
const registryIdCardAddress = getContractAddress("DeployIdCardRegistryModule#IdentityRegistryIdCard", deployedAddresses);
|
||||
const registryIdCardAddress = getContractAddress(
|
||||
"DeployIdCardRegistryModule#IdentityRegistryIdCard",
|
||||
deployedAddresses,
|
||||
);
|
||||
const hubAddress = getContractAddress("DeployHubV2#IdentityVerificationHub", deployedAddresses);
|
||||
|
||||
log.info(`Registry address: ${registryAddress}`);
|
||||
@@ -38,7 +41,7 @@ module.exports = buildModule("UpdateRegistryHubV2", (m) => {
|
||||
|
||||
return {
|
||||
deployedRegistryInstance,
|
||||
deployedRegistryIdCardInstance
|
||||
deployedRegistryIdCardInstance,
|
||||
};
|
||||
} catch (error) {
|
||||
log.error(`Failed to update registry hub: ${error}`);
|
||||
|
||||
@@ -3,7 +3,6 @@ import { RegisterVerifierId, DscVerifierId } from "@selfxyz/common/constants/con
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
|
||||
const deployVerifiers = {
|
||||
vcAndDiscloseVerifier: false,
|
||||
vcAndDiscloseIdVerifier: false,
|
||||
@@ -36,15 +35,15 @@ function contractExists(contractName: string): boolean {
|
||||
}
|
||||
|
||||
export default buildModule("DeployAllVerifiers", (m) => {
|
||||
let successfulRegisterIdDeployments = 0;
|
||||
let successfulRegisterDeployments = 0;
|
||||
let successfulDscDeployments = 0;
|
||||
let successfulRegisterIdDeployments = 0;
|
||||
let successfulRegisterDeployments = 0;
|
||||
let successfulDscDeployments = 0;
|
||||
|
||||
const deployedContracts: Record<string, any> = {};
|
||||
|
||||
// Deploy VC and Disclose verifier
|
||||
if (deployVerifiers.vcAndDiscloseVerifier) {
|
||||
console.log("Deploying VC and Disclose verifier...");
|
||||
console.log("Deploying VC and Disclose verifier...");
|
||||
deployedContracts.vcAndDiscloseVerifier = m.contract("Verifier_vc_and_disclose");
|
||||
}
|
||||
|
||||
@@ -57,17 +56,17 @@ let successfulDscDeployments = 0;
|
||||
const registerIdCircuits = ["register_id_sha256_sha256_sha256_rsa_65537_4096"];
|
||||
// Deploy Register ID verifiers (for ID cards)
|
||||
if (deployVerifiers.registerIdVerifier) {
|
||||
console.log("Deploying Register ID verifiers...");
|
||||
registerIdCircuits.forEach((circuitName) => {
|
||||
const contractName = `Verifier_${circuitName}`;
|
||||
if (contractExists(contractName)) {
|
||||
console.log(` - Deploying ${contractName}`);
|
||||
deployedContracts[circuitName] = m.contract(contractName);
|
||||
successfulRegisterIdDeployments++;
|
||||
} else {
|
||||
console.warn(` - Warning: Contract ${contractName} not found, skipping...`);
|
||||
}
|
||||
});
|
||||
console.log("Deploying Register ID verifiers...");
|
||||
registerIdCircuits.forEach((circuitName) => {
|
||||
const contractName = `Verifier_${circuitName}`;
|
||||
if (contractExists(contractName)) {
|
||||
console.log(` - Deploying ${contractName}`);
|
||||
deployedContracts[circuitName] = m.contract(contractName);
|
||||
successfulRegisterIdDeployments++;
|
||||
} else {
|
||||
console.warn(` - Warning: Contract ${contractName} not found, skipping...`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Deploy VC and Disclose ID verifier
|
||||
@@ -92,33 +91,33 @@ let successfulDscDeployments = 0;
|
||||
// Deploy Register verifiers using RegisterVerifierId enum
|
||||
const registerCircuits = getEnumKeys(RegisterVerifierId);
|
||||
if (deployVerifiers.registerVerifier) {
|
||||
console.log("Deploying Register verifiers...");
|
||||
registerCircuits.forEach((circuitName) => {
|
||||
const contractName = `Verifier_${circuitName}`;
|
||||
if (contractExists(contractName)) {
|
||||
console.log(` - Deploying ${contractName}`);
|
||||
deployedContracts[circuitName] = m.contract(contractName);
|
||||
successfulRegisterDeployments++;
|
||||
} else {
|
||||
console.warn(` - Warning: Contract ${contractName} not found, skipping...`);
|
||||
}
|
||||
});
|
||||
console.log("Deploying Register verifiers...");
|
||||
registerCircuits.forEach((circuitName) => {
|
||||
const contractName = `Verifier_${circuitName}`;
|
||||
if (contractExists(contractName)) {
|
||||
console.log(` - Deploying ${contractName}`);
|
||||
deployedContracts[circuitName] = m.contract(contractName);
|
||||
successfulRegisterDeployments++;
|
||||
} else {
|
||||
console.warn(` - Warning: Contract ${contractName} not found, skipping...`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Deploy DSC verifiers using DscVerifierId enum
|
||||
const dscCircuits = getEnumKeys(DscVerifierId);
|
||||
if (deployVerifiers.dscVerifier) {
|
||||
console.log("Deploying DSC verifiers...");
|
||||
dscCircuits.forEach((circuitName) => {
|
||||
const contractName = `Verifier_${circuitName}`;
|
||||
if (contractExists(contractName)) {
|
||||
console.log(` - Deploying ${contractName}`);
|
||||
deployedContracts[circuitName] = m.contract(contractName);
|
||||
successfulDscDeployments++;
|
||||
} else {
|
||||
console.warn(` - Warning: Contract ${contractName} not found, skipping...`);
|
||||
}
|
||||
});
|
||||
console.log("Deploying DSC verifiers...");
|
||||
dscCircuits.forEach((circuitName) => {
|
||||
const contractName = `Verifier_${circuitName}`;
|
||||
if (contractExists(contractName)) {
|
||||
console.log(` - Deploying ${contractName}`);
|
||||
deployedContracts[circuitName] = m.contract(contractName);
|
||||
successfulDscDeployments++;
|
||||
} else {
|
||||
console.warn(` - Warning: Contract ${contractName} not found, skipping...`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Total verifiers deployment summary:`);
|
||||
@@ -133,7 +132,9 @@ let successfulDscDeployments = 0;
|
||||
console.log(
|
||||
` - DSC: ${successfulDscDeployments}/${dscCircuits.length} (${dscCircuits.length - successfulDscDeployments} skipped)`,
|
||||
);
|
||||
console.log(` - Total successful deployments: ${2 + successfulRegisterIdDeployments + successfulRegisterDeployments + successfulDscDeployments}`);
|
||||
console.log(
|
||||
` - Total successful deployments: ${2 + successfulRegisterIdDeployments + successfulRegisterDeployments + successfulDscDeployments}`,
|
||||
);
|
||||
|
||||
return deployedContracts;
|
||||
});
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
how to deploy and update the protocol
|
||||
|
||||
Main contracts:
|
||||
|
||||
- Hub
|
||||
- Registries
|
||||
- Passports
|
||||
- ID cards
|
||||
|
||||
Hub and Registries are following an upgradeable proxy pattern.
|
||||
Use only the Proxy address for everything.
|
||||
Hub and Registries are following an upgradeable proxy pattern. Use only the Proxy address for everything.
|
||||
|
||||
Secondary contracts:
|
||||
|
||||
- vc_and_disclose verifiers
|
||||
- vc_and_disclose_id verifiers
|
||||
- register verifiers'
|
||||
@@ -18,7 +19,6 @@ Secondary contracts:
|
||||
|
||||
How to update the protocol:
|
||||
|
||||
|
||||
### Deploy the Hub V2 and the Identity registry
|
||||
|
||||
```
|
||||
@@ -31,9 +31,9 @@ yarn deploy:registry:idcard
|
||||
|
||||
### Set the registries address in the hub
|
||||
|
||||
````
|
||||
```
|
||||
yarn set:hub:v2
|
||||
````
|
||||
```
|
||||
|
||||
Set the verifiers in the hub
|
||||
|
||||
@@ -46,3 +46,4 @@ yarn set:verifiers:v2
|
||||
````
|
||||
yarn set:registry:hub:v2
|
||||
```
|
||||
````
|
||||
|
||||
@@ -2,28 +2,28 @@ import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
|
||||
export const ATTESTATION_ID = {
|
||||
E_PASSPORT: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
||||
EU_ID_CARD: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
||||
E_PASSPORT: "0x0000000000000000000000000000000000000000000000000000000000000001",
|
||||
EU_ID_CARD: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
||||
};
|
||||
|
||||
export const ATTESTATION_TO_REGISTRY = {
|
||||
E_PASSPORT: 'DeployRegistryModule#IdentityRegistry',
|
||||
EU_ID_CARD: 'DeployIdCardRegistryModule#IdentityRegistry',
|
||||
}
|
||||
E_PASSPORT: "DeployRegistryModule#IdentityRegistry",
|
||||
EU_ID_CARD: "DeployIdCardRegistryModule#IdentityRegistry",
|
||||
};
|
||||
|
||||
export const NETWORK_TO_CHAIN_ID: Record<string, string> = {
|
||||
localhost: '31337',
|
||||
hardhat: '31337',
|
||||
alfajores: '44787',
|
||||
celoAlfajores: '44787',
|
||||
celo: '42220',
|
||||
mainnet: '42220',
|
||||
staging: '44787',
|
||||
localhost: "31337",
|
||||
hardhat: "31337",
|
||||
alfajores: "44787",
|
||||
celoAlfajores: "44787",
|
||||
celo: "42220",
|
||||
mainnet: "42220",
|
||||
staging: "44787",
|
||||
};
|
||||
|
||||
export const CHAIN_ID_TO_SAVED_REPO: Record<string, string> = {
|
||||
'42220' : 'prod',
|
||||
'44787' : 'staging'
|
||||
"42220": "prod",
|
||||
"44787": "staging",
|
||||
};
|
||||
|
||||
export const getChainId = (network: string): string => {
|
||||
@@ -33,37 +33,36 @@ export const getChainId = (network: string): string => {
|
||||
};
|
||||
|
||||
export const getSavedRepo = (network: string): string => {
|
||||
const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]];
|
||||
return repoName;
|
||||
const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]];
|
||||
return repoName;
|
||||
};
|
||||
|
||||
|
||||
export const getDeployedAddresses = (repoName: string): any => {
|
||||
const addresses_path = path.join(__dirname, `../ignition/deployments/${repoName}/deployed_addresses.json`);
|
||||
return JSON.parse(fs.readFileSync(addresses_path, "utf-8"));
|
||||
}
|
||||
};
|
||||
export const getContractAbi = (repoName: string, deploymentArtifactName: string): any => {
|
||||
const abi_path = path.join(__dirname, `../ignition/deployments/${repoName}/artifacts/${deploymentArtifactName}.json`);
|
||||
return JSON.parse(fs.readFileSync(abi_path, "utf-8")).abi;
|
||||
}
|
||||
};
|
||||
|
||||
export function getContractAddress(exactName: string, deployedAddresses : any): any {
|
||||
export function getContractAddress(exactName: string, deployedAddresses: any): any {
|
||||
if (exactName in deployedAddresses) {
|
||||
return deployedAddresses[exactName];
|
||||
}
|
||||
throw Error(`No contract address found for ${exactName}`)
|
||||
throw Error(`No contract address found for ${exactName}`);
|
||||
}
|
||||
|
||||
// Console colors
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
red: '\x1b[31m',
|
||||
green: '\x1b[32m',
|
||||
yellow: '\x1b[33m',
|
||||
blue: '\x1b[34m',
|
||||
magenta: '\x1b[35m',
|
||||
cyan: '\x1b[36m',
|
||||
white: '\x1b[37m'
|
||||
reset: "\x1b[0m",
|
||||
red: "\x1b[31m",
|
||||
green: "\x1b[32m",
|
||||
yellow: "\x1b[33m",
|
||||
blue: "\x1b[34m",
|
||||
magenta: "\x1b[35m",
|
||||
cyan: "\x1b[36m",
|
||||
white: "\x1b[37m",
|
||||
};
|
||||
|
||||
export const log = {
|
||||
@@ -71,5 +70,5 @@ export const log = {
|
||||
success: (msg: string) => console.log(`${colors.green}[SUCCESS]${colors.reset} ${msg}`),
|
||||
warning: (msg: string) => console.log(`${colors.yellow}[WARNING]${colors.reset} ${msg}`),
|
||||
error: (msg: string) => console.log(`${colors.red}[ERROR]${colors.reset} ${msg}`),
|
||||
step: (msg: string) => console.log(`${colors.magenta}[STEP]${colors.reset} ${msg}`)
|
||||
step: (msg: string) => console.log(`${colors.magenta}[STEP]${colors.reset} ${msg}`),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { keccak256 } from 'ethers';
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { keccak256 } from "ethers";
|
||||
|
||||
interface CustomError {
|
||||
name: string;
|
||||
@@ -25,10 +25,10 @@ function findSolidityFiles(dir: string): string[] {
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// Skip node_modules, .git, and other common directories
|
||||
if (!['node_modules', '.git', 'dist', 'build', 'cache'].includes(item)) {
|
||||
if (!["node_modules", ".git", "dist", "build", "cache"].includes(item)) {
|
||||
traverse(fullPath);
|
||||
}
|
||||
} else if (item.endsWith('.sol')) {
|
||||
} else if (item.endsWith(".sol")) {
|
||||
files.push(fullPath);
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,8 @@ function findSolidityFiles(dir: string): string[] {
|
||||
* Extract custom errors from Solidity file content
|
||||
*/
|
||||
function extractCustomErrors(filePath: string): CustomError[] {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
const lines = content.split("\n");
|
||||
const errors: CustomError[] = [];
|
||||
|
||||
// Regex to match custom error declarations
|
||||
@@ -60,18 +60,18 @@ function extractCustomErrors(filePath: string): CustomError[] {
|
||||
|
||||
// Clean up parameters - remove parameter names, keep only types
|
||||
const paramTypes = params
|
||||
.split(',')
|
||||
.map(param => param.trim())
|
||||
.filter(param => param.length > 0)
|
||||
.map(param => {
|
||||
.split(",")
|
||||
.map((param) => param.trim())
|
||||
.filter((param) => param.length > 0)
|
||||
.map((param) => {
|
||||
// Extract type from "type name" or "type"
|
||||
const parts = param.split(/\s+/);
|
||||
return parts[0]; // First part is the type
|
||||
})
|
||||
.join(',');
|
||||
.join(",");
|
||||
|
||||
const signature = `${errorName}(${paramTypes})`;
|
||||
const hash = keccak256(Buffer.from(signature, 'utf8'));
|
||||
const hash = keccak256(Buffer.from(signature, "utf8"));
|
||||
const selector = hash.slice(0, 10); // First 4 bytes (8 hex chars + 0x)
|
||||
|
||||
errors.push({
|
||||
@@ -79,7 +79,7 @@ function extractCustomErrors(filePath: string): CustomError[] {
|
||||
signature,
|
||||
selector,
|
||||
file: path.relative(process.cwd(), filePath),
|
||||
line: i + 1
|
||||
line: i + 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,9 @@ function extractCustomErrors(filePath: string): CustomError[] {
|
||||
* Main function to scan all contracts and find error selectors
|
||||
*/
|
||||
async function findAllErrorSelectors(targetSelector?: string) {
|
||||
console.log('🔍 Scanning Solidity files for custom errors...\n');
|
||||
console.log("🔍 Scanning Solidity files for custom errors...\n");
|
||||
|
||||
const contractsDir = path.join(process.cwd(), 'contracts');
|
||||
const contractsDir = path.join(process.cwd(), "contracts");
|
||||
const solidityFiles = findSolidityFiles(contractsDir);
|
||||
|
||||
console.log(`Found ${solidityFiles.length} Solidity files\n`);
|
||||
@@ -107,7 +107,7 @@ async function findAllErrorSelectors(targetSelector?: string) {
|
||||
|
||||
// Check if we found the target selector
|
||||
if (targetSelector) {
|
||||
const match = errors.find(error => error.selector.toLowerCase() === targetSelector.toLowerCase());
|
||||
const match = errors.find((error) => error.selector.toLowerCase() === targetSelector.toLowerCase());
|
||||
if (match) {
|
||||
console.log(`🎯 FOUND TARGET ERROR: ${targetSelector}`);
|
||||
console.log(` Error: ${match.name}`);
|
||||
@@ -130,35 +130,38 @@ async function findAllErrorSelectors(targetSelector?: string) {
|
||||
}
|
||||
|
||||
// Group errors by file for better organization
|
||||
const errorsByFile = allErrors.reduce((acc, error) => {
|
||||
if (!acc[error.file]) {
|
||||
acc[error.file] = [];
|
||||
}
|
||||
acc[error.file].push(error);
|
||||
return acc;
|
||||
}, {} as Record<string, CustomError[]>);
|
||||
const errorsByFile = allErrors.reduce(
|
||||
(acc, error) => {
|
||||
if (!acc[error.file]) {
|
||||
acc[error.file] = [];
|
||||
}
|
||||
acc[error.file].push(error);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, CustomError[]>,
|
||||
);
|
||||
|
||||
console.log('📋 All Custom Errors by File:');
|
||||
console.log('================================\n');
|
||||
console.log("📋 All Custom Errors by File:");
|
||||
console.log("================================\n");
|
||||
|
||||
for (const [file, errors] of Object.entries(errorsByFile)) {
|
||||
console.log(`📄 ${file}:`);
|
||||
for (const error of errors) {
|
||||
console.log(` ${error.selector} → ${error.signature} (line ${error.line})`);
|
||||
}
|
||||
console.log('');
|
||||
console.log("");
|
||||
}
|
||||
|
||||
// Generate a quick lookup table
|
||||
console.log('🔗 Quick Selector Lookup:');
|
||||
console.log('=========================\n');
|
||||
console.log("🔗 Quick Selector Lookup:");
|
||||
console.log("=========================\n");
|
||||
|
||||
for (const error of allErrors) {
|
||||
console.log(`${error.selector} → ${error.name} (${error.file}:${error.line})`);
|
||||
}
|
||||
|
||||
// Save results to JSON file for future reference
|
||||
const outputFile = 'error-selectors.json';
|
||||
const outputFile = "error-selectors.json";
|
||||
fs.writeFileSync(outputFile, JSON.stringify(allErrors, null, 2));
|
||||
console.log(`\n💾 Results saved to ${outputFile}`);
|
||||
|
||||
@@ -174,9 +177,9 @@ if (targetSelector) {
|
||||
|
||||
findAllErrorSelectors(targetSelector)
|
||||
.then(() => {
|
||||
console.log('\n✅ Scan complete!');
|
||||
console.log("\n✅ Scan complete!");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('❌ Error during scan:', error);
|
||||
console.error("❌ Error during scan:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -1,38 +1,45 @@
|
||||
import { ethers } from "ethers";
|
||||
import * as dotenv from "dotenv";
|
||||
import { getDeployedAddresses, getContractAbi, getSavedRepo, getContractAddress, ATTESTATION_TO_REGISTRY, ATTESTATION_ID } from "./constants";
|
||||
import {
|
||||
getDeployedAddresses,
|
||||
getContractAbi,
|
||||
getSavedRepo,
|
||||
getContractAddress,
|
||||
ATTESTATION_TO_REGISTRY,
|
||||
ATTESTATION_ID,
|
||||
} from "./constants";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const setHubV2 = {
|
||||
'E_PASSPORT' : false,
|
||||
'EU_ID_CARD' : false,
|
||||
}
|
||||
E_PASSPORT: false,
|
||||
EU_ID_CARD: false,
|
||||
};
|
||||
|
||||
const NETWORK = process.env.NETWORK;
|
||||
const RPC_URL = process.env.RPC_URL;
|
||||
const PRIVATE_KEY = process.env.PRIVATE_KEY;
|
||||
|
||||
if (!NETWORK){
|
||||
throw new Error('One of the following parameter is null: NETWORK, RPC_URL, PRIVATE_KEY')
|
||||
if (!NETWORK) {
|
||||
throw new Error("One of the following parameter is null: NETWORK, RPC_URL, PRIVATE_KEY");
|
||||
}
|
||||
|
||||
const repoName = getSavedRepo(NETWORK);
|
||||
const deployedAddresses = getDeployedAddresses(repoName);
|
||||
console.log("Network:", NETWORK);
|
||||
console.log("Repo:", repoName)
|
||||
console.log("Repo:", repoName);
|
||||
console.log("Current directory:", __dirname);
|
||||
|
||||
try {
|
||||
console.log("Deployed addresses loaded:", deployedAddresses);
|
||||
const hubABI = getContractAbi(repoName,'DeployHubV2#IdentityVerificationHubImplV2')
|
||||
const hubABI = getContractAbi(repoName, "DeployHubV2#IdentityVerificationHubImplV2");
|
||||
|
||||
async function main() {
|
||||
const provider = new ethers.JsonRpcProvider(RPC_URL);
|
||||
const wallet = new ethers.Wallet(PRIVATE_KEY as string, provider);
|
||||
console.log("Wallet created");
|
||||
|
||||
const hubAddress = (getContractAddress("DeployHubV2#IdentityVerificationHub", deployedAddresses)) as string;
|
||||
const hubAddress = getContractAddress("DeployHubV2#IdentityVerificationHub", deployedAddresses) as string;
|
||||
|
||||
console.log("Hub address:", hubAddress);
|
||||
|
||||
@@ -46,31 +53,30 @@ try {
|
||||
|
||||
const attestationTypes = ["E_PASSPORT", "EU_ID_CARD"] as const;
|
||||
for (const attestationType of attestationTypes) {
|
||||
if (setHubV2[attestationType]){
|
||||
const registryName = ATTESTATION_TO_REGISTRY[attestationType] as any
|
||||
console.log('registry name:', registryName);
|
||||
const registryAddress = getContractAddress(registryName, deployedAddresses);
|
||||
console.log('registry address:', registryAddress);
|
||||
if (setHubV2[attestationType]) {
|
||||
const registryName = ATTESTATION_TO_REGISTRY[attestationType] as any;
|
||||
console.log("registry name:", registryName);
|
||||
const registryAddress = getContractAddress(registryName, deployedAddresses);
|
||||
console.log("registry address:", registryAddress);
|
||||
|
||||
if (!registryAddress) {
|
||||
console.log(`Skipping registry update for ${attestationType} because no deployed address was found.`);
|
||||
continue;
|
||||
}
|
||||
if (!registryAddress) {
|
||||
console.log(`Skipping registry update for ${attestationType} because no deployed address was found.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`Updating registry for ${attestationType}`);
|
||||
const attestationId = ATTESTATION_ID[attestationType];
|
||||
try {
|
||||
const tx = await identityVerificationHub.updateRegistry(attestationId, registryAddress);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`Registry for ${attestationType} updated with tx: ${receipt.hash}`);
|
||||
} catch (error) {
|
||||
console.error(`Error updating registry for ${attestationType}:`, error);
|
||||
console.log(`Updating registry for ${attestationType}`);
|
||||
const attestationId = ATTESTATION_ID[attestationType];
|
||||
try {
|
||||
const tx = await identityVerificationHub.updateRegistry(attestationId, registryAddress);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`Registry for ${attestationType} updated with tx: ${receipt.hash}`);
|
||||
} catch (error) {
|
||||
console.error(`Error updating registry for ${attestationType}:`, error);
|
||||
}
|
||||
} else {
|
||||
console.log(`Skipping registry update for ${attestationType}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log(`Skipping registry update for ${attestationType}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
main().catch((error) => {
|
||||
console.error("Execution error:", error);
|
||||
|
||||
@@ -7,27 +7,26 @@ import {
|
||||
getSavedRepo,
|
||||
getContractAddress,
|
||||
ATTESTATION_ID,
|
||||
log
|
||||
log,
|
||||
} from "./constants";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Configuration for which verifiers to set
|
||||
const setVerifiers = {
|
||||
vcAndDisclose: true, // VC and Disclose verifier for E_PASSPORT
|
||||
vcAndDiscloseId: true, // VC and Disclose ID verifier for EU_ID_CARD
|
||||
register: true, // Register verifiers for E_PASSPORT
|
||||
registerId: true, // Register ID verifiers for EU_ID_CARD
|
||||
dsc: true, // DSC verifiers for both E_PASSPORT and EU_ID_CARD
|
||||
vcAndDisclose: true, // VC and Disclose verifier for E_PASSPORT
|
||||
vcAndDiscloseId: true, // VC and Disclose ID verifier for EU_ID_CARD
|
||||
register: true, // Register verifiers for E_PASSPORT
|
||||
registerId: true, // Register ID verifiers for EU_ID_CARD
|
||||
dsc: true, // DSC verifiers for both E_PASSPORT and EU_ID_CARD
|
||||
};
|
||||
|
||||
|
||||
const NETWORK = process.env.NETWORK;
|
||||
const RPC_URL = process.env.RPC_URL;
|
||||
const PRIVATE_KEY = process.env.PRIVATE_KEY;
|
||||
|
||||
if (!NETWORK){
|
||||
throw new Error('One of the following parameter is null: NETWORK, RPC_URL, PRIVATE_KEY')
|
||||
if (!NETWORK) {
|
||||
throw new Error("One of the following parameter is null: NETWORK, RPC_URL, PRIVATE_KEY");
|
||||
}
|
||||
|
||||
const repoName = getSavedRepo(NETWORK);
|
||||
@@ -36,7 +35,7 @@ const deployedAddresses = getDeployedAddresses(repoName);
|
||||
log.info(`Network: ${NETWORK}, Repo: ${repoName}`);
|
||||
|
||||
try {
|
||||
const hubABI = getContractAbi(repoName,'DeployHubV2#IdentityVerificationHubImplV2')
|
||||
const hubABI = getContractAbi(repoName, "DeployHubV2#IdentityVerificationHubImplV2");
|
||||
|
||||
function getContractAddressByPartialName(partialName: string): string | undefined {
|
||||
console.log(`🔍 Searching for contract with partial name: "${partialName}"`);
|
||||
@@ -65,7 +64,7 @@ try {
|
||||
let totalUpdates = 0;
|
||||
let successfulUpdates = 0;
|
||||
|
||||
// Update VC and Disclose verifier for E_PASSPORT
|
||||
// Update VC and Disclose verifier for E_PASSPORT
|
||||
if (setVerifiers.vcAndDisclose) {
|
||||
log.step("Updating VC and Disclose verifier for E_PASSPORT");
|
||||
|
||||
@@ -108,7 +107,7 @@ try {
|
||||
log.step("Updating register circuit verifiers for E_PASSPORT");
|
||||
|
||||
const registerVerifierKeys = Object.keys(RegisterVerifierId).filter((key) => isNaN(Number(key)));
|
||||
const regularRegisterKeys = registerVerifierKeys.filter(key => !key.startsWith('register_id_'));
|
||||
const regularRegisterKeys = registerVerifierKeys.filter((key) => !key.startsWith("register_id_"));
|
||||
|
||||
const registerAttestationIds: string[] = [];
|
||||
const registerCircuitVerifierIds: number[] = [];
|
||||
@@ -138,7 +137,9 @@ try {
|
||||
registerCircuitVerifierAddresses,
|
||||
);
|
||||
const receipt = await tx.wait();
|
||||
log.success(`Register verifiers for E_PASSPORT updated: ${registerCircuitVerifierIds.length} verifiers (tx: ${receipt.hash})`);
|
||||
log.success(
|
||||
`Register verifiers for E_PASSPORT updated: ${registerCircuitVerifierIds.length} verifiers (tx: ${receipt.hash})`,
|
||||
);
|
||||
successfulUpdates++;
|
||||
} catch (error) {
|
||||
log.error(`Failed to update register verifiers for E_PASSPORT: ${error}`);
|
||||
@@ -194,7 +195,9 @@ try {
|
||||
registerIdCircuitVerifierAddresses,
|
||||
);
|
||||
const receipt = await tx.wait();
|
||||
log.success(`Register_id verifiers for EU_ID_CARD updated: ${registerIdCircuitVerifierIds.length} verifiers (tx: ${receipt.hash})`);
|
||||
log.success(
|
||||
`Register_id verifiers for EU_ID_CARD updated: ${registerIdCircuitVerifierIds.length} verifiers (tx: ${receipt.hash})`,
|
||||
);
|
||||
successfulUpdates++;
|
||||
} catch (error) {
|
||||
log.error(`Failed to update register_id verifiers for EU_ID_CARD: ${error}`);
|
||||
@@ -242,7 +245,9 @@ try {
|
||||
dscCircuitVerifierAddresses,
|
||||
);
|
||||
const receipt = await tx.wait();
|
||||
log.success(`DSC verifiers for ${attestationType} updated: ${dscCircuitVerifierIds.length} verifiers (tx: ${receipt.hash})`);
|
||||
log.success(
|
||||
`DSC verifiers for ${attestationType} updated: ${dscCircuitVerifierIds.length} verifiers (tx: ${receipt.hash})`,
|
||||
);
|
||||
successfulUpdates++;
|
||||
} catch (error) {
|
||||
log.error(`Failed to update DSC verifiers for ${attestationType}: ${error}`);
|
||||
|
||||
@@ -7,10 +7,7 @@ async function showRegistryAddresses() {
|
||||
|
||||
try {
|
||||
// Read the deployed addresses from the deployment artifacts
|
||||
const deployedAddressesPath = path.join(
|
||||
__dirname,
|
||||
"../ignition/deployments/chain-44787/deployed_addresses.json"
|
||||
);
|
||||
const deployedAddressesPath = path.join(__dirname, "../ignition/deployments/chain-44787/deployed_addresses.json");
|
||||
|
||||
if (!fs.existsSync(deployedAddressesPath)) {
|
||||
console.log("❌ No deployment found for chain 44787 (Alfajores)");
|
||||
@@ -21,9 +18,7 @@ async function showRegistryAddresses() {
|
||||
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
|
||||
|
||||
// Show registry-related addresses
|
||||
const registryKeys = Object.keys(deployedAddresses).filter(key =>
|
||||
key.startsWith("DeployRegistryModule#")
|
||||
);
|
||||
const registryKeys = Object.keys(deployedAddresses).filter((key) => key.startsWith("DeployRegistryModule#"));
|
||||
|
||||
if (registryKeys.length === 0) {
|
||||
console.log("❌ No registry contracts found in deployed addresses");
|
||||
@@ -31,7 +26,7 @@ async function showRegistryAddresses() {
|
||||
return;
|
||||
}
|
||||
|
||||
registryKeys.forEach(key => {
|
||||
registryKeys.forEach((key) => {
|
||||
const contractName = key.replace("DeployRegistryModule#", "");
|
||||
const address = deployedAddresses[key];
|
||||
let emoji = "📝";
|
||||
@@ -45,7 +40,6 @@ async function showRegistryAddresses() {
|
||||
});
|
||||
|
||||
console.log("\n✅ Registry deployment complete!");
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Error reading deployment addresses:", error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user