Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Aug 30, 2024
1 parent d14ea0c commit 748b202
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 542 deletions.
377 changes: 16 additions & 361 deletions Cargo.lock

Large diffs are not rendered by default.

114 changes: 22 additions & 92 deletions programs/aggregation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@
#[cfg(target_os = "zkvm")]
sp1_zkvm::entrypoint!(main);

<<<<<<< HEAD:client-programs/aggregation/src/main.rs
use alloy_consensus::Header;
use alloy_primitives::B256;
use alloy_sol_types::SolValue;
use client_utils::{boot::BootInfoStruct, types::AggregationInputs};
use sha2::{Digest, Sha256};
=======
>>>>>>> origin/main:programs/aggregation/src/main.rs
use std::collections::HashMap;

use alloy_consensus::Header;
use alloy_primitives::B256;
use itertools::Itertools;
use op_succinct_client_utils::{types::AggregationInputs, RawBootInfo};
use op_succinct_client_utils::{types::AggregationInputs, boot::BootInfoStruct};
use sha2::{Digest, Sha256};

/// The verification key for the multi-block program.
Expand All @@ -30,55 +23,46 @@ use sha2::{Digest, Sha256};
const MULTI_BLOCK_PROGRAM_VKEY_DIGEST: [u32; 8] =
[1807316243, 1400630407, 873277975, 658999266, 422343326, 774525422, 1268417967, 711858264];

<<<<<<< HEAD:client-programs/aggregation/src/main.rs
/// Verify that the L1 heads in the boot infos are in the header chain.
fn verify_l1_heads(agg_inputs: &AggregationInputs, headers: &[Header]) {
// Create a map of each l1_head in the BootInfo's to booleans
let mut l1_heads_map: HashMap<B256, bool> = agg_inputs
.boot_infos
.iter()
.map(|boot_info| (boot_info.l1Head, false))
.collect();
=======
fn main() {
// Read in the aggregation inputs corresponding to each multi-block proof.
pub fn main() {
// Read in the public values corresponding to each multi-block proof.
let agg_inputs = sp1_zkvm::io::read::<AggregationInputs>();

// Read in the headers.
//
// Note: The headers are in order from start to end. We use [serde_cbor] as bincode
// serialization causes issues with the zkVM.
// Note: The headers are in order from start to end. We use serde_cbor as bincode serialization causes
// issues with the zkVM.
let headers_bytes = sp1_zkvm::io::read_vec();
let headers: Vec<Header> = serde_cbor::from_slice(&headers_bytes).unwrap();
assert!(!agg_inputs.boot_infos.is_empty());

// Confirm that the boot infos are sequential.
agg_inputs.boot_infos.iter().tuples().for_each(|(prev_boot_info, curr_boot_info)| {
// The claimed block of the previous boot info must be the l2 output root of the current
// boot.
assert_eq!(prev_boot_info.l2_claim, curr_boot_info.l2_output_root);
agg_inputs.boot_infos.windows(2).for_each(|pair| {
let (prev_boot_info, boot_info) = (&pair[0], &pair[1]);

// The claimed block of the previous boot info must be the L2 output root of the current boot.
assert_eq!(prev_boot_info.l2PostRoot, boot_info.l2PreRoot);

// The chain id must be the same for all the boot infos, to ensure they're
// The chain ID must be the same for all the boot infos, to ensure they're
// from the same chain and span batch range.
assert_eq!(prev_boot_info.chain_id, curr_boot_info.chain_id);
assert_eq!(prev_boot_info.chainId, boot_info.chainId);

// The rollup config must be the same for all the boot infos, to ensure they're
// from the same chain and span batch range.
assert_eq!(prev_boot_info.rollupConfigHash, boot_info.rollupConfigHash);
});

// Verify each multi-block program proof.
agg_inputs.boot_infos.iter().for_each(|boot_info| {
// Compute the public values digest as the hash of the abi-encoded [`RawBootInfo`].
// In the multi-block program, the public values digest is just the hash of the ABI encoded
// boot info.
let abi_encoded_boot_info = boot_info.abi_encode();
let pv_digest = Sha256::digest(abi_encoded_boot_info);

// Verify the proof against the public values digest.
if cfg!(target_os = "zkvm") {
sp1_lib::verify::verify_sp1_proof(&MULTI_BLOCK_PROGRAM_VKEY_DIGEST, &pv_digest.into());
}
});

// Create a map of each l1 head in the [`RawBootInfo`]s to booleans
// Create a map of each l1 head in the [`RawBootInfo`]'s to booleans
let mut l1_heads_map: HashMap<B256, bool> =
agg_inputs.boot_infos.iter().map(|boot_info| (boot_info.l1_head, false)).collect();
>>>>>>> origin/main:programs/aggregation/src/main.rs
agg_inputs.boot_infos.iter().map(|boot_info| (boot_info.l1_head, false)).collect();

// Iterate through the headers in reverse order. The headers should be sequentially linked and
// include the l1 head of each boot info.
Expand All @@ -98,48 +82,6 @@ fn main() {
for (l1_head, found) in l1_heads_map.iter() {
assert!(*found, "l1 head {:?} not found in the provided header chain", l1_head);
}
<<<<<<< HEAD:client-programs/aggregation/src/main.rs
}

pub fn main() {
// Read in the public values corresponding to each multi-block proof.
let agg_inputs = sp1_zkvm::io::read::<AggregationInputs>();
// Note: The headers are in order from start to end. We use serde_cbor as bincode serialization causes
// issues with the zkVM.
let headers_bytes = sp1_zkvm::io::read_vec();
let headers: Vec<Header> = serde_cbor::from_slice(&headers_bytes).unwrap();
assert!(!agg_inputs.boot_infos.is_empty());

// Confirm that the boot infos are sequential.
agg_inputs.boot_infos.windows(2).for_each(|pair| {
let (prev_boot_info, boot_info) = (&pair[0], &pair[1]);

// The claimed block of the previous boot info must be the L2 output root of the current boot.
assert_eq!(prev_boot_info.l2PostRoot, boot_info.l2PreRoot);

// The chain ID must be the same for all the boot infos, to ensure they're
// from the same chain and span batch range.
assert_eq!(prev_boot_info.chainId, boot_info.chainId);

// The rollup config must be the same for all the boot infos, to ensure they're
// from the same chain and span batch range.
assert_eq!(prev_boot_info.rollupConfigHash, boot_info.rollupConfigHash);
});

// Verify each multi-block program proof.
agg_inputs.boot_infos.iter().for_each(|boot_info| {
// In the multi-block program, the public values digest is just the hash of the ABI encoded
// boot info.
let abi_encoded_boot_info = boot_info.abi_encode();
let pv_digest = Sha256::digest(abi_encoded_boot_info);

if cfg!(target_os = "zkvm") {
sp1_lib::verify::verify_sp1_proof(&MULTI_BLOCK_PROGRAM_VKEY_DIGEST, &pv_digest.into());
}
});

// Verify the L1 heads of each boot info are on the L1.
verify_l1_heads(&agg_inputs, &headers);

let first_boot_info = &agg_inputs.boot_infos[0];
let last_boot_info = &agg_inputs.boot_infos[agg_inputs.boot_infos.len() - 1];
Expand All @@ -152,21 +94,9 @@ pub fn main() {
l1Head: agg_inputs.latest_l1_checkpoint_head,
chainId: last_boot_info.chainId,
rollupConfigHash: last_boot_info.rollupConfigHash,
=======

let first_boot_info = &agg_inputs.boot_infos[0];
let last_boot_info = &agg_inputs.boot_infos[agg_inputs.boot_infos.len() - 1];

// Consolidate the boot info into an aggregated [`RawBootInfo`] that proves the range.
let final_boot_info = RawBootInfo {
l2_output_root: first_boot_info.l2_output_root,
l2_claim_block: last_boot_info.l2_claim_block,
l2_claim: last_boot_info.l2_claim,
l1_head: agg_inputs.latest_l1_checkpoint_head,
chain_id: last_boot_info.chain_id,
>>>>>>> origin/main:programs/aggregation/src/main.rs
};
}

Check failure on line 97 in programs/aggregation/src/main.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

expected `;`, found `sp1_zkvm`

// Commit to the aggregated [`RawBootInfo`].
sp1_zkvm::io::commit_slice(&final_boot_info.abi_encode());

}
10 changes: 1 addition & 9 deletions programs/fault-proof/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@ cfg_if! {
// from SP1 and compile to a program that can be run in zkVM.
if #[cfg(target_os = "zkvm")] {
sp1_zkvm::entrypoint!(main);
<<<<<<< HEAD:client-programs/fault-proof/src/main.rs
use client_utils::{InMemoryOracle, boot::BootInfoStruct, BootInfoWithBytesConfig};
use op_succinct_client_utils::{InMemoryOracle, boot::BootInfoStruct, BootInfoWithBytesConfig};
use kona_primitives::RollupConfig;
=======
use op_succinct_client_utils::{RawBootInfo, InMemoryOracle};
>>>>>>> origin/main:programs/fault-proof/src/main.rs
use alloc::vec::Vec;
use serde_json;
} else {
use kona_client::CachingOracle;
<<<<<<< HEAD:client-programs/fault-proof/src/main.rs
use client_utils::pipes::{ORACLE_READER, HINT_WRITER};
=======
use op_succinct_client_utils::pipes::{ORACLE_READER, HINT_WRITER};
>>>>>>> origin/main:programs/fault-proof/src/main.rs
}
}

Expand Down
6 changes: 1 addition & 5 deletions programs/range/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ repository.workspace = true
[dependencies]
# workspace (general)
cfg-if.workspace = true
<<<<<<< HEAD:client-programs/range/Cargo.toml
client-utils.workspace = true
serde_json.workspace = true
=======
op-succinct-client-utils.workspace = true
>>>>>>> origin/main:programs/range/Cargo.toml
serde_json.workspace = true

# workspace (ethereum)
op-alloy-consensus.workspace = true
Expand Down
13 changes: 1 addition & 12 deletions programs/range/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,16 @@ cfg_if! {
if #[cfg(target_os = "zkvm")] {
sp1_zkvm::entrypoint!(main);

<<<<<<< HEAD:client-programs/range/src/main.rs
use client_utils::{InMemoryOracle, BootInfoWithBytesConfig, boot::BootInfoStruct};
use kona_primitives::RollupConfig;
=======
use op_succinct_client_utils::{
RawBootInfo,
BootInfoWithBytesConfig, boot::BootInfoStruct,
InMemoryOracle
};
>>>>>>> origin/main:programs/range/src/main.rs
use alloc::vec::Vec;
use serde_json;
} else {
use kona_client::CachingOracle;
<<<<<<< HEAD:client-programs/range/src/main.rs
use client_utils::pipes::{ORACLE_READER, HINT_WRITER};
=======
use op_succinct_client_utils::pipes::{ORACLE_READER, HINT_WRITER};
>>>>>>> origin/main:programs/range/src/main.rs
}
}

Expand Down Expand Up @@ -89,11 +81,8 @@ fn main() {
oracle.verify().expect("key value verification failed");
println!("cycle-tracker-report-end: oracle-verify");
} else {
<<<<<<< HEAD:client-programs/range/src/main.rs
=======
// If we are compiling for online mode, create a caching oracle that speaks to the
// fetcher via hints, and gather boot info from this oracle.
>>>>>>> origin/main:programs/range/src/main.rs
let oracle = Arc::new(CachingOracle::new(1024, ORACLE_READER, HINT_WRITER));
let boot = Arc::new(BootInfo::load(oracle.as_ref()).await.unwrap());
}
Expand Down
17 changes: 2 additions & 15 deletions proposer/succinct/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ name = "vkey"
path = "bin/vkey.rs"

[[bin]]
<<<<<<< HEAD:op-succinct-proposer/Cargo.toml
name = "fetch-rollup-config"
path = "bin/fetch_rollup_config.rs"
=======

[[bin]]
name = "cost_estimator"
path = "bin/cost_estimator.rs"

Expand All @@ -34,7 +34,6 @@ path = "bin/load_stdin.rs"
[[bin]]
name = "span_batch_ranges"
path = "bin/span_batch_ranges.rs"
>>>>>>> origin/main:proposer/succinct/Cargo.toml

[dependencies]

Expand All @@ -48,22 +47,14 @@ kona-host = { workspace = true }
kona-primitives.workspace = true

# local
<<<<<<< HEAD:op-succinct-proposer/Cargo.toml
host-utils.workspace = true
client-utils.workspace = true
=======
op-succinct-host-utils.workspace = true
>>>>>>> origin/main:proposer/succinct/Cargo.toml

# sp1
sp1-sdk = { workspace = true }

anyhow.workspace = true
dotenv.workspace = true
<<<<<<< HEAD:op-succinct-proposer/Cargo.toml
=======
op-succinct-client-utils.workspace = true
>>>>>>> origin/main:proposer/succinct/Cargo.toml
serde = { workspace = true }
serde_json.workspace = true

Expand All @@ -77,16 +68,12 @@ tower-http.workspace = true
cargo_metadata.workspace = true
revm.workspace = true
reqwest.workspace = true
<<<<<<< HEAD:op-succinct-proposer/Cargo.toml
=======
futures.workspace = true
itertools.workspace = true
csv.workspace = true
rayon = "1.10.0"
lazy_static = "1.5.0"
uuid = "1.10.0"
>>>>>>> origin/main:proposer/succinct/Cargo.toml

[build-dependencies]
sp1-build = { workspace = true }
cargo_metadata.workspace = true
7 changes: 1 addition & 6 deletions proposer/succinct/bin/fetch_and_save_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ use alloy::hex;
use alloy::sol_types::SolValue;
use anyhow::Result;
use clap::Parser;
<<<<<<< HEAD:op-succinct-proposer/bin/fetch_and_save_proof.rs
use client_utils::boot::BootInfoStruct;
use client_utils::BOOT_INFO_SIZE;
=======
>>>>>>> origin/main:proposer/succinct/bin/fetch_and_save_proof.rs
use dotenv::dotenv;
use op_succinct_client_utils::{RawBootInfo, BOOT_INFO_SIZE};
use op_succinct_client_utils::{boot::BootInfoStruct, BOOT_INFO_SIZE};
use sp1_sdk::{NetworkProver, SP1ProofWithPublicValues};
use std::{fs, path::Path};

Expand Down
7 changes: 1 addition & 6 deletions proposer/succinct/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ use axum::{
Json, Router,
};
use base64::{engine::general_purpose, Engine as _};
<<<<<<< HEAD:op-succinct-proposer/bin/server.rs
use client_utils::boot::BootInfoStruct;
use host_utils::{fetcher::SP1KonaDataFetcher, get_agg_proof_stdin, get_proof_stdin, ProgramType};
=======
>>>>>>> origin/main:proposer/succinct/bin/server.rs
use log::info;
use op_succinct_client_utils::{RawBootInfo, BOOT_INFO_SIZE};
use op_succinct_client_utils::{boot::BootInfoStruct, BOOT_INFO_SIZE};
use op_succinct_host_utils::{
fetcher::OPSuccinctDataFetcher, get_agg_proof_stdin, get_proof_stdin, ProgramType,
};
Expand Down
1 change: 0 additions & 1 deletion scripts/prove/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ alloy-sol-types = { workspace = true }
anyhow.workspace = true
dotenv.workspace = true
num-format.workspace = true
client-utils.workspace = true
revm.workspace = true
log.workspace = true

Expand Down
1 change: 0 additions & 1 deletion utils/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ kona-client.workspace = true
kona-preimage.workspace = true
kona-mpt.workspace = true
kona-derive.workspace = true
kona-common.workspace = true

# general
serde.workspace = true
Expand Down
11 changes: 5 additions & 6 deletions utils/client/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ use sha2::{Digest, Sha256};
// ABI encoding of BootInfo is 6 * 32 bytes.
pub const BOOT_INFO_SIZE: usize = 6 * 32;

/// Hash the serialized rollup config using SHA256. Note: The rollup config is never unrolled on-chain,
/// so switching to a different hash function is not a concern, as long as the config hash is
/// consistent with the one on the contract.
/// Hash the serialized rollup config using SHA256. Note: The rollup config is never unrolled
/// on-chain, so switching to a different hash function is not a concern, as long as the config hash
/// is consistent with the one on the contract.
pub fn hash_rollup_config(serialized_config: &Vec<u8>) -> B256 {
// Create a SHA256 hasher
let mut hasher = Sha256::new();

<<<<<<< HEAD:crates/client-utils/src/boot.rs
// Hash the serialized config
hasher.update(serialized_config.as_slice());

// Finalize and convert to B256
let hash = hasher.finalize();
B256::from_slice(hash.as_slice())
=======
}

impl From<RawBootInfo> for BootInfo {
/// Convert the BootInfoWithoutRollupConfig into BootInfo by deriving the RollupConfig.
fn from(boot_info_without_rollup_config: RawBootInfo) -> Self {
Expand All @@ -33,7 +33,6 @@ impl From<RawBootInfo> for BootInfo {

Self { l1_head, l2_output_root, l2_claim, l2_claim_block, chain_id, rollup_config }
}
>>>>>>> origin/main:utils/client/src/boot.rs
}

sol! {
Expand Down
4 changes: 0 additions & 4 deletions utils/client/src/oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ impl HintWriterClient for InMemoryOracle {
/// and verify it once, rather than verifying each of the 4096 elements separately.
#[derive(Default)]
struct Blob {
<<<<<<< HEAD:crates/client-utils/src/oracle/mod.rs
// TODO: This commitment is currently unused.
=======
>>>>>>> origin/main:utils/client/src/oracle/mod.rs
_commitment: FixedBytes<48>,
// 4096 Field elements, each 32 bytes.
data: FixedBytes<131072>,
Expand Down
Loading

0 comments on commit 748b202

Please sign in to comment.