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

o1vm/pickles: regression test for proof size #2758

Draft
wants to merge 2 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
1 change: 1 addition & 0 deletions Cargo.lock

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

43 changes: 22 additions & 21 deletions o1vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,42 @@ name = "pickles_o1vm"
path = "src/pickles/main.rs"

[dependencies]
o1-utils.workspace = true
# FIXME: Only activate this when legacy_o1vm is built
ark-bn254.workspace = true
# FIXME: Only activate this when legacy_o1vm is built
folding.workspace = true
# FIXME: Only activate this when legacy_o1vm is built
kimchi = { workspace = true, features = [ "bn254" ] }
kimchi-msm.workspace = true
poly-commitment.workspace = true
ark-ec.workspace = true
ark-ff.workspace = true
ark-poly.workspace = true
ark-serialize.workspace = true
base64.workspace = true
clap.workspace = true
command-fds.workspace = true
elf.workspace = true
env_logger.workspace = true
groupmap.workspace = true
hex.workspace = true
itertools.workspace = true
kimchi-msm.workspace = true
libc.workspace = true
libflate.workspace = true
log.workspace = true
mina-curves.workspace = true
mina-poseidon.workspace = true
elf.workspace = true
o1-utils.workspace = true
os_pipe.workspace = true
poly-commitment.workspace = true
rand.workspace = true
rayon.workspace = true
regex.workspace = true
rmp-serde.workspace = true
serde_json.workspace = true
serde.workspace = true
serde_with.workspace = true
sha3.workspace = true
stacker = "0.1"
ark-poly.workspace = true
ark-ff.workspace = true
ark-ec.workspace = true
clap.workspace = true
hex.workspace = true
regex.workspace = true
libflate.workspace = true
base64.workspace = true
strum.workspace = true
strum_macros.workspace = true
log.workspace = true
env_logger.workspace = true
command-fds.workspace = true
os_pipe.workspace = true
rand.workspace = true
libc.workspace = true
rayon.workspace = true
sha3.workspace = true
itertools.workspace = true
thiserror.workspace = true
3 changes: 3 additions & 0 deletions o1vm/src/pickles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ pub const DEGREE_QUOTIENT_POLYNOMIAL: u64 = 7;
/// added for the selectors.
pub const TOTAL_NUMBER_OF_CONSTRAINTS: usize = 464;

/// Proof size for a single proof.
pub const PROOF_SIZE: usize = 18994;

#[cfg(test)]
mod tests;
71 changes: 71 additions & 0 deletions o1vm/src/pickles/proof.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ark_serialize::CanonicalSerialize;
use kimchi::{curve::KimchiCurve, proof::PointEvaluations};
use poly_commitment::{ipa::OpeningProof, PolyComm};

Expand Down Expand Up @@ -37,3 +38,73 @@ pub struct Proof<G: KimchiCurve> {
/// IPA opening proof
pub opening_proof: OpeningProof<G>,
}

impl<G: KimchiCurve> Proof<G> {
// FIXME: improve by using serialize_compressed on proof directly. This way,
// if the proof structure change, we don't need to update this function.
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
let _ = &self
.commitments
.scratch
.iter()
.map(|v| v.chunks.serialize_compressed(&mut bytes))
.collect::<Vec<_>>();
let _ = self
.commitments
.instruction_counter
.chunks
.serialize_compressed(&mut bytes);
let _ = self
.commitments
.error
.chunks
.serialize_compressed(&mut bytes);
self.commitments.selector.iter().for_each(|sel| {
let _ = sel.chunks.serialize_compressed(&mut bytes);
});
self.zeta_evaluations.scratch.iter().for_each(|eval| {
let _ = eval.serialize_compressed(&mut bytes);
});
let _ = self
.zeta_evaluations
.instruction_counter
.serialize_compressed(&mut bytes);
let _ = self.zeta_evaluations.error.serialize_compressed(&mut bytes);
self.zeta_evaluations.selector.iter().for_each(|sel| {
let _ = sel.serialize_compressed(&mut bytes);
});
self.zeta_omega_evaluations.scratch.iter().for_each(|eval| {
let _ = eval.serialize_compressed(&mut bytes);
});
let _ = self
.zeta_omega_evaluations
.instruction_counter
.serialize_compressed(&mut bytes);
let _ = self
.zeta_omega_evaluations
.error
.serialize_compressed(&mut bytes);
self.zeta_omega_evaluations.selector.iter().for_each(|sel| {
let _ = sel.serialize_compressed(&mut bytes);
});
let _ = self
.quotient_commitment
.chunks
.serialize_compressed(&mut bytes);
let _ = self
.quotient_evaluations
.zeta
.serialize_compressed(&mut bytes);
let _ = self
.quotient_evaluations
.zeta_omega
.serialize_compressed(&mut bytes);
let _ = self.opening_proof.lr.serialize_compressed(&mut bytes);
let _ = self.opening_proof.delta.serialize_compressed(&mut bytes);
let _ = self.opening_proof.z1.serialize_compressed(&mut bytes);
let _ = self.opening_proof.z2.serialize_compressed(&mut bytes);
let _ = self.opening_proof.sg.serialize_compressed(&mut bytes);
bytes
}
}
10 changes: 8 additions & 2 deletions o1vm/src/pickles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ use super::{
};
use crate::{
interpreters::mips::{
constraints as mips_constraints, interpreter, interpreter::InterpreterEnv, Instruction,
constraints as mips_constraints,
interpreter::{self, InterpreterEnv},
Instruction,
},
pickles::{
verifier::verify, MAXIMUM_DEGREE_CONSTRAINTS, PROOF_SIZE, TOTAL_NUMBER_OF_CONSTRAINTS,
},
pickles::{verifier::verify, MAXIMUM_DEGREE_CONSTRAINTS, TOTAL_NUMBER_OF_CONSTRAINTS},
};
use ark_ff::{One, Zero};
use interpreter::{ITypeInstruction, JTypeInstruction, RTypeInstruction};
Expand Down Expand Up @@ -120,4 +124,6 @@ fn test_small_circuit() {
(instant_after_verification - instant_before_verification).as_millis()
);
assert!(verif, "Verification fails");

assert_eq!(proof.to_bytes().len(), PROOF_SIZE);
}
Loading