Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Nov 4, 2024
1 parent 8c7d3f4 commit 7ffd45b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions tree/arbo/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"slices"

"go.vocdoni.io/dvote/db"
"go.vocdoni.io/dvote/log"
)

// GenProof generates a MerkleTree proof for the given key. The leaf value is
Expand All @@ -35,17 +36,28 @@ func (t *Tree) GenProofWithTx(rTx db.Reader, k []byte) ([]byte, []byte, []byte,
// go down to the leaf
var siblings, intermediates [][]byte

log.Warnf("going down to key %x, root=%x", k, root)
// , siblings[0], intermediates[0])
_, value, siblings, err := t.down(rTx, k, root, siblings, &intermediates, path, 0, true)
if err != nil {
log.Warnf("err %s", err)
return nil, nil, nil, false, err
}
for _, s := range siblings {
log.Warnf("sibling %x", s)
}

for _, s := range intermediates {
log.Warnf("intermd %x", s)
}

s, err := PackSiblings(t.hashFunction, siblings)
if err != nil {
return nil, nil, nil, false, err
}

leafK, leafV := ReadLeafValue(value)
log.Warnf("%x =? %x", k, leafK)
if !bytes.Equal(k, leafK) {
// key not in tree, proof of non-existence
return leafK, leafV, s, false, nil
Expand Down Expand Up @@ -235,6 +247,7 @@ func CheckProofBatch(hashFunc HashFunction, oldProofs, newProofs []*CircomVerifi

for level, hash := range nodes {
newBranches[hex.EncodeToString(hash)] = level
fmt.Printf("newBranch(%d): %x\n", level, hash) // debug
}

for level := range newProofs[i].Siblings {
Expand All @@ -244,6 +257,8 @@ func CheckProofBatch(hashFunc HashFunction, oldProofs, newProofs []*CircomVerifi
}
}
}
fmt.Println("\n\ni derived all these hashes from the proofs\n", newBranches) // debug
fmt.Println("the proofs had these new siblings\n", newSiblings) // debug

for hash, level := range newSiblings {
if newBranches[hash] != newSiblings[hash] {
Expand Down
9 changes: 7 additions & 2 deletions tree/arbo/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (

qt "github.com/frankban/quicktest"
"go.vocdoni.io/dvote/db/metadb"
"go.vocdoni.io/dvote/log"
)

func TestCheckProofBatch(t *testing.T) {
log.Init("warn", "stdout", nil)
database := metadb.NewTest(t)
c := qt.New(t)

Expand All @@ -36,7 +38,7 @@ func TestCheckProofBatch(t *testing.T) {

var oldProofs, newProofs []*CircomVerifierProof

for i := int64(0x00); i <= int64(0x02); i++ {
for i := int64(0x00); i <= int64(0x03); i++ {
proof, err := tree.GenerateCircomVerifierProof(BigIntToBytesLE(keyLen, big.NewInt(i)))
c.Assert(err, qt.IsNil)
oldProofs = append(oldProofs, proof)
Expand All @@ -51,7 +53,10 @@ func TestCheckProofBatch(t *testing.T) {
err = tree.Update(BigIntToBytesLE(keyLen, big.NewInt(0x02)), ballotMode)
c.Assert(err, qt.IsNil)

for i := int64(0x00); i <= int64(0x02); i++ {
err = tree.Add(BigIntToBytesLE(keyLen, big.NewInt(0x03)), ballotMode)
c.Assert(err, qt.IsNil)

for i := int64(0x00); i <= int64(0x03); i++ {
proof, err := tree.GenerateCircomVerifierProof(BigIntToBytesLE(keyLen, big.NewInt(i)))
c.Assert(err, qt.IsNil)
newProofs = append(newProofs, proof)
Expand Down

0 comments on commit 7ffd45b

Please sign in to comment.