Skip to content

Commit

Permalink
chore: fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Sep 13, 2024
1 parent 57beef8 commit c1ac8e8
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 76 deletions.
75 changes: 49 additions & 26 deletions air/src/constraints/stack/field_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ pub fn enforce_constraints<E: FieldElement>(
// TRANSITION CONSTRAINT HELPERS
// ================================================================================================

/// Enforces constraints of the ADD operation. The ADD operation adds the first two elements
/// in the current trace. Therefore, the following constraints are enforced:
/// Enforces constraints of the ADD operation.
///
/// The ADD operation adds the first two elements in the current trace. Therefore, the following
/// constraints are enforced:
/// - The first element in the trace frame should be the addition of the first two elements in the
/// current trace. s0` - s0 - s1 = 0.
pub fn enforce_add_constraints<E: FieldElement>(
Expand All @@ -118,8 +120,10 @@ pub fn enforce_add_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the NEG operation. The NEG operation updates the top element in the
/// stack with its inverse. Therefore, the following constraints are enforced:
/// Enforces constraints of the NEG operation.
///
/// The NEG operation updates the top element in the stack with its inverse. Therefore, the
/// following constraints are enforced:
/// - The first element in the next frame should be the negation of first element in the current
/// frame, therefore, their sum should be 0. s0` + s0 = 0.
pub fn enforce_neg_constraints<E: FieldElement>(
Expand All @@ -134,8 +138,10 @@ pub fn enforce_neg_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the MUL operation. The MUL operation multiplies the first two elements
/// in the current trace. Therefore, the following constraints are enforced:
/// Enforces constraints of the MUL operation.
///
/// The MUL operation multiplies the first two elements in the current trace. Therefore, the
/// following constraints are enforced:
/// - The first element in the next frame should be the product of the first two elements in the
/// current frame. s0` - s0 * s1 = 0
pub fn enforce_mul_constraints<E: FieldElement>(
Expand All @@ -153,8 +159,10 @@ pub fn enforce_mul_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the INV operation. The INV operation updates the top element
/// in the stack with its inverse. Therefore, the following constraints are enforced:
/// Enforces constraints of the INV operation.
///
/// The INV operation updates the top element in the stack with its inverse. Therefore, the
/// following constraints are enforced:
/// - The next element in the next frame should be the inverse of first element in the current
/// frame. s0` * s0 = 1.
pub fn enforce_inv_constraints<E: FieldElement>(
Expand All @@ -169,8 +177,10 @@ pub fn enforce_inv_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the INCR operation. The INCR operation increments the
/// top element in the stack by 1. Therefore, the following constraints are enforced:
/// Enforces constraints of the INCR operation.
///
/// The INCR operation increments the top element in the stack by 1. Therefore, the following
/// constraints are enforced:
/// - The next element in the next frame should be equal to the addition of first element in the
/// current frame with 1. s0` - s0 - 1 = 0.
pub fn enforce_incr_constraints<E: FieldElement>(
Expand All @@ -184,9 +194,10 @@ pub fn enforce_incr_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the NOT operation. The NOT operation updates the top element
/// in the stack with its bitwise not value. Therefore, the following constraints are
/// enforced:
/// Enforces constraints of the NOT operation.
///
/// The NOT operation updates the top element in the stack with its bitwise not value. Therefore,
/// the following constraints are enforced:
/// - The top element should be a binary. It is enforced as a general constraint.
/// - The first element of the next frame should be a binary not of the first element of the current
/// frame. s0` + s0 = 1.
Expand All @@ -205,8 +216,10 @@ pub fn enforce_not_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the AND operation. The AND operation computes the bitwise and of the
/// first two elements in the current trace. Therefore, the following constraints are enforced:
/// Enforces constraints of the AND operation.
///
/// The AND operation computes the bitwise and of the first two elements in the current trace.
/// Therefore, the following constraints are enforced:
/// - The top two element in the current frame of the stack should be binary. s0^2 - s0 = 0, s1^2 -
/// s1 = 0. The top element is binary or not is enforced as a general constraint.
/// - The first element of the next frame should be a binary and of the first two elements in the
Expand All @@ -232,8 +245,10 @@ pub fn enforce_and_constraints<E: FieldElement>(
2
}

/// Enforces constraints of the OR operation. The OR operation computes the bitwise or of the
/// first two elements in the current trace. Therefore, the following constraints are enforced:
/// Enforces constraints of the OR operation.
///
/// The OR operation computes the bitwise or of the first two elements in the current trace.
/// Therefore, the following constraints are enforced:
/// - The top two element in the current frame of the stack should be binary. s0^2 - s0 = 0, s1^2 -
/// s1 = 0. The top element is binary or not is enforced as a general constraint.
/// - The first element of the next frame should be a binary or of the first two elements in the
Expand All @@ -259,8 +274,10 @@ pub fn enforce_or_constraints<E: FieldElement>(
2
}

/// Enforces constraints of the EQ operation. The EQ operation checks if the top two elements in the
/// current frame are equal or not. Therefore, the following constraints are enforced:
/// Enforces constraints of the EQ operation.
///
/// The EQ operation checks if the top two elements in the current frame are equal or not.
/// Therefore, the following constraints are enforced:
/// - (s0 - s1) * s0' = 0
/// - s0` - (1 - (s0 - s1) * h0) = 0
pub fn enforce_eq_constraints<E: FieldElement>(
Expand Down Expand Up @@ -291,8 +308,10 @@ pub fn enforce_eq_constraints<E: FieldElement>(
2
}

/// Enforces constraints of the EQZ operation. The EQZ operation checks if the top element in the
/// current frame is 0 or not. Therefore, the following constraints are enforced:
/// Enforces constraints of the EQZ operation.
///
/// The EQZ operation checks if the top element in the current frame is 0 or not. Therefore, the
/// following constraints are enforced:
/// - s0 * s0` = 0.
/// - s0` - (1 - h0 * s0) = 0.
pub fn enforce_eqz_constraints<E: FieldElement>(
Expand All @@ -319,8 +338,10 @@ pub fn enforce_eqz_constraints<E: FieldElement>(
2
}

/// Enforces constraints of the EXPACC operation. The EXPACC operation computes a single turn of
/// exponent accumulation for the given inputs. Therefore, the following constraints are enforced:
/// Enforces constraints of the EXPACC operation.
///
/// The EXPACC operation computes a single turn of exponent accumulation for the given inputs.
/// Therefore, the following constraints are enforced:
/// - The first element in the next frame should be a binary which is enforced as a general
/// constraint.
/// - The exp value in the next frame should be the square of exp value in the current frame.
Expand Down Expand Up @@ -358,9 +379,11 @@ pub fn enforce_expacc_constraints<E: FieldElement>(
4
}

/// Enforces constraints of the EXT2MUL operation. The EXT2MUL operation computes the product of
/// two elements in the extension field of degree 2. Therefore, the following constraints are
/// enforced, assuming the first 4 elements of the stack in the current frame are a1, a0, b1, b0:
/// Enforces constraints of the EXT2MUL operation.
///
/// The EXT2MUL operation computes the product of two elements in the extension field of degree 2.
/// Therefore, the following constraints are enforced, assuming the first 4 elements of the stack in
/// the current frame are a1, a0, b1, b0:
/// - The first element in the next frame should be a1.
/// - The second element in the next frame should be a0.
/// - The third element in the next frame should be equal to (b0 + b1) * (a0 + a1) - b0 * a0.
Expand Down
18 changes: 10 additions & 8 deletions air/src/constraints/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ pub const NUM_ASSERTIONS: usize = 2 * STACK_TOP_SIZE + 2;
/// The number of general constraints in the stack operations.
pub const NUM_GENERAL_CONSTRAINTS: usize = 17;

/// The degrees of constraints in the general stack operations. Each operation being executed
/// either shifts the stack to the left, right or doesn't effect it at all. Therefore, majority
/// of the general transitions of a stack item would be common across the operations and composite
/// flags were introduced to compute the individual stack item transition. A particular item lets
/// say at depth ith in the next stack frame can be transitioned into from ith depth (no shift op)
/// or (i+1)th depth(left shift) or (i-1)th depth(right shift) in the current frame. Therefore, the
/// VM would require only 16 general constraints to encompass all the 16 stack positions.
/// The last constraint checks if the top element in the stack is a binary or not.
/// The degrees of constraints in the general stack operations.
///
/// Each operation being executed either shifts the stack to the left, right or doesn't effect it at
/// all. Therefore, majority of the general transitions of a stack item would be common across the
/// operations and composite flags were introduced to compute the individual stack item transition.
/// A particular item lets say at depth ith in the next stack frame can be transitioned into from
/// ith depth (no shift op) or (i+1)th depth(left shift) or (i-1)th depth(right shift) in the
/// current frame. Therefore, the VM would require only 16 general constraints to encompass all the
/// 16 stack positions. The last constraint checks if the top element in the stack is a binary or
/// not.
pub const CONSTRAINT_DEGREES: [usize; NUM_GENERAL_CONSTRAINTS] = [
// Each degree are being multiplied with the respective composite flags which are of degree 7.
// Therefore, all the degree would incorporate 7 in their degree calculation.
Expand Down
20 changes: 13 additions & 7 deletions air/src/constraints/stack/stack_manipulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ pub fn enforce_constraints<E: FieldElement>(
// TRANSITION CONSTRAINT HELPERS
// ================================================================================================

/// Enforces constraints of the PAD operation. The PAD operation pushes a ZERO onto
/// the stack. Therefore, the following constraints are enforced:
/// Enforces constraints of the PAD operation.
///
/// The PAD operation pushes a ZERO onto the stack. Therefore, the following constraints are
/// enforced:
/// - The top element in the next frame should be ZERO. s0` = 0.
pub fn enforce_pad_constraints<E: FieldElement>(
frame: &EvaluationFrame<E>,
Expand All @@ -91,9 +93,11 @@ pub fn enforce_pad_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the DUPn and MOVUPn operations. The DUPn operation copies the element
/// at depth n in the stack and pushes the copy onto the stack, whereas MOVUPn opearation moves the
/// element at depth n to the top of the stack. Therefore, the following constraints are enforced:
/// Enforces constraints of the DUPn and MOVUPn operations.
///
/// The DUPn operation copies the element at depth n in the stack and pushes the copy onto the
/// stack, whereas MOVUPn opearation moves the element at depth n to the top of the stack.
/// Therefore, the following constraints are enforced:
/// - The top element in the next frame should be equal to the element at depth n in the current
/// frame. s0` - sn = 0.
pub fn enforce_dup_movup_n_constraints<E: FieldElement>(
Expand Down Expand Up @@ -164,8 +168,10 @@ pub fn enforce_dup_movup_n_constraints<E: FieldElement>(
13
}

/// Enforces constraints of the SWAP operation. The SWAP operation swaps the first
/// two elements in the stack. Therefore, the following constraints are enforced:
/// Enforces constraints of the SWAP operation.
///
/// The SWAP operation swaps the first two elements in the stack. Therefore, the following
/// constraints are enforced:
/// - The first element in the current frame should be equal to the second element in the next
/// frame.
/// - The second element in the current frame should be equal to the first element in the next
Expand Down
19 changes: 12 additions & 7 deletions air/src/constraints/stack/system_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ pub fn enforce_assert_constraints<E: FieldElement>(
1
}

/// Enforces unique constraints of the FMPADD operation. The FMPADD operation increments the top
/// element in the stack by `fmp` register value. Therefore, the following constraints are enforced:
/// Enforces unique constraints of the FMPADD operation.
///
/// The FMPADD operation increments the top element in the stack by `fmp` register value. Therefore,
/// the following constraints are enforced:
/// - The first element in the next frame should be equal to the addition of the first element in
/// the current frame and the fmp value. s0` - (s0 + fmp) = 0
pub fn enforce_fmpadd_constraints<E: FieldElement>(
Expand All @@ -89,9 +91,10 @@ pub fn enforce_fmpadd_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the FMPUPDATE operation. The FMPUPDATE operation increments the fmp
/// register value by the first element value in the current trace. Therefore, the following
/// constraints are enforced:
/// Enforces constraints of the FMPUPDATE operation.
///
/// The FMPUPDATE operation increments the fmp register value by the first element value in the
/// current trace. Therefore, the following constraints are enforced:
/// - The fmp register value in the next frame should be equal to the sum of the fmp register value
/// and the top stack element in the current frame. fmp` - (s0 + fmp) = 0.
pub fn enforce_fmpupdate_constraints<E: FieldElement>(
Expand All @@ -105,8 +108,10 @@ pub fn enforce_fmpupdate_constraints<E: FieldElement>(
1
}

/// Enforces constraints of the CLK operation. The CLK operation pushes the current cycle number to
/// the stack. Therefore, the following constraints are enforced:
/// Enforces constraints of the CLK operation.
///
/// The CLK operation pushes the current cycle number to the stack. Therefore, the following
/// constraints are enforced:
/// - The first element in the next frame should be equal to the current cycle number. s0' - (cycle)
/// = 0.
pub fn enforce_clk_constraints<E: FieldElement>(
Expand Down
7 changes: 4 additions & 3 deletions air/src/constraints/stack/u32_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ pub fn enforce_u32mul_constraints<E: FieldElement<BaseField = Felt>>(
1
}

/// Enforces constraints of the U32MADD operation. The U32MADD operation adds the third
/// element to the product of the first two elements in the current trace. Therefore, the
/// following constraints are enforced:
/// Enforces constraints of the U32MADD operation.
///
/// The U32MADD operation adds the third element to the product of the first two elements in the
/// current trace. Therefore, the following constraints are enforced:
/// - The aggregation of all the limbs in the helper registers is equal to the sum of the third
/// element with the product of the first two elements in the current trace.
pub fn enforce_u32madd_constraints<E: FieldElement<BaseField = Felt>>(
Expand Down
8 changes: 4 additions & 4 deletions air/src/trace/chiplets/kernel_rom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub const TRACE_WIDTH: usize = 6;

// --- OPERATION SELECTORS ------------------------------------------------------------------------

/// Specifies a kernel procedure call operation to access a procedure in the kernel ROM. The unique
/// operation label is computed as 1 plus the combined chiplet and internal selector with the bits
/// reversed.
/// kernel ROM selector=[1, 1, 1, 0] +1=[0, 0, 0, 1]
/// Specifies a kernel procedure call operation to access a procedure in the kernel ROM.
///
/// The unique operation label is computed as 1 plus the combined chiplet and internal selector
/// with the bits reversed: kernel ROM selector=[1, 1, 1, 0] +1=[0, 0, 0, 1].
pub const KERNEL_PROC_LABEL: Felt = Felt::new(0b1000);
7 changes: 4 additions & 3 deletions air/src/trace/chiplets/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ pub const TRACE_WIDTH: usize = 12;
/// Number of selector columns in the trace.
pub const NUM_SELECTORS: usize = 2;

/// Type for Memory trace selectors. These selectors are used to define which operation and memory
/// state update (init & read / copy & read / write) is to be applied at a specific row of the
/// memory execution trace.
/// Type for Memory trace selectors.
///
/// These selectors are used to define which operation and memory state update (init & read / copy
/// & read / write) is to be applied at a specific row of the memory execution trace.
pub type Selectors = [Felt; NUM_SELECTORS];

// --- OPERATION SELECTORS ------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions assembly/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ impl From<Label> for LabeledSpan {
// RELATED LABEL
// ================================================================================================

/// This type is used to associate a more complex label or set of labels with some other error. In
/// particular, it is used to reference related bits of source code distinct from that of the
/// original error.
/// This type is used to associate a more complex label or set of labels with some other error.
///
/// A related label can have a distinct severity, its own message, and its own sub-labels, and may
/// reference code in a completely different source file that the original error.
/// In particular, it is used to reference related bits of source code distinct from that of the
/// original error. A related label can have a distinct severity, its own message, and its own
/// sub-labels, and may reference code in a completely different source file that the original
/// error.
#[derive(Debug)]
pub struct RelatedLabel {
/// The severity for this related label
Expand Down
11 changes: 6 additions & 5 deletions assembly/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ macro_rules! assert_diagnostic {
}};
}

/// Like [assert_diagnostic], but matches each non-empty line of the rendered output
/// to a corresponding pattern. So if the output has 3 lines, the second of which is
/// empty, and you provide 2 patterns, the assertion passes if the first line matches
/// the first pattern, and the third line matches the second pattern - the second
/// line is ignored because it is empty.
/// Like [assert_diagnostic], but matches each non-empty line of the rendered output to a
/// corresponding pattern.
///
/// So if the output has 3 lines, the second of which is empty, and you provide 2 patterns, the
/// assertion passes if the first line matches the first pattern, and the third line matches the
/// second pattern - the second line is ignored because it is empty.
#[macro_export]
macro_rules! assert_diagnostic_lines {
($diagnostic:expr, $($expected:expr),+) => {{
Expand Down
7 changes: 3 additions & 4 deletions processor/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ impl fmt::Display for VmState {
}

/// Iterator that iterates through vm state at each step of the execution.
/// This allows debugging or replaying ability to view various process state
/// at each clock cycle.
/// If the execution returned an error, it returns that error on the clock cycle
/// it stopped.
///
/// This allows debugging or replaying ability to view various process state at each clock cycle.
/// If the execution returned an error, it returns that error on the clock cycle it stopped.
pub struct VmStateIterator {
chiplets: Chiplets,
decoder: Decoder,
Expand Down
9 changes: 5 additions & 4 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ macro_rules! expect_exec_error {
}

/// Like [assembly::assert_diagnostic], but matches each non-empty line of the rendered output
/// to a corresponding pattern. So if the output has 3 lines, the second of which is
/// empty, and you provide 2 patterns, the assertion passes if the first line matches
/// the first pattern, and the third line matches the second pattern - the second
/// line is ignored because it is empty.
/// to a corresponding pattern.
///
/// So if the output has 3 lines, the second of which is empty, and you provide 2 patterns, the
/// assertion passes if the first line matches the first pattern, and the third line matches the
/// second pattern - the second line is ignored because it is empty.
#[cfg(all(feature = "std", not(target_family = "wasm")))]
#[macro_export]
macro_rules! assert_diagnostic_lines {
Expand Down

0 comments on commit c1ac8e8

Please sign in to comment.