From 2dee432536bf32df86e657464613f6df44ccffb6 Mon Sep 17 00:00:00 2001 From: Dankrad Feist Date: Tue, 16 Jun 2020 14:43:34 +0100 Subject: [PATCH] Refactor getting Merkle root of data part of ByteList --- tests/core/pyspec/eth2spec/test/helpers/custody.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/custody.py b/tests/core/pyspec/eth2spec/test/helpers/custody.py index 4f91e6dc5..1993e566d 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/custody.py +++ b/tests/core/pyspec/eth2spec/test/helpers/custody.py @@ -136,6 +136,12 @@ def build_proof(anchor, leaf_index): return list(reversed(proof)) +def get_block_data_merkle_root(data_as_bytelist): + # To get the Merkle root of the block data, we need the Merkle root without the length Mixing + # The below implements this in the Remerkleable framework + return data_as_bytelist.get_backing().get_left().merkle_root() + + def get_valid_custody_chunk_response(spec, state, chunk_challenge, block_length, challenge_index, invalid_chunk_data=False): custody_data = get_custody_test_vector(block_length) @@ -160,8 +166,8 @@ def get_custody_test_vector(bytelength, offset=0): def get_shard_transition(spec, start_slot, block_lengths): - b = [ByteList[spec.MAX_SHARD_BLOCK_SIZE](get_custody_test_vector(x)) - .get_backing().get_left().merkle_root() for x in block_lengths] + b = [get_block_data_merkle_root(ByteList[spec.MAX_SHARD_BLOCK_SIZE](get_custody_test_vector(x))) + for x in block_lengths] shard_transition = spec.ShardTransition( start_slot=start_slot, shard_block_lengths=block_lengths, @@ -195,5 +201,5 @@ def get_custody_slashable_shard_transition(spec, start_slot, block_lengths, cust slashable_test_vector = get_custody_slashable_test_vector(spec, custody_secret, block_lengths[0], slashable=slashable) block_data = ByteList[spec.MAX_SHARD_BLOCK_SIZE](slashable_test_vector) - shard_transition.shard_data_roots[0] = block_data.get_backing().get_left().merkle_root() + shard_transition.shard_data_roots[0] = get_block_data_merkle_root(block_data) return shard_transition, slashable_test_vector