From 31c8bbb5b0b3ace533fafab5f6abbec613803ccf Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Tue, 29 Oct 2024 10:23:21 -0600 Subject: [PATCH 1/8] refactor: update inclusion proof Signed-off-by: Gustavo Inacio --- .../examples/inclusion_proof.rs | 33 ++-- crates/header-accumulator/src/epoch.rs | 10 +- crates/header-accumulator/src/errors.rs | 19 ++ .../header-accumulator/src/inclusion_proof.rs | 167 ++++++++++++------ 4 files changed, 154 insertions(+), 75 deletions(-) diff --git a/crates/header-accumulator/examples/inclusion_proof.rs b/crates/header-accumulator/examples/inclusion_proof.rs index f27c8c51..9c279d1c 100644 --- a/crates/header-accumulator/examples/inclusion_proof.rs +++ b/crates/header-accumulator/examples/inclusion_proof.rs @@ -1,9 +1,8 @@ use std::{fs::File, io::BufReader}; -use firehose_protos::EthBlock as Block; use flat_files_decoder::{read_blocks_from_reader, Compression}; use header_accumulator::{ - generate_inclusion_proof, verify_inclusion_proof, EraValidateError, ExtHeaderRecord, + generate_inclusion_proofs, verify_inclusion_proofs, Epoch, EraValidateError, ExtHeaderRecord, }; fn create_test_reader(path: &str) -> BufReader { @@ -12,7 +11,6 @@ fn create_test_reader(path: &str) -> BufReader { fn main() -> Result<(), EraValidateError> { let mut headers: Vec = Vec::new(); - let mut all_blocks: Vec = Vec::new(); for flat_file_number in (0..=8200).step_by(100) { let file = format!( @@ -27,7 +25,6 @@ fn main() -> Result<(), EraValidateError> { .map(|block| ExtHeaderRecord::try_from(block).unwrap()) .collect::>(), ); - all_blocks.extend(blocks); } Err(e) => { eprintln!("error: {:?}", e); @@ -38,23 +35,27 @@ fn main() -> Result<(), EraValidateError> { let start_block = 301; let end_block = 402; - let inclusion_proof = - generate_inclusion_proof(headers, start_block, end_block).unwrap_or_else(|e| { + let headers_to_proof: Vec<_> = headers[start_block..end_block] + .iter() + .map(|ext| ext.full_header.as_ref().unwrap().clone()) + .collect(); + let epoch: Epoch = headers.try_into().unwrap(); + + let inclusion_proof = generate_inclusion_proofs(vec![epoch], headers_to_proof.clone()) + .unwrap_or_else(|e| { println!("Error occurred: {}", e); std::process::exit(1); }); - assert_eq!( - inclusion_proof.len() as usize, - (end_block - start_block + 1) as usize - ); + assert_eq!(inclusion_proof.len(), headers_to_proof.len()); - // Verify inclusion proof - let proof_blocks: Vec = all_blocks[start_block as usize..=end_block as usize].to_vec(); - assert!(verify_inclusion_proof(proof_blocks, None, inclusion_proof.clone()).is_ok()); + let proof_headers = headers_to_proof + .into_iter() + .zip(inclusion_proof) + .map(|(header, proof)| proof.with_header(header)) + .collect::, _>>()?; - // Verify if inclusion proof fails on not proven blocks - let proof_blocks: Vec = all_blocks[302..=403].to_vec(); - assert!(verify_inclusion_proof(proof_blocks, None, inclusion_proof.clone()).is_err()); + // Verify inclusion proof + assert!(verify_inclusion_proofs(None, proof_headers).is_ok()); println!("Inclusion proof verified successfully!"); diff --git a/crates/header-accumulator/src/epoch.rs b/crates/header-accumulator/src/epoch.rs index 3a50efbb..1f117333 100644 --- a/crates/header-accumulator/src/epoch.rs +++ b/crates/header-accumulator/src/epoch.rs @@ -1,7 +1,7 @@ use std::array::IntoIter; use alloy_primitives::map::HashSet; -use ethportal_api::types::execution::accumulator::HeaderRecord; +use ethportal_api::types::execution::accumulator::{EpochAccumulator, HeaderRecord}; use crate::{errors::EraValidateError, types::ExtHeaderRecord}; @@ -30,6 +30,7 @@ pub const MERGE_BLOCK: u64 = 15537394; /// 0 must start from block 0 to block 8191. /// /// All blocks must be at the same epoch +#[derive(Clone)] pub struct Epoch { number: usize, data: Box<[HeaderRecord; MAX_EPOCH_SIZE]>, @@ -81,6 +82,13 @@ impl TryFrom> for Epoch { } } +impl From for EpochAccumulator { + fn from(value: Epoch) -> Self { + let vec: Vec = value.data.to_vec(); + EpochAccumulator::from(vec) + } +} + impl Epoch { pub fn number(&self) -> usize { self.number diff --git a/crates/header-accumulator/src/errors.rs b/crates/header-accumulator/src/errors.rs index 39e513cc..fb7377df 100644 --- a/crates/header-accumulator/src/errors.rs +++ b/crates/header-accumulator/src/errors.rs @@ -9,6 +9,19 @@ pub enum EraValidateError { #[error("Era accumulator mismatch")] EraAccumulatorMismatch, + #[error("Block epoch {block_epoch} (block number {block_number}) could not be proven with provided epoch {epoch_number}.")] + EpochNotMatchForHeader { + epoch_number: usize, + block_number: u64, + block_epoch: usize, + }, + + #[error("Expected epoch {block_epoch} was not found in the provided epoch list. Epochs provided: {epoch_list:?}.")] + EpochNotFoundInProvidedList { + block_epoch: usize, + epoch_list: Vec, + }, + #[error("Error generating inclusion proof")] ProofGenerationFailure, #[error("Error validating inclusion proof")] @@ -28,6 +41,12 @@ pub enum EraValidateError { InvalidBlockRange(u64, u64), #[error("Epoch is in post merge: {0}")] EpochPostMerge(usize), + + #[error("Header block number ({block_number}) is different than expected ({expected_number})")] + HeaderMismatch { + expected_number: u64, + block_number: u64, + }, } impl From for EraValidateError { diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index adc82a7e..69c51756 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -1,20 +1,46 @@ -use crate::{epoch::MAX_EPOCH_SIZE, errors::EraValidateError, types::ExtHeaderRecord}; +use crate::{epoch::MAX_EPOCH_SIZE, errors::EraValidateError, Epoch}; -use alloy_primitives::FixedBytes; use ethportal_api::{ types::execution::{ - accumulator::{EpochAccumulator, HeaderRecord}, + accumulator::EpochAccumulator, header_with_proof::{BlockHeaderProof, HeaderWithProof, PreMergeAccumulatorProof}, }, Header, }; -use firehose_protos::EthBlock as Block; use tree_hash::Hash256; use trin_validation::{ accumulator::PreMergeAccumulator, header_validator::HeaderValidator, historical_roots_acc::HistoricalRootsAccumulator, }; +#[derive(Clone)] +pub struct InclusionProof { + block_number: u64, + proof: [Hash256; 15], +} + +impl InclusionProof { + pub fn with_header(self, header: Header) -> Result { + if self.block_number != header.number { + Err(EraValidateError::HeaderMismatch { + expected_number: self.block_number, + block_number: header.number, + }) + } else { + Ok(ProovableHeader { + proof: self, + header, + }) + } + } +} + +impl From for PreMergeAccumulatorProof { + fn from(value: InclusionProof) -> Self { + Self { proof: value.proof } + } +} + /// generates an inclusion proof over headers, given blocks between `start_block` and `end_block` /// /// # Arguments @@ -23,50 +49,65 @@ use trin_validation::{ /// to function without error /// * `start_block` - The starting point of blocks that are to be included in the proofs. This interval is inclusive. /// * `end_epoch` - The ending point of blocks that are to be included in the proofs. This interval is inclusive. -pub fn generate_inclusion_proof( - mut ext_headers: Vec, - start_block: u64, - end_block: u64, -) -> Result, EraValidateError> { - if start_block > end_block { - return Err(EraValidateError::InvalidBlockRange(start_block, end_block)); - } +pub fn generate_inclusion_proofs( + epochs: Vec, + headers_to_prove: Vec
, +) -> Result, EraValidateError> { + // We need to load blocks from an entire epoch to be able to generate inclusion proofs + // First compute epoch accumulators and the Merkle tree for all the epochs of interest + let mut inclusion_proof_vec: Vec = Vec::new(); + let epoch_list: Vec<_> = epochs.iter().map(|epoch| epoch.number()).collect(); + let accumulators: Vec<_> = epochs + .into_iter() + .map(|epoch| (epoch.number(), EpochAccumulator::from(epoch))) + .collect(); - // Compute the epoch accumulator for the blocks - // The epochs start on a multiple of 8192 blocks, so we need to round down to the nearest 8192 - let epoch_start = start_block / MAX_EPOCH_SIZE as u64; + for header in headers_to_prove { + let block_epoch = (header.number / MAX_EPOCH_SIZE as u64) as usize; - // The epochs end on a multiple of 8192 blocks, so we need to round up to the nearest 8192 - let epoch_end = ((end_block as f32) / MAX_EPOCH_SIZE as f32).ceil() as u64; + let accumulator = accumulators + .iter() + .find(|epoch| epoch.0 == block_epoch) + .map(|epoch| &epoch.1) + .ok_or(EraValidateError::EpochNotFoundInProvidedList { + block_epoch, + epoch_list: epoch_list.clone(), + })?; - // We need to load blocks from an entire epoch to be able to generate inclusion proofs - // First compute epoch accumulators and the Merkle tree for all the epochs of interest - let mut epoch_accumulators = Vec::new(); - let mut inclusion_proof_vec: Vec<[FixedBytes<32>; 15]> = Vec::new(); - let mut headers: Vec
= Vec::new(); - - for _ in epoch_start..epoch_end { - let epoch_headers: Vec = ext_headers.drain(0..MAX_EPOCH_SIZE).collect(); - let header_records: Vec = epoch_headers.iter().map(Into::into).collect(); - let tmp_headers: Vec
= epoch_headers - .into_iter() - .map(ExtHeaderRecord::try_into) - .collect::>()?; - headers.extend(tmp_headers); - epoch_accumulators.push(EpochAccumulator::from(header_records)); + inclusion_proof_vec.push(do_generate_inclusion_proof(&header, accumulator)?); } - for block_idx in start_block..=end_block { - let epoch = block_idx / MAX_EPOCH_SIZE as u64; - let epoch_acc = epoch_accumulators[epoch as usize].clone(); - let header = headers[block_idx as usize].clone(); - inclusion_proof_vec.push( - PreMergeAccumulator::construct_proof(&header, &epoch_acc) - .map_err(|_| EraValidateError::ProofGenerationFailure)?, - ); + Ok(inclusion_proof_vec) +} + +pub fn generate_inclusion_proof( + header: Header, + epoch: Epoch, +) -> Result { + let block_number = header.number; + let block_epoch = (block_number / MAX_EPOCH_SIZE as u64) as usize; + if block_epoch != epoch.number() { + return Err(EraValidateError::EpochNotMatchForHeader { + epoch_number: epoch.number(), + block_number, + block_epoch, + }); } - Ok(inclusion_proof_vec) + let epoch_accumulator = EpochAccumulator::from(epoch); + do_generate_inclusion_proof(&header, &epoch_accumulator) +} + +fn do_generate_inclusion_proof( + header: &Header, + epoch_accumulator: &EpochAccumulator, +) -> Result { + PreMergeAccumulator::construct_proof(header, epoch_accumulator) + .map(|proof| InclusionProof { + proof, + block_number: header.number, + }) + .map_err(|_| EraValidateError::ProofGenerationFailure) } /// verifies an inclusion proof generate by [`generate_inclusion_proof`] @@ -75,32 +116,42 @@ pub fn generate_inclusion_proof( /// * `pre_merge_accumulator_file`- An instance of [`PreMergeAccumulator`] which is a file that maintains a record of historical epoch /// it is used to verify canonical-ness of headers accumulated from the `blocks` /// * `inclusion_proof` - The inclusion proof generated from [`generate_inclusion_proof`]. -pub fn verify_inclusion_proof( - blocks: Vec, +pub fn verify_inclusion_proofs( pre_merge_accumulator_file: Option, - inclusion_proof: Vec<[Hash256; 15]>, + header_proofs: Vec, ) -> Result<(), EraValidateError> { let pre_merge_acc = pre_merge_accumulator_file.unwrap_or_default(); - let header_validator = HeaderValidator { pre_merge_acc, historical_roots_acc: HistoricalRootsAccumulator::default(), }; - for (block_idx, _) in blocks.iter().enumerate() { - let bhp = BlockHeaderProof::PreMergeAccumulatorProof(PreMergeAccumulatorProof { - proof: inclusion_proof[block_idx], - }); - - let hwp = HeaderWithProof { - header: Header::try_from(&blocks[block_idx])?, - proof: bhp, - }; - - header_validator - .validate_header_with_proof(&hwp) - .map_err(|_| EraValidateError::ProofValidationFailure)?; + for proovable_header in header_proofs { + verify_inclusion_proof( + &header_validator, + proovable_header.header, + proovable_header.proof, + )?; } Ok(()) } + +pub struct ProovableHeader { + header: Header, + proof: InclusionProof, +} + +pub fn verify_inclusion_proof( + header_validator: &HeaderValidator, + header: Header, + proof: InclusionProof, +) -> Result<(), EraValidateError> { + let proof = BlockHeaderProof::PreMergeAccumulatorProof(proof.into()); + + let hwp = HeaderWithProof { header, proof }; + + header_validator + .validate_header_with_proof(&hwp) + .map_err(|_| EraValidateError::ProofValidationFailure) +} From bc1b3e4b30106cbf636b6b812f237ae489566af5 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Mon, 4 Nov 2024 19:06:37 -0600 Subject: [PATCH 2/8] docs: add docs to inclusion proof Signed-off-by: Gustavo Inacio --- .../header-accumulator/src/inclusion_proof.rs | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index 69c51756..54f5e6dc 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -13,6 +13,7 @@ use trin_validation::{ historical_roots_acc::HistoricalRootsAccumulator, }; +/// A proof that contains the block number #[derive(Clone)] pub struct InclusionProof { block_number: u64, @@ -20,6 +21,7 @@ pub struct InclusionProof { } impl InclusionProof { + /// Takes a header and turns the proof into a proovable header pub fn with_header(self, header: Header) -> Result { if self.block_number != header.number { Err(EraValidateError::HeaderMismatch { @@ -41,20 +43,17 @@ impl From for PreMergeAccumulatorProof { } } -/// generates an inclusion proof over headers, given blocks between `start_block` and `end_block` +/// Generates inclusion proofs for headers, given a list epochs that contains +/// the headers to be prooven /// /// # Arguments /// -/// * `ext_headers`- A mutable [`Vec`]. The Vector can be any size, however, it must be in chunks of 8192 blocks to work properly -/// to function without error -/// * `start_block` - The starting point of blocks that are to be included in the proofs. This interval is inclusive. -/// * `end_epoch` - The ending point of blocks that are to be included in the proofs. This interval is inclusive. +/// * `epochs`- A list of epochs [`Vec`]. +/// * `headers_to_prove` - A list of headers [`Vec
`] pub fn generate_inclusion_proofs( epochs: Vec, headers_to_prove: Vec
, ) -> Result, EraValidateError> { - // We need to load blocks from an entire epoch to be able to generate inclusion proofs - // First compute epoch accumulators and the Merkle tree for all the epochs of interest let mut inclusion_proof_vec: Vec = Vec::new(); let epoch_list: Vec<_> = epochs.iter().map(|epoch| epoch.number()).collect(); let accumulators: Vec<_> = epochs @@ -80,6 +79,15 @@ pub fn generate_inclusion_proofs( Ok(inclusion_proof_vec) } +/// Generates an inclusion proof for the header, given the epochs that contains +/// the header to be prooven +/// +/// Returns an error if the header is not inside the epoch. +/// +/// # Arguments +/// +/// * `header`- Header to be prooven +/// * `epoch` - Epoch in which the header is located pub fn generate_inclusion_proof( header: Header, epoch: Epoch, @@ -110,12 +118,12 @@ fn do_generate_inclusion_proof( .map_err(|_| EraValidateError::ProofGenerationFailure) } -/// verifies an inclusion proof generate by [`generate_inclusion_proof`] +/// Verifies a list of proovable headers /// -/// * `blocks`- A [`Vec`]. The blocks included in the inclusion proof interval, set in `start_block` and `end_block` of [`generate_inclusion_proof`] -/// * `pre_merge_accumulator_file`- An instance of [`PreMergeAccumulator`] which is a file that maintains a record of historical epoch -/// it is used to verify canonical-ness of headers accumulated from the `blocks` -/// * `inclusion_proof` - The inclusion proof generated from [`generate_inclusion_proof`]. +/// * `pre_merge_accumulator_file`- An optional instance of [`PreMergeAccumulator`] +/// which is a file that maintains a record of historical epoch it is used to +/// verify canonical-ness of headers accumulated from the `blocks` +/// * `header_proofs`- A [`Vec`]. pub fn verify_inclusion_proofs( pre_merge_accumulator_file: Option, header_proofs: Vec, @@ -127,29 +135,29 @@ pub fn verify_inclusion_proofs( }; for proovable_header in header_proofs { - verify_inclusion_proof( - &header_validator, - proovable_header.header, - proovable_header.proof, - )?; + verify_inclusion_proof(&header_validator, proovable_header)?; } Ok(()) } +/// A header with an inclusion proof attached pub struct ProovableHeader { header: Header, proof: InclusionProof, } +/// Verifies if a proof is contained in the header validator pub fn verify_inclusion_proof( header_validator: &HeaderValidator, - header: Header, - proof: InclusionProof, + proovable_header: ProovableHeader, ) -> Result<(), EraValidateError> { - let proof = BlockHeaderProof::PreMergeAccumulatorProof(proof.into()); + let proof = BlockHeaderProof::PreMergeAccumulatorProof(proovable_header.proof.into()); - let hwp = HeaderWithProof { header, proof }; + let hwp = HeaderWithProof { + header: proovable_header.header, + proof, + }; header_validator .validate_header_with_proof(&hwp) From 6b8d63c03c02d523a21644be1a9dc976bd76e6a9 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Mon, 25 Nov 2024 11:14:55 -0600 Subject: [PATCH 3/8] refactor: rename to header with proof fix typos for "proovable" Signed-off-by: Gustavo Inacio --- .../header-accumulator/src/inclusion_proof.rs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index 54f5e6dc..4cf76131 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -3,7 +3,9 @@ use crate::{epoch::MAX_EPOCH_SIZE, errors::EraValidateError, Epoch}; use ethportal_api::{ types::execution::{ accumulator::EpochAccumulator, - header_with_proof::{BlockHeaderProof, HeaderWithProof, PreMergeAccumulatorProof}, + header_with_proof::{ + BlockHeaderProof, HeaderWithProof as PortalHeaderWithProof, PreMergeAccumulatorProof, + }, }, Header, }; @@ -21,15 +23,15 @@ pub struct InclusionProof { } impl InclusionProof { - /// Takes a header and turns the proof into a proovable header - pub fn with_header(self, header: Header) -> Result { + /// Takes a header and turns the proof into a provable header + pub fn with_header(self, header: Header) -> Result { if self.block_number != header.number { Err(EraValidateError::HeaderMismatch { expected_number: self.block_number, block_number: header.number, }) } else { - Ok(ProovableHeader { + Ok(HeaderWithProof { proof: self, header, }) @@ -118,15 +120,15 @@ fn do_generate_inclusion_proof( .map_err(|_| EraValidateError::ProofGenerationFailure) } -/// Verifies a list of proovable headers +/// Verifies a list of provable headers /// /// * `pre_merge_accumulator_file`- An optional instance of [`PreMergeAccumulator`] /// which is a file that maintains a record of historical epoch it is used to /// verify canonical-ness of headers accumulated from the `blocks` -/// * `header_proofs`- A [`Vec`]. +/// * `header_proofs`- A [`Vec`]. pub fn verify_inclusion_proofs( pre_merge_accumulator_file: Option, - header_proofs: Vec, + header_proofs: Vec, ) -> Result<(), EraValidateError> { let pre_merge_acc = pre_merge_accumulator_file.unwrap_or_default(); let header_validator = HeaderValidator { @@ -134,15 +136,15 @@ pub fn verify_inclusion_proofs( historical_roots_acc: HistoricalRootsAccumulator::default(), }; - for proovable_header in header_proofs { - verify_inclusion_proof(&header_validator, proovable_header)?; + for provable_header in header_proofs { + verify_inclusion_proof(&header_validator, provable_header)?; } Ok(()) } /// A header with an inclusion proof attached -pub struct ProovableHeader { +pub struct HeaderWithProof { header: Header, proof: InclusionProof, } @@ -150,12 +152,12 @@ pub struct ProovableHeader { /// Verifies if a proof is contained in the header validator pub fn verify_inclusion_proof( header_validator: &HeaderValidator, - proovable_header: ProovableHeader, + provable_header: HeaderWithProof, ) -> Result<(), EraValidateError> { - let proof = BlockHeaderProof::PreMergeAccumulatorProof(proovable_header.proof.into()); + let proof = BlockHeaderProof::PreMergeAccumulatorProof(provable_header.proof.into()); - let hwp = HeaderWithProof { - header: proovable_header.header, + let hwp = PortalHeaderWithProof { + header: provable_header.header, proof, }; From 4a81978f855431e4374fccdc867ca5ae1d35c949 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Mon, 25 Nov 2024 11:15:15 -0600 Subject: [PATCH 4/8] perf: use capacity while creating inclusion proof vec Signed-off-by: Gustavo Inacio --- crates/header-accumulator/src/inclusion_proof.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index 4cf76131..44e6b161 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -56,7 +56,7 @@ pub fn generate_inclusion_proofs( epochs: Vec, headers_to_prove: Vec
, ) -> Result, EraValidateError> { - let mut inclusion_proof_vec: Vec = Vec::new(); + let mut inclusion_proof_vec: Vec = Vec::with_capacity(headers_to_prove.len()); let epoch_list: Vec<_> = epochs.iter().map(|epoch| epoch.number()).collect(); let accumulators: Vec<_> = epochs .into_iter() From b84093d7713d41aa034fdeb8acf28aa4bd7c85d7 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Mon, 25 Nov 2024 11:15:32 -0600 Subject: [PATCH 5/8] refactor: use const instead of magic number Signed-off-by: Gustavo Inacio --- crates/header-accumulator/src/inclusion_proof.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index 44e6b161..ac186121 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -15,11 +15,13 @@ use trin_validation::{ historical_roots_acc::HistoricalRootsAccumulator, }; +const PROOF_SIZE: usize = 15; + /// A proof that contains the block number #[derive(Clone)] pub struct InclusionProof { block_number: u64, - proof: [Hash256; 15], + proof: [Hash256; PROOF_SIZE], } impl InclusionProof { From 32c759cb8d963c0f553af0c1235e834d813f5337 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Mon, 25 Nov 2024 20:43:13 -0600 Subject: [PATCH 6/8] docs: fix proven Signed-off-by: Gustavo Inacio --- crates/header-accumulator/src/inclusion_proof.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index ac186121..11bdd7d8 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -48,7 +48,7 @@ impl From for PreMergeAccumulatorProof { } /// Generates inclusion proofs for headers, given a list epochs that contains -/// the headers to be prooven +/// the headers to be proven /// /// # Arguments /// @@ -84,13 +84,13 @@ pub fn generate_inclusion_proofs( } /// Generates an inclusion proof for the header, given the epochs that contains -/// the header to be prooven +/// the header to be proven /// /// Returns an error if the header is not inside the epoch. /// /// # Arguments /// -/// * `header`- Header to be prooven +/// * `header`- Header to be proven /// * `epoch` - Epoch in which the header is located pub fn generate_inclusion_proof( header: Header, From c22dac05be664e6ccb1f69114bbb121b09b5ae85 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Tue, 26 Nov 2024 12:39:27 -0600 Subject: [PATCH 7/8] chore: update variable name Signed-off-by: Gustavo Inacio --- crates/header-accumulator/examples/inclusion_proof.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/header-accumulator/examples/inclusion_proof.rs b/crates/header-accumulator/examples/inclusion_proof.rs index 9c279d1c..0728f28e 100644 --- a/crates/header-accumulator/examples/inclusion_proof.rs +++ b/crates/header-accumulator/examples/inclusion_proof.rs @@ -35,20 +35,20 @@ fn main() -> Result<(), EraValidateError> { let start_block = 301; let end_block = 402; - let headers_to_proof: Vec<_> = headers[start_block..end_block] + let headers_to_prove: Vec<_> = headers[start_block..end_block] .iter() .map(|ext| ext.full_header.as_ref().unwrap().clone()) .collect(); let epoch: Epoch = headers.try_into().unwrap(); - let inclusion_proof = generate_inclusion_proofs(vec![epoch], headers_to_proof.clone()) + let inclusion_proof = generate_inclusion_proofs(vec![epoch], headers_to_prove.clone()) .unwrap_or_else(|e| { println!("Error occurred: {}", e); std::process::exit(1); }); - assert_eq!(inclusion_proof.len(), headers_to_proof.len()); + assert_eq!(inclusion_proof.len(), headers_to_prove.len()); - let proof_headers = headers_to_proof + let proof_headers = headers_to_prove .into_iter() .zip(inclusion_proof) .map(|(header, proof)| proof.with_header(header)) From ca4fdf0e9a0f48fa766bf4ac98d00902e7a47abb Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Tue, 26 Nov 2024 12:40:18 -0600 Subject: [PATCH 8/8] docs: update inclusion proof Signed-off-by: Gustavo Inacio --- crates/header-accumulator/src/inclusion_proof.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/header-accumulator/src/inclusion_proof.rs b/crates/header-accumulator/src/inclusion_proof.rs index 11bdd7d8..275e3621 100644 --- a/crates/header-accumulator/src/inclusion_proof.rs +++ b/crates/header-accumulator/src/inclusion_proof.rs @@ -83,7 +83,7 @@ pub fn generate_inclusion_proofs( Ok(inclusion_proof_vec) } -/// Generates an inclusion proof for the header, given the epochs that contains +/// Generates an inclusion proof for the header, given the epoch that contains /// the header to be proven /// /// Returns an error if the header is not inside the epoch.