Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Jun 4, 2024
1 parent 0d3d1d5 commit 9f09c64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
27 changes: 2 additions & 25 deletions ethcoder/merkle_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sort"
)

// NOTE: below is some ugly chatgpt ported code which we should refactor + clean up

type TValue interface{}
type TLeaf []byte
type TLayer []TLeaf
Expand Down Expand Up @@ -141,28 +143,3 @@ func (mt *MerkleTree) Verify(proof []Proof, targetNode, root TLeaf) bool {
}
return bytes.Equal(hash, root)
}

// TODO: move to merkle_proof_test.go
// func main() {
// leaves := []TLeaf{
// sha256Hash([]byte("a")),
// sha256Hash([]byte("b")),
// sha256Hash([]byte("c")),
// sha256Hash([]byte("d")),
// }
// mt := NewMerkleTree(leaves, Options{SortLeaves: false, SortPairs: false})
// root := mt.GetRoot()
// fmt.Printf("Root: %x\n", root)

// proof, err := mt.GetProof(sha256Hash([]byte("a")))
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// for _, p := range proof {
// fmt.Printf("Proof: Position=%s, Data=%x\n", p.Position, p.Data)
// }

// isValid := mt.Verify(proof, sha256Hash([]byte("a")), root)
// fmt.Printf("Is valid: %v\n", isValid)
// }
26 changes: 26 additions & 0 deletions ethcoder/merkle_proof_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
package ethcoder

import "testing"

func TestMerkleProof(t *testing.T) {
// leaves := []TLeaf{
// sha256Hash([]byte("a")),
// sha256Hash([]byte("b")),
// sha256Hash([]byte("c")),
// sha256Hash([]byte("d")),
// }
// mt := NewMerkleTree(leaves, Options{SortLeaves: false, SortPairs: false})
// root := mt.GetRoot()
// fmt.Printf("Root: %x\n", root)

// proof, err := mt.GetProof(sha256Hash([]byte("a")))
// if err != nil {
// fmt.Println("Error:", err)
// return
// }
// for _, p := range proof {
// fmt.Printf("Proof: Position=%s, Data=%x\n", p.Position, p.Data)
// }

// isValid := mt.Verify(proof, sha256Hash([]byte("a")), root)
// fmt.Printf("Is valid: %v\n", isValid)
}

0 comments on commit 9f09c64

Please sign in to comment.