Skip to content

Commit

Permalink
Add IssuerClaimNonRevState pub signal to MTP proof
Browse files Browse the repository at this point in the history
  • Loading branch information
demonsh committed Jun 14, 2022
1 parent fd668ca commit 3e068d5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
39 changes: 22 additions & 17 deletions credentialAtomicQueryMTP.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,25 @@ func (a AtomicQueryMTPInputs) InputsMarshal() ([]byte, error) {
// AtomicQueryMTPPubSignals public signals
type AtomicQueryMTPPubSignals struct {
BaseConfig
UserID *core.ID `json:"userID"`
UserState *merkletree.Hash `json:"userState"`
Challenge *big.Int `json:"challenge"`
ClaimSchema core.SchemaHash `json:"claimSchema"`
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`
IssuerID *core.ID `json:"issuerID"`
SlotIndex int `json:"slotIndex"`
Values []*big.Int `json:"values"`
Operator int `json:"operator"`
Timestamp int64 `json:"timestamp"`
UserID *core.ID `json:"userID"`
UserState *merkletree.Hash `json:"userState"`
Challenge *big.Int `json:"challenge"`
ClaimSchema core.SchemaHash `json:"claimSchema"`
IssuerClaimIdenState *merkletree.Hash `json:"issuerClaimIdenState"`
IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimIdenState"`
IssuerID *core.ID `json:"issuerID"`
SlotIndex int `json:"slotIndex"`
Values []*big.Int `json:"values"`
Operator int `json:"operator"`
Timestamp int64 `json:"timestamp"`
}

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

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

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

if ao.UserID, err = idFromIntStr(sVals[0]); err != nil {
Expand All @@ -199,21 +200,25 @@ func (ao *AtomicQueryMTPPubSignals) PubSignalsUnmarshal(data []byte) error {
return err
}

if ao.Timestamp, err = strconv.ParseInt(sVals[5], 10, 64); err != nil {
if ao.IssuerClaimNonRevState, err = merkletree.NewHashFromString(sVals[5]); err != nil {
return err
}

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[6], 10); !ok {
if schemaInt, ok = big.NewInt(0).SetString(sVals[7], 10); !ok {
return fmt.Errorf("invalid schema value: '%s'", sVals[0])
}
ao.ClaimSchema = core.NewSchemaHashFromInt(schemaInt)

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

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

Expand Down
29 changes: 18 additions & 11 deletions credentialAtomicQueryMTP_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ func TestAtomicQueryMTPOutputs_CircuitUnmarshal(t *testing.T) {
issuerClaimIdenState, err := merkletree.NewHashFromBigInt(issuerClaimIdenStateInt)
assert.NoError(t, err)

issuerClaimNonRevStateInt, ok := new(big.Int).SetString("4526669839764419626617575537226877836118875794723391624256342150634803457675", 10)
assert.True(t, ok)
issuerClaimNonRevState, err := merkletree.NewHashFromBigInt(issuerClaimNonRevStateInt)
assert.NoError(t, err)

issuerID, err := idFromIntStr("26599707002460144379092755370384635496563807452878989192352627271768342528")
assert.NoError(t, err)

Expand All @@ -200,22 +205,24 @@ func TestAtomicQueryMTPOutputs_CircuitUnmarshal(t *testing.T) {
timestamp := int64(1642074362)

expectedOut := AtomicQueryMTPPubSignals{
UserID: userID,
UserState: userState,
Challenge: big.NewInt(1),
ClaimSchema: schema,
IssuerClaimIdenState: issuerClaimIdenState,
IssuerID: issuerID,
SlotIndex: 2,
Values: values,
Operator: EQ,
Timestamp: timestamp,
UserID: userID,
UserState: userState,
Challenge: big.NewInt(1),
ClaimSchema: schema,
IssuerClaimIdenState: issuerClaimIdenState,
IssuerClaimNonRevState: issuerClaimNonRevState,
IssuerID: issuerID,
SlotIndex: 2,
Values: values,
Operator: EQ,
Timestamp: timestamp,
}

out := new(AtomicQueryMTPPubSignals)
err = out.PubSignalsUnmarshal([]byte(
`["379949150130214723420589610911161895495647789006649785264738141299135414272",
"18656147546666944484453899241916469544090258810192803949522794490493271005313", "1", "18605292738057394742004097311192572049290380262377486632479765119429313092475", "26599707002460144379092755370384635496563807452878989192352627271768342528", "1642074362", "180410020913331409885634153623124536270", "2", "1", "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", "9999"]`))
"18656147546666944484453899241916469544090258810192803949522794490493271005313", "1",
"18605292738057394742004097311192572049290380262377486632479765119429313092475", "26599707002460144379092755370384635496563807452878989192352627271768342528", "4526669839764419626617575537226877836118875794723391624256342150634803457675","1642074362", "180410020913331409885634153623124536270", "2", "1", "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", "9999"]`))
assert.NoError(t, err)

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

0 comments on commit 3e068d5

Please sign in to comment.