Skip to content

Commit

Permalink
add nullify and linkNonce/linkID to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Sep 19, 2023
1 parent a886cf2 commit eeb5499
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 9 deletions.
28 changes: 25 additions & 3 deletions credentialAtomicQueryV3.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type AtomicQueryV3Inputs struct {
CurrentTimeStamp int64

ProofType ProofType

LinkNonce *big.Int
}

// atomicQueryV3CircuitInputs type represents credentialAtomicQueryV3.circom private inputs required by prover
Expand Down Expand Up @@ -97,6 +99,9 @@ type atomicQueryV3CircuitInputs struct {
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`

ProofType string `json:"proofType"`

// Private random nonce, used to generate LinkID
LinkNonce string `json:"linkNonce"`
}

func (a AtomicQueryV3Inputs) Validate() error {
Expand Down Expand Up @@ -247,6 +252,7 @@ func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error) {
return nil, err
}
s.Value = bigIntArrayToStringArray(values)
s.LinkNonce = a.LinkNonce.String()

return json.Marshal(s)
}
Expand Down Expand Up @@ -294,6 +300,8 @@ type AtomicQueryV3PubSignals struct {
IsRevocationChecked int `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`
ProofType int `json:"proofType"`
OperatorOutput *big.Int `son:"operatorOutput"`
LinkID *big.Int `json:"linkID"`
}

// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
Expand All @@ -315,11 +323,13 @@ func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error {
// operator
// value
// issuerClaimIdenState
// operatorOutput
// linkID

// 12 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
// it is length could be different base on the circuit configuration. The length could be modified by set value
// 17 is a number of fields in AtomicQueryV3PubSignals, values length could be
// different base on the circuit configuration. The length could be modified by set value
// in ValueArraySize
const fieldLength = 15
const fieldLength = 17

var sVals []string
err := json.Unmarshal(data, &sVals)
Expand Down Expand Up @@ -435,6 +445,18 @@ func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error {
if ao.IssuerClaimIdenState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++

// - operatorOutput
if ao.OperatorOutput, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid operator output value: '%s'", sVals[fieldIdx])
}
fieldIdx++

// - linkID
if ao.LinkID, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid link ID value: '%s'", sVals[fieldIdx])
}

return nil
}
Expand Down
23 changes: 23 additions & 0 deletions credentialAtomicQueryV3OnChain.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type AtomicQueryV3OnChainInputs struct {
CurrentTimeStamp int64

ProofType ProofType

LinkNonce *big.Int
}

// atomicQueryV3OnChainCircuitInputs type represents credentialAtomicQueryV3OnChain.circom private inputs required by prover
Expand Down Expand Up @@ -129,6 +131,9 @@ type atomicQueryV3OnChainCircuitInputs struct {
GISTMtpAuxHi *merkletree.Hash `json:"gistMtpAuxHi"`
GISTMtpAuxHv *merkletree.Hash `json:"gistMtpAuxHv"`
GISTMtpNoAux string `json:"gistMtpNoAux"`

// Private random nonce, used to generate LinkID
LinkNonce string `json:"linkNonce"`
}

func (a AtomicQueryV3OnChainInputs) Validate() error {
Expand Down Expand Up @@ -327,6 +332,8 @@ func (a AtomicQueryV3OnChainInputs) InputsMarshal() ([]byte, error) {
s.GISTMtpAuxHv = globalNodeAux.value
s.GISTMtpNoAux = globalNodeAux.noAux

s.LinkNonce = a.LinkNonce.String()

return json.Marshal(s)
}

Expand Down Expand Up @@ -370,6 +377,8 @@ type AtomicQueryV3OnChainPubSignals struct {
GlobalRoot *merkletree.Hash `json:"gistRoot"`
ProofType int `json:"proofType"`
IssuerAuthState *merkletree.Hash `json:"issuerAuthState"`
OperatorOutput *big.Int `son:"operatorOutput"`
LinkID *big.Int `json:"linkID"`
}

// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3OnChain.circom public signals
Expand All @@ -388,6 +397,8 @@ func (ao *AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal(data []byte) error
// issuerClaimNonRevState
// timestamp
// issuerClaimIdenState // mtp specific
// operatorOutput
// linkID

var sVals []string
err := json.Unmarshal(data, &sVals)
Expand Down Expand Up @@ -475,6 +486,18 @@ func (ao *AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal(data []byte) error
if ao.IssuerClaimIdenState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return fmt.Errorf("invalid IssuerClaimIdenState value: '%s'", sVals[fieldIdx])
}
fieldIdx++

// - operatorOutput
if ao.OperatorOutput, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid operator output value: '%s'", sVals[fieldIdx])
}
fieldIdx++

// - linkID
if ao.LinkID, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid link ID value: '%s'", sVals[fieldIdx])
}

return nil
}
Expand Down
12 changes: 11 additions & 1 deletion credentialAtomicQueryV3OnChain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestAttrQueryV3OnChain_SigPart_PrepareInputs(t *testing.T) {
},
Signature: signature,
Challenge: challenge,
LinkNonce: big.NewInt(0),
}

bytesInputs, err := in.InputsMarshal()
Expand Down Expand Up @@ -190,6 +191,7 @@ func TestAttrQueryV3OnChain_MTPPart_PrepareInputs(t *testing.T) {
},
Signature: signature,
Challenge: challenge,
LinkNonce: big.NewInt(0),
}

bytesInputs, err := in.InputsMarshal()
Expand All @@ -216,6 +218,8 @@ func TestAtomicQueryV3OnChainOutputs_Sig_CircuitUnmarshal(t *testing.T) {
"1",
"20177832565449474772630743317224985532862797657496372535616634430055981993180",
"1642074362",
"0",
"0",
"0"
]`))
require.NoError(t, err)
Expand Down Expand Up @@ -252,6 +256,8 @@ func TestAtomicQueryV3OnChainOutputs_Sig_CircuitUnmarshal(t *testing.T) {
GlobalRoot: it.MTHashFromStr(t, "20177832565449474772630743317224985532862797657496372535616634430055981993180"),
ProofType: 0,
IssuerClaimIdenState: &merkletree.HashZero,
OperatorOutput: big.NewInt(0),
LinkID: big.NewInt(0),
}

jsonOut, err := json.Marshal(out)
Expand All @@ -278,7 +284,9 @@ func TestAtomicQueryV3OnChainOutputs_MTP_CircuitUnmarshal(t *testing.T) {
"1",
"20177832565449474772630743317224985532862797657496372535616634430055981993180",
"1642074362",
"2943483356559152311923412925436024635269538717812859789851139200242297094"
"2943483356559152311923412925436024635269538717812859789851139200242297094",
"0",
"0"
]`))
require.NoError(t, err)

Expand Down Expand Up @@ -314,6 +322,8 @@ func TestAtomicQueryV3OnChainOutputs_MTP_CircuitUnmarshal(t *testing.T) {
GlobalRoot: it.MTHashFromStr(t, "20177832565449474772630743317224985532862797657496372535616634430055981993180"),
ProofType: 1,
IssuerClaimIdenState: it.MTHashFromStr(t, "2943483356559152311923412925436024635269538717812859789851139200242297094"),
OperatorOutput: big.NewInt(0),
LinkID: big.NewInt(0),
}

jsonOut, err := json.Marshal(out)
Expand Down
12 changes: 11 additions & 1 deletion credentialAtomicQueryV3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestAttrQueryV3_SigPart_PrepareInputs(t *testing.T) {
},
CurrentTimeStamp: timestamp,
ProofType: SigProotType,
LinkNonce: big.NewInt(0),
}

bytesInputs, err := in.InputsMarshal()
Expand Down Expand Up @@ -144,6 +145,7 @@ func TestAttrQueryV3_MTPPart_PrepareInputs(t *testing.T) {
},
CurrentTimeStamp: timestamp,
ProofType: MTPProofType,
LinkNonce: big.NewInt(0),
}

bytesInputs, err := in.InputsMarshal()
Expand Down Expand Up @@ -237,6 +239,8 @@ func TestAtomicQueryV3Outputs_Sig_CircuitUnmarshal(t *testing.T) {
"0",
"0",
"0",
"0",
"0",
"0"
]`))
require.NoError(t, err)
Expand Down Expand Up @@ -266,6 +270,8 @@ func TestAtomicQueryV3Outputs_Sig_CircuitUnmarshal(t *testing.T) {
IsRevocationChecked: 1,
IssuerClaimIdenState: &merkletree.HashZero,
ProofType: 0,
OperatorOutput: big.NewInt(0),
LinkID: big.NewInt(0),
}

jsonOut, err := json.Marshal(out)
Expand Down Expand Up @@ -358,7 +364,9 @@ func TestAtomicQueryV3Outputs_MTP_CircuitUnmarshal(t *testing.T) {
"0",
"0",
"0",
"5687720250943511874245715094520098014548846873346473635855112185560372332782"
"5687720250943511874245715094520098014548846873346473635855112185560372332782",
"0",
"0"
]`))
require.NoError(t, err)

Expand Down Expand Up @@ -387,6 +395,8 @@ func TestAtomicQueryV3Outputs_MTP_CircuitUnmarshal(t *testing.T) {
IsRevocationChecked: 1,
ProofType: 1,
IssuerAuthState: &merkletree.HashZero,
OperatorOutput: big.NewInt(0),
LinkID: big.NewInt(0),
}

jsonOut, err := json.Marshal(out)
Expand Down
2 changes: 1 addition & 1 deletion testdata/V3_mtp_inputs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"requestID":"23","userGenesisID":"26109404700696283154998654512117952420503675471097392618762221546565140481","profileNonce":"0","claimSubjectProfileNonce":"0","issuerID":"27918766665310231445021466320959318414450284884582375163563581940319453185","issuerClaim":["3583233690122716044519380227940806650830","26109404700696283154998654512117952420503675471097392618762221546565140481","10","0","30803922965249841627828060161","0","0","0"],"issuerClaimNonRevClaimsTreeRoot":"21551875744466996287712204148827400686061292275961899951444219768723484280073","issuerClaimNonRevRevTreeRoot":"0","issuerClaimNonRevRootsTreeRoot":"0","issuerClaimNonRevState":"19157496396839393206871475267813888069926627705277243727237933406423274512449","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","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","isRevocationChecked":1,"claimPathNotExists":1,"claimPathMtp":["0","0","0","0","0","0","0","0","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":"1","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"0","claimPathValue":"0","operator":1,"slotIndex":2,"timestamp":1642074362,"value":["10","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimMtp":["0","10304430946970870697981400054531724100803206948489006715521525892274350097449","0","0","0","0","0","0","0","0","0","0","0","0","0","0","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":"21551875744466996287712204148827400686061292275961899951444219768723484280073","issuerClaimRevTreeRoot":"0","issuerClaimRootsTreeRoot":"0","issuerClaimIdenState":"19157496396839393206871475267813888069926627705277243727237933406423274512449","proofType":"1"}
{"requestID":"23","userGenesisID":"26109404700696283154998654512117952420503675471097392618762221546565140481","profileNonce":"0","claimSubjectProfileNonce":"0","issuerID":"27918766665310231445021466320959318414450284884582375163563581940319453185","issuerClaim":["3583233690122716044519380227940806650830","26109404700696283154998654512117952420503675471097392618762221546565140481","10","0","30803922965249841627828060161","0","0","0"],"issuerClaimNonRevClaimsTreeRoot":"21551875744466996287712204148827400686061292275961899951444219768723484280073","issuerClaimNonRevRevTreeRoot":"0","issuerClaimNonRevRootsTreeRoot":"0","issuerClaimNonRevState":"19157496396839393206871475267813888069926627705277243727237933406423274512449","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","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","isRevocationChecked":1,"claimPathNotExists":1,"claimPathMtp":["0","0","0","0","0","0","0","0","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":"1","claimPathMtpAuxHi":"0","claimPathMtpAuxHv":"0","claimPathKey":"0","claimPathValue":"0","operator":1,"slotIndex":2,"timestamp":1642074362,"value":["10","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"issuerClaimMtp":["0","10304430946970870697981400054531724100803206948489006715521525892274350097449","0","0","0","0","0","0","0","0","0","0","0","0","0","0","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":"21551875744466996287712204148827400686061292275961899951444219768723484280073","issuerClaimRevTreeRoot":"0","issuerClaimRootsTreeRoot":"0","issuerClaimIdenState":"19157496396839393206871475267813888069926627705277243727237933406423274512449","proofType":"1", "linkNonce": "0"}
Loading

0 comments on commit eeb5499

Please sign in to comment.