Skip to content

wip bincode #149

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

Draft
wants to merge 6 commits into
base: master
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
707 changes: 288 additions & 419 deletions Cargo.lock

Large diffs are not rendered by default.

43 changes: 20 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ openvm-transpiler = { git = "https://github.com/openvm-org/openvm.git", rev = "5
openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", tag = "v1.1.1" }
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }

sbv-core = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "chore/openvm-1.3", features = ["scroll"] }
sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "chore/openvm-1.3", features = ["scroll", "serde", "rkyv"] }
sbv-kv = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "chore/openvm-1.3" }
sbv-trie = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "chore/openvm-1.3" }
sbv-precompile = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "chore/openvm-1.3" }
sbv-core = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "feat/bump-reth", features = ["scroll"] }
sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "feat/bump-reth", features = ["scroll", "serde"] }
sbv-kv = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "feat/bump-reth" }
sbv-trie = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "feat/bump-reth" }
sbv-precompile = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "feat/bump-reth" }


alloy-primitives = { version = "1.2", default-features = false, features = ["std", "map-hashbrown", "map-fxhash", "rkyv"] }
alloy-primitives = { version = "1.3", default-features = false, features = ["std", "map-hashbrown", "map-fxhash"] }
alloy-serde = { version = "1.0.13", default-features = false }
bitcode = { version = "0.6.5", default-features = false, features = ["serde", "derive"] }
bincode_v1 = { version = "1.3", package = "bincode"}
bincode = { version = "2.0" }
bincode = { version = "2.0", features = ["serde"] }
cargo_metadata = "0.20"
c-kzg = { version = "2.0" }
derivative = "2.2.0"
Expand All @@ -82,7 +82,7 @@ metrics-util = "0.17"
metrics-tracing-context = "0.16.0"
rayon = "1.10"
rkyv = "0.8"
revm = "=24.0.0"
revm = "=27.1.0"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1.0" }
serde_with = "3.11.0"
Expand Down Expand Up @@ -110,21 +110,18 @@ scroll-zkvm-prover = { path = "crates/prover" }
scroll-zkvm-verifier = { path = "crates/verifier" }

[patch.crates-io]
revm = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-bytecode = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-context = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-context-interface = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-database = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-database-interface = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-handler = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-inspector = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }
revm-state = { git = "https://github.com/scroll-tech/revm", branch = "feat/reth-v78" }

ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.15.0" }
alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v1.2.0" }
revm = { git = "https://github.com/scroll-tech/revm" }
revm-bytecode = { git = "https://github.com/scroll-tech/revm" }
revm-context = { git = "https://github.com/scroll-tech/revm" }
revm-context-interface = { git = "https://github.com/scroll-tech/revm" }
revm-database = { git = "https://github.com/scroll-tech/revm" }
revm-database-interface = { git = "https://github.com/scroll-tech/revm" }
revm-handler = { git = "https://github.com/scroll-tech/revm" }
revm-inspector = { git = "https://github.com/scroll-tech/revm" }
revm-interpreter = { git = "https://github.com/scroll-tech/revm" }
revm-precompile = { git = "https://github.com/scroll-tech/revm" }
revm-primitives = { git = "https://github.com/scroll-tech/revm" }
revm-state = { git = "https://github.com/scroll-tech/revm" }

[profile.maxperf]
inherits = "release"
Expand Down
1 change: 1 addition & 0 deletions crates/circuits/batch-circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repository.workspace = true
version = "0.5.0"

[dependencies]
bincode.workspace = true
scroll-zkvm-types-circuit.workspace = true
scroll-zkvm-types-batch.workspace = true

Expand Down
18 changes: 11 additions & 7 deletions crates/circuits/batch-circuit/src/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_primitives::B256;
use scroll_zkvm_types_batch::ArchivedBatchWitness;
use scroll_zkvm_types_batch::BatchWitness;
use scroll_zkvm_types_circuit::{
AggCircuit, AggregationInput, Circuit, ProgramCommitment,
io::read_witnesses,
Expand All @@ -25,7 +25,7 @@ openvm::init!();
pub struct BatchCircuit;

impl Circuit for BatchCircuit {
type Witness = ArchivedBatchWitness;
type Witness = BatchWitness;

type PublicInputs = VersionedBatchInfo;

Expand All @@ -34,12 +34,16 @@ impl Circuit for BatchCircuit {
}

fn deserialize_witness(witness_bytes: &[u8]) -> &Self::Witness {
rkyv::access::<ArchivedBatchWitness, rkyv::rancor::BoxedError>(witness_bytes)
.expect("BatchCircuit: rkyc deserialisation of witness bytes failed")
let config = bincode::config::standard();
let (witness, _): (Self::Witness, _) =
bincode::serde::decode_from_slice(witness_bytes, config).unwrap();
Box::leak(Box::new(witness))
// rkyv::access::<ArchivedBatchWitness, rkyv::rancor::BoxedError>(witness_bytes)
// .expect("BatchCircuit: rkyc deserialisation of witness bytes failed")
}

fn validate(witness: &Self::Witness) -> Self::PublicInputs {
(BatchInfo::from(witness), (&witness.fork_name).into())
(BatchInfo::from(witness), (witness.fork_name.clone()))
}
}

Expand All @@ -64,11 +68,11 @@ impl AggCircuit for BatchCircuit {
}

fn aggregated_public_inputs(witness: &Self::Witness) -> Vec<Self::AggregatedPublicInputs> {
let fork_name = (&witness.fork_name).into();
let fork_name = (witness.fork_name).clone();
witness
.chunk_infos
.iter()
.map(|archived| (archived.into(), fork_name))
.map(|archived| (archived.clone(), fork_name))
.collect()
}

Expand Down
1 change: 1 addition & 0 deletions crates/circuits/bundle-circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repository.workspace = true
version = "0.5.0"

[dependencies]
bincode.workspace = true
scroll-zkvm-types-circuit.workspace = true
scroll-zkvm-types-bundle.workspace = true

Expand Down
18 changes: 11 additions & 7 deletions crates/circuits/bundle-circuit/src/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_primitives::B256;
use scroll_zkvm_types_bundle::ArchivedBundleWitness;
use scroll_zkvm_types_bundle::BundleWitness;
use scroll_zkvm_types_circuit::{
AggCircuit, AggregationInput, Circuit, ProgramCommitment,
io::read_witnesses,
Expand All @@ -18,7 +18,7 @@ use openvm_keccak256_guest;
pub struct BundleCircuit;

impl Circuit for BundleCircuit {
type Witness = ArchivedBundleWitness;
type Witness = BundleWitness;

type PublicInputs = VersionedBundleInfo;

Expand All @@ -27,12 +27,16 @@ impl Circuit for BundleCircuit {
}

fn deserialize_witness(witness_bytes: &[u8]) -> &Self::Witness {
rkyv::access::<ArchivedBundleWitness, rkyv::rancor::BoxedError>(witness_bytes)
.expect("BundleCircuit: rkyv deserialization of witness bytes failed")
let config = bincode::config::standard();
let (witness, _): (Self::Witness, _) =
bincode::serde::decode_from_slice(witness_bytes, config).unwrap();
Box::leak(Box::new(witness))
// rkyv::access::<ArchivedBundleWitness, rkyv::rancor::BoxedError>(witness_bytes)
// .expect("BundleCircuit: rkyv deserialization of witness bytes failed")
}

fn validate(witness: &Self::Witness) -> Self::PublicInputs {
(BundleInfo::from(witness), (&witness.fork_name).into())
(BundleInfo::from(witness), (witness.fork_name).clone())
}
}

Expand All @@ -57,11 +61,11 @@ impl AggCircuit for BundleCircuit {
}

fn aggregated_public_inputs(witness: &Self::Witness) -> Vec<Self::AggregatedPublicInputs> {
let fork_name = (&witness.fork_name).into();
let fork_name = (witness.fork_name).clone();
witness
.batch_infos
.iter()
.map(|archived| (archived.into(), fork_name))
.map(|archived| (archived.clone(), fork_name))
.collect()
}

Expand Down
1 change: 1 addition & 0 deletions crates/circuits/chunk-circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repository.workspace = true
version = "0.5.0"

[dependencies]
bincode = { workspace = true, features = ["serde"] }
scroll-zkvm-types-circuit = { workspace = true }
scroll-zkvm-types-chunk = { workspace = true }
sbv-precompile = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/circuits/chunk-circuit/chunk_exe_commit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
//! Generated by crates/build-guest. DO NOT EDIT!

pub const COMMIT: [u32; 8] = [1071419318, 13542696, 228098146, 1154682103, 1049712254, 1415629403, 1604860768, 985830407];
pub const COMMIT: [u32; 8] = [1800085633, 726233151, 1518603456, 652109740, 581790696, 729545535, 1686720310, 1475009617];
18 changes: 10 additions & 8 deletions crates/circuits/chunk-circuit/src/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use openvm::init;
use scroll_zkvm_types_chunk::ArchivedChunkWitness;
use scroll_zkvm_types_chunk::{ChunkWitness, execute};
use scroll_zkvm_types_circuit::{
Circuit,
io::read_witnesses,
Expand All @@ -22,22 +22,24 @@ init!();
pub struct ChunkCircuit;

impl Circuit for ChunkCircuit {
type Witness = ArchivedChunkWitness;
type Witness = ChunkWitness;
type PublicInputs = VersionedChunkInfo;

fn read_witness_bytes() -> Vec<u8> {
read_witnesses()
}

fn deserialize_witness(witness_bytes: &[u8]) -> &Self::Witness {
rkyv::access::<ArchivedChunkWitness, rkyv::rancor::BoxedError>(witness_bytes)
.expect("ChunkCircuit: rkyv deserialisation of witness bytes failed")
let config = bincode::config::standard();
let (witness, _): (Self::Witness, _) =
bincode::serde::decode_from_slice(witness_bytes, config).unwrap();
Box::leak(Box::new(witness))
// rkyv::access::<ArchivedChunkWitness, rkyv::rancor::BoxedError>(witness_bytes)
// .expect("ChunkCircuit: rkyv deserialisation of witness bytes failed")
}

fn validate(witness: &Self::Witness) -> Self::PublicInputs {
(
ChunkInfo::try_from(witness).expect("failed to execute chunk"),
(&witness.fork_name).into(),
)
let info = execute(witness).unwrap();
(info, (witness.fork_name.clone()))
}
}
4 changes: 2 additions & 2 deletions crates/integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ static DIR_TESTRUN: OnceCell<PathBuf> = OnceCell::new();
/// Circuit that implements functionality required to run e2e tests in specified phase (chunk/batch/bundle).
pub trait ProverTester {
/// Tester witness type
type Witness: rkyv::Archive + PartialProvingTask;
type Witness: PartialProvingTask;// + rkyv::Archive;

/// Tester metadata type
type Metadata: for<'a> TryFrom<&'a <Self::Witness as rkyv::Archive>::Archived>;
type Metadata;//: for<'a> TryFrom<&'a <Self::Witness as rkyv::Archive>::Archived>;

/// Naming for tester
const NAME: &str;
Expand Down
2 changes: 1 addition & 1 deletion crates/integration/src/testers/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl PartialProvingTask for BatchWitness {
}

fn write_guest_input(&self, stdin: &mut openvm_sdk::StdIn) -> Result<(), rkyv::rancor::Error> {
let b = rkyv::to_bytes::<rkyv::rancor::Error>(self)?;
let b = self.bincode_serialize(None).unwrap();
stdin.write_bytes(b.as_slice());
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/integration/src/testers/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl PartialProvingTask for BundleWitness {
}

fn write_guest_input(&self, stdin: &mut openvm_sdk::StdIn) -> Result<(), rkyv::rancor::Error> {
let b = self.rkyv_serialize(None)?;
let b = self.bincode_serialize(None).unwrap();
stdin.write_bytes(b.as_slice());
Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions crates/integration/src/testers/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use sbv_primitives::{B256, types::BlockWitness};
use sbv_primitives::{B256, BlockWitness};
use scroll_zkvm_types::{
chunk::{ChunkInfo, ChunkWitness},
proof::ProofEnum,
Expand Down Expand Up @@ -34,8 +34,9 @@ where
println!("File not found: {:?}", path_witness.as_ref());
return Err(eyre::eyre!("File not found: {:?}", path_witness.as_ref()));
}
let witness = File::open(path_witness)?;
Ok(serde_json::from_reader::<_, BlockWitness>(witness)?)
let content = std::fs::read(path_witness)?;
let result = BlockWitness::from_json_slice(&content)?;
Ok(result)
}

pub struct ChunkProverTester;
Expand Down
18 changes: 4 additions & 14 deletions crates/integration/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::testing_hardfork;
use sbv_primitives::{
B256,
types::{BlockWitness, Transaction, eips::Encodable2718, reth::primitives::TransactionSigned},
B256, BlockWitness, Transaction, U256, eips::Encodable2718, reth::primitives::TransactionSigned,
};
use scroll_zkvm_types::{
batch::{
Expand Down Expand Up @@ -105,26 +104,17 @@ impl From<&BatchHeaderV7> for LastHeader {
}

pub fn metadata_from_chunk_witnesses(witness: &ChunkWitness) -> eyre::Result<ChunkInfo> {
use scroll_zkvm_types::chunk::ArchivedChunkWitness;
let bytes = witness.rkyv_serialize(None)?;
let archieved_wit = rkyv::access::<ArchivedChunkWitness, rkyv::rancor::BoxedError>(&bytes)?;
archieved_wit
witness
.try_into()
.map_err(|e| eyre::eyre!("get chunk metadata fail {e}"))
}

pub fn metadata_from_batch_witnesses(witness: &BatchWitness) -> eyre::Result<BatchInfo> {
use scroll_zkvm_types::batch::ArchivedBatchWitness;
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(witness)?;
let archieved_wit = rkyv::access::<ArchivedBatchWitness, rkyv::rancor::BoxedError>(&bytes)?;
Ok(archieved_wit.into())
Ok(witness.into())
}

pub fn metadata_from_bundle_witnesses(witness: &BundleWitness) -> eyre::Result<BundleInfo> {
use scroll_zkvm_types::bundle::ArchivedBundleWitness;
let bytes = witness.rkyv_serialize(None)?;
let archieved_wit = rkyv::access::<ArchivedBundleWitness, rkyv::rancor::BoxedError>(&bytes)?;
Ok(archieved_wit.into())
Ok(witness.into())
}

pub fn build_batch_witnesses(
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub mod as_base64 {

pub mod point_eval {
use c_kzg;
use sbv_primitives::{B256 as H256, U256, types::eips::eip4844::BLS_MODULUS};
use sbv_primitives::{B256 as H256, U256, eips::eip4844::BLS_MODULUS};

/// Given the blob-envelope, translate it to a fixed size EIP-4844 blob.
///
Expand Down
34 changes: 1 addition & 33 deletions crates/types/base/src/public_inputs/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,26 @@ use crate::{
};

/// Represents public-input values for a batch.
#[derive(
Clone,
Debug,
rkyv::Archive,
rkyv::Deserialize,
rkyv::Serialize,
serde::Deserialize,
serde::Serialize,
)]
#[rkyv(derive(Debug))]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct BatchInfo {
/// The state root before applying the batch.
#[rkyv()]
pub parent_state_root: B256,
/// The batch hash of the parent batch.
#[rkyv()]
pub parent_batch_hash: B256,
/// The state root after applying txs in the batch.
#[rkyv()]
pub state_root: B256,
/// The batch header hash of the batch.
#[rkyv()]
pub batch_hash: B256,
/// The EIP-155 chain ID of all txs in the batch.
#[rkyv()]
pub chain_id: u64,
/// The withdraw root of the last block in the last chunk in the batch.
#[rkyv()]
pub withdraw_root: B256,
/// The L1 msg queue hash at the end of the previous batch.
#[rkyv()]
pub prev_msg_queue_hash: B256,
/// The L1 msg queue hash at the end of the current batch.
#[rkyv()]
pub post_msg_queue_hash: B256,
}

impl From<&ArchivedBatchInfo> for BatchInfo {
fn from(archived: &ArchivedBatchInfo) -> Self {
Self {
parent_state_root: archived.parent_state_root.into(),
parent_batch_hash: archived.parent_batch_hash.into(),
state_root: archived.state_root.into(),
batch_hash: archived.batch_hash.into(),
chain_id: archived.chain_id.into(),
withdraw_root: archived.withdraw_root.into(),
prev_msg_queue_hash: archived.prev_msg_queue_hash.into(),
post_msg_queue_hash: archived.post_msg_queue_hash.into(),
}
}
}

impl BatchInfo {
/// Public input hash for a batch (euclidv1 or da-codec@v6) is defined as
///
Expand Down
Loading