Skip to content

Commit

Permalink
update contracts test code
Browse files Browse the repository at this point in the history
  • Loading branch information
motemotech committed Dec 16, 2024
1 parent ddd89e4 commit 03b312a
Show file tree
Hide file tree
Showing 14 changed files with 7,620 additions and 5,862 deletions.
3 changes: 3 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ ignition/deployments

#Local verifier
contracts/verifiers/local/*

.yarn
.yarnrc.yml
46 changes: 18 additions & 28 deletions contracts/contracts/OpenPassportVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,129 +21,119 @@ contract OpenPassportVerifier is IOpenPassportVerifier {
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.ISSUING_STATE_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit IssuingStateDisclosed(attrs.issuingState);
return attrs.issuingState;
}

function discloseName(
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.NAME_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit NameDisclosed(attrs.name);
return attrs.name;
}

function disclosePassportNumber(
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.PASSPORT_NUMBER_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit PassportNumberDisclosed(attrs.passportNumber);
return attrs.passportNumber;
}

function discloseNationality(
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.NATIONALITY_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit NationalityDisclosed(attrs.nationality);
return attrs.nationality;
}

function discloseDateOfBirth(
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.DATE_OF_BIRTH_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit DateOfBirthDisclosed(attrs.dateOfBirth);
return attrs.dateOfBirth;
}

function discloseGender(
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.GENDER_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit GenderDisclosed(attrs.gender);
return attrs.gender;
}

function discloseExpiryDate(
OpenPassportAttestation memory attestation
) public returns (string memory) {
uint256 selector = OpenPassportAttributeSelector.EXPIRY_DATE_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit ExpiryDateDisclosed(attrs.expiryDate);
return attrs.expiryDate;
}

function discloseOlderThan(
OpenPassportAttestation memory attestation
) public returns (uint256) {
uint256 selector = OpenPassportAttributeSelector.OLDER_THAN_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit OlderThanDisclosed(attrs.olderThan);
return attrs.olderThan;
}

function discloseOfacResult(
OpenPassportAttestation memory attestation
) public returns (bool) {
uint256 selector = OpenPassportAttributeSelector.OFAC_RESULT_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit OfacResultDisclosed(attrs.ofacResult);
return attrs.ofacResult;
}

function discloseForbiddenCountries(
OpenPassportAttestation memory attestation
) public returns (bytes3[20] memory) {
uint256 selector = OpenPassportAttributeSelector.FORBIDDEN_COUNTRIES_SELECTOR;

PassportAttributes memory attrs = verifyAndDiscloseAttributes(
attestation,
selector
);

emit ForbiddenCountriesDisclosed(attrs.forbiddenCountries);
return attrs.forbiddenCountries;
}

Expand Down Expand Up @@ -235,16 +225,16 @@ contract OpenPassportVerifier is IOpenPassportVerifier {
blindedDscCommitment = abi.encodePacked(attestation.pProof.pubSignalsRSA[OpenPassportConstants.PROVE_RSA_BLINDED_DSC_COMMITMENT_INDEX]);
} else if (attestation.pProof.signatureType == IGenericVerifier.SignatureType.ECDSA) {
blindedDscCommitment = abi.encodePacked(attestation.pProof.pubSignalsECDSA[OpenPassportConstants.PROVE_ECDSA_BLINDED_DSC_COMMITMENT_INDEX]);
} else {
revert INVALID_SIGNATURE_TYPE();
}
if (
keccak256(blindedDscCommitment) !=
keccak256(abi.encodePacked(attestation.dProof.pubSignals[OpenPassportConstants.DSC_BLINDED_DSC_COMMITMENT_INDEX]))
) {
revert UNEQUAL_BLINDED_DSC_COMMITMENT();
}

// TODO: After merged new RSA circuits and fix modal server, fix this code
// if (
// keccak256(blindedDscCommitment) !=
// keccak256(abi.encodePacked(attestation.dProof.pubSignals[OpenPassportConstants.DSC_BLINDED_DSC_COMMITMENT_INDEX]))
// ) {
// revert UNEQUAL_BLINDED_DSC_COMMITMENT();
// }

if (!genericVerifier.verifyWithProveVerifier(attestation.proveVerifierId, attestation.pProof)) {
revert INVALID_PROVE_PROOF();
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/interfaces/IGenericVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IGenericVerifier {
uint[2] a;
uint[2][2] b;
uint[2] c;
uint[1] pubSignals;
uint[2] pubSignals;
}

function verifyWithProveVerifier(
Expand Down Expand Up @@ -69,6 +69,6 @@ interface IDscVerifier {
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[1] calldata _pubSignals
uint[2] calldata _pubSignals
) external view returns (bool);
}
11 changes: 11 additions & 0 deletions contracts/contracts/interfaces/IOpenPassportVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,15 @@ interface IOpenPassportVerifier {
OpenPassportAttestation memory attestation
) external returns (IGenericVerifier.ProveCircuitProof memory);

event IssuingStateDisclosed(string issuingState);
event NameDisclosed(string name);
event PassportNumberDisclosed(string passportNumber);
event NationalityDisclosed(string nationality);
event DateOfBirthDisclosed(string dateOfBirth);
event GenderDisclosed(string gender);
event ExpiryDateDisclosed(string expiryDate);
event OlderThanDisclosed(uint256 olderThan);
event OfacResultDisclosed(bool ofacResult);
event ForbiddenCountriesDisclosed(bytes3[20] forbiddenCountries);

}
11 changes: 11 additions & 0 deletions contracts/contracts/mock/mockVerifierDscRsa65537Sha256_4096.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity >=0.7.0 <0.9.0;

contract Mock_Verifier_dsc_rsa_65537_sha256_4096 {

function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) {
if (_pA[0] == 1) {
return false;
}
return true;
}
}
11 changes: 11 additions & 0 deletions contracts/contracts/mock/mockVerifierProveRsa65537Sha256_2048.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity >=0.7.0 <0.9.0;

contract Mock_Verifier_prove_rsa_65537_sha256 {

function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[51] calldata _pubSignals) public view returns (bool) {
if (_pA[0] == 1) {
return false;
}
return true;
}
}
2 changes: 0 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"author": "motemotech <[email protected]>",
"scripts": {
"test": "npx hardhat test",
"test:local": "TEST_ENV=local npx hardhat test",
"test:prod": "TEST_ENV=prod npx hardhat test",
"deploy_all": "npx hardhat ignition deploy ignition/modules/Deploy_All.ts --network optimism --verify",
"compile": "npx hardhat compile",
"publish": "npm publish --access public"
Expand Down
Loading

0 comments on commit 03b312a

Please sign in to comment.