Skip to content

Commit 33482cb

Browse files
authored
Merge pull request #2974 from o1-labs/marc/query-saffron
query saffron
2 parents b0c4ec9 + bd4a885 commit 33482cb

File tree

6 files changed

+328
-83
lines changed

6 files changed

+328
-83
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

saffron/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ rmp-serde.workspace = true
3535
serde.workspace = true
3636
serde_with.workspace = true
3737
sha3.workspace = true
38+
thiserror.workspace = true
3839
time = { version = "0.3", features = ["macros"] }
3940
tracing = "0.1"
4041
tracing-subscriber = { version = "0.3", features = [ "ansi", "env-filter", "fmt", "time" ] }
4142

42-
4343
[dev-dependencies]
4444
ark-std.workspace = true
4545
ctor = "0.2"

saffron/src/blob.rs

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -92,89 +92,16 @@ impl<G: CommitmentCurve> FieldBlob<G> {
9292
}
9393
}
9494

95-
#[cfg(test)]
96-
pub mod test_utils {
97-
use proptest::prelude::*;
98-
99-
#[derive(Debug)]
100-
pub struct BlobData(pub Vec<u8>);
101-
102-
#[derive(Clone, Debug)]
103-
pub enum DataSize {
104-
Small,
105-
Medium,
106-
Large,
107-
}
108-
109-
impl DataSize {
110-
const KB: usize = 1_000;
111-
const MB: usize = 1_000_000;
112-
113-
fn size_range_bytes(&self) -> (usize, usize) {
114-
match self {
115-
// Small: 1KB - 1MB
116-
Self::Small => (Self::KB, Self::MB),
117-
// Medium: 1MB - 10MB
118-
Self::Medium => (Self::MB, 10 * Self::MB),
119-
// Large: 10MB - 100MB
120-
Self::Large => (10 * Self::MB, 100 * Self::MB),
121-
}
122-
}
123-
}
124-
125-
impl Arbitrary for DataSize {
126-
type Parameters = ();
127-
type Strategy = BoxedStrategy<Self>;
128-
129-
fn arbitrary_with(_: ()) -> Self::Strategy {
130-
prop_oneof![
131-
6 => Just(DataSize::Small), // 60% chance
132-
3 => Just(DataSize::Medium),
133-
1 => Just(DataSize::Large)
134-
]
135-
.boxed()
136-
}
137-
}
138-
139-
impl Default for DataSize {
140-
fn default() -> Self {
141-
Self::Small
142-
}
143-
}
144-
145-
impl Arbitrary for BlobData {
146-
type Parameters = DataSize;
147-
type Strategy = BoxedStrategy<Self>;
148-
149-
fn arbitrary() -> Self::Strategy {
150-
DataSize::arbitrary()
151-
.prop_flat_map(|size| {
152-
let (min, max) = size.size_range_bytes();
153-
prop::collection::vec(any::<u8>(), min..max)
154-
})
155-
.prop_map(BlobData)
156-
.boxed()
157-
}
158-
159-
fn arbitrary_with(size: Self::Parameters) -> Self::Strategy {
160-
let (min, max) = size.size_range_bytes();
161-
prop::collection::vec(any::<u8>(), min..max)
162-
.prop_map(BlobData)
163-
.boxed()
164-
}
165-
}
166-
}
167-
16895
#[cfg(test)]
16996
mod tests {
17097
use crate::{commitment::commit_to_field_elems, env};
17198

17299
use super::*;
100+
use crate::utils::test_utils::*;
173101
use ark_poly::Radix2EvaluationDomain;
174102
use mina_curves::pasta::{Fp, Vesta};
175103
use once_cell::sync::Lazy;
176104
use proptest::prelude::*;
177-
use test_utils::*;
178105

179106
static SRS: Lazy<SRS<Vesta>> = Lazy::new(|| {
180107
if let Ok(srs) = std::env::var("SRS_FILEPATH") {
@@ -191,7 +118,7 @@ mod tests {
191118
proptest! {
192119
#![proptest_config(ProptestConfig::with_cases(20))]
193120
#[test]
194-
fn test_round_trip_blob_encoding(BlobData(xs) in BlobData::arbitrary())
121+
fn test_round_trip_blob_encoding(UserData(xs) in UserData::arbitrary())
195122
{ let blob = FieldBlob::<Vesta>::encode(&*SRS, *DOMAIN, &xs);
196123
let bytes = rmp_serde::to_vec(&blob).unwrap();
197124
let a = rmp_serde::from_slice(&bytes).unwrap();
@@ -206,7 +133,7 @@ mod tests {
206133
proptest! {
207134
#![proptest_config(ProptestConfig::with_cases(10))]
208135
#[test]
209-
fn test_user_and_storage_provider_commitments_equal(BlobData(xs) in BlobData::arbitrary())
136+
fn test_user_and_storage_provider_commitments_equal(UserData(xs) in UserData::arbitrary())
210137
{ let elems = encode_for_domain(&*DOMAIN, &xs);
211138
let user_commitments = commit_to_field_elems(&*SRS, *DOMAIN, elems);
212139
let blob = FieldBlob::<Vesta>::encode(&*SRS, *DOMAIN, &xs);

saffron/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
};
1212
use tracing::debug;
1313

14-
const DEFAULT_SRS_SIZE: usize = 1 << 16;
14+
pub const DEFAULT_SRS_SIZE: usize = 1 << 16;
1515

1616
fn get_srs(cache: Option<String>) -> (SRS<Vesta>, Radix2EvaluationDomain<Fp>) {
1717
match cache {

saffron/src/proof.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ where
109109
mod tests {
110110
use super::*;
111111
use crate::{
112-
blob::test_utils::*,
113112
commitment::{commit_to_field_elems, fold_commitments},
114113
env,
115-
utils::encode_for_domain,
114+
utils::{encode_for_domain, test_utils::UserData},
116115
};
117116
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
118117
use ark_std::UniformRand;
@@ -140,7 +139,7 @@ mod tests {
140139
proptest! {
141140
#![proptest_config(ProptestConfig::with_cases(5))]
142141
#[test]
143-
fn test_storage_prove_verify(BlobData(data) in BlobData::arbitrary()) {
142+
fn test_storage_prove_verify(UserData(data) in UserData::arbitrary()) {
144143
let mut rng = OsRng;
145144
let commitment = {
146145
let field_elems = encode_for_domain(&*DOMAIN, &data);

0 commit comments

Comments
 (0)