Skip to content

Commit

Permalink
chore: add custom rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Dec 10, 2022
1 parent 22cb800 commit 7a60c1e
Show file tree
Hide file tree
Showing 109 changed files with 807 additions and 1,984 deletions.
21 changes: 16 additions & 5 deletions air/src/chiplets/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ fn enforce_input_decomposition<E: FieldElement>(
constraint_offset += NUM_DECOMP_BITS;

// Values in bit decomposition columns b0..b3 should be binary.
for (idx, result) in result[constraint_offset..]
.iter_mut()
.take(NUM_DECOMP_BITS)
.enumerate()
{
for (idx, result) in result[constraint_offset..].iter_mut().take(NUM_DECOMP_BITS).enumerate() {
*result = processor_flag * is_binary(frame.b_bit(idx));
}
constraint_offset += NUM_DECOMP_BITS;
Expand Down Expand Up @@ -307,46 +303,57 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn selector(&self) -> E {
self.current()[BITWISE_SELECTOR_COL_IDX]
}

#[inline(always)]
fn selector_next(&self) -> E {
self.next()[BITWISE_SELECTOR_COL_IDX]
}

#[inline(always)]
fn a(&self) -> E {
self.current()[BITWISE_A_COL_IDX]
}

#[inline(always)]
fn a_next(&self) -> E {
self.next()[BITWISE_A_COL_IDX]
}

#[inline(always)]
fn a_bit(&self, index: usize) -> E {
self.current()[BITWISE_A_COL_RANGE.start + index]
}

#[inline(always)]
fn b(&self) -> E {
self.current()[BITWISE_B_COL_IDX]
}

#[inline(always)]
fn b_next(&self) -> E {
self.next()[BITWISE_B_COL_IDX]
}

#[inline(always)]
fn b_bit(&self, index: usize) -> E {
self.current()[BITWISE_B_COL_RANGE.start + index]
}

#[inline(always)]
fn bit_decomp(&self) -> &[E] {
&self.current()[BITWISE_A_COL_RANGE.start..BITWISE_B_COL_RANGE.end]
}

#[inline(always)]
fn output_prev(&self) -> E {
self.current()[BITWISE_PREV_OUTPUT_COL_IDX]
}

#[inline(always)]
fn output_prev_next(&self) -> E {
self.next()[BITWISE_PREV_OUTPUT_COL_IDX]
}

#[inline(always)]
fn output(&self) -> E {
self.current()[BITWISE_OUTPUT_COL_IDX]
Expand All @@ -357,14 +364,17 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn a_agg_bits(&self) -> E {
agg_bits(self.current(), BITWISE_A_COL_RANGE.start)
}

#[inline(always)]
fn a_agg_bits_next(&self) -> E {
agg_bits(self.next(), BITWISE_A_COL_RANGE.start)
}

#[inline(always)]
fn b_agg_bits(&self) -> E {
agg_bits(self.current(), BITWISE_B_COL_RANGE.start)
}

#[inline(always)]
fn b_agg_bits_next(&self) -> E {
agg_bits(self.next(), BITWISE_B_COL_RANGE.start)
Expand All @@ -376,6 +386,7 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn bitwise_and_flag(&self) -> E {
binary_not(self.current()[BITWISE_SELECTOR_COL_IDX])
}

#[inline(always)]
fn bitwise_xor_flag(&self) -> E {
self.current()[BITWISE_SELECTOR_COL_IDX]
Expand Down
51 changes: 29 additions & 22 deletions air/src/chiplets/hasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ pub const NUM_PERIODIC_COLUMNS: usize = STATE_WIDTH * 2 + NUM_PERIODIC_SELECTOR_
/// - k2 column, which has a repeating pattern of a single one followed by 7 zeros.
/// - the round constants for the Rescue Prime permutation.
pub fn get_periodic_column_values() -> Vec<Vec<Felt>> {
let mut result = vec![
HASH_K0_MASK.to_vec(),
HASH_K1_MASK.to_vec(),
HASH_K2_MASK.to_vec(),
];
let mut result = vec![HASH_K0_MASK.to_vec(), HASH_K1_MASK.to_vec(), HASH_K2_MASK.to_vec()];
result.append(&mut get_round_constants());
result
}
Expand Down Expand Up @@ -252,11 +248,7 @@ fn enforce_hasher_state<E: FieldElement + From<Felt>>(
// When absorbing the next set of elements into the state during linear hash computation,
// the first 4 elements (the capacity portion) is carried over to the next row.
let hash_abp_flag = last_row * frame.f_abp();
for (idx, result) in result[constraint_offset..]
.iter_mut()
.take(CAPACITY_LEN)
.enumerate()
{
for (idx, result) in result[constraint_offset..].iter_mut().take(CAPACITY_LEN).enumerate() {
*result = hash_abp_flag * (frame.h_next(idx) - frame.h(idx))
}
constraint_offset += CAPACITY_LEN;
Expand All @@ -266,11 +258,7 @@ fn enforce_hasher_state<E: FieldElement + From<Felt>>(
// on the value of b.
let mp_abp_flag = last_row
* (frame.f_mp(periodic_values) + frame.f_mv(periodic_values) + frame.f_mu(periodic_values));
for (idx, result) in result[constraint_offset..]
.iter_mut()
.take(DIGEST_LEN)
.enumerate()
{
for (idx, result) in result[constraint_offset..].iter_mut().take(DIGEST_LEN).enumerate() {
let digest_idx = DIGEST_RANGE.start + idx;
let h_copy_down = frame.h_next(digest_idx) - frame.h(digest_idx);
let h_copy_over = frame.h_next(DIGEST_LEN + digest_idx) - frame.h(digest_idx);
Expand Down Expand Up @@ -342,14 +330,11 @@ fn apply_mds<E: FieldElement + From<Felt>>(state: &mut [E; STATE_WIDTH]) {
#[inline(always)]
fn apply_inv_mds<E: FieldElement + From<Felt>>(state: &mut [E; STATE_WIDTH]) {
let mut result = [E::ZERO; STATE_WIDTH];
result
.iter_mut()
.zip(Hasher::INV_MDS)
.for_each(|(r, mds_row)| {
state.iter().zip(mds_row).for_each(|(&s, m)| {
*r += E::from(m) * s;
});
result.iter_mut().zip(Hasher::INV_MDS).for_each(|(r, mds_row)| {
state.iter().zip(mds_row).for_each(|(&s, m)| {
*r += E::from(m) * s;
});
});
*state = result
}

Expand Down Expand Up @@ -444,38 +429,47 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn s(&self, idx: usize) -> E {
self.current()[HASHER_SELECTOR_COL_RANGE.start + idx]
}

#[inline(always)]
fn s_next(&self, idx: usize) -> E {
self.next()[HASHER_SELECTOR_COL_RANGE.start + idx]
}

#[inline(always)]
fn row(&self) -> E {
self.current()[HASHER_ROW_COL_IDX]
}

#[inline(always)]
fn row_next(&self) -> E {
self.next()[HASHER_ROW_COL_IDX]
}

#[inline(always)]
fn hash_state(&self) -> &[E] {
&self.current()[HASHER_STATE_COL_RANGE]
}

#[inline(always)]
fn hash_state_next(&self) -> &[E] {
&self.next()[HASHER_STATE_COL_RANGE]
}

#[inline(always)]
fn h(&self, idx: usize) -> E {
self.current()[HASHER_STATE_COL_RANGE.start + idx]
}

#[inline(always)]
fn h_next(&self, idx: usize) -> E {
self.next()[HASHER_STATE_COL_RANGE.start + idx]
}

#[inline(always)]
fn i(&self) -> E {
self.current()[HASHER_NODE_INDEX_COL_IDX]
}

#[inline(always)]
fn i_next(&self) -> E {
self.next()[HASHER_NODE_INDEX_COL_IDX]
Expand All @@ -494,54 +488,67 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn f_rpr(&self, k: &[E]) -> E {
binary_not(k[0])
}

#[inline(always)]
fn f_bp(&self, k: &[E]) -> E {
k[2] * self.s(0) * binary_not(self.s(1)) * binary_not(self.s(2))
}

#[inline(always)]
fn f_mp(&self, k: &[E]) -> E {
k[2] * self.s(0) * binary_not(self.s(1)) * self.s(2)
}

#[inline(always)]
fn f_mv(&self, k: &[E]) -> E {
k[2] * self.s(0) * self.s(1) * binary_not(self.s(2))
}

#[inline(always)]
fn f_mu(&self, k: &[E]) -> E {
k[2] * self.s(0) * self.s(1) * self.s(2)
}

#[inline(always)]
fn f_hout(&self, k: &[E]) -> E {
k[0] * binary_not(self.s(0)) * binary_not(self.s(1)) * binary_not(self.s(2))
}

#[inline(always)]
fn f_sout(&self, k: &[E]) -> E {
k[0] * binary_not(self.s(0)) * binary_not(self.s(1)) * self.s(2)
}

#[inline(always)]
fn f_out(&self, k: &[E]) -> E {
k[0] * binary_not(self.s(0)) * binary_not(self.s(1))
}

#[inline(always)]
fn f_out_next(&self, k: &[E]) -> E {
k[1] * binary_not(self.s_next(0)) * binary_not(self.s_next(1))
}

#[inline(always)]
fn f_abp(&self) -> E {
self.s(0) * binary_not(self.s(1)) * binary_not(self.s(2))
}

#[inline(always)]
fn f_mpa(&self) -> E {
self.s(0) * binary_not(self.s(1)) * self.s(2)
}

#[inline(always)]
fn f_mva(&self) -> E {
self.s(0) * self.s(1) * binary_not(self.s(2))
}

#[inline(always)]
fn f_mua(&self) -> E {
self.s(0) * self.s(1) * self.s(2)
}

#[inline(always)]
fn f_an(&self, k: &[E]) -> E {
self.f_mp(k)
Expand Down
11 changes: 11 additions & 0 deletions air/src/chiplets/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,42 +240,52 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn selector(&self, idx: usize) -> E {
self.current()[MEMORY_TRACE_OFFSET + idx]
}

#[inline(always)]
fn selector_next(&self, idx: usize) -> E {
self.next()[MEMORY_TRACE_OFFSET + idx]
}

#[inline(always)]
fn ctx(&self) -> E {
self.current()[MEMORY_CTX_COL_IDX]
}

#[inline(always)]
fn addr(&self) -> E {
self.next()[MEMORY_ADDR_COL_IDX]
}

#[inline(always)]
fn clk(&self) -> E {
self.current()[MEMORY_CLK_COL_IDX]
}

#[inline(always)]
fn clk_next(&self) -> E {
self.next()[MEMORY_CLK_COL_IDX]
}

#[inline(always)]
fn v(&self, index: usize) -> E {
self.current()[MEMORY_V_COL_RANGE.start + index]
}

#[inline(always)]
fn v_next(&self, index: usize) -> E {
self.next()[MEMORY_V_COL_RANGE.start + index]
}

#[inline(always)]
fn d0_next(&self) -> E {
self.next()[MEMORY_D0_COL_IDX]
}

#[inline(always)]
fn d1_next(&self) -> E {
self.next()[MEMORY_D1_COL_IDX]
}

#[inline(always)]
fn d_inv_next(&self) -> E {
self.next()[MEMORY_D_INV_COL_IDX]
Expand Down Expand Up @@ -368,6 +378,7 @@ impl<E: FieldElement> MemoryFrameExt<E> for &EvaluationFrame<E> {
fn memory_d0(&self) -> E {
self.current()[MEMORY_D0_COL_IDX]
}

#[inline(always)]
fn memory_d1(&self) -> E {
self.current()[MEMORY_D1_COL_IDX]
Expand Down
8 changes: 3 additions & 5 deletions air/src/chiplets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ pub fn enforce_constraints<E: FieldElement<BaseField = Felt>>(
constraint_offset += bitwise::get_transition_constraint_count();

// memory transition constraints
memory::enforce_constraints(
frame,
&mut result[constraint_offset..],
frame.memory_flag(false),
);
memory::enforce_constraints(frame, &mut result[constraint_offset..], frame.memory_flag(false));
}

// TRANSITION CONSTRAINT HELPERS
Expand Down Expand Up @@ -179,10 +175,12 @@ impl<E: FieldElement> EvaluationFrameExt<E> for &EvaluationFrame<E> {
fn hasher_flag(&self) -> E {
binary_not(self.s(0))
}

#[inline(always)]
fn bitwise_flag(&self) -> E {
self.s(0) * binary_not(self.s_next(1))
}

#[inline(always)]
fn memory_flag(&self, include_last_row: bool) -> E {
if include_last_row {
Expand Down
15 changes: 3 additions & 12 deletions air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,11 @@ impl Serializable for PublicInputs {
target.write(self.stack_inputs.as_slice());

// write program outputs.
let stack = self
.outputs
.stack()
.iter()
.map(|v| Felt::new(*v))
.collect::<Vec<_>>();
let stack = self.outputs.stack().iter().map(|v| Felt::new(*v)).collect::<Vec<_>>();
target.write(&stack);

let overflow_addrs = self
.outputs
.overflow_addrs()
.iter()
.map(|v| Felt::new(*v))
.collect::<Vec<_>>();
let overflow_addrs =
self.outputs.overflow_addrs().iter().map(|v| Felt::new(*v)).collect::<Vec<_>>();
target.write(&overflow_addrs);
}
}
5 changes: 1 addition & 4 deletions air/src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@ pub fn get_aux_assertions_first_step<E: FieldElement>(
{
let step = 0;
let value = if stack_inputs.len() > STACK_TOP_SIZE {
get_overflow_table_init(
alphas.get_segment_elements(0),
&stack_inputs[STACK_TOP_SIZE..],
)
get_overflow_table_init(alphas.get_segment_elements(0), &stack_inputs[STACK_TOP_SIZE..])
} else {
E::ONE
};
Expand Down
Loading

0 comments on commit 7a60c1e

Please sign in to comment.