From 0e168cc812d08a28be1b9ee4706bcb4926771eb8 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Tue, 10 Sep 2024 17:08:13 -0400 Subject: [PATCH] chore: update all hashes in merkle tree utils to keccak256 --- cmd/sedad/utils/merkle.go | 4 ++-- cmd/sedad/utils/merkle_proof.go | 2 +- cmd/sedad/utils/merkle_test.go | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cmd/sedad/utils/merkle.go b/cmd/sedad/utils/merkle.go index 2c262577..8eb486bf 100644 --- a/cmd/sedad/utils/merkle.go +++ b/cmd/sedad/utils/merkle.go @@ -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) diff --git a/cmd/sedad/utils/merkle_proof.go b/cmd/sedad/utils/merkle_proof.go index 22e065c6..c6369ddd 100644 --- a/cmd/sedad/utils/merkle_proof.go +++ b/cmd/sedad/utils/merkle_proof.go @@ -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 { diff --git a/cmd/sedad/utils/merkle_test.go b/cmd/sedad/utils/merkle_test.go index 0e81cab1..593d0927 100644 --- a/cmd/sedad/utils/merkle_test.go +++ b/cmd/sedad/utils/merkle_test.go @@ -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 @@ -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) {