diff --git a/crates/core/executor/src/events/memcpy.rs b/crates/core/executor/src/events/memcpy.rs index c6622015d8..4224c1647f 100644 --- a/crates/core/executor/src/events/memcpy.rs +++ b/crates/core/executor/src/events/memcpy.rs @@ -1,14 +1,15 @@ -use super::{LookupId, MemoryReadRecord, MemoryWriteRecord}; +use super::{LookupId, MemoryLocalEvent, MemoryReadRecord, MemoryWriteRecord}; use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct MemCopyEvent { pub lookup_id: LookupId, pub shard: u32, - pub channel: u8, pub clk: u32, pub src_ptr: u32, pub dst_ptr: u32, pub read_records: Vec, pub write_records: Vec, + /// The local memory access records. + pub local_mem_access: Vec, } diff --git a/crates/core/executor/src/events/precompiles/bn254_scalar.rs b/crates/core/executor/src/events/precompiles/bn254_scalar.rs index 7e84528370..6bba8db5ba 100644 --- a/crates/core/executor/src/events/precompiles/bn254_scalar.rs +++ b/crates/core/executor/src/events/precompiles/bn254_scalar.rs @@ -1,10 +1,3 @@ -/* -use crate::{ - operations::field::params::{FieldParameters, NumWords}, - operations::field::{field_op::FieldOperation, params::Limbs}, - runtime::{MemoryReadRecord, MemoryWriteRecord, SyscallContext}, -}; -*/ use num::BigUint; use sp1_curves::{ params::{FieldParameters, NumWords}, @@ -15,7 +8,7 @@ use typenum::Unsigned; use serde::{Deserialize, Serialize}; use crate::{ - events::{LookupId, MemoryReadRecord, MemoryWriteRecord}, + events::{LookupId, MemoryLocalEvent, MemoryReadRecord, MemoryWriteRecord}, syscalls::SyscallContext, }; @@ -23,8 +16,10 @@ use super::FieldOperation; pub const NUM_WORDS_PER_FE: usize = 8; -#[derive(PartialEq, Copy, Clone, Debug, Serialize, Deserialize)] +#[derive(Default, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)] pub enum Bn254FieldOperation { + #[default] + Invalid = 0, Mul = 2, Mac = 4, } @@ -34,21 +29,23 @@ impl Bn254FieldOperation { match self { Bn254FieldOperation::Mul => FieldOperation::Mul, Bn254FieldOperation::Mac => panic!("not supported"), + Bn254FieldOperation::Invalid => panic!("what??"), } } } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Bn254FieldArithEvent { pub lookup_id: LookupId, pub shard: u32, - pub channel: u8, pub clk: u32, pub op: Bn254FieldOperation, pub arg1: FieldArithMemoryAccess, pub arg2: FieldArithMemoryAccess, pub a: Option>, pub b: Option>, + /// The local memory access records. + pub local_mem_access: Vec, } pub fn create_bn254_scalar_arith_event( @@ -117,17 +114,17 @@ pub fn create_bn254_scalar_arith_event( Bn254FieldArithEvent { lookup_id: rt.syscall_lookup_id, shard, - channel: rt.current_channel(), clk: start_clk, op, arg1, arg2, a, b, + local_mem_access: rt.postprocess(), } } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct FieldArithMemoryAccess { pub ptr: u32, pub memory_records: Vec, diff --git a/crates/core/executor/src/events/precompiles/mod.rs b/crates/core/executor/src/events/precompiles/mod.rs index 9757255d20..472a66d7cb 100644 --- a/crates/core/executor/src/events/precompiles/mod.rs +++ b/crates/core/executor/src/events/precompiles/mod.rs @@ -20,7 +20,7 @@ pub use sha256_extend::*; use strum::EnumIter; pub use uint256::*; -use super::MemoryLocalEvent; +use super::{MemCopyEvent, MemoryLocalEvent}; #[derive(Clone, Debug, Serialize, Deserialize, EnumIter)] /// Precompile event. There should be one variant for every precompile syscall. @@ -39,6 +39,10 @@ pub enum PrecompileEvent { Bn254Fp(FpOpEvent), Bn254Fp2AddSub(Fp2AddSubEvent), Bn254Fp2Mul(Fp2MulEvent), + Bn254ScalarMac(Bn254FieldArithEvent), + Bn254ScalarMul(Bn254FieldArithEvent), + MemCopy32(MemCopyEvent), + MemCopy64(MemCopyEvent), Bls12381Add(EllipticCurveAddEvent), Bls12381Double(EllipticCurveDoubleEvent), Bls12381Decompress(EllipticCurveDecompressEvent), @@ -98,6 +102,12 @@ impl PrecompileLocalMemory for Vec { PrecompileEvent::Bls12381Fp2Mul(e) | PrecompileEvent::Bn254Fp2Mul(e) => { iterators.push(e.local_mem_access.iter()); } + PrecompileEvent::Bn254ScalarMac(e) | PrecompileEvent::Bn254ScalarMul(e) => { + iterators.push(e.local_mem_access.iter()); + } + PrecompileEvent::MemCopy32(e) | PrecompileEvent::MemCopy64(e) => { + iterators.push(e.local_mem_access.iter()); + } } } diff --git a/crates/core/executor/src/record.rs b/crates/core/executor/src/record.rs index a4e8889d41..d2e8d5ac5f 100644 --- a/crates/core/executor/src/record.rs +++ b/crates/core/executor/src/record.rs @@ -59,11 +59,6 @@ pub struct ExecutionRecord { /// A trace of all the syscall events. pub syscall_events: Vec, - pub bn254_scalar_mul_events: Vec, - pub bn254_scalar_mac_events: Vec, - pub memcpy32_events: Vec, - pub memcpy64_events: Vec, - /// The public values. pub public_values: PublicValues, /// The nonce lookup. @@ -134,10 +129,6 @@ impl ExecutionRecord { execution_record.global_memory_finalize_events = std::mem::take(&mut self.global_memory_finalize_events); execution_record - bn254_scalar_mul_events: std::mem::take(&mut self.bn254_scalar_mul_events), - bn254_scalar_mac_events: std::mem::take(&mut self.bn254_scalar_mac_events), - memcpy32_events: std::mem::take(&mut self.memcpy32_events), - memcpy64_events: std::mem::take(&mut self.memcpy64_events), } /// Splits the deferred [`ExecutionRecord`] into multiple [`ExecutionRecord`]s, each which @@ -176,10 +167,6 @@ impl ExecutionRecord { shards.append(&mut event_shards); } - split_events!(self, memcpy32_events, shards, opts.deferred, last); - split_events!(self, memcpy64_events, shards, opts.deferred, last); - split_events!(self, bn254_scalar_mul_events, shards, opts.deferred, last); - split_events!(self, bn254_scalar_mac_events, shards, opts.deferred, last); // _ = last_pct; if last { @@ -320,12 +307,6 @@ impl MachineRecord for ExecutionRecord { ); stats.insert("local_memory_access_events".to_string(), self.cpu_local_memory_access.len()); - stats.insert("bn254_scalar_mul_events".to_string(), self.bn254_scalar_mul_events.len()); - stats.insert("bn254_scalar_mac_events".to_string(), self.bn254_scalar_mac_events.len()); - - stats.insert("memcpy32_events".to_string(), self.memcpy32_events.len()); - stats.insert("memcpy64_events".to_string(), self.memcpy64_events.len()); - if !self.cpu_events.is_empty() { let shard = self.cpu_events[0].shard; stats.insert( @@ -351,11 +332,6 @@ impl MachineRecord for ExecutionRecord { self.syscall_events.append(&mut other.syscall_events); self.precompile_events.append(&mut other.precompile_events); - self.bn254_scalar_mul_events.append(&mut other.bn254_scalar_mul_events); - self.bn254_scalar_mac_events.append(&mut other.bn254_scalar_mac_events); - self.memcpy32_events.append(&mut other.memcpy32_events); - self.memcpy64_events.append(&mut other.memcpy64_events); - if self.byte_lookups.is_empty() { self.byte_lookups = std::mem::take(&mut other.byte_lookups); @@ -400,35 +376,6 @@ impl MachineRecord for ExecutionRecord { self.lt_events.iter().enumerate().for_each(|(i, event)| { self.nonce_lookup.insert(event.lookup_id, i as u32); }); - - /* - self.memcpy32_events - .iter() - .enumerate() - .for_each(|(i, event)| { - self.nonce_lookup.insert(event.lookup_id, i as u32); - }); - - self.memcpy64_events - .iter() - .enumerate() - .for_each(|(i, event)| { - self.nonce_lookup.insert(event.lookup_id, i as u32); - }); - - self.bn254_scalar_mul_events - .iter() - .enumerate() - .for_each(|(i, event)| { - self.nonce_lookup.insert(event.lookup_id, i as u32); - }); - self.bn254_scalar_mac_events - .iter() - .enumerate() - .for_each(|(i, event)| { - self.nonce_lookup.insert(event.lookup_id, i as u32); - }); - */ } /// Retrieves the public values. This method is needed for the `MachineRecord` trait, since diff --git a/crates/core/executor/src/syscalls/precompiles/bn254_scalar/mod.rs b/crates/core/executor/src/syscalls/precompiles/bn254_scalar/mod.rs index 67388b2224..daf8ef3580 100644 --- a/crates/core/executor/src/syscalls/precompiles/bn254_scalar/mod.rs +++ b/crates/core/executor/src/syscalls/precompiles/bn254_scalar/mod.rs @@ -1,14 +1,20 @@ use crate::{ - events::{create_bn254_scalar_arith_event, Bn254FieldOperation}, - syscalls::{Syscall, SyscallContext}, + events::{create_bn254_scalar_arith_event, Bn254FieldOperation, PrecompileEvent}, + syscalls::{Syscall, SyscallCode, SyscallContext}, }; pub(crate) struct Bn254ScalarMacSyscall; impl Syscall for Bn254ScalarMacSyscall { - fn execute(&self, rt: &mut SyscallContext, arg1: u32, arg2: u32) -> Option { + fn execute( + &self, + rt: &mut SyscallContext, + syscall_code: SyscallCode, + arg1: u32, + arg2: u32, + ) -> Option { let event = create_bn254_scalar_arith_event(rt, arg1, arg2, Bn254FieldOperation::Mac); - rt.record_mut().bn254_scalar_mac_events.push(event); + rt.record_mut().add_precompile_event(syscall_code, PrecompileEvent::Bn254ScalarMac(event)); None } @@ -20,9 +26,15 @@ impl Syscall for Bn254ScalarMacSyscall { pub(crate) struct Bn254ScalarMulSyscall; impl Syscall for Bn254ScalarMulSyscall { - fn execute(&self, rt: &mut SyscallContext, arg1: u32, arg2: u32) -> Option { + fn execute( + &self, + rt: &mut SyscallContext, + syscall_code: SyscallCode, + arg1: u32, + arg2: u32, + ) -> Option { let event = create_bn254_scalar_arith_event(rt, arg1, arg2, Bn254FieldOperation::Mul); - rt.record_mut().bn254_scalar_mul_events.push(event); + rt.record_mut().add_precompile_event(syscall_code, PrecompileEvent::Bn254ScalarMul(event)); None } diff --git a/crates/core/executor/src/syscalls/precompiles/memcopy.rs b/crates/core/executor/src/syscalls/precompiles/memcopy.rs index 168a1c67a3..0d1155a577 100644 --- a/crates/core/executor/src/syscalls/precompiles/memcopy.rs +++ b/crates/core/executor/src/syscalls/precompiles/memcopy.rs @@ -3,8 +3,8 @@ use std::marker::PhantomData; use generic_array::ArrayLength; use crate::{ - events::MemCopyEvent, - syscalls::{Syscall, SyscallContext}, + events::{MemCopyEvent, PrecompileEvent}, + syscalls::{Syscall, SyscallCode, SyscallContext}, }; pub struct MemCopySyscall { @@ -20,26 +20,34 @@ impl MemCopySyscall Syscall for MemCopySyscall { - fn execute(&self, ctx: &mut SyscallContext, src: u32, dst: u32) -> Option { - let (read, read_bytes) = ctx.mr_slice(src, NumWords::USIZE); - let write = ctx.mw_slice(dst, &read_bytes); + fn execute( + &self, + rt: &mut SyscallContext, + syscall_code: SyscallCode, + src: u32, + dst: u32, + ) -> Option { + let (read, read_bytes) = rt.mr_slice(src, NumWords::USIZE); + let write = rt.mw_slice(dst, &read_bytes); let event = MemCopyEvent { - lookup_id: ctx.syscall_lookup_id, - shard: ctx.current_shard(), - channel: ctx.current_channel(), - clk: ctx.clk, + lookup_id: rt.syscall_lookup_id, + shard: rt.current_shard(), + clk: rt.clk, src_ptr: src, dst_ptr: dst, read_records: read, write_records: write, + local_mem_access: rt.postprocess(), }; - (match NumWords::USIZE { - 8 => &mut ctx.record_mut().memcpy32_events, - 16 => &mut ctx.record_mut().memcpy64_events, - _ => panic!("invalid uszie {}", NumWords::USIZE), - }) - .push(event); + rt.record_mut().add_precompile_event( + syscall_code, + match NumWords::USIZE { + 8 => PrecompileEvent::MemCopy32(event), + 16 => PrecompileEvent::MemCopy64(event), + _ => panic!("invalid uszie {}", NumWords::USIZE), + }, + ); None } diff --git a/crates/core/machine/src/riscv/mod.rs b/crates/core/machine/src/riscv/mod.rs index 9de601e0c3..80c1348ac2 100644 --- a/crates/core/machine/src/riscv/mod.rs +++ b/crates/core/machine/src/riscv/mod.rs @@ -5,7 +5,7 @@ use crate::{ syscall::{ memcpy::{self, MemCopy32Chip, MemCopy64Chip, MemCopyChip}, precompiles::{ - bn254_scalar::{self, Bn254ScalarMacChip}, + bn254_scalar::{self, Bn254ScalarMacChip, Bn254ScalarMulChip}, fptower::{Fp2AddSubAssignChip, Fp2MulAssignChip, FpOpChip}, }, }, diff --git a/crates/core/machine/src/syscall/memcpy.rs b/crates/core/machine/src/syscall/memcpy.rs index f497e2c6c4..9f08a0b2de 100644 --- a/crates/core/machine/src/syscall/memcpy.rs +++ b/crates/core/machine/src/syscall/memcpy.rs @@ -1,9 +1,11 @@ use generic_array::{ArrayLength, GenericArray}; use sp1_core_executor::events::ByteRecord; use sp1_core_executor::events::MemCopyEvent; +use sp1_core_executor::events::PrecompileEvent; use sp1_core_executor::syscalls::{Syscall, SyscallCode, SyscallContext}; use sp1_core_executor::{ExecutionRecord, Program}; use sp1_curves::params::Limbs; +use sp1_stark::air::InteractionScope; use sp1_stark::air::{MachineAir, SP1AirBuilder}; use std::borrow::{Borrow, BorrowMut}; use std::marker::PhantomData; @@ -74,19 +76,35 @@ impl &input.memcpy32_events, - 16 => &input.memcpy64_events, + 8 => input.get_precompile_events(SyscallCode::MEMCPY_32), + 16 => input.get_precompile_events(SyscallCode::MEMCPY_64), _ => unreachable!(), }; for event in events { + let event: &MemCopyEvent = match NumWords::USIZE { + 8 => { + if let PrecompileEvent::MemCopy32(event) = event { + event + } else { + unreachable!(); + } + } + 16 => { + if let PrecompileEvent::MemCopy64(event) = event { + event + } else { + unreachable!(); + } + } + _ => unreachable!(), + }; let mut row = Vec::with_capacity(Self::NUM_COLS); row.resize(Self::NUM_COLS, F::zero()); let cols: &mut MemCopyCols = row.as_mut_slice().borrow_mut(); cols.is_real = F::one(); cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u8(event.channel); cols.clk = F::from_canonical_u32(event.clk); cols.src_ptr = F::from_canonical_u32(event.src_ptr); cols.dst_ptr = F::from_canonical_u32(event.dst_ptr); @@ -102,18 +120,10 @@ impl bool { - !(match NumWords::USIZE { - 8 => &shard.memcpy32_events, - 16 => &shard.memcpy64_events, + match NumWords::USIZE { + 8 => !shard.get_precompile_events(SyscallCode::MEMCPY_32).is_empty(), + 16 => !shard.get_precompile_events(SyscallCode::MEMCPY_64).is_empty(), _ => unreachable!(), - }) - .is_empty() + } } } @@ -170,7 +179,6 @@ impl MachineAir for Bn254ScalarMacChip { } fn generate_trace(&self, input: &Self::Record, output: &mut Self::Record) -> RowMajorMatrix { + let events = input.get_precompile_events(SyscallCode::BN254_SCALAR_MAC); + let mut rows = vec![]; let mut new_byte_lookup_events = vec![]; - for event in input.bn254_scalar_mac_events.iter().filter(|e| e.op == OP) { + for event in events { + let event = if let PrecompileEvent::Bn254ScalarMac(event) = event { + event + } else { + unreachable!(); + }; let mut row = [F::zero(); NUM_COLS]; let cols: &mut Bn254ScalarMacCols = row.as_mut_slice().borrow_mut(); @@ -82,7 +91,6 @@ impl MachineAir for Bn254ScalarMacChip { cols.is_real = F::one(); cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u8(event.channel); cols.clk = F::from_canonical_u32(event.clk); cols.arg1_ptr = F::from_canonical_u32(event.arg1.ptr); cols.arg2_ptr = F::from_canonical_u32(event.arg2.ptr); @@ -100,7 +108,6 @@ impl MachineAir for Bn254ScalarMacChip { let mul = cols.mul_eval.populate( &mut new_byte_lookup_events, event.shard, - event.channel, &a, &b, FieldOperation::Mul, @@ -108,36 +115,27 @@ impl MachineAir for Bn254ScalarMacChip { cols.add_eval.populate( &mut new_byte_lookup_events, event.shard, - event.channel, &arg1, &mul, FieldOperation::Add, ); for i in 0..cols.arg1_access.len() { - cols.arg1_access[i].populate( - event.channel, - event.arg1.memory_records[i], - &mut new_byte_lookup_events, - ); + cols.arg1_access[i] + .populate(event.arg1.memory_records[i], &mut new_byte_lookup_events); } for i in 0..cols.arg2_access.len() { - cols.arg2_access[i].populate( - event.channel, - event.arg2.memory_records[i], - &mut new_byte_lookup_events, - ); + cols.arg2_access[i] + .populate(event.arg2.memory_records[i], &mut new_byte_lookup_events); } for i in 0..cols.a_access.len() { cols.a_access[i].populate( - event.channel, event.a.as_ref().unwrap().memory_records[i], &mut new_byte_lookup_events, ); } for i in 0..cols.b_access.len() { cols.b_access[i].populate( - event.channel, event.b.as_ref().unwrap().memory_records[i], &mut new_byte_lookup_events, ); @@ -154,8 +152,8 @@ impl MachineAir for Bn254ScalarMacChip { let cols: &mut Bn254ScalarMacCols = row.as_mut_slice().borrow_mut(); let zero = BigUint::zero(); - cols.mul_eval.populate(&mut vec![], 0, 0, &zero, &zero, FieldOperation::Mul); - cols.add_eval.populate(&mut vec![], 0, 0, &zero, &zero, FieldOperation::Add); + cols.mul_eval.populate(&mut vec![], 0, &zero, &zero, FieldOperation::Mul); + cols.add_eval.populate(&mut vec![], 0, &zero, &zero, FieldOperation::Add); row }, @@ -175,7 +173,7 @@ impl MachineAir for Bn254ScalarMacChip { } fn included(&self, shard: &Self::Record) -> bool { - shard.bn254_scalar_mac_events.iter().filter(|e| e.op == OP).count() != 0 + !shard.get_precompile_events(SyscallCode::BN254_SCALAR_MAC).is_empty() } } @@ -204,24 +202,8 @@ where let b: Limbs<::Var, ::Limbs> = limbs_from_prev_access(&row.b_access); - row.mul_eval.eval( - builder, - &a, - &b, - FieldOperation::Mul, - row.shard, - row.channel, - row.is_real, - ); - row.add_eval.eval( - builder, - &arg1, - &row.mul_eval.result, - FieldOperation::Add, - row.shard, - row.channel, - row.is_real, - ); + row.mul_eval.eval(builder, &a, &b, FieldOperation::Mul, row.is_real); + row.add_eval.eval(builder, &arg1, &row.mul_eval.result, FieldOperation::Add, row.is_real); for i in 0..Bn254ScalarField::NB_LIMBS { builder @@ -231,7 +213,6 @@ where builder.eval_memory_access_slice( row.shard, - row.channel, row.clk.into(), row.arg1_ptr, &row.arg1_access, @@ -240,7 +221,6 @@ where builder.eval_memory_access_slice( row.shard, - row.channel, row.clk.into(), row.arg2_ptr, &row.arg2_access, @@ -263,7 +243,6 @@ where builder.eval_memory_access_slice( row.shard, - row.channel, row.clk.into(), a_ptr, &row.a_access, @@ -272,7 +251,6 @@ where builder.eval_memory_access_slice( row.shard, - row.channel, row.clk.into(), b_ptr, &row.b_access, @@ -282,13 +260,13 @@ where let syscall_id = AB::F::from_canonical_u32(SyscallCode::BN254_SCALAR_MAC.syscall_id()); builder.receive_syscall( row.shard, - row.channel, row.clk, row.nonce, syscall_id, row.arg1_ptr, row.arg2_ptr, row.is_real, + InteractionScope::Global, ); } } diff --git a/crates/core/machine/src/syscall/precompiles/bn254_scalar/mul.rs b/crates/core/machine/src/syscall/precompiles/bn254_scalar/mul.rs index 9eb7477ec5..c136652297 100644 --- a/crates/core/machine/src/syscall/precompiles/bn254_scalar/mul.rs +++ b/crates/core/machine/src/syscall/precompiles/bn254_scalar/mul.rs @@ -8,6 +8,7 @@ use p3_field::{Field, PrimeField32}; use p3_matrix::{dense::RowMajorMatrix, Matrix}; use sp1_core_executor::events::Bn254FieldOperation; use sp1_core_executor::events::ByteRecord; +use sp1_core_executor::events::PrecompileEvent; use sp1_core_executor::events::NUM_WORDS_PER_FE; use sp1_core_executor::syscalls::SyscallCode; use sp1_core_executor::ExecutionRecord; @@ -17,6 +18,7 @@ use sp1_curves::params::Limbs; use sp1_curves::params::NumLimbs; use sp1_curves::weierstrass::bn254::Bn254ScalarField; use sp1_derive::AlignedBorrow; +use sp1_stark::air::InteractionScope; use sp1_stark::air::MachineAir; use sp1_stark::air::SP1AirBuilder; @@ -64,10 +66,17 @@ impl MachineAir for Bn254ScalarMulChip { } fn generate_trace(&self, input: &Self::Record, output: &mut Self::Record) -> RowMajorMatrix { + let events = input.get_precompile_events(SyscallCode::BN254_SCALAR_MUL); + let mut rows = vec![]; let mut new_byte_lookup_events = vec![]; - for event in input.bn254_scalar_mul_events.iter().filter(|e| e.op == OP) { + for event in events { + let event = if let PrecompileEvent::Bn254ScalarMul(event) = event { + event + } else { + unreachable!(); + }; let mut row = [F::zero(); NUM_COLS]; let cols: &mut Bn254ScalarMulCols = row.as_mut_slice().borrow_mut(); @@ -76,7 +85,6 @@ impl MachineAir for Bn254ScalarMulChip { cols.is_real = F::one(); cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u8(event.channel); cols.clk = F::from_canonical_u32(event.clk); cols.p_ptr = F::from_canonical_u32(event.arg1.ptr); cols.q_ptr = F::from_canonical_u32(event.arg2.ptr); @@ -94,25 +102,18 @@ impl MachineAir for Bn254ScalarMulChip { cols.eval.populate( &mut new_byte_lookup_events, event.shard, - event.channel, &p, &q, OP.to_field_operation(), ); for i in 0..cols.p_access.len() { - cols.p_access[i].populate( - event.channel, - event.arg1.memory_records[i], - &mut new_byte_lookup_events, - ); + cols.p_access[i] + .populate(event.arg1.memory_records[i], &mut new_byte_lookup_events); } for i in 0..cols.q_access.len() { - cols.q_access[i].populate( - event.channel, - event.arg2.memory_records[i], - &mut new_byte_lookup_events, - ); + cols.q_access[i] + .populate(event.arg2.memory_records[i], &mut new_byte_lookup_events); } rows.push(row); @@ -126,7 +127,7 @@ impl MachineAir for Bn254ScalarMulChip { let cols: &mut Bn254ScalarMulCols = row.as_mut_slice().borrow_mut(); let zero = BigUint::zero(); - cols.eval.populate(&mut vec![], 0, 0, &zero, &zero, OP.to_field_operation()); + cols.eval.populate(&mut vec![], 0, &zero, &zero, OP.to_field_operation()); row }, @@ -146,7 +147,7 @@ impl MachineAir for Bn254ScalarMulChip { } fn included(&self, shard: &Self::Record) -> bool { - shard.bn254_scalar_mul_events.iter().filter(|e| e.op == OP).count() != 0 + !shard.get_precompile_events(SyscallCode::BN254_SCALAR_MUL).is_empty() } } @@ -173,15 +174,7 @@ where let q: Limbs<::Var, ::Limbs> = limbs_from_prev_access(&row.q_access); - row.eval.eval( - builder, - &p, - &q, - OP.to_field_operation(), - row.shard, - row.channel, - row.is_real, - ); + row.eval.eval(builder, &p, &q, OP.to_field_operation(), row.is_real); for i in 0..Bn254ScalarField::NB_LIMBS { builder @@ -191,7 +184,6 @@ where builder.eval_memory_access_slice( row.shard, - row.channel, row.clk.into(), row.q_ptr, &row.q_access, @@ -200,7 +192,6 @@ where builder.eval_memory_access_slice( row.shard, - row.channel, row.clk.into(), row.p_ptr, &row.p_access, @@ -210,13 +201,13 @@ where let syscall_id = AB::F::from_canonical_u32(SyscallCode::BN254_SCALAR_MUL.syscall_id()); builder.receive_syscall( row.shard, - row.channel, row.clk, row.nonce, syscall_id, row.p_ptr, row.q_ptr, row.is_real, + InteractionScope::Global, ); } }