Skip to content

Commit

Permalink
Assert validity of padded lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
hratoanina committed Jul 29, 2024
1 parent 1309f83 commit 9c7117a
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions evm_arithmetization/src/arithmetic/arithmetic_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl<F: RichField, const D: usize> ArithmeticStark<F, D> {
// to accommodate the range check columns. Also make sure the
// trace length is a power of two.
let padded_len = 1 << ALL_DEGREE_LOGS[TABLE_TO_SORTED_INDEX[*Table::Arithmetic]];
assert!(padded_len >= trace_rows.len());
for _ in trace_rows.len()..std::cmp::max(padded_len, RANGE_MAX) {
trace_rows.push(vec![F::ZERO; columns::NUM_ARITH_COLUMNS]);
}
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/src/byte_packing/byte_packing_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl<F: RichField + Extendable<D>, const D: usize> BytePackingStark<F, D> {
rows.push(self.generate_row_for_op(op));
}
}
assert!(num_rows >= rows.len());

for _ in rows.len()..num_rows {
rows.push(self.generate_padding_row());
Expand Down
3 changes: 3 additions & 0 deletions evm_arithmetization/src/generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ fn simulate_cpu<F: Field>(
row.gas = F::from_canonical_u64(state.registers.gas_used);
row.stack_len = F::from_canonical_usize(state.registers.stack_len);

let padded_len = 1 << ALL_DEGREE_LOGS[TABLE_TO_SORTED_INDEX[*Table::Cpu]];
assert!(padded_len >= state.traces.clock());

loop {
// Padding.
state.push_cpu(row);
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/src/keccak/keccak_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl<F: RichField + Extendable<D>, const D: usize> KeccakStark<F, D> {
rows.extend(rows_for_perm);
}

assert!(num_rows >= rows.len());
while rows.len() < num_rows {
rows.push([F::ZERO; NUM_COLUMNS]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ impl<F: RichField + Extendable<D>, const D: usize> KeccakSpongeStark<F, D> {
}
// Pad the trace.
let padded_rows = 1 << ALL_DEGREE_LOGS[TABLE_TO_SORTED_INDEX[*Table::KeccakSponge]];
assert!(padded_rows >= rows.len());
for _ in rows.len()..padded_rows {
rows.push(self.generate_padding_row());
}
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl<F: RichField, const D: usize> LogicStark<F, D> {
) -> Vec<[F; NUM_COLUMNS]> {
let len = operations.len();
let padded_len = 1 << ALL_DEGREE_LOGS[TABLE_TO_SORTED_INDEX[*Table::Logic]];
assert!(padded_len >= len);

let mut rows = Vec::with_capacity(padded_len);
for op in operations {
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/src/memory/memory_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ impl<F: RichField + Extendable<D>, const D: usize> MemoryStark<F, D> {
// We want at least one padding row, so that the last real operation can have
// its flags set correctly.
let num_ops_padded = 1 << ALL_DEGREE_LOGS[TABLE_TO_SORTED_INDEX[*Table::Memory]];
assert!(num_ops_padded >= num_ops);
for _ in num_ops..num_ops_padded {
memory_ops.push(padding_op);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl<F: RichField + Extendable<D>, const D: usize> MemoryContinuationStark<F, D>

let num_rows = rows.len();
let num_rows_padded = 1 << log_padded;
assert!(num_rows_padded >= num_rows);
for _ in num_rows..num_rows_padded {
rows.push(vec![F::ZERO; NUM_COLUMNS]);
}
Expand Down

0 comments on commit 9c7117a

Please sign in to comment.