Skip to content

feat: bincode2 #156

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 5 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
54 changes: 46 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ alloy-primitives = { version = "1.2", default-features = false, features = ["std
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 Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ clean-guest:
build-guest:
sh build-guest.sh

build-guest-local:
bash build-guest-actions-entrypoint.sh

clean-build-guest: clean-guest build-guest

clean-test-cache:
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
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
3 changes: 2 additions & 1 deletion crates/integration/src/testers/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ impl PartialProvingTask for ChunkWitness {
}

fn write_guest_input(&self, stdin: &mut openvm_sdk::StdIn) -> Result<(), rkyv::rancor::Error> {
stdin.write_bytes(self.rkyv_serialize(None)?.as_slice());
let b = self.bincode_serialize(None).unwrap();
stdin.write_bytes(b.as_slice());
Ok(())
}

Expand Down
Loading