Skip to content

Commit e4e180c

Browse files
chore(fmt): wrap comments and format code comments (#1575)
1 parent 39d6771 commit e4e180c

File tree

164 files changed

+985
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+985
-677
lines changed

benchmarks/prove/src/bin/verify_fibair.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ fn main() -> Result<()> {
3535
);
3636

3737
run_with_metric_collection("OUTPUT_PATH", || -> Result<()> {
38-
// run_test tries to setup tracing, but it will be ignored since run_with_metric_collection already sets it.
38+
// run_test tries to setup tracing, but it will be ignored since run_with_metric_collection
39+
// already sets it.
3940
let (fib_air, fib_input) = collect_airs_and_inputs!(fib_chip);
4041
let vdata = engine.run_test(fib_air, fib_input).unwrap();
4142
// Unlike other apps, this "app" does not have continuations enabled.

benchmarks/prove/src/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ where
208208
});
209209
// 3. Executes runtime
210210
// 4. Generate trace
211-
// 5. Generate STARK proofs for each segment (segmentation is determined by `config`), with timer.
211+
// 5. Generate STARK proofs for each segment (segmentation is determined by `config`), with
212+
// timer.
212213
let app_vk = app_pk.get_app_vk();
213214
let prover =
214215
AppProver::<VC, E>::new(app_pk.app_vm_pk, committed_exe).with_program_name(bench_name);

crates/circuits/mod-builder/src/builder.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ pub struct ExprBuilder {
7878
/// flag for debug mode
7979
debug: bool,
8080

81-
/// Whether the builder has been finalized. Only after finalize, we can do generate_subrow and eval etc.
81+
/// Whether the builder has been finalized. Only after finalize, we can do generate_subrow and
82+
/// eval etc.
8283
finalized: bool,
8384

8485
// Setup opcode is a special op that verifies the modulus is correct.
85-
// There are some chips that don't need it because we hardcode the modulus. E.g. the pairing ones.
86-
// For those chips need setup, setup is derived: setup = is_valid - sum(all_flags)
86+
// There are some chips that don't need it because we hardcode the modulus. E.g. the pairing
87+
// ones. For those chips need setup, setup is derived: setup = is_valid - sum(all_flags)
8788
// Therefore when the chip only supports one opcode, user won't explicitly create a flag for it
8889
// and we will create a default flag for it on finalizing.
8990
needs_setup: bool,
@@ -185,7 +186,8 @@ impl ExprBuilder {
185186
// so there should be same number of calls to the new_var, add_constraint and add_compute.
186187
pub fn new_var(&mut self) -> (usize, SymbolicExpr) {
187188
self.num_variables += 1;
188-
// Allocate space for the new variable, to make sure they are corresponding to the same variable index.
189+
// Allocate space for the new variable, to make sure they are corresponding to the same
190+
// variable index.
189191
self.constraints.push(SymbolicExpr::Input(0));
190192
self.computes.push(SymbolicExpr::Input(0));
191193
self.q_limbs.push(0);
@@ -349,10 +351,9 @@ impl<AB: InteractionBuilder> SubAir<AB> for FieldExpr {
349351
builder.assert_bool(is_setup.clone());
350352
// TODO[jpw]: currently we enforce at the program code level that:
351353
// - a valid program must call the correct setup opcodes to be correct
352-
// - it would be better if we can constraint this in the circuit,
353-
// however this has the challenge that when the same chip is used
354-
// across continuation segments,
355-
// only the first segment will have setup called
354+
// - it would be better if we can constraint this in the circuit, however this has the
355+
// challenge that when the same chip is used across continuation segments, only the
356+
// first segment will have setup called
356357

357358
let expected = iter::empty()
358359
.chain({
@@ -472,7 +473,8 @@ impl<F: PrimeField64> TraceSubRowGenerator<F> for FieldExpr {
472473
.collect::<Vec<_>>();
473474
let zero = OverflowInt::<isize>::from_canonical_unsigned_limbs(vec![0], limb_bits);
474475
let mut vars_overflow = vec![zero; self.num_variables];
475-
// Note: in cases where the prime fits in less limbs than `num_limbs`, we use the smaller number of limbs.
476+
// Note: in cases where the prime fits in less limbs than `num_limbs`, we use the smaller
477+
// number of limbs.
476478
let prime_overflow = OverflowInt::<isize>::from_biguint(&self.prime, self.limb_bits, None);
477479

478480
let constants: Vec<_> = self
@@ -493,7 +495,8 @@ impl<F: PrimeField64> TraceSubRowGenerator<F> for FieldExpr {
493495
vars_overflow[i] =
494496
OverflowInt::<isize>::from_biguint(&vars[i], self.limb_bits, Some(self.num_limbs));
495497
}
496-
// We need to have all variables computed first because, e.g. constraints[2] might need variables[3].
498+
// We need to have all variables computed first because, e.g. constraints[2] might need
499+
// variables[3].
497500
for i in 0..self.constraints.len() {
498501
// expr = q * p
499502
let expr_bigint =

crates/circuits/mod-builder/src/core_chip.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ pub struct FieldExpressionCoreAir {
3535
/// All the opcode indices (including setup) supported by this Air.
3636
/// The last one must be the setup opcode if it's a chip needs setup.
3737
pub local_opcode_idx: Vec<usize>,
38-
/// Opcode flag idx (indices from builder.new_flag()) for all except setup opcode. Empty if single op chip.
38+
/// Opcode flag idx (indices from builder.new_flag()) for all except setup opcode. Empty if
39+
/// single op chip.
3940
pub opcode_flag_idx: Vec<usize>,
4041
// Example 1: 1-op chip EcAdd that needs setup
4142
// local_opcode_idx = [0, 2], where 0 is EcAdd, 2 is setup
@@ -178,7 +179,8 @@ pub struct FieldExpressionCoreChip {
178179

179180
pub name: String,
180181

181-
/// Whether to finalize the trace. True if all-zero rows don't satisfy the constraints (e.g. there is int_add)
182+
/// Whether to finalize the trace. True if all-zero rows don't satisfy the constraints (e.g.
183+
/// there is int_add)
182184
pub should_finalize: bool,
183185
}
184186

@@ -245,8 +247,9 @@ where
245247
let local_opcode_idx = opcode.local_opcode_idx(self.air.offset);
246248
let mut flags = vec![];
247249

248-
// If the chip doesn't need setup, (right now) it must be single op chip and thus no flag is needed.
249-
// Otherwise, there is a flag for each opcode and will be derived by is_valid - sum(flags).
250+
// If the chip doesn't need setup, (right now) it must be single op chip and thus no flag is
251+
// needed. Otherwise, there is a flag for each opcode and will be derived by
252+
// is_valid - sum(flags).
250253
if self.expr().needs_setup() {
251254
flags = vec![false; self.air.num_flags()];
252255
self.air

crates/circuits/mod-builder/src/field_variable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl FieldVariable {
8989

9090
fn save_if_overflow(
9191
a: &mut FieldVariable, // will save this variable if overflow
92-
expr: SymbolicExpr, // the "compute" expression of the result variable. Note that we need to check if constraint overflows
92+
expr: SymbolicExpr, /* the "compute" expression of the result variable. Note that we
93+
* need to check if constraint overflows */
9394
limb_max_abs: usize, // The max abs of limbs of compute expression.
9495
) {
9596
if let SymbolicExpr::Var(_) = a.expr {
@@ -115,7 +116,8 @@ impl FieldVariable {
115116

116117
// TODO[Lun-Kai]: rethink about how should auto-save work.
117118
// This implementation requires self and other to be mutable, and might actually mutate them.
118-
// This might surprise the caller or introduce hard bug if the caller clone the FieldVariable and then call this.
119+
// This might surprise the caller or introduce hard bug if the caller clone the FieldVariable
120+
// and then call this.
119121
pub fn add(&mut self, other: &mut FieldVariable) -> FieldVariable {
120122
assert!(Rc::ptr_eq(&self.builder, &other.builder));
121123
let limb_max_fn = |a: &FieldVariable, b: &FieldVariable| a.limb_max_abs + b.limb_max_abs;

crates/circuits/mod-builder/src/symbolic_expr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ impl SymbolicExpr {
222222
SymbolicExpr::IntAdd(lhs, s) => {
223223
let (lhs_max_pos, lhs_max_neg) = lhs.max_abs(proper_max);
224224
let scalar = BigUint::from_usize(s.unsigned_abs()).unwrap();
225-
// Optimization opportunity: since `s` is a constant, we can likely do better than this bound.
225+
// Optimization opportunity: since `s` is a constant, we can likely do better than
226+
// this bound.
226227
(lhs_max_pos + &scalar, lhs_max_neg + &scalar)
227228
}
228229
SymbolicExpr::IntMul(lhs, s) => {
@@ -243,8 +244,8 @@ impl SymbolicExpr {
243244
}
244245

245246
/// Returns the maximum possible size, in bits, of each limb in `self.expr`.
246-
/// This is already tracked in `FieldVariable`. However when auto saving in `FieldVariable::div`,
247-
/// we need to know it from the `SymbolicExpr` only.
247+
/// This is already tracked in `FieldVariable`. However when auto saving in
248+
/// `FieldVariable::div`, we need to know it from the `SymbolicExpr` only.
248249
/// self should be a constraint expr.
249250
pub fn constraint_limb_max_abs(&self, limb_bits: usize, num_limbs: usize) -> usize {
250251
let canonical_limb_max_abs = (1 << limb_bits) - 1;

crates/circuits/mod-builder/src/tests.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ fn test_auto_carry_intmul() {
135135
let mut x3 = &mut x1 * &mut x2;
136136
// The int_mul below will overflow:
137137
// x3 should have max_overflow_bits = 8 + 8 + log2(32) = 21
138-
// The carry bits = "max_overflow_bits - limb_bits + 1" will exceed 17 if it exceeds 17 + 8 - 1 = 24.
139-
// So it triggers x3 to be saved first.
138+
// The carry bits = "max_overflow_bits - limb_bits + 1" will exceed 17 if it exceeds 17 + 8 - 1
139+
// = 24. So it triggers x3 to be saved first.
140140
let mut x4 = x3.int_mul(9);
141141
assert_eq!(x3.expr, SymbolicExpr::Var(0));
142142
x4.save();
@@ -229,7 +229,8 @@ fn test_auto_carry_div() {
229229
let x2 = ExprBuilder::new_input(builder.clone());
230230
// The choice of scalar (7) needs to be such that
231231
// 1. the denominator 7x^2 doesn't trigger autosave, >=8 doesn't work.
232-
// 2. But doing a division on it triggers autosave, because of division constraint, <= 6 doesn't work.
232+
// 2. But doing a division on it triggers autosave, because of division constraint, <= 6 doesn't
233+
// work.
233234
let mut x3 = x1.square().int_mul(7) / x2;
234235
x3.save();
235236

@@ -387,8 +388,9 @@ fn test_symbolic_limbs_mul() {
387388
Box::new(SymbolicExpr::Var(0)),
388389
Box::new(SymbolicExpr::Var(1)),
389390
);
390-
// x * y = pq, and x,y can be up to 2^256 - 1 so q can be up to ceil((2^256 - 1)^2 / p) which has 257 bits, which is 33 limbs
391-
// x * y has 63 limbs, but p * q can have 64 limbs since q is 33 limbs
391+
// x * y = pq, and x,y can be up to 2^256 - 1 so q can be up to ceil((2^256 - 1)^2 / p) which
392+
// has 257 bits, which is 33 limbs x * y has 63 limbs, but p * q can have 64 limbs since q
393+
// is 33 limbs
392394
let expected_q = 33;
393395
let expected_carry = 64;
394396
test_symbolic_limbs(expr, expected_q, expected_carry);

crates/circuits/poseidon2-air/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use super::{
88
BABY_BEAR_POSEIDON2_HALF_FULL_ROUNDS, BABY_BEAR_POSEIDON2_PARTIAL_ROUNDS, POSEIDON2_WIDTH,
99
};
1010

11-
// Currently only contains round constants, but this struct may contain other configuration parameters in the future.
11+
// Currently only contains round constants, but this struct may contain other configuration
12+
// parameters in the future.
1213
#[derive(Clone, Copy, Debug)]
1314
pub struct Poseidon2Config<F> {
1415
pub constants: Poseidon2Constants<F>,

crates/circuits/poseidon2-air/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//! get around some complications with field-specific generics associated with Poseidon2.
33
//! Currently it is only intended for use in OpenVM with BabyBear.
44
//!
5-
//! We do not recommend external use of this crate, and suggest using the [p3_poseidon2_air] crate directly.
5+
//! We do not recommend external use of this crate, and suggest using the [p3_poseidon2_air] crate
6+
//! directly.
67
78
use std::sync::Arc;
89

@@ -39,7 +40,8 @@ pub const BABY_BEAR_POSEIDON2_PARTIAL_ROUNDS: usize = 13;
3940
// Currently we only support SBOX_DEGREE = 7
4041
pub const BABY_BEAR_POSEIDON2_SBOX_DEGREE: u64 = 7;
4142

42-
/// `SBOX_REGISTERS` affects the max constraint degree of the AIR. See [p3_poseidon2_air] for more details.
43+
/// `SBOX_REGISTERS` affects the max constraint degree of the AIR. See [p3_poseidon2_air] for more
44+
/// details.
4345
#[derive(Debug)]
4446
pub struct Poseidon2SubChip<F: Field, const SBOX_REGISTERS: usize> {
4547
// This is Arc purely because Poseidon2Air cannot derive Clone

crates/circuits/poseidon2-air/src/permute.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ pub trait Poseidon2MatrixConfig: Clone + Sync {
1818
fn int_diag_m1_matrix<F: FieldAlgebra>() -> [F; WIDTH];
1919
}
2020

21-
/// This type needs to implement GenericPoseidon2LinearLayers generic in F so that our Poseidon2SubAir can also
22-
/// be generic in F, but in reality each implementation of this struct's functions should be field specific. To
23-
/// circumvent this, Poseidon2LinearLayers is generic in F but **currently requires** that F is BabyBear.
21+
/// This type needs to implement GenericPoseidon2LinearLayers generic in F so that our
22+
/// Poseidon2SubAir can also be generic in F, but in reality each implementation of this struct's
23+
/// functions should be field specific. To circumvent this, Poseidon2LinearLayers is generic in F
24+
/// but **currently requires** that F is BabyBear.
2425
#[derive(Debug, Clone)]
2526
pub struct BabyBearPoseidon2LinearLayers;
2627

27-
// This is the same as the implementation for GenericPoseidon2LinearLayersMonty31<BabyBearParameters, BabyBearInternalLayerParameters> except that we drop the
28-
// clause that FA needs be multipliable by BabyBear.
28+
// This is the same as the implementation for
29+
// GenericPoseidon2LinearLayersMonty31<BabyBearParameters, BabyBearInternalLayerParameters> except
30+
// that we drop the clause that FA needs be multipliable by BabyBear.
2931
// TODO[jpw/stephen]: This is clearly not the best way to do this, but it would
3032
// require some reworking in plonky3 to get around the generics.
3133
impl<FA: FieldAlgebra> GenericPoseidon2LinearLayers<FA, WIDTH> for BabyBearPoseidon2LinearLayers {

crates/circuits/primitives/derive/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub fn aligned_borrow_derive(input: TokenStream) -> TokenStream {
3838
})
3939
.collect::<Vec<_>>();
4040

41-
// Get impl generics (`<T, N: NumLimbs, const M: usize>`), type generics (`<T, N>`), where clause (`where T: Clone`)
41+
// Get impl generics (`<T, N: NumLimbs, const M: usize>`), type generics (`<T, N>`), where
42+
// clause (`where T: Clone`)
4243
let (impl_generics, type_generics, where_clause) = ast.generics.split_for_impl();
4344

4445
let methods = quote! {
@@ -331,8 +332,8 @@ pub fn bytes_stateful_derive(input: TokenStream) -> TokenStream {
331332
}
332333
_ => panic!("Only unnamed fields are supported"),
333334
};
334-
// Use full path ::openvm_circuit... so it can be used either within or outside the vm crate.
335-
// Assume F is already generic of the field.
335+
// Use full path ::openvm_circuit... so it can be used either within or outside the vm
336+
// crate. Assume F is already generic of the field.
336337
let mut new_generics = generics.clone();
337338
let where_clause = new_generics.make_where_clause();
338339
where_clause
@@ -365,7 +366,8 @@ pub fn bytes_stateful_derive(input: TokenStream) -> TokenStream {
365366
(variant_name, field)
366367
})
367368
.collect::<Vec<_>>();
368-
// Use full path ::openvm_stark_backend... so it can be used either within or outside the vm crate.
369+
// Use full path ::openvm_stark_backend... so it can be used either within or outside
370+
// the vm crate.
369371
let (load_state_arms, store_state_arms): (Vec<_>, Vec<_>) =
370372
multiunzip(variants.iter().map(|(variant_name, field)| {
371373
let field_ty = &field.ty;

crates/circuits/primitives/src/assert_less_than/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ impl AssertLtSubAir {
131131
});
132132

133133
// constrain that y - x - 1 is equal to the constructed lower value.
134-
// this enforces that the intermediate value is in the range [0, 2^max_bits - 1], which is equivalent to x < y
134+
// this enforces that the intermediate value is in the range [0, 2^max_bits - 1], which is
135+
// equivalent to x < y
135136
builder.when(io.count).assert_eq(intermed_val, lower);
136-
// the degree of this constraint is expected to be deg(count) + max(deg(intermed_val), deg(lower))
137-
// since we are constraining count * intermed_val == count * lower
137+
// the degree of this constraint is expected to be deg(count) + max(deg(intermed_val),
138+
// deg(lower)) since we are constraining count * intermed_val == count * lower
138139
}
139140

140141
#[inline(always)]
@@ -185,7 +186,8 @@ impl<AB: InteractionBuilder> SubAir<AB> for AssertLtSubAir {
185186

186187
impl<F: Field> TraceSubRowGenerator<F> for AssertLtSubAir {
187188
/// (range_checker, x, y)
188-
// x, y are u32 because memory records are storing u32 and there would be needless conversions. It also prevents a F: PrimeField32 trait bound.
189+
// x, y are u32 because memory records are storing u32 and there would be needless conversions.
190+
// It also prevents a F: PrimeField32 trait bound.
189191
type TraceContext<'a> = (&'a VariableRangeCheckerChip, u32, u32);
190192
/// lower_decomp
191193
type ColsMut<'a> = &'a mut [F];

crates/circuits/primitives/src/bigint/check_carry_mod_to_zero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub struct CheckCarryModToZeroCols<T> {
1818
pub carries: Vec<T>,
1919

2020
// We will check that expr - quotient * modulus = 0, which imples expr is 0 mod modulus.
21-
// quotient can be negative, and this means there is no unique way to represent it as limbs but it's fine.
22-
// Each limb will be range-checked to be in [-2^limb_bits, 2^limb_bits).
21+
// quotient can be negative, and this means there is no unique way to represent it as limbs but
22+
// it's fine. Each limb will be range-checked to be in [-2^limb_bits, 2^limb_bits).
2323
pub quotient: Vec<T>,
2424
}
2525

crates/circuits/primitives/src/bigint/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl<T> OverflowInt<T> {
3636
}
3737
}
3838

39-
// Limbs can be negative. So the max_overflow_bits and limb_max_abs are different from the range check result.
39+
// Limbs can be negative. So the max_overflow_bits and limb_max_abs are different from the range
40+
// check result.
4041
pub fn from_canonical_signed_limbs(x: Vec<T>, limb_bits: usize) -> OverflowInt<T> {
4142
OverflowInt {
4243
limbs: x,

crates/circuits/primitives/src/encoder/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub struct Encoder {
2020
/// The number of flags, excluding the invalid/dummy flag.
2121
flag_cnt: usize,
2222
/// Maximal degree of the flag expressions.
23-
/// The maximal degree of the equalities in the AIR, however, **is one higher:** that is, `max_flag_degree + 1`.
23+
/// The maximal degree of the equalities in the AIR, however, **is one higher:** that is,
24+
/// `max_flag_degree + 1`.
2425
max_flag_degree: u32,
2526
/// All possible points in the k-dimensional space that can be used to encode flags
2627
pts: Vec<Vec<u32>>,
@@ -34,7 +35,8 @@ impl Encoder {
3435
/// The zero point is reserved for the dummy row.
3536
/// `max_degree` is the upper bound for the flag expressions, but the `eval` function
3637
/// of the encoder itself will use some constraints of degree `max_degree + 1`.
37-
/// `reserve_invalid` indicates if the encoder should reserve the (0, ..., 0) point as an invalid/dummy flag.
38+
/// `reserve_invalid` indicates if the encoder should reserve the (0, ..., 0) point as an
39+
/// invalid/dummy flag.
3840
pub fn new(cnt: usize, max_degree: u32, reserve_invalid: bool) -> Self {
3941
// Calculate binomial coefficient (d+k choose k) to determine how many points we can encode
4042
let binomial = |x: u32| {
@@ -109,7 +111,8 @@ impl Encoder {
109111
expr * denom.inverse()
110112
}
111113

112-
/// Get the polynomial expression that equals 1 when the variables encode the flag at index flag_idx
114+
/// Get the polynomial expression that equals 1 when the variables encode the flag at index
115+
/// flag_idx
113116
pub fn get_flag_expr<AB: InteractionBuilder>(
114117
&self,
115118
flag_idx: usize,
@@ -125,7 +128,8 @@ impl Encoder {
125128
self.pts[flag_idx + self.reserve_invalid as usize].clone()
126129
}
127130

128-
/// Returns an expression that is 1 if the variables encode a valid flag and 0 if they encode the invalid point
131+
/// Returns an expression that is 1 if the variables encode a valid flag and 0 if they encode
132+
/// the invalid point
129133
pub fn is_valid<AB: InteractionBuilder>(&self, vars: &[AB::Var]) -> AB::Expr {
130134
AB::Expr::ONE - self.expression_for_point::<AB>(&self.pts[0], vars)
131135
}

0 commit comments

Comments
 (0)