Skip to content

Commit

Permalink
Remove redundant MerkleRoot function (#8733)
Browse files Browse the repository at this point in the history
* Remove redundant MerkleRoot function

* update merle_tree() specs comment
  • Loading branch information
farazdagi authored Apr 10, 2021
1 parent e3149c4 commit 1af88b2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 65 deletions.
10 changes: 2 additions & 8 deletions shared/hashutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_library(
name = "go_default_library",
srcs = [
"hash.go",
"merkleRoot.go",
],
srcs = ["hash.go"],
importpath = "github.com/prysmaticlabs/prysm/shared/hashutil",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -22,10 +19,7 @@ go_library(
go_test(
name = "go_default_test",
size = "small",
srcs = [
"hash_test.go",
"merkleRoot_test.go",
],
srcs = ["hash_test.go"],
deps = [
":go_default_library",
"//proto/testing:go_default_library",
Expand Down
26 changes: 0 additions & 26 deletions shared/hashutil/merkleRoot.go

This file was deleted.

27 changes: 0 additions & 27 deletions shared/hashutil/merkleRoot_test.go

This file was deleted.

13 changes: 9 additions & 4 deletions shared/trieutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ func PrevPowerOf2(n int) int {
// MerkleTree returns all the nodes in a merkle tree from inputting merkle leaves.
//
// Spec pseudocode definition:
// def merkle_tree(leaves: Sequence[Hash]) -> Sequence[Hash]:
// padded_length = get_next_power_of_two(len(leaves))
// o = [Hash()] * padded_length + list(leaves) + [Hash()] * (padded_length - len(leaves))
// for i in range(padded_length - 1, 0, -1):
// def merkle_tree(leaves: Sequence[Bytes32]) -> Sequence[Bytes32]:
// """
// Return an array representing the tree nodes by generalized index:
// [0, 1, 2, 3, 4, 5, 6, 7], where each layer is a power of 2. The 0 index is ignored. The 1 index is the root.
// The result will be twice the size as the padded bottom layer for the input leaves.
// """
// bottom_length = get_power_of_two_ceil(len(leaves))
// o = [Bytes32()] * bottom_length + list(leaves) + [Bytes32()] * (bottom_length - len(leaves))
// for i in range(bottom_length - 1, 0, -1):
// o[i] = hash(o[i * 2] + o[i * 2 + 1])
// return o
func MerkleTree(leaves [][]byte) [][]byte {
Expand Down

0 comments on commit 1af88b2

Please sign in to comment.