Skip to content

Commit

Permalink
Compute depth instead of hardcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Dec 1, 2023
1 parent a6ab6ac commit e981f2b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ mod observed_aggregates;
mod observed_attesters;
mod observed_blob_sidecars;
pub mod observed_block_producers;
pub mod proposer_signature_cache;
pub mod observed_operations;
pub mod otb_verification_service;
mod persisted_beacon_chain;
mod persisted_fork_choice;
mod pre_finalization_cache;
pub mod proposer_prep_service;
pub mod proposer_signature_cache;
pub mod schema_change;
pub mod shuffling_cache;
mod snapshot_cache;
Expand Down
8 changes: 3 additions & 5 deletions consensus/types/src/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ pub type KzgCommitmentOpts<T> =
/// Index of the `blob_kzg_commitments` leaf in the `BeaconBlockBody` tree post-deneb.
pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11;

/// Depth of the `BeaconBlockBody` merkle tree.
pub const BEACON_BLOCK_BODY_TREE_DEPTH: usize = 4;

/// The body of a `BeaconChain` block, containing operations.
///
/// This *superstruct* abstracts over the hard-fork.
Expand Down Expand Up @@ -130,9 +127,10 @@ impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> BeaconBlockBodyRef<'a, T,
body.bls_to_execution_changes.tree_hash_root(),
body.blob_kzg_commitments.tree_hash_root(),
];
let tree = MerkleTree::create(&leaves, BEACON_BLOCK_BODY_TREE_DEPTH);
let depth = leaves.len().next_power_of_two().ilog2() as usize;
let tree = MerkleTree::create(&leaves, depth);
let (_, proof_body) = tree
.generate_proof(BLOB_KZG_COMMITMENTS_INDEX, BEACON_BLOCK_BODY_TREE_DEPTH)
.generate_proof(BLOB_KZG_COMMITMENTS_INDEX, depth)
.map_err(Error::MerkleTreeError)?;
Ok(proof_body)
}
Expand Down
2 changes: 1 addition & 1 deletion testing/ef_tests/src/cases/merkle_proof_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<E: EthSpec> Case for KzgInclusionMerkleProofValidity<E> {
let expected_leaf = self.merkle_proof.branch[i];
if *proof_leaf != expected_leaf {
return Err(Error::NotEqual(format!(
"Leaves not equal in merke proof computed: {}, expected: {}",
"Leaves not equal in merkle proof computed: {}, expected: {}",
hex::encode(proof_leaf),
hex::encode(expected_leaf)
)));
Expand Down

0 comments on commit e981f2b

Please sign in to comment.