Added Merkle Proof Generation for Beacon State (#3674)

## Issue Addressed

This PR addresses partially #3651

## Proposed Changes

This PR adds the following methods:

* a new method to trait `TreeHash`, `hash_tree_leaves` which returns all the Merkle leaves of the ssz object.
* a new method to `BeaconState`: `compute_merkle_proof` which generates a specific merkle proof for given depth and index by using the `hash_tree_leaves` as leaves function.

## Additional Info

Now here is some rationale on why I decided to go down this route: adding a new function to commonly used trait is a pain but was necessary to make sure we have all merkle leaves for every object, that is why I just added  `hash_tree_leaves`  in the trait and not  `compute_merkle_proof` as well. although it would make sense it gives us code duplication/harder review time and we just need it from one specific object in one specific usecase so not worth the effort YET. In my humble opinion.

Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
Giulio rebuffo
2022-11-08 01:58:18 +00:00
parent 84c7d8cc70
commit 9d6209725f
11 changed files with 277 additions and 132 deletions

View File

@@ -18,6 +18,7 @@ mod fork;
mod fork_choice;
mod genesis_initialization;
mod genesis_validity;
mod merkle_proof_validity;
mod operations;
mod rewards;
mod sanity_blocks;
@@ -41,6 +42,7 @@ pub use epoch_processing::*;
pub use fork::ForkTest;
pub use genesis_initialization::*;
pub use genesis_validity::*;
pub use merkle_proof_validity::*;
pub use operations::*;
pub use rewards::RewardsTest;
pub use sanity_blocks::*;