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 {

0 commit comments

Comments
 (0)