Skip to content

Commit

Permalink
Remove IssuerClaimsTreeRoot, IssuerState, IssuerRevTreeRoot, IssuerRo…
Browse files Browse the repository at this point in the history
…otsTreeRoot private signals
  • Loading branch information
demonsh committed Jun 14, 2022
1 parent 3e068d5 commit 1c27198
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
33 changes: 8 additions & 25 deletions credentialAtomicQuerySig.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ type atomicQuerySigCircuitInputs struct {
IssuerAuthClaimsTreeRoot *merkletree.Hash `json:"issuerAuthClaimsTreeRoot"`
IssuerAuthRevTreeRoot *merkletree.Hash `json:"issuerAuthRevTreeRoot"`
IssuerAuthRootsTreeRoot *merkletree.Hash `json:"issuerAuthRootsTreeRoot"`

IssuerClaimsTreeRoot *merkletree.Hash `json:"issuerClaimsTreeRoot"`
IssuerState *merkletree.Hash `json:"issuerState"`
IssuerRevTreeRoot *merkletree.Hash `json:"issuerRevTreeRoot"`
IssuerRootsTreeRoot *merkletree.Hash `json:"issuerRootsTreeRoot"`
}

// InputsMarshal returns Circom private inputs for credentialAtomicQuerySig.circom
Expand Down Expand Up @@ -158,13 +153,6 @@ func (a AtomicQuerySigInputs) InputsMarshal() ([]byte, error) {

IssuerAuthClaimNonRevMtp: bigIntArrayToStringArray(
PrepareSiblings(a.SignatureProof.IssuerAuthNonRevProof.Proof.AllSiblings(), a.GetMTLevel())),

IssuerClaimsTreeRoot: a.SignatureProof.IssuerTreeState.ClaimsRoot,
IssuerState: a.SignatureProof.IssuerTreeState.State,
//IssuerPubKeyX: a.SignatureProof.IssuerPublicKey.X.String(),
//IssuerPubKeyY: a.SignatureProof.IssuerPublicKey.Y.String(),
IssuerRevTreeRoot: a.SignatureProof.IssuerTreeState.RevocationRoot,
IssuerRootsTreeRoot: a.SignatureProof.IssuerTreeState.RootOfRoots,
}

values, err := PrepareCircuitArrayValues(a.Values, a.GetValueArrSize())
Expand Down Expand Up @@ -199,7 +187,6 @@ type AtomicQuerySigPubSignals struct {
Challenge *big.Int `json:"challenge"`
ClaimSchema core.SchemaHash `json:"claimSchema"`
IssuerID *core.ID `json:"issuerID"`
IssuerState *merkletree.Hash `json:"issuerState"`
IssuerAuthState *merkletree.Hash `json:"issuerAuthState"`
IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
SlotIndex int `json:"slotIndex"`
Expand All @@ -210,10 +197,10 @@ type AtomicQuerySigPubSignals struct {

// PubSignalsUnmarshal unmarshal credentialAtomicQuerySig.circom public signals
func (ao *AtomicQuerySigPubSignals) PubSignalsUnmarshal(data []byte) error {
// 11 is a number of fields in AtomicQuerySigPubSignals before values, values is last element in the proof and
// 10 is a number of fields in AtomicQuerySigPubSignals 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
// in ValueArraySize
const fieldLength = 11
const fieldLength = 10

var sVals []string
err := json.Unmarshal(data, &sVals)
Expand All @@ -222,7 +209,7 @@ func (ao *AtomicQuerySigPubSignals) PubSignalsUnmarshal(data []byte) error {
}

if len(sVals) != fieldLength+ao.GetValueArrSize() {
return fmt.Errorf("invalid number of Output values expected {%d} go {%d} ", 11+ao.GetValueArrSize(), len(sVals))
return fmt.Errorf("invalid number of Output values expected {%d} go {%d} ", fieldLength+ao.GetValueArrSize(), len(sVals))
}

if ao.IssuerAuthState, err = merkletree.NewHashFromString(sVals[0]); err != nil {
Expand All @@ -246,29 +233,25 @@ func (ao *AtomicQuerySigPubSignals) PubSignalsUnmarshal(data []byte) error {
return err
}

if ao.IssuerState, err = merkletree.NewHashFromString(sVals[5]); err != nil {
return err
}

if ao.IssuerClaimNonRevState, err = merkletree.NewHashFromString(sVals[6]); err != nil {
if ao.IssuerClaimNonRevState, err = merkletree.NewHashFromString(sVals[5]); err != nil {
return err
}

if ao.Timestamp, err = strconv.ParseInt(sVals[7], 10, 64); err != nil {
if ao.Timestamp, err = strconv.ParseInt(sVals[6], 10, 64); err != nil {
return err
}

var schemaInt *big.Int
if schemaInt, ok = big.NewInt(0).SetString(sVals[8], 10); !ok {
if schemaInt, ok = big.NewInt(0).SetString(sVals[7], 10); !ok {
return fmt.Errorf("invalid schema value: '%s'", sVals[3])
}
ao.ClaimSchema = core.NewSchemaHashFromInt(schemaInt)

if ao.SlotIndex, err = strconv.Atoi(sVals[9]); err != nil {
if ao.SlotIndex, err = strconv.Atoi(sVals[8]); err != nil {
return err
}

if ao.Operator, err = strconv.Atoi(sVals[10]); err != nil {
if ao.Operator, err = strconv.Atoi(sVals[9]); err != nil {
return err
}

Expand Down
12 changes: 2 additions & 10 deletions credentialAtomicQuerySig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ func TestAttrQuerySig_PrepareInputs(t *testing.T) {
assert.Nil(t, err)

t.Log(string(bytesInputs))
expectedJSONInputs := `{"userAuthClaim":["304427537360709784173770334266246861770","0",
"17640206035128972995519606214765283372613874593503528180869261482403155458945","20634138280259599560273310290025659992320584624461316485434108770067472477956","15930428023331155902","0","0","0"],"userAuthClaimMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"userAuthClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"userAuthClaimNonRevMtpAuxHi":"0","userAuthClaimNonRevMtpAuxHv":"0","userAuthClaimNonRevMtpNoAux":"1","userClaimsTreeRoot":"9763429684850732628215303952870004997159843236039795272605841029866455670219","userState":"18656147546666944484453899241916469544090258810192803949522794490493271005313","userRevTreeRoot":"0","userRootsTreeRoot":"0","userID":"379949150130214723420589610911161895495647789006649785264738141299135414272","challenge":"1","challengeSignatureR8x":"8553678144208642175027223770335048072652078621216414881653012537434846327449","challengeSignatureR8y":"5507837342589329113352496188906367161790372084365285966741761856353367255709","challengeSignatureS":"2093461910575977345603199789919760192811763972089699387324401771367839603655","issuerClaim":["3583233690122716044519380227940806650830","379949150130214723420589610911161895495647789006649785264738141299135414272","10","0","30803922965249841627828060161","0","0","0"],"issuerClaimNonRevClaimsTreeRoot":"3077200351284676204723270374054827783313480677490603169533924119235084704890","issuerClaimNonRevRevTreeRoot":"0","issuerClaimNonRevRootsTreeRoot":"0","issuerClaimNonRevState":"18605292738057394742004097311192572049290380262377486632479765119429313092475","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"],"issuerClaimNonRevMtpAuxHi":"0","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"1","claimSchema":"180410020913331409885634153623124536270","issuerID":"26599707002460144379092755370384635496563807452878989192352627271768342528","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"],"issuerClaimSignatureR8x":"18625305647089498634672127449050652473073470525382360069529718632627474482386","issuerClaimSignatureR8y":"14539700345423181413201048131770723125531044953576671601029329833956725811279","issuerClaimSignatureS":"772934080142423067561028786350670095248312416624185973552603152377549415467","issuerAuthClaim":["304427537360709784173770334266246861770","0","9582165609074695838007712438814613121302719752874385708394134542816240804696","18271435592817415588213874506882839610978320325722319742324814767882756910515","11203087622270641253","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"],"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"],"issuerAuthClaimNonRevMtpAuxHi":"0","issuerAuthClaimNonRevMtpAuxHv":"0","issuerAuthClaimNonRevMtpNoAux":"1","issuerAuthClaimsTreeRoot":"18337129644116656308842422695567930755039142442806278977230099338026575870840","issuerAuthRevTreeRoot":"0","issuerAuthRootsTreeRoot":"0","issuerClaimsTreeRoot":"18337129644116656308842422695567930755039142442806278977230099338026575870840","issuerState":"6317996369756476782464660619835940615734517981889733696047139451453239145426","issuerRevTreeRoot":"0","issuerRootsTreeRoot":"0"}`
expectedJSONInputs := `{"userAuthClaim":["304427537360709784173770334266246861770","0","17640206035128972995519606214765283372613874593503528180869261482403155458945","20634138280259599560273310290025659992320584624461316485434108770067472477956","15930428023331155902","0","0","0"],"userAuthClaimMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"userAuthClaimNonRevMtp":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"userAuthClaimNonRevMtpAuxHi":"0","userAuthClaimNonRevMtpAuxHv":"0","userAuthClaimNonRevMtpNoAux":"1","userClaimsTreeRoot":"9763429684850732628215303952870004997159843236039795272605841029866455670219","userState":"18656147546666944484453899241916469544090258810192803949522794490493271005313","userRevTreeRoot":"0","userRootsTreeRoot":"0","userID":"379949150130214723420589610911161895495647789006649785264738141299135414272","challenge":"1","challengeSignatureR8x":"8553678144208642175027223770335048072652078621216414881653012537434846327449","challengeSignatureR8y":"5507837342589329113352496188906367161790372084365285966741761856353367255709","challengeSignatureS":"2093461910575977345603199789919760192811763972089699387324401771367839603655","issuerClaim":["3583233690122716044519380227940806650830","379949150130214723420589610911161895495647789006649785264738141299135414272","10","0","30803922965249841627828060161","0","0","0"],"issuerClaimNonRevClaimsTreeRoot":"3077200351284676204723270374054827783313480677490603169533924119235084704890","issuerClaimNonRevRevTreeRoot":"0","issuerClaimNonRevRootsTreeRoot":"0","issuerClaimNonRevState":"18605292738057394742004097311192572049290380262377486632479765119429313092475","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"],"issuerClaimNonRevMtpAuxHi":"0","issuerClaimNonRevMtpAuxHv":"0","issuerClaimNonRevMtpNoAux":"1","claimSchema":"180410020913331409885634153623124536270","issuerID":"26599707002460144379092755370384635496563807452878989192352627271768342528","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"],"issuerClaimSignatureR8x":"18625305647089498634672127449050652473073470525382360069529718632627474482386","issuerClaimSignatureR8y":"14539700345423181413201048131770723125531044953576671601029329833956725811279","issuerClaimSignatureS":"772934080142423067561028786350670095248312416624185973552603152377549415467","issuerAuthClaim":["304427537360709784173770334266246861770","0","9582165609074695838007712438814613121302719752874385708394134542816240804696","18271435592817415588213874506882839610978320325722319742324814767882756910515","11203087622270641253","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"],"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"],"issuerAuthClaimNonRevMtpAuxHi":"0","issuerAuthClaimNonRevMtpAuxHv":"0","issuerAuthClaimNonRevMtpNoAux":"1","issuerAuthClaimsTreeRoot":"18337129644116656308842422695567930755039142442806278977230099338026575870840","issuerAuthRevTreeRoot":"0","issuerAuthRootsTreeRoot":"0"}`

assert.JSONEq(t, expectedJSONInputs, string(bytesInputs))

Expand Down Expand Up @@ -231,12 +230,6 @@ func TestAtomicQuerySigOutputs_CircuitUnmarshal(t *testing.T) {
issuerID, err := idFromIntStr("330477016068568275516898063887311212065482015025379036159122139014924926976")
assert.Nil(t, err)

issuerStateInt, ok := new(big.Int).SetString(
"11672667429383627660992648216772306271234451162443612055001584519010749218959", 10)
assert.True(t, ok)
issuerState, err := merkletree.NewHashFromBigInt(issuerStateInt)
assert.NoError(t, err)

values := make([]*big.Int, 64)
for i := 0; i < 64; i++ {
values[i] = big.NewInt(0)
Expand All @@ -252,7 +245,6 @@ func TestAtomicQuerySigOutputs_CircuitUnmarshal(t *testing.T) {
Challenge: big.NewInt(84239),
ClaimSchema: schema,
IssuerID: issuerID,
IssuerState: issuerState,
IssuerAuthState: issuerAuthState,
IssuerClaimNonRevState: issuerClaimNonRevState,
SlotIndex: 2,
Expand All @@ -263,7 +255,7 @@ func TestAtomicQuerySigOutputs_CircuitUnmarshal(t *testing.T) {

out := new(AtomicQuerySigPubSignals)
err = out.PubSignalsUnmarshal([]byte(
`["11672667429383627660992648216772306271234451162443612055001584519010749218959", "222712906379570502079611869905711649383946316867077911802139171411787317248", "7608718875990494885422326673876913565155307854054144181362485232187902102852", "84239", "330477016068568275516898063887311212065482015025379036159122139014924926976", "11672667429383627660992648216772306271234451162443612055001584519010749218959", "19221836623970007220538457599669851375427558847917606787084815224761802529201", "1651850376", "210459579859058135404770043788028292398", "2", "1", "20000101", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "9999"]`))
`["11672667429383627660992648216772306271234451162443612055001584519010749218959", "222712906379570502079611869905711649383946316867077911802139171411787317248", "7608718875990494885422326673876913565155307854054144181362485232187902102852", "84239", "330477016068568275516898063887311212065482015025379036159122139014924926976", "19221836623970007220538457599669851375427558847917606787084815224761802529201", "1651850376", "210459579859058135404770043788028292398", "2", "1", "20000101", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "9999"]`))
assert.NoError(t, err)

assert.Equal(t, expectedOut, *out)
Expand Down

0 comments on commit 1c27198

Please sign in to comment.