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

add linkNonce/linkID input/output #103

Merged
merged 5 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
23 changes: 23 additions & 0 deletions circuits/lib/linked/linkId.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma circom 2.1.5;

include "../../../node_modules/circomlib/circuits/poseidon.circom";
include "../utils/claimUtils.circom";

template LinkID() {
signal input claim[8];
signal input linkNonce;

signal output out;

signal isNonceZero <== IsZero()(linkNonce);

component claimHash = getClaimHash();
claimHash.claim <== claim;

signal linkID <== Poseidon(2)([claimHash.hash, linkNonce]);

out <== Mux1()(
[linkID, 0],
isNonceZero
);
}
10 changes: 10 additions & 0 deletions circuits/offchain/credentialAtomicQueryV3OffChain.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ pragma circom 2.1.5; /* chage to 2.1.6 */

include "./credentialAtomicQueryMTPOffChain.circom";
include "./credentialAtomicQuerySigOffChain.circom";
include "../lib/linked/linkId.circom";

template credentialAtomicQueryV3OffChain(issuerLevels, claimLevels, valueArraySize) {
// common outputs for Sig and MTP
signal output merklized;
signal output userID;
signal output linkID;
volodymyr-basiuk marked this conversation as resolved.
Show resolved Hide resolved

// common inputs for Sig and MTP
signal input proofType; // sig 0, mtp 1
Expand Down Expand Up @@ -66,6 +68,9 @@ template credentialAtomicQueryV3OffChain(issuerLevels, claimLevels, valueArraySi
signal input issuerClaimSignatureR8y;
signal input issuerClaimSignatureS;

// Private random nonce, used to generate LinkID
signal input linkNonce;

// Sig specific outputs
signal output issuerAuthState;

Expand Down Expand Up @@ -184,6 +189,11 @@ template credentialAtomicQueryV3OffChain(issuerLevels, claimLevels, valueArraySi

/* ProfileID calculation */
userID <== SelectProfile()(userGenesisID, profileNonce);

/////////////////////////////////////////////////////////////////
// Link ID calculation
/////////////////////////////////////////////////////////////////
linkID <== LinkID()(issuerClaim, linkNonce);
}

template sigFlow(issuerLevels) {
Expand Down
9 changes: 7 additions & 2 deletions circuits/onchain/credentialAtomicQueryV3OnChain.circom
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ template credentialAtomicQueryV3OnChain(issuerLevels, claimLevels, valueArraySiz
// unless nonce == 0, in which case userID will be assigned with userGenesisID
signal output userID;

signal output linkID;
volodymyr-basiuk marked this conversation as resolved.
Show resolved Hide resolved

// circuits query Hash
signal output circuitQueryHash;

Expand Down Expand Up @@ -151,6 +153,8 @@ template credentialAtomicQueryV3OnChain(issuerLevels, claimLevels, valueArraySiz
signal input issuerClaimSignatureR8y;
signal input issuerClaimSignatureS;

// Private random nonce, used to generate LinkID
signal input linkNonce;

// Sig specific output
signal output issuerAuthState;
Expand Down Expand Up @@ -186,7 +190,7 @@ template credentialAtomicQueryV3OnChain(issuerLevels, claimLevels, valueArraySiz
gistMtpNoAux
);

(merklized, userID, issuerAuthState) <== credentialAtomicQueryV3OffChain(issuerLevels, claimLevels, valueArraySize)(
(merklized, userID, linkID, issuerAuthState) <== credentialAtomicQueryV3OffChain(issuerLevels, claimLevels, valueArraySize)(
proofType <== proofType,
requestID <== requestID,
userGenesisID <== userGenesisID,
Expand Down Expand Up @@ -231,7 +235,8 @@ template credentialAtomicQueryV3OnChain(issuerLevels, claimLevels, valueArraySiz
issuerAuthClaimNonRevMtpAuxHv <== issuerAuthClaimNonRevMtpAuxHv,
issuerClaimSignatureR8x <== issuerClaimSignatureR8x,
issuerClaimSignatureR8y <== issuerClaimSignatureR8y,
issuerClaimSignatureS <== issuerClaimSignatureS
issuerClaimSignatureS <== issuerClaimSignatureS,
linkNonce <== linkNonce
);

// verify query hash matches
Expand Down
15 changes: 15 additions & 0 deletions testvectorgen/credentials/onchain/v3/mtp/mtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type Inputs struct {
IssuerAuthRootsTreeRoot string `json:"issuerAuthRootsTreeRoot"`

ProofType string `json:"proofType"` // 0 for sig, 1 for mtp
// Private random nonce, used to generate LinkID
LinkNonce string `json:"linkNonce"`
}

type Outputs struct {
Expand All @@ -118,6 +120,7 @@ type Outputs struct {
Challenge string `json:"challenge"`
GistRoot string `json:"gistRoot"`
IssuerClaimIdenState string `json:"issuerClaimIdenState"`
LinkID string `json:"linkID"`
// Sig specific
IssuerAuthState string `json:"issuerAuthState"`
}
Expand Down Expand Up @@ -268,6 +271,8 @@ func Test_RevokedClaimWithRevocationCheck(t *testing.T) {
IssuerAuthRevTreeRoot: "0",
IssuerAuthRootsTreeRoot: "0",

LinkNonce: "0",

ProofType: "1",
}

Expand Down Expand Up @@ -298,6 +303,7 @@ func Test_RevokedClaimWithRevocationCheck(t *testing.T) {
IsRevocationChecked: "1",
ProofType: "1",
IssuerAuthState: "0",
LinkID: "0",
}

json, err := json2.Marshal(TestData{
Expand Down Expand Up @@ -418,6 +424,8 @@ func Test_RevokedClaimWithoutRevocationCheck(t *testing.T) {
IssuerAuthRevTreeRoot: "0",
IssuerAuthRootsTreeRoot: "0",

LinkNonce: "0",

ProofType: "1",
}

Expand Down Expand Up @@ -448,6 +456,7 @@ func Test_RevokedClaimWithoutRevocationCheck(t *testing.T) {
IsRevocationChecked: "0",
ProofType: "1",
IssuerAuthState: "0",
LinkID: "0",
}

json, err := json2.Marshal(TestData{
Expand Down Expand Up @@ -593,6 +602,8 @@ func generateJSONLDTestData(t *testing.T, desc string, isUserIDProfile, isSubjec
IssuerAuthRevTreeRoot: "0",
IssuerAuthRootsTreeRoot: "0",

LinkNonce: "0",

ProofType: "1",
}
valuesHash, err := utils.PoseidonHashValue(utils.FromStringArrayToBigIntArray(inputs.Value))
Expand Down Expand Up @@ -623,6 +634,7 @@ func generateJSONLDTestData(t *testing.T, desc string, isUserIDProfile, isSubjec
IsRevocationChecked: "1",
ProofType: "1",
IssuerAuthState: "0",
LinkID: "0",
}

json, err := json2.Marshal(TestData{
Expand Down Expand Up @@ -754,6 +766,8 @@ func generateTestData(t *testing.T, desc string, isUserIDProfile, isSubjectIDPro
IssuerAuthRevTreeRoot: "0",
IssuerAuthRootsTreeRoot: "0",

LinkNonce: "0",

ProofType: "1",
}

Expand Down Expand Up @@ -785,6 +799,7 @@ func generateTestData(t *testing.T, desc string, isUserIDProfile, isSubjectIDPro
IsRevocationChecked: "1",
ProofType: "1",
IssuerAuthState: "0",
LinkID: "0",
}

json, err := json2.Marshal(TestData{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"desc":"User != Subject. Claim issued on ProfileID","inputs":{"requestID":"41","userGenesisID":"23148936466334350744548790012294489365207440754509988986684797708370051073","profileNonce":"0","claimSubjectProfileNonce":"999","authClaim":["80551937543569765027552589160822318028","0","4720763745722683616702324599137259461509439547324750011830105416383780791263","4844030361230692908091131578688419341633213823133966379083981236400104720538","16547485850637761685","0","0","0"],"authClaimIncMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"authClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"authClaimNonRevMtpAuxHi":"0","authClaimNonRevMtpAuxHv":"0","authClaimNonRevMtpNoAux":"1","challenge":"12345","challengeSignatureR8x":"15829360093371098546177008474519342171461782120259125067189481965541223738777","challengeSignatureR8y":"10840522802382821290541462398953040493080116495308402635486440290351677745960","challengeSignatureS":"1196477404779941775725836688033485533497812196897664950083199167075327114562","userClaimsTreeRoot":"8162166103065016664685834856644195001371303013149727027131225893397958846382","userRevTreeRoot":"0","userRootsTreeRoot":"0","userState":"8039964009611210398788855768060749920589777058607598891238307089541758339342","gistRoot":"1243904711429961858774220647610724273798918457991486031567244100767259239747","gistMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"gistMtpAuxHi":"1","gistMtpAuxHv":"1","gistMtpNoAux":"0","issuerID":"21933750065545691586450392143787330185992517860945727248803138245838110721","issuerClaim":["14472269431592746875347367665757389417422","24497320812635010775435456013830217801375919178980935564312517783529521153","17568057213828477233507447080689055308823020388972334380526849356111335110900","0","30803922965249841627828060170","0","0","0"],"issuerClaimMtp":["20643387758736831799596675626240785455902781070167728593409367019626753600795","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimClaimsTreeRoot":"6807394214856867182702861581688414112931887520929949769131382186542423406679","issuerClaimRevTreeRoot":"0","issuerClaimRootsTreeRoot":"0","issuerClaimIdenState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","isRevocationChecked":1,"issuerClaimNonRevClaimsTreeRoot":"6807394214856867182702861581688414112931887520929949769131382186542423406679","issuerClaimNonRevRevTreeRoot":"0","issuerClaimNonRevRootsTreeRoot":"0","issuerClaimNonRevState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","issuerClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimNonRevMtpAuxHi":"0","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"1","claimSchema":"180410020913331409885634153623124536270","claimPathNotExists":"0","claimPathMtp":["5559250731000753554753485016695600829384855452867544273344893815961938985436","20222899544143787877985297439625828822272100269106711904511119118819809140477","14730426618666280941604039095550905490156541514901979358549599762282042588641","20497288520738821800886677250569208588689763166335933087499619993954968899866","3295720551404287572425718873751040314503774617833462052445584373469655789999","796356776410152646380783209242693344675665178494017735650545708722024766291","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"claimPathMtpNoAux":"0","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"8566939875427719562376598811066985304309117528846759529734201066483458512800","claimPathValue":"1420070400000000000","operator":1,"slotIndex":0,"timestamp":"1642074362","value":["1420070400000000000","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimSignatureR8x":"0","issuerClaimSignatureR8y":"0","issuerClaimSignatureS":"0","issuerAuthClaim":["0","0","0","0","0","0","0","0"],"issuerAuthClaimMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerAuthClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerAuthClaimNonRevMtpAuxHi":"0","issuerAuthClaimNonRevMtpAuxHv":"0","issuerAuthClaimNonRevMtpNoAux":"0","issuerAuthClaimsTreeRoot":"0","issuerAuthRevTreeRoot":"0","issuerAuthRootsTreeRoot":"0","proofType":"1"},"expOut":{"proofType":"1","merklized":"1","userID":"23148936466334350744548790012294489365207440754509988986684797708370051073","circuitQueryHash":"1496222740463292783938163206931059379817846775593932664024082849882751356658","requestID":"41","issuerID":"21933750065545691586450392143787330185992517860945727248803138245838110721","issuerClaimNonRevState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","timestamp":"1642074362","isRevocationChecked":"1","challenge":"12345","gistRoot":"1243904711429961858774220647610724273798918457991486031567244100767259239747","issuerClaimIdenState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","issuerAuthState":"0"}}
{"desc":"User != Subject. Claim issued on ProfileID","inputs":{"requestID":"41","userGenesisID":"23148936466334350744548790012294489365207440754509988986684797708370051073","profileNonce":"0","claimSubjectProfileNonce":"999","authClaim":["80551937543569765027552589160822318028","0","4720763745722683616702324599137259461509439547324750011830105416383780791263","4844030361230692908091131578688419341633213823133966379083981236400104720538","16547485850637761685","0","0","0"],"authClaimIncMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"authClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"authClaimNonRevMtpAuxHi":"0","authClaimNonRevMtpAuxHv":"0","authClaimNonRevMtpNoAux":"1","challenge":"12345","challengeSignatureR8x":"15829360093371098546177008474519342171461782120259125067189481965541223738777","challengeSignatureR8y":"10840522802382821290541462398953040493080116495308402635486440290351677745960","challengeSignatureS":"1196477404779941775725836688033485533497812196897664950083199167075327114562","userClaimsTreeRoot":"8162166103065016664685834856644195001371303013149727027131225893397958846382","userRevTreeRoot":"0","userRootsTreeRoot":"0","userState":"8039964009611210398788855768060749920589777058607598891238307089541758339342","gistRoot":"1243904711429961858774220647610724273798918457991486031567244100767259239747","gistMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"gistMtpAuxHi":"1","gistMtpAuxHv":"1","gistMtpNoAux":"0","issuerID":"21933750065545691586450392143787330185992517860945727248803138245838110721","issuerClaim":["14472269431592746875347367665757389417422","24497320812635010775435456013830217801375919178980935564312517783529521153","17568057213828477233507447080689055308823020388972334380526849356111335110900","0","30803922965249841627828060170","0","0","0"],"issuerClaimMtp":["20643387758736831799596675626240785455902781070167728593409367019626753600795","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimClaimsTreeRoot":"6807394214856867182702861581688414112931887520929949769131382186542423406679","issuerClaimRevTreeRoot":"0","issuerClaimRootsTreeRoot":"0","issuerClaimIdenState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","isRevocationChecked":1,"issuerClaimNonRevClaimsTreeRoot":"6807394214856867182702861581688414112931887520929949769131382186542423406679","issuerClaimNonRevRevTreeRoot":"0","issuerClaimNonRevRootsTreeRoot":"0","issuerClaimNonRevState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","issuerClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimNonRevMtpAuxHi":"0","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"1","claimSchema":"180410020913331409885634153623124536270","claimPathNotExists":"0","claimPathMtp":["5559250731000753554753485016695600829384855452867544273344893815961938985436","20222899544143787877985297439625828822272100269106711904511119118819809140477","14730426618666280941604039095550905490156541514901979358549599762282042588641","20497288520738821800886677250569208588689763166335933087499619993954968899866","3295720551404287572425718873751040314503774617833462052445584373469655789999","796356776410152646380783209242693344675665178494017735650545708722024766291","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"claimPathMtpNoAux":"0","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"8566939875427719562376598811066985304309117528846759529734201066483458512800","claimPathValue":"1420070400000000000","operator":1,"slotIndex":0,"timestamp":"1642074362","value":["1420070400000000000","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimSignatureR8x":"0","issuerClaimSignatureR8y":"0","issuerClaimSignatureS":"0","issuerAuthClaim":["0","0","0","0","0","0","0","0"],"issuerAuthClaimMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerAuthClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerAuthClaimNonRevMtpAuxHi":"0","issuerAuthClaimNonRevMtpAuxHv":"0","issuerAuthClaimNonRevMtpNoAux":"0","issuerAuthClaimsTreeRoot":"0","issuerAuthRevTreeRoot":"0","issuerAuthRootsTreeRoot":"0","proofType":"1","linkNonce":"0"},"expOut":{"proofType":"1","merklized":"1","userID":"23148936466334350744548790012294489365207440754509988986684797708370051073","circuitQueryHash":"1496222740463292783938163206931059379817846775593932664024082849882751356658","requestID":"41","issuerID":"21933750065545691586450392143787330185992517860945727248803138245838110721","issuerClaimNonRevState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","timestamp":"1642074362","isRevocationChecked":"1","challenge":"12345","gistRoot":"1243904711429961858774220647610724273798918457991486031567244100767259239747","issuerClaimIdenState":"19610686287062380962892375049625048425838961734261320467083164088209350256405","linkID":"0","issuerAuthState":"0"}}
Loading