Skip to content

Commit

Permalink
Merge pull request #2974 from o1-labs/marc/query-saffron
Browse files Browse the repository at this point in the history
query saffron
  • Loading branch information
dannywillems authored Feb 3, 2025
2 parents b0c4ec9 + bd4a885 commit 33482cb
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 83 deletions.
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.

2 changes: 1 addition & 1 deletion saffron/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ rmp-serde.workspace = true
serde.workspace = true
serde_with.workspace = true
sha3.workspace = true
thiserror.workspace = true
time = { version = "0.3", features = ["macros"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [ "ansi", "env-filter", "fmt", "time" ] }


[dev-dependencies]
ark-std.workspace = true
ctor = "0.2"
Expand Down
79 changes: 3 additions & 76 deletions saffron/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,89 +92,16 @@ impl<G: CommitmentCurve> FieldBlob<G> {
}
}

#[cfg(test)]
pub mod test_utils {
use proptest::prelude::*;

#[derive(Debug)]
pub struct BlobData(pub Vec<u8>);

#[derive(Clone, Debug)]
pub enum DataSize {
Small,
Medium,
Large,
}

impl DataSize {
const KB: usize = 1_000;
const MB: usize = 1_000_000;

fn size_range_bytes(&self) -> (usize, usize) {
match self {
// Small: 1KB - 1MB
Self::Small => (Self::KB, Self::MB),
// Medium: 1MB - 10MB
Self::Medium => (Self::MB, 10 * Self::MB),
// Large: 10MB - 100MB
Self::Large => (10 * Self::MB, 100 * Self::MB),
}
}
}

impl Arbitrary for DataSize {
type Parameters = ();
type Strategy = BoxedStrategy<Self>;

fn arbitrary_with(_: ()) -> Self::Strategy {
prop_oneof![
6 => Just(DataSize::Small), // 60% chance
3 => Just(DataSize::Medium),
1 => Just(DataSize::Large)
]
.boxed()
}
}

impl Default for DataSize {
fn default() -> Self {
Self::Small
}
}

impl Arbitrary for BlobData {
type Parameters = DataSize;
type Strategy = BoxedStrategy<Self>;

fn arbitrary() -> Self::Strategy {
DataSize::arbitrary()
.prop_flat_map(|size| {
let (min, max) = size.size_range_bytes();
prop::collection::vec(any::<u8>(), min..max)
})
.prop_map(BlobData)
.boxed()
}

fn arbitrary_with(size: Self::Parameters) -> Self::Strategy {
let (min, max) = size.size_range_bytes();
prop::collection::vec(any::<u8>(), min..max)
.prop_map(BlobData)
.boxed()
}
}
}

#[cfg(test)]
mod tests {
use crate::{commitment::commit_to_field_elems, env};

use super::*;
use crate::utils::test_utils::*;
use ark_poly::Radix2EvaluationDomain;
use mina_curves::pasta::{Fp, Vesta};
use once_cell::sync::Lazy;
use proptest::prelude::*;
use test_utils::*;

static SRS: Lazy<SRS<Vesta>> = Lazy::new(|| {
if let Ok(srs) = std::env::var("SRS_FILEPATH") {
Expand All @@ -191,7 +118,7 @@ mod tests {
proptest! {
#![proptest_config(ProptestConfig::with_cases(20))]
#[test]
fn test_round_trip_blob_encoding(BlobData(xs) in BlobData::arbitrary())
fn test_round_trip_blob_encoding(UserData(xs) in UserData::arbitrary())
{ let blob = FieldBlob::<Vesta>::encode(&*SRS, *DOMAIN, &xs);
let bytes = rmp_serde::to_vec(&blob).unwrap();
let a = rmp_serde::from_slice(&bytes).unwrap();
Expand All @@ -206,7 +133,7 @@ mod tests {
proptest! {
#![proptest_config(ProptestConfig::with_cases(10))]
#[test]
fn test_user_and_storage_provider_commitments_equal(BlobData(xs) in BlobData::arbitrary())
fn test_user_and_storage_provider_commitments_equal(UserData(xs) in UserData::arbitrary())
{ let elems = encode_for_domain(&*DOMAIN, &xs);
let user_commitments = commit_to_field_elems(&*SRS, *DOMAIN, elems);
let blob = FieldBlob::<Vesta>::encode(&*SRS, *DOMAIN, &xs);
Expand Down
2 changes: 1 addition & 1 deletion saffron/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
};
use tracing::debug;

const DEFAULT_SRS_SIZE: usize = 1 << 16;
pub const DEFAULT_SRS_SIZE: usize = 1 << 16;

fn get_srs(cache: Option<String>) -> (SRS<Vesta>, Radix2EvaluationDomain<Fp>) {
match cache {
Expand Down
5 changes: 2 additions & 3 deletions saffron/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ where
mod tests {
use super::*;
use crate::{
blob::test_utils::*,
commitment::{commit_to_field_elems, fold_commitments},
env,
utils::encode_for_domain,
utils::{encode_for_domain, test_utils::UserData},
};
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
use ark_std::UniformRand;
Expand Down Expand Up @@ -140,7 +139,7 @@ mod tests {
proptest! {
#![proptest_config(ProptestConfig::with_cases(5))]
#[test]
fn test_storage_prove_verify(BlobData(data) in BlobData::arbitrary()) {
fn test_storage_prove_verify(UserData(data) in UserData::arbitrary()) {
let mut rng = OsRng;
let commitment = {
let field_elems = encode_for_domain(&*DOMAIN, &data);
Expand Down
Loading

0 comments on commit 33482cb

Please sign in to comment.