Skip to content

Commit 269139c

Browse files
committed
Remove level of redirection in ConfigRef
1 parent e94cae1 commit 269139c

27 files changed

Lines changed: 202 additions & 286 deletions

benches/spartan_benches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn benchmark_spartan_verifier<ZT: ZipTypes, C: ConfigReference>(
110110
config,
111111
)
112112
.expect("Failed to generate Spartan proof");
113-
config.reference().expect("Field config cannot be none");
113+
config.reference();
114114
group.bench_function(format!("n={n}"), |b| {
115115
b.iter_batched(
116116
KeccakTranscript::new,

benches/zip_benches.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ fn verify<const P: usize>(group: &mut BenchmarkGroup<WallTime>, modulus: &str, s
242242
.unwrap();
243243

244244
let proof = transcript.into_proof();
245-
field_config
246-
.reference()
247-
.expect("Field config cannot be none");
245+
field_config.reference();
248246
group.bench_function(
249247
format!("Verify: RandomField<{FIELD_LIMBS}>, poly_size = 2^{P}(Int limbs = {INT_LIMBS}), ZipSpec{spec}, modulus={modulus}"),
250248
|b| {
@@ -298,9 +296,7 @@ fn verify_static<const P: usize>(group: &mut BenchmarkGroup<WallTime>, spec: usi
298296
.unwrap();
299297

300298
let proof = transcript.into_proof();
301-
field_config
302-
.reference()
303-
.expect("Field config cannot be none");
299+
field_config.reference();
304300
group.bench_function(
305301
format!("Verify: StaticRandomField<{FIELD_LIMBS}>, poly_size = 2^{P}(Int limbs = {INT_LIMBS}), ZipSpec{spec}, modulus={MODULUS}"),
306302
|b| {

src/ccs/ccs_f.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
33
#![allow(non_snake_case, non_camel_case_types)]
44

5-
use ark_std::{
6-
rand,
7-
sync::atomic::{AtomicPtr, Ordering},
8-
vec,
9-
vec::Vec,
10-
};
5+
use ark_std::{rand, vec, vec::Vec};
116
use crypto_bigint::Random;
127
use num_traits::{One, Zero};
138

@@ -63,7 +58,7 @@ pub struct CCS_F<C: ConfigReference> {
6358
/// vector of coefficients
6459
pub c: Vec<RandomField<C>>,
6560
/// The field the constraint system operates in
66-
pub config: AtomicPtr<C::C>,
61+
pub config: C,
6762
}
6863

6964
impl<C: ConfigReference> Arith<C> for CCS_F<C> {
@@ -147,11 +142,7 @@ impl<C: ConfigReference> Statement_F<C> {
147142

148143
self.constraints
149144
.iter()
150-
.map(|M| {
151-
compute_eval_table_sparse(M, evals, num_rows, num_cols, unsafe {
152-
C::new(ccs.config.load(Ordering::Acquire))
153-
})
154-
})
145+
.map(|M| compute_eval_table_sparse(M, evals, num_rows, num_cols, ccs.config))
155146
.collect()
156147
}
157148
}
@@ -254,25 +245,20 @@ pub(crate) fn get_test_ccs_F<C: ConfigReference>(config: C) -> CCS_F<C> {
254245

255246
let m = 4;
256247
let n = 6;
257-
match config.pointer() {
258-
None => panic!("FieldConfig cannot be null"),
259-
Some(config_ptr) => {
260-
let mut c: Vec<RandomField<C>> = vec![1u32, 1].map_to_field(config);
261-
c[1] = -c[1].clone();
262-
CCS_F {
263-
m,
264-
n,
265-
l: 1,
266-
t: 3,
267-
q: 2,
268-
d: 2,
269-
s: log2(m) as usize,
270-
s_prime: log2(n) as usize,
271-
S: vec![vec![0, 1], vec![2]],
272-
c,
273-
config: AtomicPtr::new(config_ptr),
274-
}
275-
}
248+
let mut c: Vec<RandomField<C>> = vec![1u32, 1].map_to_field(config);
249+
c[1] = -c[1].clone();
250+
CCS_F {
251+
m,
252+
n,
253+
l: 1,
254+
t: 3,
255+
q: 2,
256+
d: 2,
257+
s: log2(m) as usize,
258+
s_prime: log2(n) as usize,
259+
S: vec![vec![0, 1], vec![2]],
260+
c,
261+
config,
276262
}
277263
}
278264

src/ccs/ccs_z.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![allow(non_snake_case, non_camel_case_types)]
44

5-
use ark_std::{log2, marker::PhantomData, sync::atomic::AtomicPtr, vec, vec::Vec};
5+
use ark_std::{log2, marker::PhantomData, vec, vec::Vec};
66

77
use super::{
88
ccs_f::{CCS_F, Statement_F, Witness_F},
@@ -133,21 +133,18 @@ impl<C: ConfigReference, I: Integer + MapsToField<C>> FieldMap<C> for CCS_Z<I> {
133133
type Output = CCS_F<C>;
134134

135135
fn map_to_field(&self, config_ref: C) -> Self::Output {
136-
match config_ref.pointer() {
137-
Some(config_ptr) => CCS_F {
138-
m: self.m,
139-
n: self.n,
140-
l: self.l,
141-
t: self.t,
142-
q: self.q,
143-
d: self.d,
144-
s: self.s,
145-
s_prime: self.s_prime,
146-
S: self.S.clone(),
147-
c: self.c.iter().map(|c| c.map_to_field(config_ref)).collect(),
148-
config: AtomicPtr::new(config_ptr),
149-
},
150-
None => panic!("FieldConfig cannot be null"),
136+
CCS_F {
137+
m: self.m,
138+
n: self.n,
139+
l: self.l,
140+
t: self.t,
141+
q: self.q,
142+
d: self.d,
143+
s: self.s,
144+
s_prime: self.s_prime,
145+
S: self.S.clone(),
146+
c: self.c.iter().map(|c| c.map_to_field(config_ref)).collect(),
147+
config: config_ref,
151148
}
152149
}
153150
}

src/ccs/test_utils.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use ark_std::{log2, marker::PhantomData, rand::Rng, sync::atomic::AtomicPtr, vec, vec::Vec};
3+
use ark_std::{log2, marker::PhantomData, rand::Rng, vec, vec::Vec};
44

55
use super::{
66
ccs_f::{CCS_F, Statement_F, Witness_F},
@@ -126,21 +126,18 @@ fn get_dummy_ccs_F_from_z<C: ConfigReference>(
126126
pub_io_len: usize,
127127
config: C,
128128
) -> (CCS_F<C>, Statement_F<C>, Witness_F<C>) {
129-
let ccs = match config.pointer() {
130-
None => panic!("FieldConfig cannot be null"),
131-
Some(config_ptr) => CCS_F {
132-
m: z.len(),
133-
n: z.len(),
134-
l: pub_io_len,
135-
t: 3,
136-
q: 2,
137-
d: 2,
138-
s: log2(z.len()) as usize,
139-
s_prime: log2(z.len()) as usize,
140-
S: vec![vec![0, 1], vec![2]],
141-
c: vec![1u32.map_to_field(config), (-1i32).map_to_field(config)],
142-
config: AtomicPtr::new(config_ptr),
143-
},
129+
let ccs = CCS_F {
130+
m: z.len(),
131+
n: z.len(),
132+
l: pub_io_len,
133+
t: 3,
134+
q: 2,
135+
d: 2,
136+
s: log2(z.len()) as usize,
137+
s_prime: log2(z.len()) as usize,
138+
S: vec![vec![0, 1], vec![2]],
139+
c: vec![1u32.map_to_field(config), (-1i32).map_to_field(config)],
140+
config,
144141
};
145142

146143
let A = create_dummy_identity_sparse_matrix_F(z.len(), z.len(), config);

src/conversion.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ macro_rules! impl_field_map_for_int {
1515
type Output = RandomField<C>;
1616

1717
fn map_to_field(&self, config_ref: C) -> Self::Output {
18-
let config = match config_ref.reference() {
19-
Some(config) => config,
20-
None => {
21-
panic!("Cannot convert integer to prime field element without a modulus")
22-
}
23-
};
18+
let config = config_ref.reference();
2419
let value = self.abs_diff(0);
2520
let mut words = C::W::default();
2621

@@ -67,10 +62,7 @@ impl<C: ConfigReference> FieldMap<C> for bool {
6762
type Output = RandomField<C>;
6863

6964
fn map_to_field(&self, config_ref: C) -> Self::Output {
70-
let config = match config_ref.reference() {
71-
Some(config) => config,
72-
None => panic!("Cannot convert boolean to prime field element without a modulus"),
73-
};
65+
let config = config_ref.reference();
7466

7567
let mut r = C::B::from(*self as u64);
7668
config.mul_assign(&mut r, config.r2());
@@ -514,20 +506,6 @@ mod tests {
514506
test_unsigned_type_edge_cases!(u64, field_1, config, ConfigRef::<1>);
515507
test_unsigned_type_edge_cases!(u128, field_1, config, ConfigRef::<1>);
516508
}
517-
518-
#[test]
519-
#[should_panic(expected = "Cannot convert integer to prime field element without a modulus")]
520-
fn test_signed_field_map_null_config() {
521-
let i32_val: i32 = 5;
522-
i32_val.map_to_field(ConfigRef::<1>::NONE);
523-
}
524-
525-
#[test]
526-
#[should_panic(expected = "Cannot convert integer to prime field element without a modulus")]
527-
fn test_unsigned_field_map_null_config() {
528-
let u32_val: u32 = 5;
529-
u32_val.map_to_field(ConfigRef::<1>::NONE);
530-
}
531509
}
532510

533511
#[cfg(test)]
@@ -623,13 +601,6 @@ mod bigint_field_map_tests {
623601
);
624602
}
625603

626-
#[test]
627-
#[should_panic(expected = "Cannot convert BigInt to prime field element without a modulus")]
628-
fn test_null_config() {
629-
let value = BigInt::<2>::from(123u64);
630-
let _result = value.map_to_field(ConfigRef::<2>::NONE);
631-
}
632-
633604
#[test]
634605
fn test_bigint_max_value() {
635606
let modulus = big_int!(18446744069414584321);

0 commit comments

Comments
 (0)