Skip to content

Commit

Permalink
feat: refactor and update types
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Mar 6, 2025
1 parent 6c438c6 commit dc3368c
Show file tree
Hide file tree
Showing 37 changed files with 472 additions and 145 deletions.
25 changes: 20 additions & 5 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ aggchain-proof-builder = { path = "crates/aggchain-proof-builder" }
aggchain-proof-contracts = { path = "crates/aggchain-proof-contracts" }
aggchain-proof-core = { path = "crates/aggchain-proof-core" }
aggchain-proof-service = { path = "crates/aggchain-proof-service" }
aggchain-proof-types = { path = "crates/aggchain-proof-types" }
aggkit-prover = { path = "crates/aggkit-prover" }
aggkit-prover-config = { path = "crates/aggkit-prover-config" }
aggkit-prover-types = { path = "crates/aggkit-prover-types" }
Expand Down
2 changes: 1 addition & 1 deletion crates/aggchain-proof-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ sp1-sdk.workspace = true
url.workspace = true

aggchain-proof-contracts.workspace = true
aggchain-proof-types.workspace = true
aggchain-proof-core.workspace = true
aggkit-prover-types.workspace = true
prover-alloy.workspace = true
prover-config.workspace = true
prover-executor.workspace = true
Expand Down
32 changes: 9 additions & 23 deletions crates/aggchain-proof-builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
pub mod config;
mod error;

use std::collections::HashMap;
use std::sync::Arc;
use std::task::{Context, Poll};

use aggchain_proof_contracts::contracts::{
L1RollupConfigHashFetcher, L2LocalExitRootFetcher, L2OutputAtBlockFetcher,
};
use aggchain_proof_contracts::{AggchainContractsClient, AggchainContractsRpcClient};
use aggchain_proof_core::proof::{AggchainProofWitness, InclusionProof, L1InfoTreeLeaf};
use aggkit_prover_types::Hash;
use aggchain_proof_core::AggchainProofWitness;
use aggchain_proof_types::AggchainProofRequest;
pub use error::Error;
use futures::{future::BoxFuture, FutureExt};
use prover_alloy::AlloyFillProvider;
Expand Down Expand Up @@ -39,26 +38,13 @@ pub struct AggchainProverInputs {
pub end_block: u64,
}

#[derive(Clone, Debug)]
pub struct AggchainProofBuilderRequest {
/// Aggregated full execution proof for the number of aggregated block
/// spans.
pub agg_span_proof: SP1ProofWithPublicValues,
/// First block in the aggregated span.
pub start_block: u64,
/// Last block in the aggregated span (inclusive).
pub end_block: u64,
/// Root hash of the l1 info tree, containing all relevant GER.
/// Provided by agg-sender.
pub l1_info_tree_root_hash: Hash,
/// Particular leaf of the l1 info tree corresponding
/// to the max_block.
pub l1_info_tree_leaf: L1InfoTreeLeaf,
/// Inclusion proof of the l1 info tree leaf to the
/// l1 info tree root
pub l1_info_tree_merkle_proof: [Hash; 32],
/// Map of the Global Exit Roots with their inclusion proof.
/// Note: the GER (string) is a base64 encoded string of the GER digest.
pub ger_inclusion_proofs: HashMap<String, InclusionProof>,
/// Aggchain proof request information, public inputs, bridge data,...
pub aggchain_proof_request: AggchainProofRequest,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -127,22 +113,22 @@ impl<ContractsClient> AggchainProofBuilder<ContractsClient> {
L2LocalExitRootFetcher + L2OutputAtBlockFetcher + L1RollupConfigHashFetcher,
{
let _prev_local_exit_root = contracts_client
.get_l2_local_exit_root(request.start_block - 1)
.get_l2_local_exit_root(request.aggchain_proof_request.start_block - 1)
.await
.map_err(Error::L2ChainDataRetrievalError)?;

let _new_local_exit_root = contracts_client
.get_l2_local_exit_root(request.end_block)
.get_l2_local_exit_root(request.aggchain_proof_request.max_end_block)
.await
.map_err(Error::L2ChainDataRetrievalError)?;

let _l2_pre_root_output_at_block = contracts_client
.get_l2_output_at_block(request.start_block - 1)
.get_l2_output_at_block(request.aggchain_proof_request.start_block - 1)
.await
.map_err(Error::L2ChainDataRetrievalError)?;

let _claim_root_output_at_block = contracts_client
.get_l2_output_at_block(request.end_block)
.get_l2_output_at_block(request.aggchain_proof_request.max_end_block)
.await
.map_err(Error::L2ChainDataRetrievalError)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/aggchain-proof-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tokio.workspace = true
tracing.workspace = true
url.workspace = true

aggchain-proof-core.workspace = true
aggchain-proof-types.workspace = true
prover-alloy.workspace = true
prover-utils.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/aggchain-proof-contracts/src/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aggchain_proof_core::Digest;
use aggchain_proof_types::Digest;
use alloy::network::Ethereum;
use alloy::sol;

Expand Down
2 changes: 1 addition & 1 deletion crates/aggchain-proof-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod error;
use std::str::FromStr;
use std::sync::Arc;

use aggchain_proof_core::Digest;
use aggchain_proof_types::Digest;
use alloy::primitives::B256;
use jsonrpsee::core::client::ClientT;
use jsonrpsee::http_client::HttpClient;
Expand Down
2 changes: 2 additions & 0 deletions crates/aggchain-proof-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", tag = "patch
"keccak",
] }

aggchain-proof-types.workspace = true

[dev-dependencies]
alloy.workspace = true
dotenvy.workspace = true
Expand Down
6 changes: 2 additions & 4 deletions crates/aggchain-proof-core/src/bridge/inserted_ger.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use aggchain_proof_types::{keccak256_combine, Digest};
use serde::{Deserialize, Serialize};

use crate::{
keccak::{digest::Digest, keccak256_combine},
local_exit_tree::{hasher::Keccak256Hasher, proof::LETMerkleProof},
};
use crate::local_exit_tree::{hasher::Keccak256Hasher, proof::LETMerkleProof};

impl L1InfoTreeLeaf {
/// Hashes the L1 Info Tree leaf.
Expand Down
3 changes: 1 addition & 2 deletions crates/aggchain-proof-core/src/bridge/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! A program that verifies the bridge integrity
use aggchain_proof_types::{keccak256_combine, Digest};
use alloy_primitives::{address, Address};
use alloy_sol_macro::sol;
use serde::{Deserialize, Serialize};
use sp1_cc_client_executor::io::EVMStateSketch;
use static_call::{execute_static_call, StaticCallError, StaticCallStage};

use crate::bridge::inserted_ger::InsertedGER;
use crate::keccak::digest::Digest;
use crate::keccak::keccak256_combine;

mod inserted_ger;
mod static_call;
Expand Down
3 changes: 1 addition & 2 deletions crates/aggchain-proof-core/src/bridge/static_call.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use aggchain_proof_types::Digest;
use alloy_primitives::Address;
use alloy_sol_types::SolCall;
use sp1_cc_client_executor::{io::EVMStateSketch, ClientExecutor, ContractInput};

use crate::keccak::digest::Digest;

/// Context giver about the stage of the error.
#[derive(Clone, Debug)]
pub enum StaticCallStage {
Expand Down
3 changes: 2 additions & 1 deletion crates/aggchain-proof-core/src/full_execution_proof.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use aggchain_proof_types::{keccak256_combine, Digest};
use serde::{Deserialize, Serialize};
#[cfg(target_os = "zkvm")]
use sha2::{Digest as Sha256Digest, Sha256};
use sp1_zkvm::lib::utils::words_to_bytes_le;

use crate::{error::ProofError, keccak::digest::Digest, keccak::keccak256_combine};
use crate::error::ProofError;

type Vkey = [u32; 8];

Expand Down
5 changes: 2 additions & 3 deletions crates/aggchain-proof-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mod bridge;
pub mod error;
mod full_execution_proof;
mod keccak;
mod local_exit_tree;
pub mod proof;
mod proof;

pub use keccak::digest::Digest;
pub use proof::AggchainProofWitness;
3 changes: 1 addition & 2 deletions crates/aggchain-proof-core/src/local_exit_tree/hasher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use aggchain_proof_types::{keccak256_combine, Digest};
use serde::{Deserialize, Serialize};

use crate::keccak::{digest::Digest, keccak256_combine};

/// A hasher used in constructing a [`super::LocalExitTree`].
pub trait Hasher {
type Digest;
Expand Down
28 changes: 1 addition & 27 deletions crates/aggchain-proof-core/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use aggchain_proof_types::Digest;
use serde::{Deserialize, Serialize};

use crate::{
bridge::{BridgeConstraintsInput, BridgeWitness, L2_GER_ADDR},
error::ProofError,
full_execution_proof::FepWithPublicValues,
keccak::digest::Digest,
};

/// Aggchain proof is generated from the FEP proof and additional
Expand Down Expand Up @@ -88,29 +88,3 @@ pub struct AggchainProofPublicValues {
/// Chain-specific commitment forwarded by the PP.
pub aggchain_params: Digest,
}

/// Leaf tree inclusion proof.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct InclusionProof {
pub siblings: Vec<Digest>,
}

/// L1 info tree leaf, part of the
/// L1 info tree.
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct L1InfoTreeLeaf {
/// Previous block hash of leaf.
pub previous_block_hash: Digest,
/// Block number timestamp.
pub timestamp: u64,
/// Mainnet exit root hash.
pub mainnet_exit_root_hash: Digest,
/// Rollup exit root hash.
pub rollup_exit_root_hash: Digest,
/// Global exit root hash.
pub global_exit_root_hash: Digest,
/// Leaf hash.
pub leaf_hash: Digest,
/// Leaf index.
pub l1_info_tree_index: u32,
}
3 changes: 1 addition & 2 deletions crates/aggchain-proof-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ tower = { workspace = true, features = ["timeout"] }
tracing.workspace = true

aggchain-proof-builder.workspace = true
aggchain-proof-core.workspace = true
aggkit-prover-types.workspace = true
aggchain-proof-types.workspace = true
proposer-service.workspace = true
prover-alloy.workspace = true
Loading

0 comments on commit dc3368c

Please sign in to comment.