Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run cargo fmt on all files #1385

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions evm/src/all_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
cpu_stark::ctl_data_partial_memory::<F>(),
Some(cpu_stark::ctl_filter_partial_memory()),
);
let keccak_sponge_reads = (0..KECCAK_RATE_BYTES).map(|i| {
TableWithColumns::new(
Table::KeccakSponge,
keccak_sponge_stark::ctl_looking_memory(i),
Some(keccak_sponge_stark::ctl_looking_memory_filter(i)),
)
});
let keccak_sponge_reads =
(0..KECCAK_RATE_BYTES).map(|i| {
TableWithColumns::new(
Table::KeccakSponge,
keccak_sponge_stark::ctl_looking_memory(i),
Some(keccak_sponge_stark::ctl_looking_memory_filter(i)),
)
});
let byte_packing_ops = (0..32).map(|i| {
TableWithColumns::new(
Table::BytePacking,
Expand Down
13 changes: 7 additions & 6 deletions evm/src/arithmetic/addcy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,13 @@ mod tests {
lv[IS_LT] = F::ZERO;
lv[IS_GT] = F::ZERO;

let mut constrant_consumer = ConstraintConsumer::new(
vec![GoldilocksField(2), GoldilocksField(3), GoldilocksField(5)],
F::ONE,
F::ONE,
F::ONE,
);
let mut constrant_consumer =
ConstraintConsumer::new(
vec![GoldilocksField(2), GoldilocksField(3), GoldilocksField(5)],
F::ONE,
F::ONE,
F::ONE,
);
eval_packed_generic(&lv, &mut constrant_consumer);
for &acc in &constrant_consumer.constraint_accs {
assert_eq!(acc, F::ZERO);
Expand Down
59 changes: 31 additions & 28 deletions evm/src/arithmetic/modular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,26 +785,28 @@ pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
let addmul_filter = builder.add_extension(add_filter, mul_filter);

// constr_poly has 2*N_LIMBS limbs
let submod_constr_poly = submod_constr_poly_ext_circuit(
lv,
nv,
builder,
yield_constr,
sub_filter,
output,
modulus,
quo_input,
);
let modular_constr_poly = modular_constr_poly_ext_circuit(
lv,
nv,
builder,
yield_constr,
addmul_filter,
output,
modulus,
quo_input,
);
let submod_constr_poly =
submod_constr_poly_ext_circuit(
lv,
nv,
builder,
yield_constr,
sub_filter,
output,
modulus,
quo_input,
);
let modular_constr_poly =
modular_constr_poly_ext_circuit(
lv,
nv,
builder,
yield_constr,
addmul_filter,
output,
modulus,
quo_input,
);
let input0 = read_value(lv, MODULAR_INPUT_0);
let input1 = read_value(lv, MODULAR_INPUT_1);

Expand Down Expand Up @@ -839,14 +841,15 @@ mod tests {
use crate::extension_tower::BN_BASE;

const N_RND_TESTS: usize = 1000;
const MODULAR_OPS: [usize; 6] = [
IS_ADDMOD,
IS_SUBMOD,
IS_MULMOD,
IS_ADDFP254,
IS_SUBFP254,
IS_MULFP254,
];
const MODULAR_OPS: [usize; 6] =
[
IS_ADDMOD,
IS_SUBMOD,
IS_MULMOD,
IS_ADDFP254,
IS_SUBFP254,
IS_MULFP254,
];

// TODO: Should be able to refactor this test to apply to all operations.
#[test]
Expand Down
23 changes: 12 additions & 11 deletions evm/src/arithmetic/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ pub(crate) fn eval_packed_generic_mul<P: PackedField>(

let base = P::Scalar::from_canonical_u64(1 << LIMB_BITS);

let aux_limbs = {
// MUL_AUX_INPUT was offset by 2^20 in generation, so we undo
// that here
let offset = P::Scalar::from_canonical_u64(AUX_COEFF_ABS_MAX as u64);
let mut aux_limbs = read_value::<N_LIMBS, _>(lv, MUL_AUX_INPUT_LO);
let aux_limbs_hi = &lv[MUL_AUX_INPUT_HI];
for (lo, &hi) in aux_limbs.iter_mut().zip(aux_limbs_hi) {
*lo += hi * base - offset;
}
aux_limbs
};
let aux_limbs =
{
// MUL_AUX_INPUT was offset by 2^20 in generation, so we undo
// that here
let offset = P::Scalar::from_canonical_u64(AUX_COEFF_ABS_MAX as u64);
let mut aux_limbs = read_value::<N_LIMBS, _>(lv, MUL_AUX_INPUT_LO);
let aux_limbs_hi = &lv[MUL_AUX_INPUT_HI];
for (lo, &hi) in aux_limbs.iter_mut().zip(aux_limbs_hi) {
*lo += hi * base - offset;
}
aux_limbs
};

// Constraint poly holds the coefficients of the polynomial that
// must be identically zero for this multiplication to be
Expand Down
11 changes: 6 additions & 5 deletions evm/src/arithmetic/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ mod tests {
U256::from(lv[ai].to_canonical_u64()) + full_input * U256::from(1 << 16);
}

let output = if is_shl {
full_input << shift
} else {
full_input >> shift
};
let output =
if is_shl {
full_input << shift
} else {
full_input >> shift
};

generate(&mut lv, &mut nv, is_shl, shift, full_input, output);

Expand Down
21 changes: 11 additions & 10 deletions evm/src/byte_packing/byte_packing_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ pub(crate) fn ctl_looked_data<F: Field>() -> Vec<Column<F>> {
// being read/written from the underlying byte values. For each,
// we pack 4 consecutive bytes and shift them accordingly to
// obtain the corresponding limb.
let outputs: Vec<Column<F>> = (0..8)
.map(|i| {
let range = (value_bytes(i * 4)..value_bytes(i * 4) + 4);
Column::linear_combination(
range
.enumerate()
.map(|(j, c)| (c, F::from_canonical_u64(1 << (8 * j)))),
)
})
.collect();
let outputs: Vec<Column<F>> =
(0..8)
.map(|i| {
let range = (value_bytes(i * 4)..value_bytes(i * 4) + 4);
Column::linear_combination(
range
.enumerate()
.map(|(j, c)| (c, F::from_canonical_u64(1 << (8 * j)))),
)
})
.collect();

// This will correspond to the actual sequence length when the `SEQUENCE_END` flag is on.
let sequence_len: Column<F> = Column::linear_combination(
Expand Down
10 changes: 4 additions & 6 deletions evm/src/cpu/contextops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,10 @@ fn eval_ext_circuit_set<F: RichField + Extendable<D>, const D: usize>(
let stack_top = lv.mem_channels[0].value;
let write_old_sp_channel = lv.mem_channels[1];
let read_new_sp_channel = lv.mem_channels[2];
let ctx_metadata_segment = builder.constant_extension(F::Extension::from_canonical_u32(
Segment::ContextMetadata as u32,
));
let stack_size_field = builder.constant_extension(F::Extension::from_canonical_u32(
ContextMetadata::StackSize as u32,
));
let ctx_metadata_segment = builder
.constant_extension(F::Extension::from_canonical_u32(Segment::ContextMetadata as u32));
let stack_size_field = builder
.constant_extension(F::Extension::from_canonical_u32(ContextMetadata::StackSize as u32));
let one = builder.one_extension();
let local_sp_dec = builder.sub_extension(lv.stack_len, one);

Expand Down
34 changes: 17 additions & 17 deletions evm/src/cpu/cpu_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ pub(crate) fn ctl_data_code_memory<F: Field>() -> Vec<Column<F>> {
/// Creates the vector of `Columns` corresponding to the contents of General Purpose channels.
pub(crate) fn ctl_data_gp_memory<F: Field>(channel: usize) -> Vec<Column<F>> {
let channel_map = COL_MAP.mem_channels[channel];
let mut cols: Vec<_> = Column::singles([
channel_map.is_read,
channel_map.addr_context,
channel_map.addr_segment,
channel_map.addr_virtual,
])
.collect();
let mut cols: Vec<_> =
Column::singles([
channel_map.is_read,
channel_map.addr_context,
channel_map.addr_segment,
channel_map.addr_virtual,
])
.collect();

cols.extend(Column::singles(channel_map.value));

Expand All @@ -237,19 +238,18 @@ pub(crate) fn ctl_data_gp_memory<F: Field>(channel: usize) -> Vec<Column<F>> {
pub(crate) fn ctl_data_partial_memory<F: Field>() -> Vec<Column<F>> {
let channel_map = COL_MAP.partial_channel;
let values = COL_MAP.mem_channels[0].value;
let mut cols: Vec<_> = Column::singles([
channel_map.is_read,
channel_map.addr_context,
channel_map.addr_segment,
channel_map.addr_virtual,
])
.collect();
let mut cols: Vec<_> =
Column::singles([
channel_map.is_read,
channel_map.addr_context,
channel_map.addr_segment,
channel_map.addr_virtual,
])
.collect();

cols.extend(Column::singles(values));

cols.push(mem_time_and_channel(
MEM_GP_CHANNELS_IDX_START + NUM_GP_CHANNELS,
));
cols.push(mem_time_and_channel(MEM_GP_CHANNELS_IDX_START + NUM_GP_CHANNELS));

cols
}
Expand Down
47 changes: 24 additions & 23 deletions evm/src/cpu/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ const OPCODES: [(u8, usize, bool, usize); 9] = [
/// List of combined opcodes requiring a special handling.
/// Each index in the list corresponds to an arbitrary combination
/// of opcodes defined in evm/src/cpu/columns/ops.rs.
const COMBINED_OPCODES: [usize; 9] = [
COL_MAP.op.logic_op,
COL_MAP.op.fp254_op,
COL_MAP.op.binary_op,
COL_MAP.op.ternary_op,
COL_MAP.op.shift,
COL_MAP.op.m_op_general,
COL_MAP.op.jumpdest_keccak_general,
COL_MAP.op.not_pop,
COL_MAP.op.pc_push0,
];
const COMBINED_OPCODES: [usize; 9] =
[
COL_MAP.op.logic_op,
COL_MAP.op.fp254_op,
COL_MAP.op.binary_op,
COL_MAP.op.ternary_op,
COL_MAP.op.shift,
COL_MAP.op.m_op_general,
COL_MAP.op.jumpdest_keccak_general,
COL_MAP.op.not_pop,
COL_MAP.op.pc_push0,
];

/// Break up an opcode (which is 8 bits long) into its eight bits.
const fn bits_from_opcode(opcode: u8) -> [bool; 8] {
Expand Down Expand Up @@ -115,18 +116,18 @@ pub(crate) fn eval_packed_generic<P: PackedField>(
true => P::ONES - kernel_mode,
};
// 0 if all the opcode bits match, and something in {1, ..., 8}, otherwise.
let opcode_mismatch: P = lv
.opcode_bits
.into_iter()
.zip(bits_from_opcode(oc))
.rev()
.take(8 - block_length)
.map(|(row_bit, flag_bit)| match flag_bit {
// 1 if the bit does not match, and 0 otherwise
false => row_bit,
true => P::ONES - row_bit,
})
.sum();
let opcode_mismatch: P =
lv.opcode_bits
.into_iter()
.zip(bits_from_opcode(oc))
.rev()
.take(8 - block_length)
.map(|(row_bit, flag_bit)| match flag_bit {
// 1 if the bit does not match, and 0 otherwise
false => row_bit,
true => P::ONES - row_bit,
})
.sum();

// If unavailable + opcode_mismatch is 0, then the opcode bits all match and we are in the
// correct mode.
Expand Down
44 changes: 23 additions & 21 deletions evm/src/cpu/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ fn eval_packed_accumulate<P: PackedField>(
) {
// Is it an instruction that we constrain here?
// I.e., does it always cost a constant amount of gas?
let filter: P = SIMPLE_OPCODES
.into_iter()
.enumerate()
.filter_map(|(i, maybe_cost)| {
// Add flag `lv.op[i]` to the sum if `SIMPLE_OPCODES[i]` is `Some`.
maybe_cost.map(|_| lv.op[i])
})
.sum();
let filter: P =
SIMPLE_OPCODES
.into_iter()
.enumerate()
.filter_map(|(i, maybe_cost)| {
// Add flag `lv.op[i]` to the sum if `SIMPLE_OPCODES[i]` is `Some`.
maybe_cost.map(|_| lv.op[i])
})
.sum();

// How much gas did we use?
let gas_used: P = SIMPLE_OPCODES
.into_iter()
.enumerate()
.filter_map(|(i, maybe_cost)| {
maybe_cost.map(|cost| P::Scalar::from_canonical_u32(cost) * lv.op[i])
})
.filter_map(
|(i, maybe_cost)| maybe_cost.map(|cost| P::Scalar::from_canonical_u32(cost) * lv.op[i])
)
.sum();

let constr = nv.gas - (lv.gas + gas_used);
Expand Down Expand Up @@ -146,16 +147,17 @@ fn eval_ext_circuit_accumulate<F: RichField + Extendable<D>, const D: usize>(
) {
// Is it an instruction that we constrain here?
// I.e., does it always cost a constant amount of gas?
let filter = SIMPLE_OPCODES.into_iter().enumerate().fold(
builder.zero_extension(),
|cumul, (i, maybe_cost)| {
// Add flag `lv.op[i]` to the sum if `SIMPLE_OPCODES[i]` is `Some`.
match maybe_cost {
None => cumul,
Some(_) => builder.add_extension(lv.op[i], cumul),
}
},
);
let filter =
SIMPLE_OPCODES.into_iter().enumerate().fold(
builder.zero_extension(),
|cumul, (i, maybe_cost)| {
// Add flag `lv.op[i]` to the sum if `SIMPLE_OPCODES[i]` is `Some`.
match maybe_cost {
None => cumul,
Some(_) => builder.add_extension(lv.op[i], cumul),
}
},
);

// How much gas did we use?
let gas_used = SIMPLE_OPCODES.into_iter().enumerate().fold(
Expand Down
Loading
Loading