From 7eab98880591e89b97051f8b0326b57b362fdf25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Men=C3=A9ndez?= Date: Wed, 20 Nov 2024 18:29:39 +0100 Subject: [PATCH] fixing wrong commits --- arbo/utils_test.go | 92 ---------------------------------- arbo/verifier_bls12377_test.go | 2 +- arbo/verifier_bn254_test.go | 2 +- 3 files changed, 2 insertions(+), 94 deletions(-) delete mode 100644 arbo/utils_test.go diff --git a/arbo/utils_test.go b/arbo/utils_test.go deleted file mode 100644 index 91d1868..0000000 --- a/arbo/utils_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package arbo - -import ( - "fmt" - "math/big" - "os" - - arbotree "github.com/vocdoni/arbo" - "go.vocdoni.io/dvote/db" - "go.vocdoni.io/dvote/db/pebbledb" - "go.vocdoni.io/dvote/tree/arbo" - "go.vocdoni.io/dvote/util" -) - -type censusConfig struct { - dir string - validSiblings int - totalSiblings int - keyLen int - hash arbotree.HashFunction - baseFiled *big.Int -} - -// GenerateCensusProofForTest generates a census proof for testing purposes, it -// receives a configuration and a key-value pair to generate the proof for. -// It returns the root, key, value, and siblings of the proof. The configuration -// includes the temp directory to store the database, the number of valid -// siblings, the total number of siblings, the key length, the hash function to -// use in the merkle tree, and the base field to use in the finite field. -func GenerateCensusProofForTest(conf censusConfig, k, v []byte) (*big.Int, *big.Int, *big.Int, []*big.Int, error) { - defer func() { - _ = os.RemoveAll(conf.dir) - }() - database, err := pebbledb.New(db.Options{Path: conf.dir}) - if err != nil { - return nil, nil, nil, nil, err - } - tree, err := arbotree.NewTree(arbotree.Config{ - Database: database, - MaxLevels: conf.totalSiblings, - HashFunction: conf.hash, - }) - if err != nil { - return nil, nil, nil, nil, err - } - - k = arbotree.BigToFF(conf.baseFiled, new(big.Int).SetBytes(k)).Bytes() - // add the first key-value pair - if err = tree.Add(k, v); err != nil { - return nil, nil, nil, nil, err - } - // add random addresses - for i := 1; i < conf.validSiblings; i++ { - rk := arbotree.BigToFF(conf.baseFiled, new(big.Int).SetBytes(util.RandomBytes(conf.keyLen))).Bytes() - rv := new(big.Int).SetBytes(util.RandomBytes(8)).Bytes() - if err = tree.Add(rk, rv); err != nil { - return nil, nil, nil, nil, err - } - } - // generate the proof - _, _, siblings, exist, err := tree.GenProof(k) - if err != nil { - return nil, nil, nil, nil, err - } - if !exist { - return nil, nil, nil, nil, fmt.Errorf("error building the merkle tree: key not found") - } - unpackedSiblings, err := arbo.UnpackSiblings(tree.HashFunction(), siblings) - if err != nil { - return nil, nil, nil, nil, err - } - paddedSiblings := make([]*big.Int, conf.totalSiblings) - for i := 0; i < conf.totalSiblings; i++ { - if i < len(unpackedSiblings) { - paddedSiblings[i] = arbo.BytesLEToBigInt(unpackedSiblings[i]) - } else { - paddedSiblings[i] = big.NewInt(0) - } - } - root, err := tree.Root() - if err != nil { - return nil, nil, nil, nil, err - } - verified, err := arbotree.CheckProof(tree.HashFunction(), k, v, root, siblings) - if !verified { - return nil, nil, nil, nil, fmt.Errorf("error verifying the proof") - } - if err != nil { - return nil, nil, nil, nil, err - } - return arbo.BytesLEToBigInt(root), arbo.BytesLEToBigInt(k), new(big.Int).SetBytes(v), paddedSiblings, nil -} diff --git a/arbo/verifier_bls12377_test.go b/arbo/verifier_bls12377_test.go index 983c372..3395e19 100644 --- a/arbo/verifier_bls12377_test.go +++ b/arbo/verifier_bls12377_test.go @@ -54,7 +54,7 @@ func TestVerifierBLS12377(t *testing.T) { p.Stop() fmt.Println("constrains", p.NbConstraints()) // generate census proof - root, key, value, siblings, err := GenerateCensusProofForTest(censusConfig{ + root, key, value, siblings, err := GenerateCensusProofForTest(CensusConfig{ dir: t.TempDir() + "/bls12377", validSiblings: v_siblings, totalSiblings: n_siblings, diff --git a/arbo/verifier_bn254_test.go b/arbo/verifier_bn254_test.go index f6177c9..4e3534b 100644 --- a/arbo/verifier_bn254_test.go +++ b/arbo/verifier_bn254_test.go @@ -40,7 +40,7 @@ func TestVerifierBN254(t *testing.T) { p.Stop() fmt.Println("constrains", p.NbConstraints()) // generate census proof - root, key, value, siblings, err := GenerateCensusProofForTest(censusConfig{ + root, key, value, siblings, err := GenerateCensusProofForTest(CensusConfig{ dir: t.TempDir() + "/bn254", validSiblings: v_siblings, totalSiblings: n_siblings,