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: refactor and update proof types #87

Draft
wants to merge 1 commit into
base: bridge-proof-remaining
Choose a base branch
from
Draft
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
29 changes: 22 additions & 7 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 @@ -15,7 +15,7 @@ url.workspace = true

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

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

Expand All @@ -10,8 +9,7 @@ use aggchain_proof_contracts::contracts::{
};
use aggchain_proof_contracts::{AggchainContractsClient, AggchainContractsRpcClient};
use aggchain_proof_core::proof::AggchainProofWitness;
use aggkit_prover_types::v1::{InclusionProof, L1InfoTreeLeaf};
use aggkit_prover_types::Hash;
use aggchain_proof_types::AggchainProofRequest;
pub use error::Error;
use futures::{future::BoxFuture, FutureExt};
use prover_alloy::AlloyFillProvider;
Expand Down Expand Up @@ -44,22 +42,11 @@ 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).
/// Last block in the agg_span_proof provided by the proposer.
/// Could be different from the max_end_block requested by the agg-sender.
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 @@ -128,7 +115,7 @@ 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)?;

Expand All @@ -138,7 +125,7 @@ impl<ContractsClient> AggchainProofBuilder<ContractsClient> {
.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)?;

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: 1 addition & 1 deletion crates/aggchain-proof-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod bridge;
pub mod error;
mod full_execution_proof;
mod keccak;
pub mod keccak;
mod local_exit_tree;
pub mod proof;

Expand Down
4 changes: 2 additions & 2 deletions crates/aggchain-proof-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ workspace = true

[dependencies]
anyhow = { workspace = true }
alloy-primitives.workspace = true
futures.workspace = true
serde.workspace = true
sp1-sdk = { workspace = true }
Expand All @@ -17,7 +18,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
41 changes: 13 additions & 28 deletions crates/aggchain-proof-service/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::{
future::Future,
pin::Pin,
Expand All @@ -7,8 +6,8 @@ use std::{
};

use aggchain_proof_builder::{AggchainProofBuilder, AggchainProofBuilderResponse};
use aggkit_prover_types::v1::{InclusionProof, L1InfoTreeLeaf};
use aggkit_prover_types::Hash;
use aggchain_proof_types::AggchainProofRequest;
use alloy_primitives::B256;
use futures::{FutureExt as _, TryFutureExt};
use proposer_service::{ProposerRequest, ProposerService};
use sp1_sdk::SP1Proof;
Expand All @@ -20,23 +19,9 @@ use crate::error::Error;
/// A request for the AggchainProofService to generate the
/// aggchain proof for the range of blocks.
#[derive(Default, Clone, Debug)]
#[allow(unused)]
pub struct AggchainProofServiceRequest {
/// Aggchain proof starting block
pub start_block: u64,
/// Max number of blocks that the aggchain proof is allowed to contain
pub max_block: u64,
/// Root hash of the L1 info tree.
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
pub aggchain_proof_request: AggchainProofRequest,
}

/// Resulting generated Aggchain proof
Expand Down Expand Up @@ -129,12 +114,16 @@ impl tower::Service<AggchainProofServiceRequest> for AggchainProofService {
}

fn call(&mut self, req: AggchainProofServiceRequest) -> Self::Future {
let l1_block_number = req.max_block;
let l1_block_hash = req
.aggchain_proof_request
.l1_info_tree_leaf
.inner_leaf
.block_hash;

let proposer_request = ProposerRequest {
start_block: req.start_block,
max_block: req.max_block,
l1_block_number,
start_block: req.aggchain_proof_request.start_block,
max_block: req.aggchain_proof_request.max_end_block,
l1_block_hash: B256::from(l1_block_hash.0),
};

let mut proof_builder = self.aggchain_proof_builder.clone();
Expand All @@ -146,12 +135,8 @@ impl tower::Service<AggchainProofServiceRequest> for AggchainProofService {
let aggchain_proof_builder_request =
aggchain_proof_builder::AggchainProofBuilderRequest {
agg_span_proof: agg_span_proof_response.agg_span_proof,
start_block: agg_span_proof_response.start_block,
end_block: agg_span_proof_response.end_block,
l1_info_tree_merkle_proof: req.l1_info_tree_merkle_proof,
l1_info_tree_leaf: req.l1_info_tree_leaf,
l1_info_tree_root_hash: req.l1_info_tree_root_hash,
ger_inclusion_proofs: req.ger_inclusion_proofs,
aggchain_proof_request: req.aggchain_proof_request,
};

proof_builder
Expand Down
20 changes: 20 additions & 0 deletions crates/aggchain-proof-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "aggchain-proof-types"
version.workspace = true
edition.workspace = true
license.workspace = true

[dependencies]
alloy-primitives.workspace = true
anyhow.workspace = true
hex.workspace = true
serde.workspace = true
thiserror.workspace = true
tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", tag = "patch-2.0.2-sp1-4.0.0", features = [
"keccak",
] }

aggchain-proof-core.workspace = true

[lints]
workspace = true
12 changes: 12 additions & 0 deletions crates/aggchain-proof-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod proof;

pub use aggchain_proof_core::keccak::{digest::Digest, keccak256_combine};
pub use proof::*;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub enum NetworkIndex {
#[default]
Mainnet,
Rollup(u32),
}
Loading
Loading