Skip to content

Commit

Permalink
chore: Prefer copy_from_slice to clone().try_into().unwrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
zlangley committed Jan 23, 2025
1 parent 586b026 commit 899ceda
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
8 changes: 3 additions & 5 deletions crates/vm/src/arch/testing/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ where
address_space: record.address_space,
pointer: record.pointer,
};
row.data = match &record.prev_data {
Some(prev_data) => prev_data.clone().try_into().unwrap(),
None => record.data.clone().try_into().unwrap(),
};
row.data
.copy_from_slice(record.prev_data.as_ref().unwrap_or(&record.data));
row.timestamp = Val::<SC>::from_canonical_u32(record.prev_timestamp);
row.count = -Val::<SC>::ONE;

Expand All @@ -111,7 +109,7 @@ where
address_space: record.address_space,
pointer: record.pointer,
};
row.data = record.data.clone().try_into().unwrap();
row.data.copy_from_slice(&record.data);
row.timestamp = Val::<SC>::from_canonical_u32(record.timestamp);
row.count = Val::<SC>::ONE;
}
Expand Down
21 changes: 7 additions & 14 deletions extensions/keccak256/circuit/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,6 @@ where
.zip(instruction_blocks.into_par_iter())
.for_each(|((rows, p3_keccak_mat), (instruction, diff, block))| {
let height = rows.len() / trace_width;
let partial_read_data = if let Some(partial_read_idx) = block.partial_read_idx {
memory
.record_by_id(block.reads[partial_read_idx])
.data
.clone()
.try_into()
.unwrap()
} else {
[Val::<SC>::ZERO; KECCAK_WORD_SIZE]
};
for (row, p3_keccak_row) in rows
.chunks_exact_mut(trace_width)
.zip(p3_keccak_mat.chunks_exact(NUM_KECCAK_PERM_COLS))
Expand All @@ -184,10 +174,13 @@ where

row_mut.sponge.block_bytes =
block.padded_bytes.map(Val::<SC>::from_canonical_u8);
row_mut
.mem_oc
.partial_block
.copy_from_slice(&partial_read_data[1..]);
if let Some(partial_read_idx) = block.partial_read_idx {
let partial_read = memory.record_by_id(block.reads[partial_read_idx]);
row_mut
.mem_oc
.partial_block
.copy_from_slice(&partial_read.data[1..]);
}
for (i, is_padding) in row_mut.sponge.is_padding_byte.iter_mut().enumerate() {
*is_padding = Val::<SC>::from_bool(i >= block.remaining_len);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/rv32-adapters/src/eq_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl<
let rs = read_record.rs.map(|r| memory.record_by_id(r));
for (i, r) in rs.iter().enumerate() {
row_slice.rs_ptr[i] = r.pointer;
row_slice.rs_val[i] = r.data.clone().try_into().unwrap();
row_slice.rs_val[i].copy_from_slice(&r.data);
aux_cols_factory.generate_read_aux(r, &mut row_slice.rs_read_aux[i]);
for (j, x) in read_record.reads[i].iter().enumerate() {
let read = memory.record_by_id(*x);
Expand Down
2 changes: 1 addition & 1 deletion extensions/rv32im/circuit/src/adapters/hintstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<F: PrimeField32> VmAdapterChip<F> for Rv32HintStoreAdapterChip<F> {
let adapter_cols: &mut Rv32HintStoreAdapterCols<_> = row_slice.borrow_mut();
adapter_cols.from_state = write_record.from_state.map(F::from_canonical_u32);
let rs1 = memory.record_by_id(read_record.rs1_record);
adapter_cols.rs1_data = rs1.data.clone().try_into().unwrap();
adapter_cols.rs1_data.copy_from_slice(&rs1.data);
aux_cols_factory.generate_read_aux(rs1, &mut adapter_cols.rs1_aux_cols);
adapter_cols.rs1_ptr = read_record.rs1_ptr;
adapter_cols.imm = read_record.imm;
Expand Down
2 changes: 1 addition & 1 deletion extensions/rv32im/circuit/src/adapters/loadstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl<F: PrimeField32> VmAdapterChip<F> for Rv32LoadStoreAdapterChip<F> {
let adapter_cols: &mut Rv32LoadStoreAdapterCols<_> = row_slice.borrow_mut();
adapter_cols.from_state = write_record.from_state.map(F::from_canonical_u32);
let rs1 = memory.record_by_id(read_record.rs1_record);
adapter_cols.rs1_data = rs1.data.clone().try_into().unwrap();
adapter_cols.rs1_data.copy_from_slice(&rs1.data);
aux_cols_factory.generate_read_aux(rs1, &mut adapter_cols.rs1_aux_cols);
adapter_cols.rs1_ptr = read_record.rs1_ptr;
adapter_cols.rd_rs2_ptr = write_record.rd_rs2_ptr;
Expand Down
6 changes: 3 additions & 3 deletions extensions/sha256/circuit/src/sha256_chip/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ where
cols.rd_ptr = dst_read.pointer;
cols.rs1_ptr = src_read.pointer;
cols.rs2_ptr = len_read.pointer;
cols.dst_ptr = dst_read.data.clone().try_into().unwrap();
cols.src_ptr = src_read.data.clone().try_into().unwrap();
cols.len_data = len_read.data.clone().try_into().unwrap();
cols.dst_ptr.copy_from_slice(&dst_read.data);
cols.src_ptr.copy_from_slice(&src_read.data);
cols.len_data.copy_from_slice(&len_read.data);
memory_aux_cols_factory
.generate_read_aux(dst_read, &mut cols.register_reads_aux[0]);
memory_aux_cols_factory
Expand Down

0 comments on commit 899ceda

Please sign in to comment.