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

Do not require the array of nil-pointer Queries for multi-query inputs #82

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion linkedMultiQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (l LinkedMultiQueryInputs) InputsMarshal() ([]byte, error) {
s.ActualValueArraySize = make([]int, LinkedMultiQueryLength)

for i := 0; i < LinkedMultiQueryLength; i++ {
if l.Query[i] == nil {
if i >= len(l.Query) || l.Query[i] == nil {
s.ClaimPathMtp[i] = PrepareSiblingsStr([]*merkletree.Hash{}, l.GetMTLevelsClaim())

s.ClaimPathMtpNoAux[i] = "0"
Expand Down
37 changes: 37 additions & 0 deletions linkedMultiQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ func TestLinkedMultiQueryInputs_PrepareInputs(t *testing.T) {
require.JSONEq(t, exp, string(bytesInputs))
}

// test if query slice length is less than LinkedMultiQueryLength
func TestLinkedMultiQueryInputs_PrepareInputs_Ln(t *testing.T) {
user := it.NewIdentity(t, userPK)
subjectID := user.ID
claim := it.DefaultUserClaim(t, subjectID)
in := LinkedMultiQueryInputs{
LinkNonce: big.NewInt(35346346369657418),
Claim: claim,
}
in.Query = append(in.Query,
&Query{
ValueProof: nil,
Operator: EQ,
Values: []*big.Int{big.NewInt(10)},
SlotIndex: 2,
},
&Query{
ValueProof: nil,
Operator: LT,
Values: []*big.Int{big.NewInt(133)},
SlotIndex: 2,
},
&Query{
ValueProof: nil,
Operator: LTE,
Values: []*big.Int{big.NewInt(555)},
SlotIndex: 2,
},
)

bytesInputs, err := in.InputsMarshal()
require.NoError(t, err)

exp := it.TestData(t, "linkedMultiQuery_inputs", string(bytesInputs), *generate)
require.JSONEq(t, exp, string(bytesInputs))
}

func TestLinkedMultiQueryPubSignals_CircuitUnmarshal(t *testing.T) {
out := new(LinkedMultiQueryPubSignals)
err := out.PubSignalsUnmarshal([]byte(
Expand Down
Loading