|
6 | 6 |
|
7 | 7 | "github.com/pkg/errors"
|
8 | 8 | ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
9 |
| - "github.com/prysmaticlabs/go-ssz" |
10 | 9 | "github.com/prysmaticlabs/prysm/shared/bytesutil"
|
11 | 10 | "github.com/prysmaticlabs/prysm/shared/featureconfig"
|
12 | 11 | "github.com/prysmaticlabs/prysm/shared/hashutil"
|
@@ -38,105 +37,6 @@ func BlockHeaderRoot(header *ethpb.BeaconBlockHeader) ([32]byte, error) {
|
38 | 37 | return htrutils.BitwiseMerkleize(hashutil.CustomSHA256Hasher(), fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots)))
|
39 | 38 | }
|
40 | 39 |
|
41 |
| -// BlockRoot returns the block hash tree root of the provided block. |
42 |
| -func BlockRoot(blk *ethpb.BeaconBlock) ([32]byte, error) { |
43 |
| - fieldRoots := make([][32]byte, 5) |
44 |
| - if blk != nil { |
45 |
| - headerSlotBuf := make([]byte, 8) |
46 |
| - binary.LittleEndian.PutUint64(headerSlotBuf, blk.Slot) |
47 |
| - headerSlotRoot := bytesutil.ToBytes32(headerSlotBuf) |
48 |
| - fieldRoots[0] = headerSlotRoot |
49 |
| - proposerIdxBuf := make([]byte, 8) |
50 |
| - binary.LittleEndian.PutUint64(proposerIdxBuf, blk.ProposerIndex) |
51 |
| - proposerIndexRoot := bytesutil.ToBytes32(proposerIdxBuf) |
52 |
| - fieldRoots[1] = proposerIndexRoot |
53 |
| - parentRoot := bytesutil.ToBytes32(blk.ParentRoot) |
54 |
| - fieldRoots[2] = parentRoot |
55 |
| - stateRoot := bytesutil.ToBytes32(blk.StateRoot) |
56 |
| - fieldRoots[3] = stateRoot |
57 |
| - bodyRoot, err := BlockBodyRoot(blk.Body) |
58 |
| - if err != nil { |
59 |
| - return [32]byte{}, err |
60 |
| - } |
61 |
| - fieldRoots[4] = bodyRoot |
62 |
| - } |
63 |
| - return htrutils.BitwiseMerkleizeArrays(hashutil.CustomSHA256Hasher(), fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots))) |
64 |
| -} |
65 |
| - |
66 |
| -// BlockBodyRoot returns the hash tree root of the block body. |
67 |
| -func BlockBodyRoot(body *ethpb.BeaconBlockBody) ([32]byte, error) { |
68 |
| - if body == nil { |
69 |
| - // Treat nil body to be the same as empty. This is mostly for test setup purposes and would |
70 |
| - // be very unlikely to happen in production workflow. |
71 |
| - emptyRoot := make([]byte, 32) |
72 |
| - emptyRandao := make([]byte, 96) |
73 |
| - body = ðpb.BeaconBlockBody{ |
74 |
| - RandaoReveal: emptyRandao, |
75 |
| - Eth1Data: ðpb.Eth1Data{ |
76 |
| - DepositRoot: emptyRoot, |
77 |
| - DepositCount: 0, |
78 |
| - BlockHash: emptyRoot, |
79 |
| - }, |
80 |
| - Graffiti: emptyRoot, |
81 |
| - ProposerSlashings: make([]*ethpb.ProposerSlashing, 0), |
82 |
| - AttesterSlashings: make([]*ethpb.AttesterSlashing, 0), |
83 |
| - Attestations: make([]*ethpb.Attestation, 0), |
84 |
| - Deposits: make([]*ethpb.Deposit, 0), |
85 |
| - VoluntaryExits: make([]*ethpb.SignedVoluntaryExit, 0), |
86 |
| - } |
87 |
| - } |
88 |
| - hasher := hashutil.CustomSHA256Hasher() |
89 |
| - fieldRoots := make([][32]byte, 8) |
90 |
| - rawRandao := bytesutil.ToBytes96(body.RandaoReveal) |
91 |
| - packedRandao, err := htrutils.Pack([][]byte{rawRandao[:]}) |
92 |
| - if err != nil { |
93 |
| - return [32]byte{}, err |
94 |
| - } |
95 |
| - randaoRoot, err := htrutils.BitwiseMerkleize(hasher, packedRandao, uint64(len(packedRandao)), uint64(len(packedRandao))) |
96 |
| - if err != nil { |
97 |
| - return [32]byte{}, err |
98 |
| - } |
99 |
| - fieldRoots[0] = randaoRoot |
100 |
| - |
101 |
| - eth1Root, err := Eth1Root(hasher, body.Eth1Data) |
102 |
| - if err != nil { |
103 |
| - return [32]byte{}, err |
104 |
| - } |
105 |
| - fieldRoots[1] = eth1Root |
106 |
| - |
107 |
| - graffitiRoot := bytesutil.ToBytes32(body.Graffiti) |
108 |
| - fieldRoots[2] = graffitiRoot |
109 |
| - |
110 |
| - proposerSlashingsRoot, err := ssz.HashTreeRootWithCapacity(body.ProposerSlashings, params.BeaconConfig().MaxProposerSlashings) |
111 |
| - if err != nil { |
112 |
| - return [32]byte{}, err |
113 |
| - } |
114 |
| - fieldRoots[3] = proposerSlashingsRoot |
115 |
| - attesterSlashingsRoot, err := ssz.HashTreeRootWithCapacity(body.AttesterSlashings, params.BeaconConfig().MaxAttesterSlashings) |
116 |
| - if err != nil { |
117 |
| - return [32]byte{}, err |
118 |
| - } |
119 |
| - fieldRoots[4] = attesterSlashingsRoot |
120 |
| - attsRoot, err := blockAttestationRoot(body.Attestations) |
121 |
| - if err != nil { |
122 |
| - return [32]byte{}, err |
123 |
| - } |
124 |
| - fieldRoots[5] = attsRoot |
125 |
| - |
126 |
| - depositRoot, err := ssz.HashTreeRootWithCapacity(body.Deposits, params.BeaconConfig().MaxDeposits) |
127 |
| - if err != nil { |
128 |
| - return [32]byte{}, err |
129 |
| - } |
130 |
| - fieldRoots[6] = depositRoot |
131 |
| - |
132 |
| - exitRoot, err := ssz.HashTreeRootWithCapacity(body.VoluntaryExits, params.BeaconConfig().MaxVoluntaryExits) |
133 |
| - if err != nil { |
134 |
| - return [32]byte{}, err |
135 |
| - } |
136 |
| - fieldRoots[7] = exitRoot |
137 |
| - return htrutils.BitwiseMerkleizeArrays(hasher, fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots))) |
138 |
| -} |
139 |
| - |
140 | 40 | // Eth1Root computes the HashTreeRoot Merkleization of
|
141 | 41 | // a BeaconBlockHeader struct according to the eth2
|
142 | 42 | // Simple Serialize specification.
|
|
0 commit comments