2018-12-04 13:26:25 +00:00
|
|
|
# beacon_chain
|
2022-06-26 17:33:06 +00:00
|
|
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
2018-12-04 13:26:25 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
2018-12-04 13:26:25 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2021-08-18 18:57:58 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
|
|
|
# Import this module to get access to `hash_tree_root` for spec types
|
2019-11-14 10:47:55 +00:00
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
import
|
2022-06-26 17:33:06 +00:00
|
|
|
ssz_serialization/[merkleization, proofs],
|
2021-08-18 18:57:58 +00:00
|
|
|
./ssz_codec,
|
2021-09-28 18:08:03 +00:00
|
|
|
./datatypes/[phase0, altair]
|
2019-11-18 12:48:41 +00:00
|
|
|
|
2022-06-26 17:33:06 +00:00
|
|
|
export ssz_codec, merkleization, proofs
|
2021-09-28 18:08:03 +00:00
|
|
|
|
2022-06-29 16:53:59 +00:00
|
|
|
type
|
|
|
|
DepositsMerkleizer* = SszMerkleizer[DEPOSIT_CONTRACT_LIMIT]
|
|
|
|
|
2021-09-28 18:08:03 +00:00
|
|
|
func hash_tree_root*(x: phase0.HashedBeaconState | altair.HashedBeaconState) {.
|
|
|
|
error: "HashedBeaconState should not be hashed".}
|
|
|
|
|
|
|
|
func hash_tree_root*(x: phase0.SomeSignedBeaconBlock | altair.SomeSignedBeaconBlock) {.
|
|
|
|
error: "SignedBeaconBlock should not be hashed".}
|
2022-06-29 16:53:59 +00:00
|
|
|
|
|
|
|
func depositCountU64(s: DepositContractState): uint64 =
|
|
|
|
for i in 0 .. 23:
|
|
|
|
doAssert s.deposit_count[i] == 0
|
|
|
|
|
|
|
|
uint64.fromBytesBE s.deposit_count.toOpenArray(24, 31)
|
|
|
|
|
|
|
|
func init*(T: type DepositsMerkleizer, s: DepositContractState): DepositsMerkleizer =
|
|
|
|
DepositsMerkleizer.init(s.branch, s.depositCountU64)
|
|
|
|
|
|
|
|
func toDepositContractState*(merkleizer: DepositsMerkleizer): DepositContractState =
|
|
|
|
# TODO There is an off by one discrepancy in the size of the arrays here that
|
|
|
|
# need to be investigated. It shouldn't matter as long as the tree is
|
|
|
|
# not populated to its maximum size.
|
|
|
|
result.branch[0..31] = merkleizer.getCombinedChunks[0..31]
|
|
|
|
result.deposit_count[24..31] = merkleizer.getChunkCount().toBytesBE
|