From 9f09c64c574e78742b270a4418df19dbe15abe69 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Mon, 3 Jun 2024 21:43:31 -0400 Subject: [PATCH] update --- ethcoder/merkle_proof.go | 27 ++------------------------- ethcoder/merkle_proof_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/ethcoder/merkle_proof.go b/ethcoder/merkle_proof.go index 0ca4835..4584ae8 100644 --- a/ethcoder/merkle_proof.go +++ b/ethcoder/merkle_proof.go @@ -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 @@ -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) -// } diff --git a/ethcoder/merkle_proof_test.go b/ethcoder/merkle_proof_test.go index d764c30..3633cb0 100644 --- a/ethcoder/merkle_proof_test.go +++ b/ethcoder/merkle_proof_test.go @@ -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) +}