Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compact data inclusion #125

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions aptos/docs/src/benchmark/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ Here are the standard config variables that are worth setting for any benchmark:

- `cargo +nightly-2024-05-31`

This ensures you are on a nightly toolchain. Nightly allows usage of AVX512 instructions which is crucial for performance.
This is the same version set on `rust-toolchain.toml`. It's pinned to a specific release (`v1.80.0-nightly`) to prevent
unexpected issues caused by newer Rust versions.
This ensures you are on a nightly toolchain. Nightly allows usage of AVX512 instructions which is crucial for
performance. This is the same version set on `rust-toolchain.toml`. It's pinned
to a specific release (`v1.80.0-nightly`) to prevent unexpected issues caused
by newer Rust versions.

- `cargo bench --release <...>`

Expand Down
3 changes: 3 additions & 0 deletions ethereum/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ xclippy = [
"-Wclippy::all",
"-Wclippy::cast_lossless",
"-Wclippy::checked_conversions",
"-Wclippy::clone_on_copy",
"-Wclippy::dbg_macro",
"-Wclippy::disallowed_methods",
"-Wclippy::derive_partial_eq_without_eq",
Expand Down Expand Up @@ -35,11 +36,13 @@ xclippy = [
"-Wclippy::needless_for_each",
"-Wclippy::needless_pass_by_value",
"-Wclippy::option_option",
"-Wclippy::redundant_clone",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::single_match_else",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::unnecessary_wraps",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unnecessary_to_owned",
"-Wnonstandard_style",
"-Wrust_2018_idioms",
"-Wtrivial_numeric_casts",
Expand Down
1 change: 1 addition & 0 deletions ethereum/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion ethereum/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ethers-core = { workspace = true }
hex = { workspace = true }
getset = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, optional = true }
sha2 = { workspace = true }
thiserror = { workspace = true }
tiny-keccak = { workspace = true, features = ["keccak"] }
Expand All @@ -23,4 +24,10 @@ ethereum_ssz = { workspace = true }
ethereum-types = { workspace = true }
ssz_types = { workspace = true, features = ["arbitrary"] }
tree_hash = { workspace = true }
tree_hash_derive = { workspace = true }
tree_hash_derive = { workspace = true }

[features]
default = []
ethereum = [
"dep:serde_json"
]
4 changes: 4 additions & 0 deletions ethereum/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
//! ## Sub-modules
//!
//! - `crypto`: This sub-module contains the cryptographic utilities used by the Light Client.
//! - `merkle`: This sub-module contains the utilities to generate and verify Merkle proofs.
//! - `test_utils`: This sub-module contains utilities to help with testing the Light Client.
//! - `types`: This sub-module contains the types and utilities necessary to prove sync committee changes
//! and value inclusion in the state of the chain.
//!
//! For more detailed information, users should refer to the specific documentation for each sub-module.

pub mod crypto;
pub mod merkle;
#[cfg(feature = "ethereum")]
pub mod test_utils;
pub mod types;
25 changes: 12 additions & 13 deletions ethereum/core/src/merkle/update_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::merkle::error::MerkleError;
use crate::merkle::utils::get_subtree_index;
use crate::merkle::Merkleized;
use crate::types::block::consensus::BeaconBlockHeader;
use crate::types::block::LightClientHeader;
use crate::types::committee::{
SyncCommittee, SyncCommitteeBranch, CURRENT_SYNC_COMMITTEE_GENERALIZED_INDEX,
NEXT_SYNC_COMMITTEE_GENERALIZED_INDEX, SYNC_COMMITTEE_BRANCH_NBR_SIBLINGS,
Expand All @@ -20,20 +19,20 @@ use crate::types::{
///
/// # Arguments
///
/// * `attested_header` - The header of the block that the update is attesting to.
/// * `state_root` - The state root of the Beacon block that the proof is attesting to.
/// * `finality_header` - The header of the block that the update is attesting to be finalized.
/// * `finality_branch` - The branch of the Merkle tree that proves the finality of the block.
///
/// # Returns
///
/// A `bool` indicating whether the finality proof is valid.
pub fn is_finality_proof_valid(
attested_header: &LightClientHeader,
state_root: &Bytes32,
finality_header: &mut BeaconBlockHeader,
finality_branch: &FinalizedRootBranch,
) -> Result<bool, MerkleError> {
is_proof_valid(
attested_header,
state_root,
finality_header,
finality_branch,
FINALIZED_CHECKPOINT_BRANCH_NBR_SIBLINGS,
Expand All @@ -45,20 +44,20 @@ pub fn is_finality_proof_valid(
///
/// # Arguments
///
/// * `attested_header` - The header of the block that the update is attesting to.
/// * `state_root` - The state root of the Beacon block that the proof is attesting to.
/// * `sync_committee` - The next sync committee that the update is attesting to.
/// * `sync_committee_branch` - The branch of the Merkle tree that proves the sync committee of the block.
///
/// # Returns
///
/// A `bool` indicating whether the sync committee proof is valid.
pub fn is_next_committee_proof_valid(
attested_header: &LightClientHeader,
state_root: &Bytes32,
next_committee: &mut SyncCommittee,
next_committee_branch: &SyncCommitteeBranch,
) -> Result<bool, MerkleError> {
is_proof_valid(
attested_header,
state_root,
next_committee,
next_committee_branch,
SYNC_COMMITTEE_BRANCH_NBR_SIBLINGS,
Expand All @@ -70,20 +69,20 @@ pub fn is_next_committee_proof_valid(
///
/// # Arguments
///
/// * `bootstrap_header` - The header of the block that the bootstrap is attesting to.
/// * `state_root` - The state root of the Beacon block that the proof is attesting to.
/// * `current_committee` - The current sync committee that the bootstrap is attesting to.
/// * `current_committee_branch` - The branch of the Merkle tree that proves the current committee of the block.
///
/// # Returns
///
/// A `bool` indicating whether the current committee proof is valid.
pub fn is_current_committee_proof_valid(
bootstrap_header: &LightClientHeader,
state_root: &Bytes32,
current_committee: &mut SyncCommittee,
current_committee_branch: &SyncCommitteeBranch,
) -> Result<bool, MerkleError> {
is_proof_valid(
bootstrap_header,
state_root,
current_committee,
current_committee_branch,
SYNC_COMMITTEE_BRANCH_NBR_SIBLINGS,
Expand All @@ -95,7 +94,7 @@ pub fn is_current_committee_proof_valid(
///
/// # Arguments
///
/// * `attested_header` - The header of the block that the update is attesting to.
/// * `state_root` - The state root of the Beacon block that the proof is attesting to.
/// * `leaf_object` - The object that the proof is attesting to.
/// * `branch` - The branch of the Merkle tree that proves the object.
/// * `depth` - The depth of the Merkle tree.
Expand All @@ -105,7 +104,7 @@ pub fn is_current_committee_proof_valid(
///
/// A `bool` indicating whether the proof is valid.
fn is_proof_valid<M: Merkleized>(
attested_header: &LightClientHeader,
state_root: &Bytes32,
leaf_object: &mut M,
branch: &[Bytes32],
depth: usize,
Expand Down Expand Up @@ -143,7 +142,7 @@ fn is_proof_valid<M: Merkleized>(
.map_err(|err| MerkleError::Hash { source: err.into() })?;

// 4. Instantiate expected root and siblings as `HashValue`
let state_root = HashValue::new(*attested_header.beacon().state_root());
let state_root = HashValue::new(*state_root);
let branch_hashes = branch
.iter()
.map(|bytes| HashValue::new(*bytes))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::types::storage::GetProofResponse;
use ethereum_lc_core::merkle::storage_proofs::EIP1186Proof;
use ethereum_lc_core::types::bootstrap::Bootstrap;
use ethereum_lc_core::types::store::LightClientStore;
use ethereum_lc_core::types::update::{FinalityUpdate, Update};
use crate::merkle::storage_proofs::EIP1186Proof;
use crate::types::bootstrap::Bootstrap;
use crate::types::store::LightClientStore;
use crate::types::update::{FinalityUpdate, Update};
use ethers_core::types::EIP1186ProofResponse;
use getset::Getters;
use serde_json::Value;
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -105,7 +106,13 @@ pub fn generate_inclusion_test_assets() -> InclusionTestAssets {

let test_bytes = fs::read(test_asset_path).unwrap();

let ethers_eip1186_proof: GetProofResponse = serde_json::from_slice(&test_bytes).unwrap();
let ethers_eip1186_proof: Value = serde_json::from_slice(&test_bytes).unwrap();

let call_res = ethers_eip1186_proof
.get("result")
.expect("Ethers EIP1186 proof result not found");
let ethers_eip1186_proof: EIP1186ProofResponse =
serde_json::from_value(call_res.clone()).unwrap();

// Initialize the LightClientStore
let trusted_block_root = hex::decode(INCLUSION_CHECKPOINT.strip_prefix("0x").unwrap())
Expand All @@ -120,6 +127,6 @@ pub fn generate_inclusion_test_assets() -> InclusionTestAssets {
InclusionTestAssets {
store,
finality_update,
eip1186_proof: EIP1186Proof::try_from(ethers_eip1186_proof.result().clone()).unwrap(),
eip1186_proof: EIP1186Proof::try_from(ethers_eip1186_proof).unwrap(),
}
}
2 changes: 1 addition & 1 deletion ethereum/core/src/types/block/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub(crate) mod test {

// Hash for lighthouse implementation
let test_execution_block_header =
ExecutionBlockHeaderTreeHash::try_from(execution_block_header.clone()).unwrap();
ExecutionBlockHeaderTreeHash::try_from(execution_block_header).unwrap();
let execution_block_header_tree_hash = test_execution_block_header.tree_hash_root();

assert_eq!(hash_tree_root.hash(), execution_block_header_tree_hash.0);
Expand Down
2 changes: 1 addition & 1 deletion ethereum/core/src/types/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub const LIGHT_CLIENT_HEADER_BASE_BYTES_LEN: usize = BEACON_BLOCK_HEADER_BYTES_
#[derive(Debug, Clone, Eq, PartialEq, Getters)]
#[getset(get = "pub")]
pub struct LightClientHeader {
beacon: BeaconBlockHeader,
pub(crate) beacon: BeaconBlockHeader,
execution: ExecutionBlockHeader,
execution_branch: ExecutionBranch,
}
Expand Down
Loading
Loading