Skip to content

Commit

Permalink
chore: update all hashes in merkle tree utils to keccak256
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Sep 10, 2024
1 parent 69514b7 commit 0e168cc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/sedad/utils/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func rootFromEntries(sha hash.Hash, entries [][]byte) []byte {

// SuperRoot computes the merkle parent of two existing merkle roots.
func SuperRoot(root1, root2 []byte) []byte {
sha := sha3.New256()
sha := sha3.NewLegacyKeccak256()
return parentHash(sha, root1, root2)
}

// SuperRootWithLeaf computes the merkle parent of an existing root
// and a new (unhashed) entry in a byte slice.
func SuperRootWithEntry(root, entry []byte) []byte {
sha := sha3.New256()
sha := sha3.NewLegacyKeccak256()
var hashedLeaf []byte
if len(entry) == 0 {
hashedLeaf = emptyHash(sha)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sedad/utils/merkle_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GenerateProof(entries [][]byte, i int) ([][]byte, error) {
}

func VerifyProof(proof [][]byte, root, entry []byte) bool {
return bytes.Equal(processProof(sha3.New256(), proof, entry), root)
return bytes.Equal(processProof(sha3.NewLegacyKeccak256(), proof, entry), root)
}

func processProof(sha hash.Hash, proof [][]byte, entry []byte) []byte {
Expand Down
4 changes: 0 additions & 4 deletions cmd/sedad/utils/merkle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
)

func TestRootFromEntries(t *testing.T) {
// Define a custom hash for testing
// customHash := sha3.New256()

tests := []struct {
name string
entries []string // hex-encoded entries
Expand Down Expand Up @@ -57,7 +54,6 @@ func TestRootFromEntries(t *testing.T) {
entries[i], err = hex.DecodeString(tt.entries[i])
require.NoError(t, err)
}

t.Run(tt.name, func(t *testing.T) {
got := utils.RootFromEntries(entries)
if !bytes.Equal(got, expected) {
Expand Down

0 comments on commit 0e168cc

Please sign in to comment.