From a5cadadfab6c2df619d12ce8c4d9db68eb9a0912 Mon Sep 17 00:00:00 2001 From: ananas-block Date: Sat, 22 Jun 2024 02:38:01 +0100 Subject: [PATCH] renamed leafIndex to nextIndex --- light-prover/integration_test.go | 4 +-- .../{tree_test.go => gen_test_data.go} | 5 ++++ .../{test_tree.go => gen_test_data_utils.go} | 10 +++---- light-prover/prover/circuit_utils.go | 22 +++++++------- light-prover/prover/combined_circuit.go | 30 +++++++++---------- .../prover/combined_proving_system.go | 4 +-- light-prover/prover/combined_test.go | 6 ++-- light-prover/prover/marshal_non_inclusion.go | 6 ++-- light-prover/prover/non_inclusion_circuit.go | 26 ++++++++-------- .../prover/non_inclusion_proving_system.go | 8 ++--- light-prover/prover/non_inclusion_test.go | 8 ++--- 11 files changed, 67 insertions(+), 62 deletions(-) rename light-prover/merkle-tree/{tree_test.go => gen_test_data.go} (97%) rename light-prover/merkle-tree/{test_tree.go => gen_test_data_utils.go} (97%) diff --git a/light-prover/integration_test.go b/light-prover/integration_test.go index 178e2ea3e5..2a1a3c7940 100644 --- a/light-prover/integration_test.go +++ b/light-prover/integration_test.go @@ -258,7 +258,7 @@ func TestNonInclusionHappyPath26_1_JSON(t *testing.T) { ], "leafLowerRangeValue": "0x201", "leafHigherRangeValue": "0x203", - "leafIndex": 46336290 + "nextIndex": 46336290 } ] } @@ -352,7 +352,7 @@ func TestCombinedHappyPath_JSON(t *testing.T) { ], "leafLowerRangeValue": "0x201", "leafHigherRangeValue": "0x203", - "leafIndex": 46336290 + "nextIndex": 46336290 } ] } diff --git a/light-prover/merkle-tree/tree_test.go b/light-prover/merkle-tree/gen_test_data.go similarity index 97% rename from light-prover/merkle-tree/tree_test.go rename to light-prover/merkle-tree/gen_test_data.go index acb60fd509..1e9f2fc12b 100644 --- a/light-prover/merkle-tree/tree_test.go +++ b/light-prover/merkle-tree/gen_test_data.go @@ -273,6 +273,10 @@ func MakeTestNonInclusionTrees(depth int, numberOfCompressedAccounts int) []NonI invalidRootTree.Inputs[0].Root = *big.NewInt(999) invalidRootPair := NonInclusionTreeValidPair{Tree: invalidRootTree, Valid: false} + invalidNextIndex := BuildValidTestNonInclusionTree(depth, numberOfCompressedAccounts, true) + invalidNextIndex.Inputs[0].NextIndex = 999 + invalidNextIndexPair := NonInclusionTreeValidPair{Tree: invalidRootTree, Valid: false} + invalidLowValueTree := BuildTestNonInclusionTree(depth, numberOfCompressedAccounts, true, false, true) invalidLowValuePair := NonInclusionTreeValidPair{Tree: invalidLowValueTree, Valid: false} @@ -293,6 +297,7 @@ func MakeTestNonInclusionTrees(depth int, numberOfCompressedAccounts int) []NonI trees = append(trees, validPair) trees = append(trees, invalidRootPair) + trees = append(trees, invalidNextIndexPair) trees = append(trees, invalidLowValuePair) trees = append(trees, invalidHighValuePair) trees = append(trees, invalidInPathIndicesPairAddOne) diff --git a/light-prover/merkle-tree/test_tree.go b/light-prover/merkle-tree/gen_test_data_utils.go similarity index 97% rename from light-prover/merkle-tree/test_tree.go rename to light-prover/merkle-tree/gen_test_data_utils.go index adeef132f7..54d88ce772 100644 --- a/light-prover/merkle-tree/test_tree.go +++ b/light-prover/merkle-tree/gen_test_data_utils.go @@ -182,12 +182,12 @@ func BuildTestNonInclusionTree(depth int, numberOfCompressedAccounts int, random var leafLower = big.NewInt(0) var leafUpper = big.NewInt(2) var pathIndex int - var leafIndex int + var nextIndex int if random { leafLower = big.NewInt(int64(rangeIn(0, 1000))) leafUpper.Add(leafUpper, leafLower) numberOfLeaves := 1 << depth - leafIndex = rand.Intn(numberOfLeaves) + nextIndex = rand.Intn(numberOfLeaves) if valid { value.Add(leafLower, big.NewInt(1)) } else { @@ -201,7 +201,7 @@ func BuildTestNonInclusionTree(depth int, numberOfCompressedAccounts int, random } else { leafLower = big.NewInt(1) leafUpper = big.NewInt(123) - leafIndex = 1 + nextIndex = 1 if valid { value = big.NewInt(2) } else { @@ -210,7 +210,7 @@ func BuildTestNonInclusionTree(depth int, numberOfCompressedAccounts int, random pathIndex = 0 } - leaf, err := poseidon.Hash([]*big.Int{leafLower, big.NewInt(int64(leafIndex)), leafUpper}) + leaf, err := poseidon.Hash([]*big.Int{leafLower, big.NewInt(int64(nextIndex)), leafUpper}) if err != nil { fmt.Println("error: ", err) } @@ -221,7 +221,7 @@ func BuildTestNonInclusionTree(depth int, numberOfCompressedAccounts int, random inputs[i].Root = tree.Root() inputs[i].LeafLowerRangeValue = *leafLower inputs[i].LeafHigherRangeValue = *leafUpper - inputs[i].LeafIndex = uint32(leafIndex) + inputs[i].NextIndex = uint32(nextIndex) } return prover.NonInclusionParameters{ diff --git a/light-prover/prover/circuit_utils.go b/light-prover/prover/circuit_utils.go index df4dc3f206..498b7877c5 100644 --- a/light-prover/prover/circuit_utils.go +++ b/light-prover/prover/circuit_utils.go @@ -20,13 +20,13 @@ type Proof struct { } type ProvingSystem struct { - InclusionTreeDepth uint32 + InclusionTreeDepth uint32 InclusionNumberOfCompressedAccounts uint32 - NonInclusionTreeDepth uint32 + NonInclusionTreeDepth uint32 NonInclusionNumberOfCompressedAccounts uint32 - ProvingKey groth16.ProvingKey - VerifyingKey groth16.VerifyingKey - ConstraintSystem constraint.ConstraintSystem + ProvingKey groth16.ProvingKey + VerifyingKey groth16.VerifyingKey + ConstraintSystem constraint.ConstraintSystem } // ProveParentHash gadget generates the ParentHash @@ -51,7 +51,7 @@ type InclusionProof struct { InPathElements [][]frontend.Variable NumberOfCompressedAccounts uint32 - Depth uint32 + Depth uint32 } func (gadget InclusionProof) DefineGadget(api frontend.API) interface{} { @@ -74,13 +74,13 @@ type NonInclusionProof struct { LeafLowerRangeValues []frontend.Variable LeafHigherRangeValues []frontend.Variable - LeafIndices []frontend.Variable + NextIndices []frontend.Variable InPathIndices []frontend.Variable InPathElements [][]frontend.Variable NumberOfCompressedAccounts uint32 - Depth uint32 + Depth uint32 } func (gadget NonInclusionProof) DefineGadget(api frontend.API) interface{} { @@ -88,7 +88,7 @@ func (gadget NonInclusionProof) DefineGadget(api frontend.API) interface{} { for proofIndex := 0; proofIndex < int(gadget.NumberOfCompressedAccounts); proofIndex++ { leaf := LeafHashGadget{ LeafLowerRangeValue: gadget.LeafLowerRangeValues[proofIndex], - LeafIndex: gadget.LeafIndices[proofIndex], + NextIndex: gadget.NextIndices[proofIndex], LeafHigherRangeValue: gadget.LeafHigherRangeValues[proofIndex], Value: gadget.Values[proofIndex]} currentHash[proofIndex] = abstractor.Call(api, leaf) @@ -117,7 +117,7 @@ func (gadget CombinedProof) DefineGadget(api frontend.API) interface{} { type LeafHashGadget struct { LeafLowerRangeValue frontend.Variable - LeafIndex frontend.Variable + NextIndex frontend.Variable LeafHigherRangeValue frontend.Variable Value frontend.Variable } @@ -130,7 +130,7 @@ func (gadget LeafHashGadget) DefineGadget(api frontend.API) interface{} { AssertIsLess{A: gadget.LeafLowerRangeValue, B: gadget.Value, N: 248}.DefineGadget(api) // Value is less than upper bound AssertIsLess{A: gadget.Value, B: gadget.LeafHigherRangeValue, N: 248}.DefineGadget(api) - return abstractor.Call(api, poseidon.Poseidon3{In1: gadget.LeafLowerRangeValue, In2: gadget.LeafIndex, In3: gadget.LeafHigherRangeValue}) + return abstractor.Call(api, poseidon.Poseidon3{In1: gadget.LeafLowerRangeValue, In2: gadget.NextIndex, In3: gadget.LeafHigherRangeValue}) } // Assert A is less than B. diff --git a/light-prover/prover/combined_circuit.go b/light-prover/prover/combined_circuit.go index 3a1bb00fc1..b4d6813fa0 100644 --- a/light-prover/prover/combined_circuit.go +++ b/light-prover/prover/combined_circuit.go @@ -12,24 +12,24 @@ type CombinedCircuit struct { func (circuit *CombinedCircuit) Define(api frontend.API) error { abstractor.CallVoid(api, InclusionProof{ - Roots: circuit.Inclusion.Roots, - Leaves: circuit.Inclusion.Leaves, - InPathElements: circuit.Inclusion.InPathElements, - InPathIndices: circuit.Inclusion.InPathIndices, - NumberOfCompressedAccounts: circuit.Inclusion.NumberOfCompressedAccounts, - Depth: circuit.Inclusion.Depth, + Roots: circuit.Inclusion.Roots, + Leaves: circuit.Inclusion.Leaves, + InPathElements: circuit.Inclusion.InPathElements, + InPathIndices: circuit.Inclusion.InPathIndices, + NumberOfCompressedAccounts: circuit.Inclusion.NumberOfCompressedAccounts, + Depth: circuit.Inclusion.Depth, }) abstractor.CallVoid(api, NonInclusionProof{ - Roots: circuit.NonInclusion.Roots, - Values: circuit.NonInclusion.Values, - LeafLowerRangeValues: circuit.NonInclusion.LeafLowerRangeValues, - LeafHigherRangeValues: circuit.NonInclusion.LeafHigherRangeValues, - LeafIndices: circuit.NonInclusion.LeafIndices, - InPathIndices: circuit.NonInclusion.InPathIndices, - InPathElements: circuit.NonInclusion.InPathElements, - NumberOfCompressedAccounts: circuit.NonInclusion.NumberOfCompressedAccounts, - Depth: circuit.NonInclusion.Depth, + Roots: circuit.NonInclusion.Roots, + Values: circuit.NonInclusion.Values, + LeafLowerRangeValues: circuit.NonInclusion.LeafLowerRangeValues, + LeafHigherRangeValues: circuit.NonInclusion.LeafHigherRangeValues, + NextIndices: circuit.NonInclusion.NextIndices, + InPathIndices: circuit.NonInclusion.InPathIndices, + InPathElements: circuit.NonInclusion.InPathElements, + NumberOfCompressedAccounts: circuit.NonInclusion.NumberOfCompressedAccounts, + Depth: circuit.NonInclusion.Depth, }) return nil } diff --git a/light-prover/prover/combined_proving_system.go b/light-prover/prover/combined_proving_system.go index a7b1c2b64e..a6095fa705 100644 --- a/light-prover/prover/combined_proving_system.go +++ b/light-prover/prover/combined_proving_system.go @@ -83,7 +83,7 @@ func InitializeCombinedCircuit(inclusionTreeDepth uint32, inclusionNumberOfCompr Values: nonInclusionValues, LeafLowerRangeValues: nonInclusionLeafLowerRangeValues, LeafHigherRangeValues: nonInclusionLeafHigherRangeValues, - LeafIndices: nonInclusionLeafIndices, + NextIndices: nonInclusionLeafIndices, InPathIndices: nonInclusionInPathIndices, InPathElements: nonInclusionInPathElements, NumberOfCompressedAccounts: nonInclusionNumberOfCompressedAccounts, @@ -127,7 +127,7 @@ func (ps *ProvingSystem) ProveCombined(params *CombinedParameters) (*Proof, erro circuit.NonInclusion.Values[i] = params.NonInclusionParameters.Inputs[i].Value circuit.NonInclusion.LeafLowerRangeValues[i] = params.NonInclusionParameters.Inputs[i].LeafLowerRangeValue circuit.NonInclusion.LeafHigherRangeValues[i] = params.NonInclusionParameters.Inputs[i].LeafHigherRangeValue - circuit.NonInclusion.LeafIndices[i] = params.NonInclusionParameters.Inputs[i].LeafIndex + circuit.NonInclusion.NextIndices[i] = params.NonInclusionParameters.Inputs[i].NextIndex circuit.NonInclusion.InPathIndices[i] = params.NonInclusionParameters.Inputs[i].PathIndex circuit.NonInclusion.InPathElements[i] = make([]frontend.Variable, ps.NonInclusionTreeDepth) for j := 0; j < int(ps.NonInclusionTreeDepth); j++ { diff --git a/light-prover/prover/combined_test.go b/light-prover/prover/combined_test.go index adfc34af38..5693226a99 100644 --- a/light-prover/prover/combined_test.go +++ b/light-prover/prover/combined_test.go @@ -82,7 +82,7 @@ func TestCombined(t *testing.T) { nonInclusionValues[i] = v.Value nonInclusionLeafLowerRangeValues[i] = v.LeafLowerRangeValue nonInclusionLeafHigherRangeValues[i] = v.LeafHigherRangeValue - nonInclusionLeafIndices[i] = v.LeafIndex + nonInclusionLeafIndices[i] = v.NextIndex nonInclusionInPathIndices[i] = v.PathIndex for j, v2 := range v.PathElements { nonInclusionInPathElements[i][j] = v2 @@ -108,7 +108,7 @@ func TestCombined(t *testing.T) { circuit.NonInclusion.Values = make([]frontend.Variable, nonInclusionNumberOfCompressedAccounts) circuit.NonInclusion.LeafLowerRangeValues = make([]frontend.Variable, nonInclusionNumberOfCompressedAccounts) circuit.NonInclusion.LeafHigherRangeValues = make([]frontend.Variable, nonInclusionNumberOfCompressedAccounts) - circuit.NonInclusion.LeafIndices = make([]frontend.Variable, nonInclusionNumberOfCompressedAccounts) + circuit.NonInclusion.NextIndices = make([]frontend.Variable, nonInclusionNumberOfCompressedAccounts) circuit.NonInclusion.InPathIndices = make([]frontend.Variable, nonInclusionNumberOfCompressedAccounts) circuit.NonInclusion.InPathElements = make([][]frontend.Variable, nonInclusionNumberOfCompressedAccounts) for i := 0; i < int(nonInclusionNumberOfCompressedAccounts); i++ { @@ -132,7 +132,7 @@ func TestCombined(t *testing.T) { Values: nonInclusionValues, LeafLowerRangeValues: nonInclusionLeafLowerRangeValues, LeafHigherRangeValues: nonInclusionLeafHigherRangeValues, - LeafIndices: nonInclusionLeafIndices, + NextIndices: nonInclusionLeafIndices, InPathIndices: nonInclusionInPathIndices, InPathElements: nonInclusionInPathElements, NumberOfCompressedAccounts: nonInclusionNumberOfCompressedAccounts, diff --git a/light-prover/prover/marshal_non_inclusion.go b/light-prover/prover/marshal_non_inclusion.go index 08e248c8b4..f339262bee 100644 --- a/light-prover/prover/marshal_non_inclusion.go +++ b/light-prover/prover/marshal_non_inclusion.go @@ -13,7 +13,7 @@ type NonInclusionProofInputsJSON struct { PathElements []string `json:"pathElements"` LeafLowerRangeValue string `json:"leafLowerRangeValue"` LeafHigherRangeValue string `json:"leafHigherRangeValue"` - LeafIndex uint32 `json:"leafIndex"` + NextIndex uint32 `json:"nextIndex"` } type NonInclusionParametersJSON struct { @@ -47,7 +47,7 @@ func (p *NonInclusionParameters) CreateNonInclusionParametersJSON() NonInclusion } paramsJson.Inputs[i].LeafLowerRangeValue = toHex(&p.Inputs[i].LeafLowerRangeValue) paramsJson.Inputs[i].LeafHigherRangeValue = toHex(&p.Inputs[i].LeafHigherRangeValue) - paramsJson.Inputs[i].LeafIndex = p.Inputs[i].LeafIndex + paramsJson.Inputs[i].NextIndex = p.Inputs[i].NextIndex } return paramsJson } @@ -92,7 +92,7 @@ func (p *NonInclusionParameters) UpdateWithJSON(params NonInclusionParametersJSO if err != nil { return err } - p.Inputs[i].LeafIndex = params.Inputs[i].LeafIndex + p.Inputs[i].NextIndex = params.Inputs[i].NextIndex } return nil } diff --git a/light-prover/prover/non_inclusion_circuit.go b/light-prover/prover/non_inclusion_circuit.go index 177c401007..a69af9d063 100644 --- a/light-prover/prover/non_inclusion_circuit.go +++ b/light-prover/prover/non_inclusion_circuit.go @@ -15,13 +15,13 @@ type NonInclusionCircuit struct { // private inputs LeafLowerRangeValues []frontend.Variable `gnark:"input"` LeafHigherRangeValues []frontend.Variable `gnark:"input"` - LeafIndices []frontend.Variable `gnark:"input"` + NextIndices []frontend.Variable `gnark:"input"` InPathIndices []frontend.Variable `gnark:"input"` InPathElements [][]frontend.Variable `gnark:"input"` NumberOfCompressedAccounts uint32 - Depth uint32 + Depth uint32 } func (circuit *NonInclusionCircuit) Define(api frontend.API) error { @@ -31,13 +31,13 @@ func (circuit *NonInclusionCircuit) Define(api frontend.API) error { LeafLowerRangeValues: circuit.LeafLowerRangeValues, LeafHigherRangeValues: circuit.LeafHigherRangeValues, - LeafIndices: circuit.LeafIndices, + NextIndices: circuit.NextIndices, InPathElements: circuit.InPathElements, InPathIndices: circuit.InPathIndices, NumberOfCompressedAccounts: circuit.NumberOfCompressedAccounts, - Depth: circuit.Depth, + Depth: circuit.Depth, } roots := abstractor.Call1(api, proof) for i := 0; i < int(circuit.NumberOfCompressedAccounts); i++ { @@ -62,15 +62,15 @@ func ImportNonInclusionSetup(treeDepth uint32, numberOfCompressedAccounts uint32 } circuit := NonInclusionCircuit{ - Depth: treeDepth, - NumberOfCompressedAccounts: numberOfCompressedAccounts, - Roots: roots, - Values: values, - LeafLowerRangeValues: leafLowerRangeValues, - LeafHigherRangeValues: leafHigherRangeValues, - LeafIndices: leafIndices, - InPathIndices: inPathIndices, - InPathElements: inPathElements, + Depth: treeDepth, + NumberOfCompressedAccounts: numberOfCompressedAccounts, + Roots: roots, + Values: values, + LeafLowerRangeValues: leafLowerRangeValues, + LeafHigherRangeValues: leafHigherRangeValues, + NextIndices: leafIndices, + InPathIndices: inPathIndices, + InPathElements: inPathElements, } ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit) diff --git a/light-prover/prover/non_inclusion_proving_system.go b/light-prover/prover/non_inclusion_proving_system.go index 6477beee4b..1407e1d33c 100644 --- a/light-prover/prover/non_inclusion_proving_system.go +++ b/light-prover/prover/non_inclusion_proving_system.go @@ -21,7 +21,7 @@ type NonInclusionInputs struct { LeafLowerRangeValue big.Int LeafHigherRangeValue big.Int - LeafIndex uint32 + NextIndex uint32 } type NonInclusionParameters struct { @@ -71,7 +71,7 @@ func R1CSNonInclusion(treeDepth uint32, numberOfCompressedAccounts uint32) (cons Values: values, LeafLowerRangeValues: leafLowerRangeValues, LeafHigherRangeValues: leafHigherRangeValues, - LeafIndices: leafIndices, + NextIndices: leafIndices, InPathIndices: inPathIndices, InPathElements: inPathElements, } @@ -110,7 +110,7 @@ func (ps *ProvingSystem) ProveNonInclusion(params *NonInclusionParameters) (*Pro values[i] = params.Inputs[i].Value leafLowerRangeValues[i] = params.Inputs[i].LeafLowerRangeValue leafHigherRangeValues[i] = params.Inputs[i].LeafHigherRangeValue - leafIndices[i] = params.Inputs[i].LeafIndex + leafIndices[i] = params.Inputs[i].NextIndex inPathIndices[i] = params.Inputs[i].PathIndex inPathElements[i] = make([]frontend.Variable, ps.NonInclusionTreeDepth) for j := 0; j < int(ps.NonInclusionTreeDepth); j++ { @@ -123,7 +123,7 @@ func (ps *ProvingSystem) ProveNonInclusion(params *NonInclusionParameters) (*Pro Values: values, LeafLowerRangeValues: leafLowerRangeValues, LeafHigherRangeValues: leafHigherRangeValues, - LeafIndices: leafIndices, + NextIndices: leafIndices, InPathIndices: inPathIndices, InPathElements: inPathElements, } diff --git a/light-prover/prover/non_inclusion_test.go b/light-prover/prover/non_inclusion_test.go index b757e0ad5c..f2771d08c3 100644 --- a/light-prover/prover/non_inclusion_test.go +++ b/light-prover/prover/non_inclusion_test.go @@ -59,7 +59,7 @@ func TestNonInclusion(t *testing.T) { values[i] = v.Value leafLowerRangeValues[i] = v.LeafLowerRangeValue leafHigherRangeValues[i] = v.LeafHigherRangeValue - leafIndices[i] = v.LeafIndex + leafIndices[i] = v.NextIndex inPathIndices[i] = v.PathIndex for j, v2 := range v.PathElements { inPathElements[i][j] = v2 @@ -71,7 +71,7 @@ func TestNonInclusion(t *testing.T) { circuit.Values = make([]frontend.Variable, numberOfCompressedAccounts) circuit.LeafLowerRangeValues = make([]frontend.Variable, numberOfCompressedAccounts) circuit.LeafHigherRangeValues = make([]frontend.Variable, numberOfCompressedAccounts) - circuit.LeafIndices = make([]frontend.Variable, numberOfCompressedAccounts) + circuit.NextIndices = make([]frontend.Variable, numberOfCompressedAccounts) circuit.InPathIndices = make([]frontend.Variable, numberOfCompressedAccounts) circuit.InPathElements = make([][]frontend.Variable, numberOfCompressedAccounts) for i := 0; i < int(numberOfCompressedAccounts); i++ { @@ -90,7 +90,7 @@ func TestNonInclusion(t *testing.T) { Values: values, LeafLowerRangeValues: leafLowerRangeValues, LeafHigherRangeValues: leafHigherRangeValues, - LeafIndices: leafIndices, + NextIndices: leafIndices, InPathIndices: inPathIndices, InPathElements: inPathElements, NumberOfCompressedAccounts: numberOfCompressedAccounts, @@ -103,7 +103,7 @@ func TestNonInclusion(t *testing.T) { Values: values, LeafLowerRangeValues: leafLowerRangeValues, LeafHigherRangeValues: leafHigherRangeValues, - LeafIndices: leafIndices, + NextIndices: leafIndices, InPathIndices: inPathIndices, InPathElements: inPathElements, NumberOfCompressedAccounts: numberOfCompressedAccounts,