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 nullify and linkNonce/linkID to v3 #72

Merged
merged 30 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eeb5499
add nullify and linkNonce/linkID to v3
volodymyr-basiuk Sep 19, 2023
3d55068
comment operatorOutput
volodymyr-basiuk Sep 22, 2023
b5e30f3
fix order
volodymyr-basiuk Sep 22, 2023
b25a64d
move linkID input to the end
volodymyr-basiuk Sep 25, 2023
1b73e6f
fix linkID order
volodymyr-basiuk Sep 25, 2023
cd1568a
add verifier ID
volodymyr-basiuk Sep 29, 2023
4b64ac9
fix test
volodymyr-basiuk Sep 29, 2023
67f9832
fix verifierID - input signal
volodymyr-basiuk Sep 29, 2023
98c8bb5
fix order for verifyID
volodymyr-basiuk Sep 29, 2023
b67923b
fix verifier id convert from ID to big int
volodymyr-basiuk Sep 29, 2023
007f079
allow verifier ID to be nil
volodymyr-basiuk Oct 3, 2023
58c82c9
refactor if else to one if
volodymyr-basiuk Oct 3, 2023
7fe871d
add new operators to query.go
volodymyr-basiuk Oct 4, 2023
e1971f9
update to latest V3 changes (verifierSessionID)
volodymyr-basiuk Nov 6, 2023
0f40b78
add IssuerAuthState input
volodymyr-basiuk Nov 6, 2023
eb84f90
fix IssuerAuthState
volodymyr-basiuk Nov 7, 2023
63fa310
add AuthV2Enabled in/out param
volodymyr-basiuk Nov 13, 2023
75d2c64
rename AuthV2Enabled to AuthEnabled
volodymyr-basiuk Nov 13, 2023
dffd68a
Make ClaimWithSigAndMTPProof.SignatureProof & ClaimWithSigAndMTPProof…
olomix Nov 20, 2023
0e13eb3
fix ProofType naming for V3
volodymyr-basiuk Nov 20, 2023
95d2706
Iden3SparseMerkleTreeProofType
volodymyr-basiuk Nov 20, 2023
9d0c776
Default value for LinkNonce
olomix Nov 21, 2023
20a5243
add AuthEnabled logic in Validate inputs
volodymyr-basiuk Nov 21, 2023
ec8abd8
AuthEnabled logic in Validate (2)
volodymyr-basiuk Nov 21, 2023
316ee77
AuthEnabled in InputsMarshal
volodymyr-basiuk Nov 21, 2023
53c9352
AuthEnabled in InputsMarshal (2)
volodymyr-basiuk Nov 21, 2023
6360327
add fillAuthWithZero
volodymyr-basiuk Nov 21, 2023
8bd867c
fix AuthClaim nil
volodymyr-basiuk Nov 21, 2023
bf84e38
fix empty circom siblings MTP on no Auth flow
volodymyr-basiuk Nov 21, 2023
c7d45cd
fix Mtp length in fillAuthWithZero
volodymyr-basiuk Nov 21, 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
123 changes: 102 additions & 21 deletions credentialAtomicQueryV3.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
type ProofType string

const (
SigProotType ProofType = "sig"
MTPProofType ProofType = "mtp"
BJJSignatureProofType ProofType = "BJJSignature2021"
Iden3SparseMerkleTreeProofType ProofType = "Iden3SparseMerkleTreeProof"
)

// AtomicQueryV3Inputs ZK private inputs for credentialAtomicQuerySig.circom
Expand All @@ -38,6 +38,12 @@ type AtomicQueryV3Inputs struct {
CurrentTimeStamp int64

ProofType ProofType

LinkNonce *big.Int

VerifierID *core.ID

VerifierSessionID *big.Int
}

// atomicQueryV3CircuitInputs type represents credentialAtomicQueryV3.circom private inputs required by prover
Expand Down Expand Up @@ -73,6 +79,7 @@ type atomicQueryV3CircuitInputs struct {
IssuerAuthClaimsTreeRoot string `json:"issuerAuthClaimsTreeRoot"`
IssuerAuthRevTreeRoot string `json:"issuerAuthRevTreeRoot"`
IssuerAuthRootsTreeRoot string `json:"issuerAuthRootsTreeRoot"`
IssuerAuthState *merkletree.Hash `json:"issuerAuthState"`

IsRevocationChecked int `json:"isRevocationChecked"`
// Query
Expand All @@ -97,6 +104,13 @@ type atomicQueryV3CircuitInputs struct {
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`

ProofType string `json:"proofType"`

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

VerifierID string `json:"verifierID"`

VerifierSessionID string `json:"verifierSessionID"`
}

func (a AtomicQueryV3Inputs) Validate() error {
Expand All @@ -114,7 +128,11 @@ func (a AtomicQueryV3Inputs) Validate() error {
}

switch a.ProofType {
case SigProotType:
case BJJSignatureProofType:
if a.Claim.SignatureProof == nil {
return errors.New(ErrorEmptySignatureProof)
}

if a.Claim.SignatureProof.IssuerAuthIncProof.Proof == nil {
return errors.New(ErrorEmptyIssuerAuthClaimProof)
}
Expand All @@ -126,7 +144,11 @@ func (a AtomicQueryV3Inputs) Validate() error {
if a.Claim.SignatureProof.Signature == nil {
return errors.New(ErrorEmptyClaimSignature)
}
case MTPProofType:
case Iden3SparseMerkleTreeProofType:
if a.Claim.IncProof == nil {
return errors.New(ErrorEmptyMTPProof)
}

if a.Claim.IncProof.Proof == nil {
return errors.New(ErrorEmptyClaimProof)
}
Expand Down Expand Up @@ -195,8 +217,12 @@ func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error) {
}

switch a.ProofType {
case SigProotType:
s.ProofType = "0"
case BJJSignatureProofType:
s.ProofType = "1"

if a.Claim.SignatureProof == nil {
return nil, errors.New(ErrorEmptySignatureProof)
}

s.IssuerClaimSignatureR8X = a.Claim.SignatureProof.Signature.R8.X.String()
s.IssuerClaimSignatureR8Y = a.Claim.SignatureProof.Signature.R8.Y.String()
Expand All @@ -215,10 +241,15 @@ func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error) {
s.IssuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key
s.IssuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value
s.IssuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux
s.IssuerAuthState = a.Claim.SignatureProof.IssuerAuthIncProof.TreeState.State

a.fillMTPProofsWithZero(&s)
case MTPProofType:
s.ProofType = "1"
case Iden3SparseMerkleTreeProofType:
s.ProofType = "2"

if a.Claim.IncProof == nil {
return nil, errors.New(ErrorEmptyMTPProof)
}

s.IssuerClaimMtp = CircomSiblings(a.Claim.IncProof.Proof, a.GetMTLevel())
s.IssuerClaimClaimsTreeRoot = a.Claim.IncProof.TreeState.ClaimsRoot
Expand Down Expand Up @@ -248,6 +279,21 @@ func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error) {
}
s.Value = bigIntArrayToStringArray(values)

s.LinkNonce = "0"
if a.LinkNonce != nil {
s.LinkNonce = a.LinkNonce.String()
}

s.VerifierID = "0"
if a.VerifierID != nil {
s.VerifierID = a.VerifierID.BigInt().String()
}

s.VerifierSessionID = "0"
if a.VerifierSessionID != nil {
s.VerifierSessionID = a.VerifierSessionID.String()
}

return json.Marshal(s)
}

Expand All @@ -273,6 +319,7 @@ func (a AtomicQueryV3Inputs) fillSigProofWithZero(s *atomicQueryV3CircuitInputs)
s.IssuerAuthClaimNonRevMtpAuxHi = &merkletree.HashZero
s.IssuerAuthClaimNonRevMtpAuxHv = &merkletree.HashZero
s.IssuerAuthClaimNonRevMtpNoAux = "0"
s.IssuerAuthState = &merkletree.HashZero
}

// AtomicQueryV3PubSignals public inputs
Expand All @@ -281,7 +328,7 @@ type AtomicQueryV3PubSignals struct {
RequestID *big.Int `json:"requestID"`
UserID *core.ID `json:"userID"`
IssuerID *core.ID `json:"issuerID"`
IssuerAuthState *merkletree.Hash `json:"issuerAuthState"`
IssuerState *merkletree.Hash `json:"issuerState"`
IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
ClaimSchema core.SchemaHash `json:"claimSchema"`
SlotIndex int `json:"slotIndex"`
Expand All @@ -292,16 +339,23 @@ type AtomicQueryV3PubSignals struct {
ClaimPathKey *big.Int `json:"claimPathKey"`
ClaimPathNotExists int `json:"claimPathNotExists"` // 0 for inclusion, 1 for non-inclusion
IsRevocationChecked int `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`
ProofType int `json:"proofType"`
LinkID *big.Int `json:"linkID"`
Nullifier *big.Int `json:"nullifier"`
OperatorOutput *big.Int `json:"operatorOutput"`
VerifierID *core.ID `json:"verifierID"`
VerifierSessionID *big.Int `json:"verifierSessionID"`
}

// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error {
// expected order:
// merklized
// userID
// issuerAuthState
// issuerState
// linkID
// nullifier
// operatorOutput
// proofType
// requestID
// issuerID
Expand All @@ -314,12 +368,13 @@ func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error {
// slotIndex
// operator
// value
// issuerClaimIdenState
// verifierID
// verifierSessionID

// 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
// 19 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 = 19

var sVals []string
err := json.Unmarshal(data, &sVals)
Expand All @@ -345,19 +400,37 @@ func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error {
}
fieldIdx++

// - issuerAuthState
if ao.IssuerAuthState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
// - issuerState
if ao.IssuerState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++

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

// - nullifier
if ao.Nullifier, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid link ID 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++

if ao.ProofType, err = strconv.Atoi(sVals[fieldIdx]); err != nil {
return err
}
fieldIdx++

// - requestID
var ok bool
if ao.RequestID, ok = big.NewInt(0).SetString(sVals[fieldIdx], 10); !ok {
return fmt.Errorf("invalid requestID value: '%s'", sVals[fieldIdx])
}
Expand Down Expand Up @@ -431,9 +504,17 @@ func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error {
fieldIdx++
}

// - issuerClaimIdenState
if ao.IssuerClaimIdenState, err = merkletree.NewHashFromString(sVals[fieldIdx]); err != nil {
return err
// - VerifierID
if sVals[fieldIdx] != "0" {
if ao.VerifierID, err = idFromIntStr(sVals[fieldIdx]); err != nil {
return err
}
}
fieldIdx++

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

return nil
Expand Down
Loading