Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pid 1054 #170

Merged
merged 47 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fe9c6bb
add allowed issuers check
volodymyr-basiuk Aug 7, 2023
2805726
add packer
volodymyr-basiuk Aug 8, 2023
5c118cb
remove ustom packer
volodymyr-basiuk Aug 8, 2023
2d04621
fix solhint
volodymyr-basiuk Aug 8, 2023
3cbc53b
move queryHash calculation to validator
volodymyr-basiuk Aug 8, 2023
bed984b
add pagination unit test
volodymyr-basiuk Aug 8, 2023
00b670b
fix test name
volodymyr-basiuk Aug 8, 2023
fb271ac
add one more check in test
volodymyr-basiuk Aug 8, 2023
b0c3804
remove ZKPResponse struct
volodymyr-basiuk Aug 9, 2023
e32e135
change memory to calldata in submitZKPResponse
volodymyr-basiuk Aug 9, 2023
348fb66
CircuitQuery -> ZKPRequest
volodymyr-basiuk Aug 9, 2023
2e18535
add upgradeValidator to Helper utils
volodymyr-basiuk Aug 9, 2023
3dcd035
add submitZKPResponse utin test (for estimation)
volodymyr-basiuk Aug 9, 2023
9bdad16
add non-merklized support & inputIndexOf
volodymyr-basiuk Aug 9, 2023
8ce0fa3
disable solhint code-complexity
volodymyr-basiuk Aug 9, 2023
0aff68e
set pure to inputIndexOf
volodymyr-basiuk Aug 9, 2023
2d7faac
rm contract address
volodymyr-basiuk Aug 9, 2023
cdc29a8
refactor inputIndexOf with arr implementation
volodymyr-basiuk Aug 9, 2023
4b6edf4
move inputIndexOf to abstract class implementation
volodymyr-basiuk Aug 9, 2023
dee0760
add getSupportedCircuitIds to validator
volodymyr-basiuk Aug 10, 2023
69deab9
revert to one queryHash
volodymyr-basiuk Aug 10, 2023
ca98f8c
fix linter
volodymyr-basiuk Aug 10, 2023
01a0482
add circuitIds to query struct
volodymyr-basiuk Aug 10, 2023
501da84
add ValidationParams & rename requests vars
volodymyr-basiuk Aug 14, 2023
a62868e
fix linter
volodymyr-basiuk Aug 14, 2023
79f0d77
add gap to support upgradable & rm duplicated arr
volodymyr-basiuk Aug 14, 2023
6dc6639
fix gap name & onlyInitializing modifier
volodymyr-basiuk Aug 14, 2023
1a4383c
move gap_before to abstract contract
volodymyr-basiuk Aug 14, 2023
59f3baa
move _gap var
volodymyr-basiuk Aug 16, 2023
7f13287
rm empty spaces
volodymyr-basiuk Aug 16, 2023
3fe824d
Feauture/verifier snarkjs 0.7.0 (#171)
vmidyllic Aug 15, 2023
407a796
fix lint
volodymyr-basiuk Aug 17, 2023
8db32fc
merge master
volodymyr-basiuk Aug 17, 2023
c8fb382
add prettierignore
volodymyr-basiuk Aug 18, 2023
810088b
undo formatting changes is verification keys
volodymyr-basiuk Aug 18, 2023
cbd9f99
Refactoring of CredentialAtomicQueryValidators (#173)
OBrezhniev Aug 29, 2023
3c2a57f
remove returns bool & fix comments
volodymyr-basiuk Sep 6, 2023
2ebc172
rm unsafeSkipStorageCheck from validator upgrade
volodymyr-basiuk Sep 6, 2023
36f81c0
fix naming of requestIdExists
volodymyr-basiuk Sep 9, 2023
fccd1ab
refactor verify and pubSignals struct & fix gaps
volodymyr-basiuk Sep 12, 2023
f8a389b
change ZKPRequest to calldata
volodymyr-basiuk Sep 12, 2023
60649a5
fix solhint
volodymyr-basiuk Sep 12, 2023
f99477b
fix typo
volodymyr-basiuk Sep 12, 2023
e055901
make parsePublicSignals virtual
volodymyr-basiuk Sep 12, 2023
e822d0c
rename parsePublicSignals -> parseBasePubSignals
volodymyr-basiuk Sep 12, 2023
35c650e
rn base -> comm pub signals & add issuanceState
volodymyr-basiuk Sep 12, 2023
c808cd9
rename issuanceState to issuerState
volodymyr-basiuk Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/lib/VerifierMTP.sol
**/lib/VerifierSig.sol
**/lib/VerifierStateTransition.sol
17 changes: 4 additions & 13 deletions contracts/interfaces/ICircuitValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@
pragma solidity 0.8.16;

interface ICircuitValidator {
struct CircuitQuery {
uint256 schema;
uint256 claimPathKey;
uint256 operator;
uint256[] value;
uint256 queryHash;
string circuitId;
}

function verify(
uint256[] memory inputs,
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256 queryHash
) external view returns (bool r);
bytes calldata data
) external view;

function getCircuitId() external pure returns (string memory id);
function getSupportedCircuitIds() external view returns (string[] memory ids);

function getChallengeInputIndex() external pure returns (uint256 index);
function inputIndexOf(string memory name) external view returns (uint256);
}
42 changes: 19 additions & 23 deletions contracts/interfaces/IZKPVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,30 @@ pragma solidity 0.8.16;
import {ICircuitValidator} from "./ICircuitValidator.sol";

interface IZKPVerifier {
struct ZKPRequest {
string metadata;
ICircuitValidator validator;
bytes data;
}

function submitZKPResponse(
uint64 requestId,
uint256[] memory inputs,
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c
) external returns (bool);
) external;

function setZKPRequest(
uint64 requestId,
ICircuitValidator validator,
uint256 schema,
uint256 slotIndex,
uint256 operator,
uint256[] calldata value
) external returns (bool);

function setZKPRequestRaw(
uint64 requestId,
ICircuitValidator validator,
uint256 schema,
uint256 slotIndex,
uint256 operator,
uint256[] calldata value,
uint256 queryHash
) external returns (bool);

function getZKPRequest(
uint64 requestId
) external returns (ICircuitValidator.CircuitQuery memory);
function setZKPRequest(uint64 requestId, ZKPRequest calldata request) external;

function getZKPRequestsCount() external view returns (uint256);

function requestIdExists(uint64 requestId) external view returns (bool);

function getZKPRequest(uint64 requestId) external view returns (ZKPRequest memory);

function getZKPRequests(
uint256 startIndex,
uint256 length
) external view returns (ZKPRequest[] memory);
}
36 changes: 18 additions & 18 deletions contracts/lib/VerifierMTP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ contract VerifierMTP {
uint256 constant IC11x = 13613305841160720689914712433320508347546323189059844660259139894452538774575;
uint256 constant IC11y = 5325101314795154200638690464360192908052407201796948025470533168336651686116;


// 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[11] calldata _pubSignals) public view returns (bool) {
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[11] calldata _pubSignals
) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
Expand All @@ -95,7 +99,7 @@ contract VerifierMTP {
}
}

// G1 function to multiply a G1 value(x,y) to value in an address
// G1 function to multiply a G1 value(x,y) to value in an address
function g1_mulAccC(pR, x, y, s) {
let success
let mIn := mload(0x40)
Expand Down Expand Up @@ -128,7 +132,7 @@ contract VerifierMTP {
mstore(_pVk, IC0x)
mstore(add(_pVk, 32), IC0y)

// Compute the linear combination vk_x
// Compute the linear combination vk_x

g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))

Expand All @@ -152,49 +156,46 @@ contract VerifierMTP {

g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))


// -A
// -A
mstore(_pPairing, calldataload(pA))
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))

// B
// B
mstore(add(_pPairing, 64), calldataload(pB))
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))

// alpha1
// alpha1
mstore(add(_pPairing, 192), alphax)
mstore(add(_pPairing, 224), alphay)

// beta2
// beta2
mstore(add(_pPairing, 256), betax1)
mstore(add(_pPairing, 288), betax2)
mstore(add(_pPairing, 320), betay1)
mstore(add(_pPairing, 352), betay2)

// vk_x
// vk_x
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))


// gamma2
// gamma2
mstore(add(_pPairing, 448), gammax1)
mstore(add(_pPairing, 480), gammax2)
mstore(add(_pPairing, 512), gammay1)
mstore(add(_pPairing, 544), gammay2)

// C
// C
mstore(add(_pPairing, 576), calldataload(pC))
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))

// delta2
// delta2
mstore(add(_pPairing, 640), deltax1)
mstore(add(_pPairing, 672), deltax2)
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))
Expand All @@ -203,7 +204,7 @@ contract VerifierMTP {
let pMem := mload(0x40)
mstore(0x40, add(pMem, pLastMem))

// Validate that all evaluations ∈ F
// Validate that all evaluations ∈ F

checkField(calldataload(add(_pubSignals, 0)))

Expand All @@ -229,8 +230,7 @@ contract VerifierMTP {

checkField(calldataload(add(_pubSignals, 352)))


// Validate all evaluations
// Validate all evaluations
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)

mstore(0, isValid)
Expand Down
9 changes: 3 additions & 6 deletions contracts/lib/VerifierMTPWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ pragma solidity 0.8.16;
import "./VerifierMTP.sol";
import "../interfaces/IVerifier.sol";

contract VerifierMTPWrapper is VerifierMTP,IVerifier {

contract VerifierMTPWrapper is VerifierMTP, IVerifier {
/**
* @dev Number of public signals for atomic mtp circuit
* @dev Number of public signals for atomic mtp circuit
*/
uint constant PUBSIGNALS_LENGTH = 11;

Expand All @@ -30,7 +29,6 @@ contract VerifierMTPWrapper is VerifierMTP,IVerifier {
uint256[2] calldata c,
uint256[] calldata input
) public view returns (bool r) {

uint[PUBSIGNALS_LENGTH] memory pubSignals;

require(input.length == PUBSIGNALS_LENGTH, "expected array length is 11");
Expand All @@ -39,7 +37,6 @@ contract VerifierMTPWrapper is VerifierMTP,IVerifier {
pubSignals[i] = input[i];
}

return this.verifyProof(a,b,c,pubSignals) ;

return this.verifyProof(a, b, c, pubSignals);
}
}
35 changes: 18 additions & 17 deletions contracts/lib/VerifierSig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ contract VerifierSig {

uint16 constant pLastMem = 896;

function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[11] calldata _pubSignals) public view returns (bool) {
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[11] calldata _pubSignals
) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
Expand All @@ -95,7 +100,7 @@ contract VerifierSig {
}
}

// G1 function to multiply a G1 value(x,y) to value in an address
// G1 function to multiply a G1 value(x,y) to value in an address
function g1_mulAccC(pR, x, y, s) {
let success
let mIn := mload(0x40)
Expand Down Expand Up @@ -128,7 +133,7 @@ contract VerifierSig {
mstore(_pVk, IC0x)
mstore(add(_pVk, 32), IC0y)

// Compute the linear combination vk_x
// Compute the linear combination vk_x

g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))

Expand All @@ -152,49 +157,46 @@ contract VerifierSig {

g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))


// -A
// -A
mstore(_pPairing, calldataload(pA))
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))

// B
// B
mstore(add(_pPairing, 64), calldataload(pB))
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))

// alpha1
// alpha1
mstore(add(_pPairing, 192), alphax)
mstore(add(_pPairing, 224), alphay)

// beta2
// beta2
mstore(add(_pPairing, 256), betax1)
mstore(add(_pPairing, 288), betax2)
mstore(add(_pPairing, 320), betay1)
mstore(add(_pPairing, 352), betay2)

// vk_x
// vk_x
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))


// gamma2
// gamma2
mstore(add(_pPairing, 448), gammax1)
mstore(add(_pPairing, 480), gammax2)
mstore(add(_pPairing, 512), gammay1)
mstore(add(_pPairing, 544), gammay2)

// C
// C
mstore(add(_pPairing, 576), calldataload(pC))
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))

// delta2
// delta2
mstore(add(_pPairing, 640), deltax1)
mstore(add(_pPairing, 672), deltax2)
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))
Expand All @@ -203,7 +205,7 @@ contract VerifierSig {
let pMem := mload(0x40)
mstore(0x40, add(pMem, pLastMem))

// Validate that all evaluations ∈ F
// Validate that all evaluations ∈ F

checkField(calldataload(add(_pubSignals, 0)))

Expand All @@ -229,8 +231,7 @@ contract VerifierSig {

checkField(calldataload(add(_pubSignals, 352)))


// Validate all evaluations
// Validate all evaluations
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)

mstore(0, isValid)
Expand Down
3 changes: 1 addition & 2 deletions contracts/lib/VerifierSigWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import "./VerifierSig.sol";
import "../interfaces/IVerifier.sol";

contract VerifierSigWrapper is VerifierSig, IVerifier {

/**
* @dev Number of public signals for atomic sig circuit
*/
Expand All @@ -38,6 +37,6 @@ contract VerifierSigWrapper is VerifierSig, IVerifier {
for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) {
pubSignals[i] = input[i];
}
return this.verifyProof(a,b,c,pubSignals) ;
return this.verifyProof(a, b, c, pubSignals);
}
}
Loading
Loading