From c1818a8aeffbd8bcf7e415f465d578dcef6f2e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Wed, 5 Jun 2024 16:41:30 -0400 Subject: [PATCH] refactor: Refactor operations to use ByteRecord trait - 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. --- core/src/operations/add.rs | 5 +---- core/src/operations/add4.rs | 5 +---- core/src/operations/add5.rs | 5 +---- core/src/operations/and.rs | 3 +-- core/src/operations/fixed_rotate_right.rs | 5 +---- core/src/operations/fixed_shift_right.rs | 5 +---- core/src/operations/not.rs | 3 +-- core/src/operations/or.rs | 3 +-- core/src/operations/xor.rs | 3 +-- core/src/syscall/precompiles/blake3/compress/g.rs | 8 ++------ core/src/syscall/precompiles/edwards/ed_decompress.rs | 2 +- 11 files changed, 12 insertions(+), 35 deletions(-) diff --git a/core/src/operations/add.rs b/core/src/operations/add.rs index 1fce9652a..2ee5bbf2f 100644 --- a/core/src/operations/add.rs +++ b/core/src/operations/add.rs @@ -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}; @@ -19,9 +18,7 @@ pub struct AddOperation { impl AddOperation { 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 { diff --git a/core/src/operations/add4.rs b/core/src/operations/add4.rs index aecd25e0d..b9c15ca19 100644 --- a/core/src/operations/add4.rs +++ b/core/src/operations/add4.rs @@ -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)] @@ -33,9 +32,7 @@ pub struct Add4Operation { impl Add4Operation { 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, diff --git a/core/src/operations/add5.rs b/core/src/operations/add5.rs index f469c83b1..a5f3fc406 100644 --- a/core/src/operations/add5.rs +++ b/core/src/operations/add5.rs @@ -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)] @@ -37,9 +36,7 @@ pub struct Add5Operation { impl Add5Operation { #[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, diff --git a/core/src/operations/and.rs b/core/src/operations/and.rs index 72ab07c3f..9df2c9170 100644 --- a/core/src/operations/and.rs +++ b/core/src/operations/and.rs @@ -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)] @@ -18,7 +17,7 @@ pub struct AndOperation { } impl AndOperation { - 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(); diff --git a/core/src/operations/fixed_rotate_right.rs b/core/src/operations/fixed_rotate_right.rs index a24e39b5b..f4b3468b6 100644 --- a/core/src/operations/fixed_rotate_right.rs +++ b/core/src/operations/fixed_rotate_right.rs @@ -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. /// @@ -41,9 +40,7 @@ impl FixedRotateRightOperation { } pub fn populate( - &mut self, - record: &mut ExecutionRecord, - shard: u32, + &mut self, record: &mut impl ByteRecord, shard: u32, input: u32, rotation: usize, ) -> u32 { diff --git a/core/src/operations/fixed_shift_right.rs b/core/src/operations/fixed_shift_right.rs index 8064def41..dcea20061 100644 --- a/core/src/operations/fixed_shift_right.rs +++ b/core/src/operations/fixed_shift_right.rs @@ -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. /// @@ -41,9 +40,7 @@ impl FixedShiftRightOperation { } pub fn populate( - &mut self, - record: &mut ExecutionRecord, - shard: u32, + &mut self, record: &mut impl ByteRecord, shard: u32, input: u32, rotation: usize, ) -> u32 { diff --git a/core/src/operations/not.rs b/core/src/operations/not.rs index 6568347e2..42fa92531 100644 --- a/core/src/operations/not.rs +++ b/core/src/operations/not.rs @@ -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)] @@ -18,7 +17,7 @@ pub struct NotOperation { } impl NotOperation { - 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 { diff --git a/core/src/operations/or.rs b/core/src/operations/or.rs index c06f690b0..c0ccae6df 100644 --- a/core/src/operations/or.rs +++ b/core/src/operations/or.rs @@ -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. /// @@ -19,7 +18,7 @@ pub struct OrOperation { } impl OrOperation { - 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(); diff --git a/core/src/operations/xor.rs b/core/src/operations/xor.rs index 9da6a1c26..27ad739da 100644 --- a/core/src/operations/xor.rs +++ b/core/src/operations/xor.rs @@ -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)] @@ -18,7 +17,7 @@ pub struct XorOperation { } impl XorOperation { - 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(); diff --git a/core/src/syscall/precompiles/blake3/compress/g.rs b/core/src/syscall/precompiles/blake3/compress/g.rs index cfd3a1454..4b5664826 100644 --- a/core/src/syscall/precompiles/blake3/compress/g.rs +++ b/core/src/syscall/precompiles/blake3/compress/g.rs @@ -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 @@ -43,9 +41,7 @@ pub struct GOperation { impl GOperation { 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]; diff --git a/core/src/syscall/precompiles/edwards/ed_decompress.rs b/core/src/syscall/precompiles/edwards/ed_decompress.rs index 5d6054226..0478668da 100644 --- a/core/src/syscall/precompiles/edwards/ed_decompress.rs +++ b/core/src/syscall/precompiles/edwards/ed_decompress.rs @@ -97,7 +97,7 @@ impl EdDecompressCols { pub fn populate>( &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);