Skip to content

Commit

Permalink
refactor: Refactor operations to use ByteRecord trait
Browse files Browse the repository at this point in the history
- Replaced the specific `ExecutionRecord` argument with the more general `impl ByteRecord` across all `populate` functions, promoting better flexibility.
- Removed unused `ExecutionRecord` imports in various operation implementation files.
  • Loading branch information
huitseeker committed Jun 5, 2024
1 parent 434aec7 commit c1818a8
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 35 deletions.
5 changes: 1 addition & 4 deletions core/src/operations/add.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::air::{Word, WordAirBuilder};
use crate::bytes::event::ByteRecord;
use crate::runtime::ExecutionRecord;

use p3_air::AirBuilder;
use p3_field::{AbstractField, Field};
Expand All @@ -19,9 +18,7 @@ pub struct AddOperation<T> {

impl<F: Field> AddOperation<F> {
pub fn populate(
&mut self,
record: &mut ExecutionRecord,
shard: u32,
&mut self, record: &mut impl ByteRecord, shard: u32,
a_u32: u32,
b_u32: u32,
) -> u32 {
Expand Down
5 changes: 1 addition & 4 deletions core/src/operations/add4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::air::Word;
use crate::air::WordAirBuilder;
use crate::air::WORD_SIZE;
use crate::bytes::event::ByteRecord;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute the add of four words.
#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
Expand All @@ -33,9 +32,7 @@ pub struct Add4Operation<T> {

impl<F: Field> Add4Operation<F> {
pub fn populate(
&mut self,
record: &mut ExecutionRecord,
shard: u32,
&mut self, record: &mut impl ByteRecord, shard: u32,
a_u32: u32,
b_u32: u32,
c_u32: u32,
Expand Down
5 changes: 1 addition & 4 deletions core/src/operations/add5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::air::Word;
use crate::air::WordAirBuilder;
use crate::air::WORD_SIZE;
use crate::bytes::event::ByteRecord;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute the sum of five words.
#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
Expand Down Expand Up @@ -37,9 +36,7 @@ pub struct Add5Operation<T> {
impl<F: Field> Add5Operation<F> {
#[allow(clippy::too_many_arguments)]
pub fn populate(
&mut self,
record: &mut ExecutionRecord,
shard: u32,
&mut self, record: &mut impl ByteRecord, shard: u32,
a_u32: u32,
b_u32: u32,
c_u32: u32,
Expand Down
3 changes: 1 addition & 2 deletions core/src/operations/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::bytes::event::ByteRecord;
use crate::bytes::ByteLookupEvent;
use crate::bytes::ByteOpcode;
use crate::disassembler::WORD_SIZE;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute the and of two words.
#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
Expand All @@ -18,7 +17,7 @@ pub struct AndOperation<T> {
}

impl<F: Field> AndOperation<F> {
pub fn populate(&mut self, record: &mut ExecutionRecord, shard: u32, x: u32, y: u32) -> u32 {
pub fn populate(&mut self, record: &mut impl ByteRecord, shard: u32, x: u32, y: u32) -> u32 {
let expected = x & y;
let x_bytes = x.to_le_bytes();
let y_bytes = y.to_le_bytes();
Expand Down
5 changes: 1 addition & 4 deletions core/src/operations/fixed_rotate_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::bytes::utils::shr_carry;
use crate::bytes::ByteLookupEvent;
use crate::bytes::ByteOpcode;
use crate::disassembler::WORD_SIZE;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute `rotateright` of a word with a fixed offset R.
///
Expand Down Expand Up @@ -41,9 +40,7 @@ impl<F: Field> FixedRotateRightOperation<F> {
}

pub fn populate(
&mut self,
record: &mut ExecutionRecord,
shard: u32,
&mut self, record: &mut impl ByteRecord, shard: u32,
input: u32,
rotation: usize,
) -> u32 {
Expand Down
5 changes: 1 addition & 4 deletions core/src/operations/fixed_shift_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::bytes::utils::shr_carry;
use crate::bytes::ByteLookupEvent;
use crate::bytes::ByteOpcode;
use crate::disassembler::WORD_SIZE;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute `>>` of a word with a fixed offset R.
///
Expand Down Expand Up @@ -41,9 +40,7 @@ impl<F: Field> FixedShiftRightOperation<F> {
}

pub fn populate(
&mut self,
record: &mut ExecutionRecord,
shard: u32,
&mut self, record: &mut impl ByteRecord, shard: u32,
input: u32,
rotation: usize,
) -> u32 {
Expand Down
3 changes: 1 addition & 2 deletions core/src/operations/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::air::Word;
use crate::bytes::event::ByteRecord;
use crate::bytes::ByteOpcode;
use crate::disassembler::WORD_SIZE;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute the not of a word.
#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
Expand All @@ -18,7 +17,7 @@ pub struct NotOperation<T> {
}

impl<F: Field> NotOperation<F> {
pub fn populate(&mut self, record: &mut ExecutionRecord, shard: u32, x: u32) -> u32 {
pub fn populate(&mut self, record: &mut impl ByteRecord, shard: u32, x: u32) -> u32 {
let expected = !x;
let x_bytes = x.to_le_bytes();
for i in 0..WORD_SIZE {
Expand Down
3 changes: 1 addition & 2 deletions core/src/operations/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::air::Word;
use crate::bytes::event::ByteRecord;
use crate::bytes::ByteOpcode;
use crate::disassembler::WORD_SIZE;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute the or of two words.
///
Expand All @@ -19,7 +18,7 @@ pub struct OrOperation<T> {
}

impl<F: Field> OrOperation<F> {
pub fn populate(&mut self, record: &mut ExecutionRecord, shard: u32, x: u32, y: u32) -> u32 {
pub fn populate(&mut self, record: &mut impl ByteRecord, shard: u32, x: u32, y: u32) -> u32 {
let expected = x | y;
let x_bytes = x.to_le_bytes();
let y_bytes = y.to_le_bytes();
Expand Down
3 changes: 1 addition & 2 deletions core/src/operations/xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::bytes::event::ByteRecord;
use crate::bytes::ByteLookupEvent;
use crate::bytes::ByteOpcode;
use crate::disassembler::WORD_SIZE;
use crate::runtime::ExecutionRecord;

/// A set of columns needed to compute the xor of two words.
#[derive(AlignedBorrow, Default, Debug, Clone, Copy)]
Expand All @@ -18,7 +17,7 @@ pub struct XorOperation<T> {
}

impl<F: Field> XorOperation<F> {
pub fn populate(&mut self, record: &mut ExecutionRecord, shard: u32, x: u32, y: u32) -> u32 {
pub fn populate(&mut self, record: &mut impl ByteRecord, shard: u32, x: u32, y: u32) -> u32 {
let expected = x ^ y;
let x_bytes = x.to_le_bytes();
let y_bytes = y.to_le_bytes();
Expand Down
8 changes: 2 additions & 6 deletions core/src/syscall/precompiles/blake3/compress/g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use sphinx_derive::AlignedBorrow;

use super::g_func;
use crate::{
air::{Word, WordAirBuilder, WORD_SIZE},
operations::{AddOperation, FixedRotateRightOperation, XorOperation},
runtime::ExecutionRecord,
air::{Word, WordAirBuilder, WORD_SIZE}, bytes::event::ByteRecord, operations::{AddOperation, FixedRotateRightOperation, XorOperation}
};
/// A set of columns needed to compute the `g` of the input state.
/// ``` ignore
Expand Down Expand Up @@ -43,9 +41,7 @@ pub struct GOperation<T> {

impl<F: Field> GOperation<F> {
pub fn populate(
&mut self,
record: &mut ExecutionRecord,
shard: u32,
&mut self, record: &mut impl ByteRecord, shard: u32,
input: [u32; 6],
) -> [u32; 4] {
let mut a = input[0];
Expand Down
2 changes: 1 addition & 1 deletion core/src/syscall/precompiles/edwards/ed_decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<F: PrimeField32, P: FieldParameters> EdDecompressCols<F, P> {
pub fn populate<E: EdwardsParameters<BaseField = P>>(
&mut self,
event: &EdDecompressEvent,
record: &mut ExecutionRecord,
record: &mut impl ByteRecord,
) {
let mut new_byte_lookup_events = Vec::new();
self.is_real = F::from_bool(true);
Expand Down

0 comments on commit c1818a8

Please sign in to comment.