From e46abebbd5e64c9f64127262b49408f14346a7f6 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 9 Sep 2024 13:53:13 +0300 Subject: [PATCH 01/30] chore: Empty precompile --- core/src/runtime/record.rs | 19 ++ core/src/runtime/syscall.rs | 10 ++ core/src/stark/air.rs | 6 + core/src/syscall/precompiles/blake2s/mod.rs | 185 ++++++++++++++++++++ core/src/syscall/precompiles/mod.rs | 1 + zkvm/entrypoint/src/syscalls/mod.rs | 2 + 6 files changed, 223 insertions(+) create mode 100644 core/src/syscall/precompiles/blake2s/mod.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index d21c7c28c..7fc240c53 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -10,6 +10,7 @@ use super::{program::Program, Opcode}; use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; +use crate::syscall::precompiles::blake2s::{EmptyChip, EmptyEvent}; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; use crate::syscall::precompiles::sha256::{ShaCompressEvent, ShaExtendEvent}; @@ -96,6 +97,8 @@ pub struct ExecutionRecord { pub sha_extend_events: Vec, + pub empty_events: Vec, + pub sha_compress_events: Vec, pub keccak_permute_events: Vec, @@ -214,6 +217,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.empty_events + } +} + impl EventLens for ExecutionRecord { fn events(&self) -> >::Events { &self.sha_compress_events @@ -411,6 +420,7 @@ impl MachineRecord for ExecutionRecord { "sha_compress_events".to_string(), self.sha_compress_events.len(), ); + stats.insert("empty_events".to_string(), self.empty_events.len()); stats.insert( "keccak_permute_events".to_string(), self.keccak_permute_events.len(), @@ -482,6 +492,9 @@ impl MachineRecord for ExecutionRecord { self.sha_extend_events.append(&mut other.sha_extend_events); self.sha_compress_events .append(&mut other.sha_compress_events); + + self.empty_events.append(&mut other.empty_events); + self.keccak_permute_events .append(&mut other.keccak_permute_events); self.ed_add_events.append(&mut other.ed_add_events); @@ -795,6 +808,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); } + // Empty events + first.empty_events = take(&mut self.empty_events); + for (i, event) in first.empty_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); + } + // SHA-256 compress events. first.sha_compress_events = take(&mut self.sha_compress_events); for (i, event) in first.sha_compress_events.iter().enumerate() { diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 8b6c68e59..370b96033 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -6,6 +6,7 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; +use crate::syscall::precompiles::blake2s::EmptyChip; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; use crate::syscall::precompiles::bls12_381::g2_double::Bls12381G2AffineDoubleChip; @@ -116,6 +117,8 @@ pub enum SyscallCode { /// Executes the `HINT_READ` precompile. HINT_READ = 0x00_00_00_F1, + + EMPTY = 0x00_00_01_CC, } impl SyscallCode { @@ -152,6 +155,7 @@ impl SyscallCode { 0x00_01_01_F2 => SyscallCode::BLS12381_G1_DECOMPRESS, 0x00_01_01_80 => SyscallCode::BLS12381_G2_ADD, 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, + 0x00_00_01_CC => SyscallCode::EMPTY, _ => panic!("invalid syscall number: {}", value), } } @@ -390,6 +394,8 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Bls12381G2AffineDoubleChip::new()), ); + syscall_map.insert(SyscallCode::EMPTY, Arc::new(EmptyChip::new())); + syscall_map } @@ -503,6 +509,10 @@ mod tests { SyscallCode::BLS12381_G2_DOUBLE => { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLS12381_G2_DOUBLE) } + + SyscallCode::EMPTY => { + assert_eq!(code as u32, sphinx_zkvm::syscalls::EMPTY) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 7a2f08c46..5cdeec2e3 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -3,6 +3,7 @@ pub use crate::air::SphinxAirBuilder; use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; +use crate::syscall::precompiles::blake2s::EmptyChip; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; use crate::syscall::precompiles::quad_field::QuadFieldChip; @@ -106,6 +107,8 @@ pub enum RiscvAir { Bls12381Fp2Op(QuadFieldChip), /// A precompile for decompressing a point on the BLS12-381 curve. Bls12381G1Decompress(Bls12381G1DecompressChip), + + Empty(EmptyChip), } impl RiscvAir { @@ -182,6 +185,9 @@ impl RiscvAir { let byte = ByteChip::default(); chips.push(RiscvAir::ByteLookup(byte)); + let empty = EmptyChip::default(); + chips.push(RiscvAir::Empty(empty)); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs new file mode 100644 index 000000000..928117cc9 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -0,0 +1,185 @@ +use crate::stark::SphinxAirBuilder; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +#[derive(Default)] +pub struct EmptyChip; + +impl EmptyChip { + pub fn new() -> Self { + EmptyChip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EmptyEvent { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, +} + +impl Syscall for EmptyChip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, _arg1: u32, _arg2: u32) -> Option { + let clk = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + ctx.record_mut().empty_events.push(EmptyEvent { + lookup_id, + clk, + shard, + channel, + }); + + None + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct EmptyCols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a: T, +} + +impl BaseAir for EmptyChip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for EmptyChip { + type Events = &'a [EmptyEvent]; +} + +impl MachineAir for EmptyChip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "EmptyChip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + _output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + + let width = >::width(self); + + for event in input.events() { + let mut row = vec![F::zero(); width]; + let cols: &mut EmptyCols = row.as_mut_slice().borrow_mut(); + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + + cols.a = F::from_canonical_u32(100500u32); + + rows.push(row); + } + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut EmptyCols = trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.empty_events.is_empty() + } +} + +impl Air for EmptyChip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &EmptyCols = (*local).borrow(); + let next: &EmptyCols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::EMPTY.syscall_id()), + AB::Expr::zero(), + AB::Expr::zero(), + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::{run_test, setup_logger}; + use crate::Program; + + fn risc_v_program() -> Program { + let mut instructions = vec![]; + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::EMPTY as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, 0, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, 0, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_empty_precompile() { + setup_logger(); + let program = risc_v_program(); + run_test(program).unwrap(); + } +} diff --git a/core/src/syscall/precompiles/mod.rs b/core/src/syscall/precompiles/mod.rs index d85d25e4b..4d4757af1 100644 --- a/core/src/syscall/precompiles/mod.rs +++ b/core/src/syscall/precompiles/mod.rs @@ -1,3 +1,4 @@ +pub mod blake2s; pub mod bls12_381; pub mod edwards; pub mod field; diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 206f68c97..a7f4993e9 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -106,3 +106,5 @@ pub const BLS12381_G1_DOUBLE: u32 = 0x00_00_01_72; /// Executes `BLS12381_G1_DECOMPRESS`. pub const BLS12381_G1_DECOMPRESS: u32 = 0x00_01_01_F2; + +pub const EMPTY: u32 = 0x00_00_01_CC; From c02b2001acf7c2ffc574cb826d5e2cdd60c4951b Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Tue, 10 Sep 2024 17:37:52 +0300 Subject: [PATCH 02/30] chore: working XOR operation --- core/src/syscall/precompiles/blake2s/mod.rs | 381 +++++++++++++++++++- 1 file changed, 367 insertions(+), 14 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 928117cc9..2666cf8f7 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -13,6 +13,10 @@ use serde::Deserialize; use serde::Serialize; use sphinx_derive::AlignedBorrow; use std::mem::size_of; +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::XorOperation; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; #[derive(Default)] pub struct EmptyChip; @@ -29,20 +33,54 @@ pub struct EmptyEvent { pub clk: u32, pub shard: u32, pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + pub a_reads: Vec, + pub b_reads: Vec, + //pub xor_writes: Vec, } impl Syscall for EmptyChip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, _arg1: u32, _arg2: u32) -> Option { - let clk = ctx.clk; + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; let shard = ctx.current_shard(); let lookup_id = ctx.syscall_lookup_id; let channel = ctx.current_channel(); + let a_ptr = arg1; + let a_ptr_init = a_ptr; + let b_ptr = arg2; + let b_ptr_init = b_ptr; + + let mut a_reads = Vec::new(); + let mut b_reads = Vec::new(); + + // Read a0. + let (record, a) = ctx.mr(a_ptr); + a_reads.push(record); + + // Read b0. + let (record, b) = ctx.mr(b_ptr); + b_reads.push(record); + + // compute a ^ b xor + let _xor = a ^ b; + + // Write xor to a_ptr. + //xor_writes.push(ctx.mw(a_ptr, xor0)); + //ctx.clk += 1; + + ctx.record_mut().empty_events.push(EmptyEvent { lookup_id, - clk, + clk: clk_init, shard, channel, + a_ptr: a_ptr_init, + b_ptr: b_ptr_init, + a_reads, + b_reads, + //xor_writes: xor0_writes, }); None @@ -58,7 +96,13 @@ struct EmptyCols { pub nonce: T, pub is_real: T, - pub a: T, + pub a_ptr: T, + pub b_ptr: T, + + pub a0: MemoryReadCols, + pub b0: MemoryReadCols, + pub xor0: XorOperation, + //pub axorb: MemoryWriteCols, } impl BaseAir for EmptyChip { @@ -82,25 +126,58 @@ impl MachineAir for EmptyChip { fn generate_trace>( &self, input: &EL, - _output: &mut Self::Record, + output: &mut Self::Record, ) -> RowMajorMatrix { let mut rows = vec![]; - let width = >::width(self); - + let mut new_byte_lookup_events = Vec::new(); for event in input.events() { + let shard = event.shard; let mut row = vec![F::zero(); width]; let cols: &mut EmptyCols = row.as_mut_slice().borrow_mut(); + cols.clk = F::from_canonical_u32(event.clk); cols.is_real = F::one(); cols.shard = F::from_canonical_u32(event.shard); cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + cols.a0.populate( + event.channel, + event.a_reads[0], + &mut new_byte_lookup_events, + ); + + cols.b0.populate( + event.channel, + event.b_reads[0], + &mut new_byte_lookup_events, + ); - cols.a = F::from_canonical_u32(100500u32); + let a0 = event.a_reads[0].value; + let b0 = event.b_reads[0].value; + let xor0 = cols.xor0.populate( + output, + shard, + event.channel, + a0, + b0, + ); + + assert_eq!(a0 ^ b0, xor0); + + //cols.axorb0.populate( + // event.channel, + // event.xor_writes[0], + // &mut new_byte_lookup_events, + //); rows.push(row); } + output.add_byte_lookup_events(new_byte_lookup_events); + pad_rows(&mut rows, || { let row = vec![F::zero(); width]; @@ -117,6 +194,7 @@ impl MachineAir for EmptyChip { } trace + } fn included(&self, shard: &Self::Record) -> bool { @@ -141,14 +219,56 @@ where .when_transition() .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + // Read a. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.a_ptr, + &local.a0, + local.is_real, + ); + + // Read b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr, + &local.b0, + local.is_real, + ); + + // XOR + XorOperation::::eval( + builder, + *local.a0.value(), + *local.b0.value(), + local.xor0, + local.shard, + &local.channel, + local.is_real, + ); + + // Write XOR to memory. + //builder.eval_memory_access( + // local.shard, + // local.channel, + // local.clk, + // local.a_ptr, + // &local.a0, + // local.is_real, + //); + //builder.assert_word_eq(*local.a0.value(), local.xor0.value); + builder.receive_syscall( local.shard, local.channel, local.clk, local.nonce, AB::F::from_canonical_u32(SyscallCode::EMPTY.syscall_id()), - AB::Expr::zero(), - AB::Expr::zero(), + local.a_ptr, + local.b_ptr, local.is_real, ) } @@ -160,8 +280,38 @@ mod tests { use crate::utils::{run_test, setup_logger}; use crate::Program; - fn risc_v_program() -> Program { + fn risc_v_program(a: [u32; 4], b: [u32; 4]) -> Program { + let a_ptr = 100100100; + let b_ptr = 200200200; + let mut instructions = vec![]; + + //for (index, word) in a_words.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, a[0], false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (0 * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + //} + + //for (index, word) in b_words.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, b[0], false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (0 * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + //} + instructions.push(Instruction::new( Opcode::ADD, 5, @@ -170,8 +320,8 @@ mod tests { false, true, )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, 0, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, 0, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); Program::new(instructions, 0, 0) } @@ -179,7 +329,210 @@ mod tests { #[test] fn test_empty_precompile() { setup_logger(); - let program = risc_v_program(); + let program = risc_v_program( + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + ); run_test(program).unwrap(); } + + fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { + [ + a[0] ^ b[0], + a[1] ^ b[1], + a[2] ^ b[2], + a[3] ^ b[3], + ] + } + + + + + + + + + + + + fn shuffle_left_1_u32x4(a: [u32; 4]) -> [u32; 4] { + [a[1], a[2], a[3], a[0]] + } + + fn shuffle_left_2_u32x4(a: [u32; 4]) -> [u32; 4] { + [a[2], a[3], a[0], a[1]] + } + + fn shuffle_left_3_u32x4(a: [u32; 4]) -> [u32; 4] { + [a[3], a[0], a[1], a[2]] + } + + fn shuffle_right_1_u32x4(a: [u32; 4]) -> [u32; 4] { + shuffle_left_3_u32x4(a) + } + fn shuffle_right_2_u32x4(a: [u32; 4]) -> [u32; 4] { + shuffle_left_2_u32x4(a) + } + fn shuffle_right_3_u32x4(a: [u32; 4]) -> [u32; 4] { + shuffle_left_1_u32x4(a) + } + + fn wrapping_add_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { + [ + a[0].wrapping_add(b[0]), + a[1].wrapping_add(b[1]), + a[2].wrapping_add(b[2]), + a[3].wrapping_add(b[3]) + ] + } + + fn rotate_right_const(a: [u32; 4], n: u32) -> [u32; 4] { + [ + a[0].rotate_right(n), + a[1].rotate_right(n), + a[2].rotate_right(n), + a[3].rotate_right(n), + ] + } + + fn quarter_round(v: &mut Vec<[u32; 4]>, rd: u32, rb: u32, m: [u32; 4]) { + v[0] = wrapping_add_u32x4(wrapping_add_u32x4(v[0], v[1]), m); // m.from_le (?) + v[3] = rotate_right_const(xor_u32x4(v[3], v[0]), rd); + v[2] = wrapping_add_u32x4(v[2], v[3]); + v[1] = rotate_right_const(xor_u32x4(v[1], v[2]), rb); + } + + fn shuffle(v: &mut Vec<[u32; 4]>) { + v[1] = shuffle_left_1_u32x4(v[1]); + v[2] = shuffle_left_2_u32x4(v[2]); + v[3] = shuffle_left_3_u32x4(v[3]); + } + + fn unshuffle(v: &mut Vec<[u32; 4]>) { + v[1] = shuffle_right_1_u32x4(v[1]); + v[2] = shuffle_right_2_u32x4(v[2]); + v[3] = shuffle_right_3_u32x4(v[3]); + } + + fn gather(m: [u32; 16], i0: usize, i1: usize, i2: usize, i3: usize) -> [u32; 4]{ + [ + m[i0], + m[i1], + m[i2], + m[i3] + ] + } + + fn round(v: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16]) { + let r1 = 16; + let r2 = 12; + let r3 = 8; + let r4 = 7; + + quarter_round(v, r1, r2, gather(m, s[0], s[2], s[4], s[6])); + quarter_round(v, r3, r4, gather(m, s[1], s[3], s[5], s[7])); + shuffle(v); + quarter_round(v, r1, r2, gather(m, s[8], s[10], s[12], s[14])); + quarter_round(v, r3, r4, gather(m, s[9], s[11], s[13], s[15])); + unshuffle(v); + } + + #[test] + fn test_blake2s_round_function() { + fn test_inner(input: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16], output: Vec<[u32; 4]>) { + round(input, m, s); + assert_eq!(input.clone(), output); + } + + let mut v: Vec<[u32; 4]> = vec![ + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], + ]; + + let m: [u32; 16] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let s: [usize; 16] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]; + + test_inner(&mut v, m, s, vec![ + [0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3], + [0x515f5af4, 0x0301095b, 0xb151a3c2, 0x5e17f96f], + [0xc561666d, 0x0f291605, 0x990c6d13, 0x76fff6f1], + [0x1e53bf19, 0x6fe4a680, 0x08e33663, 0x97fd885e], + ]); + + + let mut v: Vec<[u32; 4]> = vec![ + [0x01, 0x01, 0x01, 0x01], + [0x01, 0x01, 0x01, 0x01], + [0x01, 0x01, 0x01, 0x01], + [0x01, 0x01, 0x01, 0x01], + ]; + + let m: [u32; 16] = [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]; + let s: [usize; 16] = [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]; + + test_inner(&mut v, m, s, vec![ + [0x071e8a60, 0x071e8a60, 0x071e8a60, 0x071e8a60], + [0x072df44c, 0x072df44c, 0x072df44c, 0x072df44c], + [0x522ca035, 0x522ca035, 0x522ca035, 0x522ca035], + [0x280137ec, 0x280137ec, 0x280137ec, 0x280137ec] + ]); + } + + #[test] + fn test_blake2s_unshuffle_function() { + let mut v: Vec<[u32; 4]> = vec![ + [0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3], + [0x0301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4], + [0x990c6d13, 0x76fff6f1, 0xc561666d, 0x0f291605], + [0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x08e33663], + ]; + + unshuffle(&mut v); + + assert_eq!(v[0].to_vec(), vec![0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3]); + assert_eq!(v[1].to_vec(), vec![0x515f5af4, 0x0301095b, 0xb151a3c2, 0x5e17f96f]); + assert_eq!(v[2].to_vec(), vec![0xc561666d, 0x0f291605, 0x990c6d13, 0x76fff6f1]); + assert_eq!(v[3].to_vec(), vec![0x1e53bf19, 0x6fe4a680, 0x08e33663, 0x97fd885e]); + + } + + #[test] + fn test_blake2s_shuffle_function() { + let mut v: Vec<[u32; 4]> = vec![ + [0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc], + [0x408705aa, 0x8d07c52d, 0xb9d6aa3a, 0x88609304], + [0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed], + [0x87b6b678, 0x7af31ada, 0x5a2defeb, 0x2cdd25e3], + ]; + + shuffle(&mut v); + + assert_eq!(v[0].to_vec(), vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc]); + assert_eq!(v[1].to_vec(), vec![0x8d07c52d, 0xb9d6aa3a, 0x88609304, 0x408705aa]); + assert_eq!(v[2].to_vec(), vec![0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7]); + assert_eq!(v[3].to_vec(), vec![0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb]); + + } + + #[test] + fn test_blake2s_quarter_round_function() { + let mut v: Vec<[u32; 4]> = vec![ + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], + ]; + let m = [0, 0, 0, 0]; + let rd = 16; + let rb = 12; + + quarter_round(&mut v, rd, rb, m); + + assert_eq!(v[0].to_vec(), vec![0xbc1738c6, 0x566d1711, 0x5bf2cd1d, 0x130c253]); + assert_eq!(v[1].to_vec(), vec![0x1ff85cd8, 0x361a0001, 0x6ab383b7, 0xd13ef7a9]); + assert_eq!(v[2].to_vec(), vec![0xd4c3d380, 0x3b057bed, 0x27b8af00, 0xb49a500a]); + assert_eq!(v[3].to_vec(), vec![0x6ab9ed19, 0x7f9dcd68, 0xeb49bb8e, 0xf4a5ad0]); + } } From 734909cd32dcd0d85e5504385d80ed7de8c53e4d Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Tue, 10 Sep 2024 19:43:33 +0300 Subject: [PATCH 03/30] chore: Fix event's lookup_id insertion to nonce_lookup --- core/src/runtime/record.rs | 2 +- core/src/utils/prove.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 7fc240c53..28acd247b 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -811,7 +811,7 @@ impl MachineRecord for ExecutionRecord { // Empty events first.empty_events = take(&mut self.empty_events); for (i, event) in first.empty_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); + self.nonce_lookup.insert(event.lookup_id, i as u32); } // SHA-256 compress events. diff --git a/core/src/utils/prove.rs b/core/src/utils/prove.rs index dee783732..84be69a52 100644 --- a/core/src/utils/prove.rs +++ b/core/src/utils/prove.rs @@ -356,11 +356,11 @@ where OpeningProof: Send + Sync, ShardMainData: Serialize + DeserializeOwned, { - #[cfg(debug_assertions)] - { + //#[cfg(debug_assertions)] + //{ let record_clone = record.clone(); machine.debug_constraints(pk, record_clone); - } + //} let stats = record.stats().clone(); let cycles = stats.get("cpu_events").unwrap(); From f6516d5166a31a2258966c135140b4cf988fe131 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 11 Sep 2024 16:19:28 +0300 Subject: [PATCH 04/30] chore: Working XOR operation for 4 u32 words --- core/src/syscall/precompiles/blake2s/mod.rs | 290 +++++++++++--------- core/src/utils/prove.rs | 4 +- 2 files changed, 162 insertions(+), 132 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 2666cf8f7..7faae1447 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,3 +1,7 @@ +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::XorOperation; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; use crate::stark::SphinxAirBuilder; use crate::utils::pad_rows; use crate::{ @@ -13,10 +17,6 @@ use serde::Deserialize; use serde::Serialize; use sphinx_derive::AlignedBorrow; use std::mem::size_of; -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::XorOperation; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; #[derive(Default)] pub struct EmptyChip; @@ -48,36 +48,34 @@ impl Syscall for EmptyChip { let channel = ctx.current_channel(); let a_ptr = arg1; - let a_ptr_init = a_ptr; let b_ptr = arg2; - let b_ptr_init = b_ptr; let mut a_reads = Vec::new(); let mut b_reads = Vec::new(); - // Read a0. - let (record, a) = ctx.mr(a_ptr); - a_reads.push(record); + for i in 0..4usize { + // Read a. + let (record, a) = ctx.mr(a_ptr + (i * 4) as u32); + a_reads.push(record); - // Read b0. - let (record, b) = ctx.mr(b_ptr); - b_reads.push(record); + // Read b. + let (record, b) = ctx.mr(b_ptr + (i * 4) as u32); + b_reads.push(record); - // compute a ^ b xor - let _xor = a ^ b; + let _xor = a ^ b; + } // Write xor to a_ptr. //xor_writes.push(ctx.mw(a_ptr, xor0)); //ctx.clk += 1; - ctx.record_mut().empty_events.push(EmptyEvent { lookup_id, clk: clk_init, shard, channel, - a_ptr: a_ptr_init, - b_ptr: b_ptr_init, + a_ptr, + b_ptr, a_reads, b_reads, //xor_writes: xor0_writes, @@ -99,9 +97,10 @@ struct EmptyCols { pub a_ptr: T, pub b_ptr: T, - pub a0: MemoryReadCols, - pub b0: MemoryReadCols, - pub xor0: XorOperation, + pub a: [MemoryReadCols; 4], + pub b: [MemoryReadCols; 4], + + pub xor: [XorOperation; 4], //pub axorb: MemoryWriteCols, } @@ -143,29 +142,16 @@ impl MachineAir for EmptyChip { cols.a_ptr = F::from_canonical_u32(event.a_ptr); cols.b_ptr = F::from_canonical_u32(event.b_ptr); - cols.a0.populate( - event.channel, - event.a_reads[0], - &mut new_byte_lookup_events, - ); + for i in 0..4usize { + cols.a[i].populate(event.channel, event.a_reads[i], &mut new_byte_lookup_events); - cols.b0.populate( - event.channel, - event.b_reads[0], - &mut new_byte_lookup_events, - ); + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - let a0 = event.a_reads[0].value; - let b0 = event.b_reads[0].value; - let xor0 = cols.xor0.populate( - output, - shard, - event.channel, - a0, - b0, - ); - - assert_eq!(a0 ^ b0, xor0); + let a = event.a_reads[i].value; + let b = event.b_reads[i].value; + let xor = cols.xor[i].populate(output, shard, event.channel, a, b); + assert_eq!(a ^ b, xor); + } //cols.axorb0.populate( // event.channel, @@ -194,7 +180,6 @@ impl MachineAir for EmptyChip { } trace - } fn included(&self, shard: &Self::Record) -> bool { @@ -219,36 +204,38 @@ where .when_transition() .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - // Read a. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.a_ptr, - &local.a0, - local.is_real, - ); + for i in 0..4usize { + // Read a. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); - // Read b. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr, - &local.b0, - local.is_real, - ); + // Read b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); - // XOR - XorOperation::::eval( - builder, - *local.a0.value(), - *local.b0.value(), - local.xor0, - local.shard, - &local.channel, - local.is_real, - ); + // XOR + XorOperation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + } // Write XOR to memory. //builder.eval_memory_access( @@ -286,32 +273,35 @@ mod tests { let mut instructions = vec![]; - //for (index, word) in a_words.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, a[0], false, true)); + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); instructions.push(Instruction::new( Opcode::ADD, 30, 0, - a_ptr + (0 * 4) as u32, + a_ptr + (index * 4) as u32, false, true, )); instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - //} + } - //for (index, word) in b_words.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, b[0], false, true)); + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); instructions.push(Instruction::new( Opcode::ADD, 30, 0, - b_ptr + (0 * 4) as u32, + b_ptr + (index * 4) as u32, false, true, )); instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - //} + } + // Syscall invocation instructions.push(Instruction::new( Opcode::ADD, 5, @@ -337,24 +327,9 @@ mod tests { } fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { - [ - a[0] ^ b[0], - a[1] ^ b[1], - a[2] ^ b[2], - a[3] ^ b[3], - ] + [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] } - - - - - - - - - - fn shuffle_left_1_u32x4(a: [u32; 4]) -> [u32; 4] { [a[1], a[2], a[3], a[0]] } @@ -382,7 +357,7 @@ mod tests { a[0].wrapping_add(b[0]), a[1].wrapping_add(b[1]), a[2].wrapping_add(b[2]), - a[3].wrapping_add(b[3]) + a[3].wrapping_add(b[3]), ] } @@ -414,13 +389,8 @@ mod tests { v[3] = shuffle_right_3_u32x4(v[3]); } - fn gather(m: [u32; 16], i0: usize, i1: usize, i2: usize, i3: usize) -> [u32; 4]{ - [ - m[i0], - m[i1], - m[i2], - m[i3] - ] + fn gather(m: [u32; 16], i0: usize, i1: usize, i2: usize, i3: usize) -> [u32; 4] { + [m[i0], m[i1], m[i2], m[i3]] } fn round(v: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16]) { @@ -439,7 +409,12 @@ mod tests { #[test] fn test_blake2s_round_function() { - fn test_inner(input: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16], output: Vec<[u32; 4]>) { + fn test_inner( + input: &mut Vec<[u32; 4]>, + m: [u32; 16], + s: [usize; 16], + output: Vec<[u32; 4]>, + ) { round(input, m, s); assert_eq!(input.clone(), output); } @@ -451,16 +426,26 @@ mod tests { [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], ]; - let m: [u32; 16] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; - let s: [usize; 16] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]; + let m: [u32; 16] = [ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + ]; + let s: [usize; 16] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, + ]; - test_inner(&mut v, m, s, vec![ + test_inner( + &mut v, + m, + s, + vec![ [0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3], [0x515f5af4, 0x0301095b, 0xb151a3c2, 0x5e17f96f], [0xc561666d, 0x0f291605, 0x990c6d13, 0x76fff6f1], [0x1e53bf19, 0x6fe4a680, 0x08e33663, 0x97fd885e], - ]); - + ], + ); let mut v: Vec<[u32; 4]> = vec![ [0x01, 0x01, 0x01, 0x01], @@ -469,15 +454,26 @@ mod tests { [0x01, 0x01, 0x01, 0x01], ]; - let m: [u32; 16] = [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]; - let s: [usize; 16] = [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]; + let m: [u32; 16] = [ + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, + ]; + let s: [usize; 16] = [ + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, + ]; - test_inner(&mut v, m, s, vec![ - [0x071e8a60, 0x071e8a60, 0x071e8a60, 0x071e8a60], - [0x072df44c, 0x072df44c, 0x072df44c, 0x072df44c], - [0x522ca035, 0x522ca035, 0x522ca035, 0x522ca035], - [0x280137ec, 0x280137ec, 0x280137ec, 0x280137ec] - ]); + test_inner( + &mut v, + m, + s, + vec![ + [0x071e8a60, 0x071e8a60, 0x071e8a60, 0x071e8a60], + [0x072df44c, 0x072df44c, 0x072df44c, 0x072df44c], + [0x522ca035, 0x522ca035, 0x522ca035, 0x522ca035], + [0x280137ec, 0x280137ec, 0x280137ec, 0x280137ec], + ], + ); } #[test] @@ -491,11 +487,22 @@ mod tests { unshuffle(&mut v); - assert_eq!(v[0].to_vec(), vec![0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3]); - assert_eq!(v[1].to_vec(), vec![0x515f5af4, 0x0301095b, 0xb151a3c2, 0x5e17f96f]); - assert_eq!(v[2].to_vec(), vec![0xc561666d, 0x0f291605, 0x990c6d13, 0x76fff6f1]); - assert_eq!(v[3].to_vec(), vec![0x1e53bf19, 0x6fe4a680, 0x08e33663, 0x97fd885e]); - + assert_eq!( + v[0].to_vec(), + vec![0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3] + ); + assert_eq!( + v[1].to_vec(), + vec![0x515f5af4, 0x0301095b, 0xb151a3c2, 0x5e17f96f] + ); + assert_eq!( + v[2].to_vec(), + vec![0xc561666d, 0x0f291605, 0x990c6d13, 0x76fff6f1] + ); + assert_eq!( + v[3].to_vec(), + vec![0x1e53bf19, 0x6fe4a680, 0x08e33663, 0x97fd885e] + ); } #[test] @@ -509,11 +516,22 @@ mod tests { shuffle(&mut v); - assert_eq!(v[0].to_vec(), vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc]); - assert_eq!(v[1].to_vec(), vec![0x8d07c52d, 0xb9d6aa3a, 0x88609304, 0x408705aa]); - assert_eq!(v[2].to_vec(), vec![0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7]); - assert_eq!(v[3].to_vec(), vec![0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb]); - + assert_eq!( + v[0].to_vec(), + vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc] + ); + assert_eq!( + v[1].to_vec(), + vec![0x8d07c52d, 0xb9d6aa3a, 0x88609304, 0x408705aa] + ); + assert_eq!( + v[2].to_vec(), + vec![0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7] + ); + assert_eq!( + v[3].to_vec(), + vec![0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb] + ); } #[test] @@ -530,9 +548,21 @@ mod tests { quarter_round(&mut v, rd, rb, m); - assert_eq!(v[0].to_vec(), vec![0xbc1738c6, 0x566d1711, 0x5bf2cd1d, 0x130c253]); - assert_eq!(v[1].to_vec(), vec![0x1ff85cd8, 0x361a0001, 0x6ab383b7, 0xd13ef7a9]); - assert_eq!(v[2].to_vec(), vec![0xd4c3d380, 0x3b057bed, 0x27b8af00, 0xb49a500a]); - assert_eq!(v[3].to_vec(), vec![0x6ab9ed19, 0x7f9dcd68, 0xeb49bb8e, 0xf4a5ad0]); + assert_eq!( + v[0].to_vec(), + vec![0xbc1738c6, 0x566d1711, 0x5bf2cd1d, 0x130c253] + ); + assert_eq!( + v[1].to_vec(), + vec![0x1ff85cd8, 0x361a0001, 0x6ab383b7, 0xd13ef7a9] + ); + assert_eq!( + v[2].to_vec(), + vec![0xd4c3d380, 0x3b057bed, 0x27b8af00, 0xb49a500a] + ); + assert_eq!( + v[3].to_vec(), + vec![0x6ab9ed19, 0x7f9dcd68, 0xeb49bb8e, 0xf4a5ad0] + ); } } diff --git a/core/src/utils/prove.rs b/core/src/utils/prove.rs index 84be69a52..1f223cdcf 100644 --- a/core/src/utils/prove.rs +++ b/core/src/utils/prove.rs @@ -358,8 +358,8 @@ where { //#[cfg(debug_assertions)] //{ - let record_clone = record.clone(); - machine.debug_constraints(pk, record_clone); + let record_clone = record.clone(); + machine.debug_constraints(pk, record_clone); //} let stats = record.stats().clone(); let cycles = stats.get("cpu_events").unwrap(); From 04a153a2d9669bfeb5b20daf140ac4ae9b681145 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 11 Sep 2024 17:20:25 +0300 Subject: [PATCH 05/30] chore: Add computation result writing to the memory --- core/src/runtime/syscall.rs | 4 +- core/src/syscall/precompiles/blake2s/mod.rs | 77 +++++++++++---------- zkvm/entrypoint/src/syscalls/mod.rs | 2 +- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 370b96033..837b90e5a 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -118,7 +118,7 @@ pub enum SyscallCode { /// Executes the `HINT_READ` precompile. HINT_READ = 0x00_00_00_F1, - EMPTY = 0x00_00_01_CC, + EMPTY = 0x00_01_01_CC, } impl SyscallCode { @@ -155,7 +155,7 @@ impl SyscallCode { 0x00_01_01_F2 => SyscallCode::BLS12381_G1_DECOMPRESS, 0x00_01_01_80 => SyscallCode::BLS12381_G2_ADD, 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, - 0x00_00_01_CC => SyscallCode::EMPTY, + 0x00_01_01_CC => SyscallCode::EMPTY, _ => panic!("invalid syscall number: {}", value), } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 7faae1447..75e575a10 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -35,9 +35,8 @@ pub struct EmptyEvent { pub channel: u32, pub a_ptr: u32, pub b_ptr: u32, - pub a_reads: Vec, + pub a_reads_writes: Vec, pub b_reads: Vec, - //pub xor_writes: Vec, } impl Syscall for EmptyChip { @@ -50,24 +49,24 @@ impl Syscall for EmptyChip { let a_ptr = arg1; let b_ptr = arg2; - let mut a_reads = Vec::new(); let mut b_reads = Vec::new(); + let mut xor = vec![]; for i in 0..4usize { // Read a. - let (record, a) = ctx.mr(a_ptr + (i * 4) as u32); - a_reads.push(record); + let a = ctx.word_unsafe(a_ptr + (i * 4) as u32); // Read b. let (record, b) = ctx.mr(b_ptr + (i * 4) as u32); b_reads.push(record); - let _xor = a ^ b; + xor.push(a ^ b); } + ctx.clk += 1; + // Write xor to a_ptr. - //xor_writes.push(ctx.mw(a_ptr, xor0)); - //ctx.clk += 1; + let a_reads_writes = ctx.mw_slice(a_ptr, xor.as_slice()); ctx.record_mut().empty_events.push(EmptyEvent { lookup_id, @@ -76,13 +75,16 @@ impl Syscall for EmptyChip { channel, a_ptr, b_ptr, - a_reads, + a_reads_writes, b_reads, - //xor_writes: xor0_writes, }); None } + + fn num_extra_cycles(&self) -> u32 { + 1 + } } #[derive(Debug, Clone, AlignedBorrow)] @@ -97,11 +99,10 @@ struct EmptyCols { pub a_ptr: T, pub b_ptr: T, - pub a: [MemoryReadCols; 4], + pub a: [MemoryWriteCols; 4], pub b: [MemoryReadCols; 4], pub xor: [XorOperation; 4], - //pub axorb: MemoryWriteCols, } impl BaseAir for EmptyChip { @@ -143,11 +144,15 @@ impl MachineAir for EmptyChip { cols.b_ptr = F::from_canonical_u32(event.b_ptr); for i in 0..4usize { - cols.a[i].populate(event.channel, event.a_reads[i], &mut new_byte_lookup_events); + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - let a = event.a_reads[i].value; + let a = event.a_reads_writes[i].value; let b = event.b_reads[i].value; let xor = cols.xor[i].populate(output, shard, event.channel, a, b); assert_eq!(a ^ b, xor); @@ -205,17 +210,17 @@ where .assert_eq(local.nonce + AB::Expr::one(), next.nonce); for i in 0..4usize { - // Read a. + // Eval a builder.eval_memory_access( local.shard, local.channel, - local.clk, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), &local.a[i], local.is_real, ); - // Read b. + // Eval b. builder.eval_memory_access( local.shard, local.channel, @@ -225,7 +230,7 @@ where local.is_real, ); - // XOR + // Eval XOR XorOperation::::eval( builder, *local.a[i].value(), @@ -237,17 +242,6 @@ where ); } - // Write XOR to memory. - //builder.eval_memory_access( - // local.shard, - // local.channel, - // local.clk, - // local.a_ptr, - // &local.a0, - // local.is_real, - //); - //builder.assert_word_eq(*local.a0.value(), local.xor0.value); - builder.receive_syscall( local.shard, local.channel, @@ -264,15 +258,11 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::{run_test, setup_logger}; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; - fn risc_v_program(a: [u32; 4], b: [u32; 4]) -> Program { - let a_ptr = 100100100; - let b_ptr = 200200200; - + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { let mut instructions = vec![]; - // memory write a for (index, word) in a.into_iter().enumerate() { instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); @@ -319,11 +309,26 @@ mod tests { #[test] fn test_empty_precompile() { setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; let program = risc_v_program( + a_ptr, + b_ptr, [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], ); - run_test(program).unwrap(); + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!( + result, + [0x3a06b438, 0x2062c609, 0x23ed2ad9, 0xfeaf3823].to_vec() + ); } fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index a7f4993e9..490fd67c7 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -107,4 +107,4 @@ pub const BLS12381_G1_DOUBLE: u32 = 0x00_00_01_72; /// Executes `BLS12381_G1_DECOMPRESS`. pub const BLS12381_G1_DECOMPRESS: u32 = 0x00_01_01_F2; -pub const EMPTY: u32 = 0x00_00_01_CC; +pub const EMPTY: u32 = 0x00_01_01_CC; From e52394d8e615cd8051899bdefb702597d007487c Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 11 Sep 2024 17:52:10 +0300 Subject: [PATCH 06/30] chore: Inject R_D, R_B constants into memory layout --- core/src/syscall/precompiles/blake2s/mod.rs | 64 ++++++++++++++------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 75e575a10..a36310266 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -18,6 +18,11 @@ use serde::Serialize; use sphinx_derive::AlignedBorrow; use std::mem::size_of; +const R_1: u32 = 16; +const R_2: u32 = 12; +//const R_3: u32 = 8; +//const R_4: u32 = 7; + #[derive(Default)] pub struct EmptyChip; @@ -49,19 +54,18 @@ impl Syscall for EmptyChip { let a_ptr = arg1; let b_ptr = arg2; - let mut b_reads = Vec::new(); + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, mut b) = ctx.mr_slice(b_ptr, 6); - let mut xor = vec![]; - for i in 0..4usize { - // Read a. - let a = ctx.word_unsafe(a_ptr + (i * 4) as u32); + let _r_d = b[4].clone(); + let _r_b = b[5].clone(); + b.truncate(4); - // Read b. - let (record, b) = ctx.mr(b_ptr + (i * 4) as u32); - b_reads.push(record); - - xor.push(a ^ b); - } + let xor = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| a ^ b) + .collect::>(); ctx.clk += 1; @@ -100,7 +104,7 @@ struct EmptyCols { pub b_ptr: T, pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], + pub b: [MemoryReadCols; 6], // includes r_d, r_b words pub xor: [XorOperation; 4], } @@ -158,11 +162,8 @@ impl MachineAir for EmptyChip { assert_eq!(a ^ b, xor); } - //cols.axorb0.populate( - // event.channel, - // event.xor_writes[0], - // &mut new_byte_lookup_events, - //); + cols.b[4].populate(event.channel, event.b_reads[4], &mut new_byte_lookup_events); // handle r_d + cols.b[5].populate(event.channel, event.b_reads[5], &mut new_byte_lookup_events); // handle r_b rows.push(row); } @@ -242,6 +243,28 @@ where ); } + // Eval r_d (included in b_ptr). + let i = 4usize; + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // Eval r_d (included in b_ptr). + let i = 5usize; + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + builder.receive_syscall( local.shard, local.channel, @@ -258,10 +281,11 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::syscall::precompiles::blake2s::{R_1, R_2}; + use crate::utils::{run_test_with_memory_inspection, setup_logger}; use crate::Program; - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 6]) -> Program { let mut instructions = vec![]; // memory write a for (index, word) in a.into_iter().enumerate() { @@ -316,7 +340,7 @@ mod tests { a_ptr, b_ptr, [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, R_1, R_2], ); let (_, memory) = run_test_with_memory_inspection(program); let mut result = vec![]; From 51d5d6e84ff768c3bdcea13f71e022262bcb46a4 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 11 Sep 2024 20:07:41 +0300 Subject: [PATCH 07/30] chore: Rename Empty to Blake2sXorRotateRight precompile --- core/src/runtime/record.rs | 40 ++--- core/src/runtime/syscall.rs | 18 ++- core/src/stark/air.rs | 8 +- core/src/syscall/precompiles/blake2s/mod.rs | 159 +++++++++++--------- zkvm/entrypoint/src/syscalls/mod.rs | 2 +- 5 files changed, 127 insertions(+), 100 deletions(-) diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 28acd247b..50ace6dd2 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -10,7 +10,7 @@ use super::{program::Program, Opcode}; use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; -use crate::syscall::precompiles::blake2s::{EmptyChip, EmptyEvent}; +use crate::syscall::precompiles::blake2s::{Blake2sXorRotateRightChip, Blake2sXorRotateRightEvent}; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; use crate::syscall::precompiles::sha256::{ShaCompressEvent, ShaExtendEvent}; @@ -97,8 +97,6 @@ pub struct ExecutionRecord { pub sha_extend_events: Vec, - pub empty_events: Vec, - pub sha_compress_events: Vec, pub keccak_permute_events: Vec, @@ -128,6 +126,8 @@ pub struct ExecutionRecord { pub bls12381_g2_add_events: Vec, pub bls12381_g2_double_events: Vec, + pub blake2s_xor_rotate_right_events: Vec, + pub memory_initialize_events: Vec, pub memory_finalize_events: Vec, @@ -217,12 +217,6 @@ impl EventLens for ExecutionRecord { } } -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.empty_events - } -} - impl EventLens for ExecutionRecord { fn events(&self) -> >::Events { &self.sha_compress_events @@ -327,6 +321,12 @@ impl EventLens> for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_xor_rotate_right_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -420,7 +420,6 @@ impl MachineRecord for ExecutionRecord { "sha_compress_events".to_string(), self.sha_compress_events.len(), ); - stats.insert("empty_events".to_string(), self.empty_events.len()); stats.insert( "keccak_permute_events".to_string(), self.keccak_permute_events.len(), @@ -475,6 +474,10 @@ impl MachineRecord for ExecutionRecord { "bls12381_g2_double_events".to_string(), self.bls12381_g2_double_events.len(), ); + stats.insert( + "blake2s_xor_rotate_right_events".to_string(), + self.blake2s_xor_rotate_right_events.len(), + ); stats } @@ -492,9 +495,6 @@ impl MachineRecord for ExecutionRecord { self.sha_extend_events.append(&mut other.sha_extend_events); self.sha_compress_events .append(&mut other.sha_compress_events); - - self.empty_events.append(&mut other.empty_events); - self.keccak_permute_events .append(&mut other.keccak_permute_events); self.ed_add_events.append(&mut other.ed_add_events); @@ -523,6 +523,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.bls12381_g2_add_events); self.bls12381_g2_double_events .append(&mut other.bls12381_g2_double_events); + self.blake2s_xor_rotate_right_events + .append(&mut other.blake2s_xor_rotate_right_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -808,12 +810,6 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); } - // Empty events - first.empty_events = take(&mut self.empty_events); - for (i, event) in first.empty_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - // SHA-256 compress events. first.sha_compress_events = take(&mut self.sha_compress_events); for (i, event) in first.sha_compress_events.iter().enumerate() { @@ -856,6 +852,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_xor_rotate_right events + first.blake2s_xor_rotate_right_events = take(&mut self.blake2s_xor_rotate_right_events); + for (i, event) in first.blake2s_xor_rotate_right_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 837b90e5a..2f2372564 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -6,7 +6,7 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; -use crate::syscall::precompiles::blake2s::EmptyChip; +use crate::syscall::precompiles::blake2s::Blake2sXorRotateRightChip; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; use crate::syscall::precompiles::bls12_381::g2_double::Bls12381G2AffineDoubleChip; @@ -118,7 +118,7 @@ pub enum SyscallCode { /// Executes the `HINT_READ` precompile. HINT_READ = 0x00_00_00_F1, - EMPTY = 0x00_01_01_CC, + BLAKE_2S_XOR_ROTATE_RIGHT = 0x00_01_01_CC, } impl SyscallCode { @@ -155,7 +155,7 @@ impl SyscallCode { 0x00_01_01_F2 => SyscallCode::BLS12381_G1_DECOMPRESS, 0x00_01_01_80 => SyscallCode::BLS12381_G2_ADD, 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, - 0x00_01_01_CC => SyscallCode::EMPTY, + 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, _ => panic!("invalid syscall number: {}", value), } } @@ -394,7 +394,10 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Bls12381G2AffineDoubleChip::new()), ); - syscall_map.insert(SyscallCode::EMPTY, Arc::new(EmptyChip::new())); + syscall_map.insert( + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, + Arc::new(Blake2sXorRotateRightChip::new()), + ); syscall_map } @@ -510,8 +513,11 @@ mod tests { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLS12381_G2_DOUBLE) } - SyscallCode::EMPTY => { - assert_eq!(code as u32, sphinx_zkvm::syscalls::EMPTY) + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT => { + assert_eq!( + code as u32, + sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT + ) } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 5cdeec2e3..835709f3f 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -3,7 +3,7 @@ pub use crate::air::SphinxAirBuilder; use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; -use crate::syscall::precompiles::blake2s::EmptyChip; +use crate::syscall::precompiles::blake2s::Blake2sXorRotateRightChip; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; use crate::syscall::precompiles::quad_field::QuadFieldChip; @@ -108,7 +108,7 @@ pub enum RiscvAir { /// A precompile for decompressing a point on the BLS12-381 curve. Bls12381G1Decompress(Bls12381G1DecompressChip), - Empty(EmptyChip), + Blake2sXorRotateRight(Blake2sXorRotateRightChip), } impl RiscvAir { @@ -185,8 +185,8 @@ impl RiscvAir { let byte = ByteChip::default(); chips.push(RiscvAir::ByteLookup(byte)); - let empty = EmptyChip::default(); - chips.push(RiscvAir::Empty(empty)); + let blake_2s_xor_rotate_right = Blake2sXorRotateRightChip::default(); + chips.push(RiscvAir::Blake2sXorRotateRight(blake_2s_xor_rotate_right)); chips } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index a36310266..66e66d740 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,6 +1,6 @@ use crate::bytes::event::ByteRecord; use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::XorOperation; +use crate::operations::{FixedRotateRightOperation, XorOperation}; use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; use crate::stark::SphinxAirBuilder; use crate::utils::pad_rows; @@ -19,32 +19,33 @@ use sphinx_derive::AlignedBorrow; use std::mem::size_of; const R_1: u32 = 16; -const R_2: u32 = 12; +//const R_2: u32 = 12; //const R_3: u32 = 8; //const R_4: u32 = 7; #[derive(Default)] -pub struct EmptyChip; +pub struct Blake2sXorRotateRightChip; -impl EmptyChip { +impl Blake2sXorRotateRightChip { pub fn new() -> Self { - EmptyChip + Blake2sXorRotateRightChip } } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EmptyEvent { +pub struct Blake2sXorRotateRightEvent { pub lookup_id: usize, pub clk: u32, pub shard: u32, pub channel: u32, pub a_ptr: u32, pub b_ptr: u32, + pub rot: u32, pub a_reads_writes: Vec, pub b_reads: Vec, } -impl Syscall for EmptyChip { +impl Syscall for Blake2sXorRotateRightChip { fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { let clk_init = ctx.clk; let shard = ctx.current_shard(); @@ -55,10 +56,9 @@ impl Syscall for EmptyChip { let b_ptr = arg2; let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, mut b) = ctx.mr_slice(b_ptr, 6); + let (b_reads, mut b) = ctx.mr_slice(b_ptr, 5); - let _r_d = b[4].clone(); - let _r_b = b[5].clone(); + let rot = b[4].clone(); b.truncate(4); let xor = a @@ -67,21 +67,29 @@ impl Syscall for EmptyChip { .map(|(a, b)| a ^ b) .collect::>(); - ctx.clk += 1; + let rotate_right = xor + .into_iter() + .map(|xor_i| xor_i.rotate_right(rot)) + .collect::>(); - // Write xor to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, xor.as_slice()); + ctx.clk += 1; - ctx.record_mut().empty_events.push(EmptyEvent { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); + + ctx.record_mut() + .blake2s_xor_rotate_right_events + .push(Blake2sXorRotateRightEvent { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + rot, + a_reads_writes, + b_reads, + }); None } @@ -93,7 +101,7 @@ impl Syscall for EmptyChip { #[derive(Debug, Clone, AlignedBorrow)] #[repr(C)] -struct EmptyCols { +struct Blake2sXorRotateRightCols { pub clk: T, pub shard: T, pub channel: T, @@ -104,27 +112,28 @@ struct EmptyCols { pub b_ptr: T, pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 6], // includes r_d, r_b words + pub b: [MemoryReadCols; 5], // includes rotation constant pub xor: [XorOperation; 4], + pub rotate_right: [FixedRotateRightOperation; 4], } -impl BaseAir for EmptyChip { +impl BaseAir for Blake2sXorRotateRightChip { fn width(&self) -> usize { - size_of::>() + size_of::>() } } -impl<'a> WithEvents<'a> for EmptyChip { - type Events = &'a [EmptyEvent]; +impl<'a> WithEvents<'a> for Blake2sXorRotateRightChip { + type Events = &'a [Blake2sXorRotateRightEvent]; } -impl MachineAir for EmptyChip { +impl MachineAir for Blake2sXorRotateRightChip { type Record = ExecutionRecord; type Program = Program; fn name(&self) -> String { - "EmptyChip".to_string() + "Blake2sXorRotateRightChip".to_string() } fn generate_trace>( @@ -133,12 +142,12 @@ impl MachineAir for EmptyChip { output: &mut Self::Record, ) -> RowMajorMatrix { let mut rows = vec![]; - let width = >::width(self); + let width = >::width(self); let mut new_byte_lookup_events = Vec::new(); for event in input.events() { let shard = event.shard; let mut row = vec![F::zero(); width]; - let cols: &mut EmptyCols = row.as_mut_slice().borrow_mut(); + let cols: &mut Blake2sXorRotateRightCols = row.as_mut_slice().borrow_mut(); cols.clk = F::from_canonical_u32(event.clk); cols.is_real = F::one(); @@ -147,6 +156,10 @@ impl MachineAir for EmptyChip { cols.a_ptr = F::from_canonical_u32(event.a_ptr); cols.b_ptr = F::from_canonical_u32(event.b_ptr); + cols.b[4].populate(event.channel, event.b_reads[4], &mut new_byte_lookup_events); // handle rotation_constant + + let rot = event.b_reads[4].value; + for i in 0..4usize { cols.a[i].populate( event.channel, @@ -160,10 +173,11 @@ impl MachineAir for EmptyChip { let b = event.b_reads[i].value; let xor = cols.xor[i].populate(output, shard, event.channel, a, b); assert_eq!(a ^ b, xor); - } - cols.b[4].populate(event.channel, event.b_reads[4], &mut new_byte_lookup_events); // handle r_d - cols.b[5].populate(event.channel, event.b_reads[5], &mut new_byte_lookup_events); // handle r_b + let rotate_right = + cols.rotate_right[i].populate(output, shard, event.channel, xor, rot as usize); + assert_eq!(xor.rotate_right(rot), rotate_right); + } rows.push(row); } @@ -181,7 +195,8 @@ impl MachineAir for EmptyChip { // Write the nonces to the trace. for i in 0..trace.height() { - let cols: &mut EmptyCols = trace.values[i * width..(i + 1) * width].borrow_mut(); + let cols: &mut Blake2sXorRotateRightCols = + trace.values[i * width..(i + 1) * width].borrow_mut(); cols.nonce = F::from_canonical_usize(i); } @@ -189,11 +204,11 @@ impl MachineAir for EmptyChip { } fn included(&self, shard: &Self::Record) -> bool { - !shard.empty_events.is_empty() + !shard.blake2s_xor_rotate_right_events.is_empty() } } -impl Air for EmptyChip +impl Air for Blake2sXorRotateRightChip where AB::F: PrimeField32, { @@ -201,8 +216,8 @@ where let main = builder.main(); let local = main.row_slice(0); let next = main.row_slice(1); - let local: &EmptyCols = (*local).borrow(); - let next: &EmptyCols = (*next).borrow(); + let local: &Blake2sXorRotateRightCols = (*local).borrow(); + let next: &Blake2sXorRotateRightCols = (*next).borrow(); // Constrain the incrementing nonce. builder.when_first_row().assert_zero(local.nonce); @@ -210,6 +225,20 @@ where .when_transition() .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + // Eval rotation_constant (included as 4th word in b_ptr). + let i = 4usize; + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // TODO: get rotation constant from memory somehow + let _rot = *local.b[4].value(); + for i in 0..4usize { // Eval a builder.eval_memory_access( @@ -241,36 +270,25 @@ where &local.channel, local.is_real, ); - } - - // Eval r_d (included in b_ptr). - let i = 4usize; - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - // Eval r_d (included in b_ptr). - let i = 5usize; - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_1 as usize, // TODO use value from memory instead ! + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + } builder.receive_syscall( local.shard, local.channel, local.clk, local.nonce, - AB::F::from_canonical_u32(SyscallCode::EMPTY.syscall_id()), + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT.syscall_id()), local.a_ptr, local.b_ptr, local.is_real, @@ -281,11 +299,11 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::syscall::precompiles::blake2s::{R_1, R_2}; + use crate::syscall::precompiles::blake2s::R_1; use crate::utils::{run_test_with_memory_inspection, setup_logger}; use crate::Program; - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 6]) -> Program { + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 5]) -> Program { let mut instructions = vec![]; // memory write a for (index, word) in a.into_iter().enumerate() { @@ -320,7 +338,7 @@ mod tests { Opcode::ADD, 5, 0, - SyscallCode::EMPTY as u32, + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT as u32, false, true, )); @@ -331,7 +349,7 @@ mod tests { } #[test] - fn test_empty_precompile() { + fn test_blake2s_xor_rotate_right_precompile() { setup_logger(); let a_ptr = 100100100; @@ -340,8 +358,9 @@ mod tests { a_ptr, b_ptr, [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, R_1, R_2], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, R_1], ); + let (_, memory) = run_test_with_memory_inspection(program); let mut result = vec![]; // result is 4 words, written to a_ptr @@ -351,7 +370,7 @@ mod tests { assert_eq!( result, - [0x3a06b438, 0x2062c609, 0x23ed2ad9, 0xfeaf3823].to_vec() + [0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf].to_vec() ); } diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 490fd67c7..ec16b486e 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -107,4 +107,4 @@ pub const BLS12381_G1_DOUBLE: u32 = 0x00_00_01_72; /// Executes `BLS12381_G1_DECOMPRESS`. pub const BLS12381_G1_DECOMPRESS: u32 = 0x00_01_01_F2; -pub const EMPTY: u32 = 0x00_01_01_CC; +pub const BLAKE_2S_XOR_ROTATE_RIGHT: u32 = 0x00_01_01_CC; From b1831c6f9780c0ec7ac2d6b47042af7372d7b059 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 11 Sep 2024 21:01:35 +0300 Subject: [PATCH 08/30] chore: Add integration test for BLAKE2S_XOR_ROTATE_RIGHT precompile --- core/src/syscall/precompiles/blake2s/mod.rs | 18 +- core/src/utils/programs.rs | 3 + tests/blake2s-xor-rotate-right/Cargo.lock | 539 ++++++++++++++++++ tests/blake2s-xor-rotate-right/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25148 bytes tests/blake2s-xor-rotate-right/src/main.rs | 31 + .../src/syscalls/blake2s_xor_rotate_right.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 2 + zkvm/precompiles/src/lib.rs | 1 + 9 files changed, 616 insertions(+), 5 deletions(-) create mode 100644 tests/blake2s-xor-rotate-right/Cargo.lock create mode 100644 tests/blake2s-xor-rotate-right/Cargo.toml create mode 100755 tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-xor-rotate-right/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right.rs diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 66e66d740..beac20a1c 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -172,11 +172,11 @@ impl MachineAir for Blake2sXorRotateRightChip { let a = event.a_reads_writes[i].value; let b = event.b_reads[i].value; let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - assert_eq!(a ^ b, xor); + //assert_eq!(a ^ b, xor); - let rotate_right = + let _rotate_right = cols.rotate_right[i].populate(output, shard, event.channel, xor, rot as usize); - assert_eq!(xor.rotate_right(rot), rotate_right); + //assert_eq!(xor.rotate_right(rot), rotate_right); } rows.push(row); @@ -237,7 +237,7 @@ where ); // TODO: get rotation constant from memory somehow - let _rot = *local.b[4].value(); + //let _rot = *local.b[4].value(); for i in 0..4usize { // Eval a @@ -300,7 +300,8 @@ where mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; use crate::syscall::precompiles::blake2s::R_1; - use crate::utils::{run_test_with_memory_inspection, setup_logger}; + use crate::utils::tests::BLAKE2S_XOR_RIGHT_ROTATE_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 5]) -> Program { @@ -374,6 +375,13 @@ mod tests { ); } + #[test] + fn test_blake2s_xor_right_rotate_program() { + setup_logger(); + let program = Program::from(BLAKE2S_XOR_RIGHT_ROTATE_ELF); + run_test(program).unwrap(); + } + fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] } diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index 132f6c5cf..bbaf1f342 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -121,6 +121,9 @@ pub mod tests { pub const BLS12381_G2_DOUBLE_ELF: &[u8] = include_bytes!("../../../tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_XOR_RIGHT_ROTATE_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-xor-rotate-right/Cargo.lock b/tests/blake2s-xor-rotate-right/Cargo.lock new file mode 100644 index 000000000..733b51ebb --- /dev/null +++ b/tests/blake2s-xor-rotate-right/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-xor-rotate-right-test" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right/Cargo.toml b/tests/blake2s-xor-rotate-right/Cargo.toml new file mode 100644 index 000000000..8d49fdcb8 --- /dev/null +++ b/tests/blake2s-xor-rotate-right/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-xor-rotate-right-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..77111e1412cde84eb8a5897002ba4d0f055cfc2d GIT binary patch literal 25148 zcmeHwdw3MrdH0#?u7oTE!z~W62SyTC3rQI-1INg7y2E2LORiY|cN ze0arbB%svA88FzTjb5=YOzH_M{2+X@gcAnAKtvBeb1kV@NI3*=aXFfKY zWwH#W0z_pcs7d$F@J_ev-lM(Io4_XFK{u7N9D?BT)2;J+_A{NO zW&4vwX~m4Kn*=2kVLfuQz;xZIv;jRmC{3 zr)<>+x-mg|c4^8!)gjo^wzBxs?Wx4si_GX8VD|l61#RyZ7Jv3wDzOf*rw7o-7Qy~D z>OG^fzdE1z}6Xg$uj>yhK)fwh|EzXA_G)wjZ?4xQDvCwPlI#9lcb;W_B?-^#a0pB*1E4|FH2zDIhr&yOobK^eLtuM!#?HoK1)3mSF!Cq(HRyzRcT$k@ATNW8U`|p+dq5GfRw}`4 zB?mgj&*FNYA8j(GYFr=td6^IWs(pT2=_FnkH6QfxsxV8mzrni3zkZo?iKhCPnXSn7 z2FSRdN&O!j8Mgfm3h?{QZ`DT@a2eZ&M14T6{Q+wrWS;33gHavhCBHy8+bZ4_Kik7- zzDNJW!=HGdm+G}EH&NR?h{sU=zcIJVM!^JT%x{JMevBEjX9#v1(Z&*_Ij}q3ON4k& zlDD<3K>DX#*$2zcd%({MV;aUy&)8EdJ?v}S^o+bYC!D=-JxEkWQi zgJ+6#qmjFxahfUCM}!}}+luuefBM1~G^Lf+m&=kf7j^^M4uei&@U;IyO=+n#bhJCX z?w>Se)qBQFybsjfswsIv-uJ*=-I~(9g7>{D`yNdhm}SgHofhSu5tgu5{t-<&qd zk7*4ZT7*7AA1TNXZ~(n6k`>kEH#UT_k5MKYxvetzLpJmoicwG`8S^V7W9~hYF*_m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ajUEV#CN^N!5=hJ8$LcLr65pzLX z8aJKBIzVes{vygZIpf^@Ksr58PV*s~m-A1fYfbp=1#B8%m3T+LoW2DA9^jRL6Mq8E z`HJ38xNvtqg?BpR@c!RL*|(BoX?PK^TENIA&_#G;fv;j|^=LdDum-^Hph{`ul>^>M zaA#g2Z@lTKwi0DOI+jZ9blQxe36(da{MO@`o6}am+oK7}XfC@@9y^gr#qdrvy@Sf} z%IA-=cTq;N;Ng>t*AswmdIfYQrdX2QDO^RcsQo$AJMmMOm)-f$-2Gs%qkxy-oi2h+ z2kd8n5zcf``$E9p11v;za*PON^ zYe%%`L|OT3pDZJsUPReBl(}+rcRKG;`CBM&czv{O`nWWgVU*{d8cPd;Pf{>BpAjY5F!0xT;Hwi2)%fR&`dssVceur~+>x>4J20oL$FDn)Wf7r}M{ zwiPgs<^)5Ui0uT7=z+F;9lj6PF2L?~U|bHU?oR;!QCfSN&%1!V2H0C^b@}`O-}~l> zZs7BzF(#>uy$raEYbc%n3Q-pO4_8N}@y{KAe+%$(8Uq*M@-@IZ0pobPum->m0Orw# z@Mr_IsQw|qC;jJ$?2YJv9|6AP?NqATzG$;or6?FEE-Ec3Dh)DnpUlzD3WB8tg}2mEvH~f9 z*~JS>*On~|R95L|T5?Na@h!zAbJ(3Vbq_}2AK!WB61^x$!?OxPx3Q+l+`xn>c$IUM z#tnhun&O6{)$5BJ3K=Uv7NMCHG}c$b)n*0J>eW?^h;~>(lLKg4+tkDg_&;X-dJ0oe znK~?h&)itE7Fh_CH&w%lXpXGK5TE%XveOMxL!s!n;d3ve59jja#)nU;N3k^jzXtAt zogk;ky-0=8MLs*#qvhXP4d4C&$Sm(109;;wpTj%VgKBgBZ-Uj19>piWym~smsBfy* z`H0T;q23I *mut u8; pub fn syscall_bls12381_g2_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g2_double(p: *mut u32); + pub fn syscall_blake2s_xor_rotate_right(left: *mut u32, right: *const u32); } From 121b819c55b55c39b8230a5f091d3b1c94e8adfb Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Fri, 13 Sep 2024 20:03:30 +0300 Subject: [PATCH 09/30] feat: More optimal Blake2s XOR right-rotate syscall --- Cargo.lock | 740 ++++++++++-------- core/src/runtime/record.rs | 25 +- core/src/runtime/syscall.rs | 14 +- core/src/stark/air.rs | 6 +- core/src/syscall/precompiles/blake2s/mod.rs | 48 +- .../precompiles/blake2s/xor_rotate_16/air.rs | 291 +++++++ .../blake2s/xor_rotate_16/columns.rs | 71 ++ .../blake2s/xor_rotate_16/execute.rs | 101 +++ .../blake2s/xor_rotate_16/flags.rs | 130 +++ .../precompiles/blake2s/xor_rotate_16/mod.rs | 116 +++ .../blake2s/xor_rotate_16/trace.rs | 178 +++++ core/src/utils/programs.rs | 3 + tests/blake2s-xor-rotate-16/Cargo.lock | 539 +++++++++++++ tests/blake2s-xor-rotate-16/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 22924 bytes tests/blake2s-xor-rotate-16/src/main.rs | 13 + .../elf/riscv32im-succinct-zkvm-elf | Bin 25148 -> 25140 bytes tests/blake2s-xor-rotate-right/src/main.rs | 4 +- .../src/syscalls/blake2s_xor_rotate_16.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 3 + zkvm/precompiles/src/lib.rs | 1 + 21 files changed, 1923 insertions(+), 387 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs create mode 100644 tests/blake2s-xor-rotate-16/Cargo.lock create mode 100644 tests/blake2s-xor-rotate-16/Cargo.toml create mode 100755 tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-xor-rotate-16/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_16.rs diff --git a/Cargo.lock b/Cargo.lock index 6bc253a64..48201fb87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,18 +25,18 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "aes" @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "alloy-rlp" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b155716bab55763c95ba212806cf43d05bcc70e5f35b02bad20cf5ec7fe11fed" +checksum = "26154390b1d205a4a7ac7352aa2eb4f81f391399d4e2f546fb81a2f8bb383f62" dependencies = [ "arrayvec", "bytes", @@ -119,7 +119,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -131,11 +131,11 @@ dependencies = [ "alloy-sol-macro-input", "const-hex", "heck", - "indexmap 2.2.6", + "indexmap 2.5.0", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", "syn-solidity", "tiny-keccak", ] @@ -151,7 +151,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", "syn-solidity", ] @@ -199,9 +199,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -220,27 +220,27 @@ checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -248,9 +248,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" dependencies = [ "backtrace", ] @@ -289,7 +289,7 @@ dependencies = [ "num-bigint 0.4.6", "num-traits", "paste", - "rustc_version 0.4.0", + "rustc_version 0.4.1", "zeroize", ] @@ -387,19 +387,19 @@ checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -410,7 +410,7 @@ checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" dependencies = [ "futures", "pharos", - "rustc_version 0.4.0", + "rustc_version 0.4.1", ] [[package]] @@ -421,7 +421,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -441,9 +441,9 @@ dependencies = [ "bytes", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "http-body-util", - "hyper 1.3.1", + "hyper 1.4.1", "hyper-util", "itoa", "matchit", @@ -474,7 +474,7 @@ dependencies = [ "bytes", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "http-body-util", "mime", "pin-project-lite", @@ -487,18 +487,18 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", "serde", + "windows-targets 0.52.6", ] [[package]] @@ -552,10 +552,10 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -563,9 +563,9 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", - "syn 2.0.68", + "syn 2.0.77", "which", ] @@ -592,9 +592,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -630,9 +630,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.3" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9ec96fe9a81b5e365f9db71fe00edc4fe4ca2cc7dcb7861f0603012a7caa210" +checksum = "d82033247fd8e890df8f740e407ad4d038debb9eb1f40533fffb32e7d17dc6f7" dependencies = [ "arrayref", "arrayvec", @@ -667,13 +667,14 @@ dependencies = [ [[package]] name = "bls12_381" version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" +source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#2a96eccde19bf861b0d1707b61b2ab15e294b154" dependencies = [ "cfg-if", "ff 0.13.0", "group 0.13.0", "pairing 0.23.0", "rand_core", + "sphinx-precompiles 1.0.0 (git+https://github.com/argumentcomputer/sphinx?branch=dev)", "subtle", ] @@ -701,9 +702,9 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "bytemuck" -version = "1.16.3" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" [[package]] name = "byteorder" @@ -713,18 +714,18 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" dependencies = [ "serde", ] [[package]] name = "camino" -version = "1.1.7" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" dependencies = [ "serde", ] @@ -760,12 +761,13 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.10" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ "jobserver", "libc", + "shlex", ] [[package]] @@ -846,9 +848,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.15" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d8838454fda655dafd3accb2b6e2bea645b9e4078abe84a22ceb947235c5cc" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ "clap_builder", "clap_derive", @@ -856,9 +858,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.15" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" dependencies = [ "anstream", "anstyle", @@ -875,14 +877,14 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "coins-bip32" @@ -938,9 +940,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "console" @@ -976,9 +978,9 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "constant_time_eq" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" [[package]] name = "convert_case" @@ -998,15 +1000,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -1140,7 +1142,7 @@ dependencies = [ "cpufeatures", "curve25519-dalek-derive", "fiat-crypto", - "rustc_version 0.4.0", + "rustc_version 0.4.1", "subtle", "zeroize", ] @@ -1153,14 +1155,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] name = "darling" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ "darling_core", "darling_macro", @@ -1168,27 +1170,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] name = "darling_macro" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -1231,8 +1233,8 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.0", - "syn 2.0.68", + "rustc_version 0.4.1", + "syn 2.0.77", ] [[package]] @@ -1264,9 +1266,9 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dunce" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "ecdsa" @@ -1284,9 +1286,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elf" @@ -1495,7 +1497,7 @@ dependencies = [ "regex", "serde", "serde_json", - "syn 2.0.68", + "syn 2.0.77", "toml", "walkdir", ] @@ -1513,7 +1515,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -1531,7 +1533,7 @@ dependencies = [ "ethabi", "generic-array", "k256", - "num_enum 0.7.2", + "num_enum 0.7.3", "once_cell", "open-fastrlp", "rand", @@ -1539,7 +1541,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.68", + "syn 2.0.77", "tempfile", "thiserror", "tiny-keccak", @@ -1639,9 +1641,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fastrlp" @@ -1799,7 +1801,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -1881,17 +1883,17 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "git2" -version = "0.18.3" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "libc", "libgit2-sys", "log", @@ -1951,7 +1953,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.2.6", + "indexmap 2.5.0", "slab", "tokio", "tokio-util", @@ -2029,6 +2031,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + [[package]] name = "hex" version = "0.4.3" @@ -2094,9 +2102,9 @@ dependencies = [ [[package]] name = "http-body" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", "http 1.1.0", @@ -2111,7 +2119,7 @@ dependencies = [ "bytes", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "pin-project-lite", ] @@ -2138,9 +2146,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.29" +version = "0.14.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" dependencies = [ "bytes", "futures-channel", @@ -2162,15 +2170,15 @@ dependencies = [ [[package]] name = "hyper" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "httparse", "httpdate", "itoa", @@ -2182,13 +2190,13 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.2" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", "http 1.1.0", - "hyper 1.3.1", + "hyper 1.4.1", "hyper-util", "rustls", "rustls-pki-types", @@ -2200,16 +2208,16 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.5" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ "bytes", "futures-channel", "futures-util", "http 1.1.0", - "http-body 1.0.0", - "hyper 1.3.1", + "http-body 1.0.1", + "hyper 1.4.1", "pin-project-lite", "socket2", "tokio", @@ -2314,9 +2322,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -2356,26 +2364,26 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" [[package]] name = "is-terminal" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" dependencies = [ - "hermit-abi", + "hermit-abi 0.4.0", "libc", "windows-sys 0.52.0", ] [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" @@ -2403,18 +2411,18 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -2472,9 +2480,9 @@ dependencies = [ [[package]] name = "keccak-asm" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47a3633291834c4fbebf8673acbc1b04ec9d151418ff9b8e26dcd79129928758" +checksum = "505d1856a39b200489082f90d897c3f07c455563880bc5952e38eabf731c83b6" dependencies = [ "digest 0.10.7", "sha3-asm", @@ -2497,15 +2505,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libgit2-sys" -version = "0.16.2+1.7.2" +version = "0.17.0+1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" dependencies = [ "cc", "libc", @@ -2515,12 +2523,12 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -2531,9 +2539,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libz-sys" -version = "1.1.18" +version = "1.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" +checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" dependencies = [ "cc", "libc", @@ -2604,20 +2612,20 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "adler", + "adler2", ] [[package]] name = "mio" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", "wasi", "windows-sys 0.52.0", @@ -2748,7 +2756,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", ] @@ -2763,11 +2771,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" dependencies = [ - "num_enum_derive 0.7.2", + "num_enum_derive 0.7.3", ] [[package]] @@ -2784,14 +2792,14 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -2811,9 +2819,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "object" -version = "0.36.0" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -2826,9 +2834,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" -version = "11.1.3" +version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "open-fastrlp" @@ -2864,7 +2872,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p3-air" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-field", "p3-matrix", @@ -2873,7 +2881,7 @@ dependencies = [ [[package]] name = "p3-baby-bear" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "num-bigint 0.4.6", "p3-field", @@ -2887,7 +2895,7 @@ dependencies = [ [[package]] name = "p3-blake3" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "blake3", "p3-symmetric", @@ -2896,7 +2904,7 @@ dependencies = [ [[package]] name = "p3-bn254-fr" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "ff 0.13.0", "num-bigint 0.4.6", @@ -2910,7 +2918,7 @@ dependencies = [ [[package]] name = "p3-challenger" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-field", "p3-maybe-rayon", @@ -2922,7 +2930,7 @@ dependencies = [ [[package]] name = "p3-commit" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-challenger", @@ -2935,7 +2943,7 @@ dependencies = [ [[package]] name = "p3-dft" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-field", "p3-matrix", @@ -2947,7 +2955,7 @@ dependencies = [ [[package]] name = "p3-field" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "num-bigint 0.4.6", @@ -2960,7 +2968,7 @@ dependencies = [ [[package]] name = "p3-fri" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-challenger", @@ -2978,7 +2986,7 @@ dependencies = [ [[package]] name = "p3-interpolation" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-field", "p3-matrix", @@ -2988,7 +2996,7 @@ dependencies = [ [[package]] name = "p3-keccak" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-symmetric", "tiny-keccak", @@ -2997,7 +3005,7 @@ dependencies = [ [[package]] name = "p3-keccak-air" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-air", "p3-field", @@ -3010,7 +3018,7 @@ dependencies = [ [[package]] name = "p3-matrix" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-field", @@ -3024,7 +3032,7 @@ dependencies = [ [[package]] name = "p3-maybe-rayon" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "rayon", ] @@ -3032,7 +3040,7 @@ dependencies = [ [[package]] name = "p3-mds" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-dft", @@ -3046,7 +3054,7 @@ dependencies = [ [[package]] name = "p3-merkle-tree" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-commit", @@ -3062,7 +3070,7 @@ dependencies = [ [[package]] name = "p3-poseidon2" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "gcd", "p3-field", @@ -3074,7 +3082,7 @@ dependencies = [ [[package]] name = "p3-symmetric" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-field", @@ -3084,7 +3092,7 @@ dependencies = [ [[package]] name = "p3-uni-stark" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-air", @@ -3102,7 +3110,7 @@ dependencies = [ [[package]] name = "p3-util" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "serde", ] @@ -3145,7 +3153,7 @@ version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 1.0.109", @@ -3246,9 +3254,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.10" +version = "2.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" dependencies = [ "memchr", "thiserror", @@ -3262,7 +3270,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" dependencies = [ "futures", - "rustc_version 0.4.0", + "rustc_version 0.4.1", ] [[package]] @@ -3282,7 +3290,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -3315,9 +3323,9 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "plotters" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ "num-traits", "plotters-backend", @@ -3328,24 +3336,24 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" [[package]] name = "plotters-svg" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" dependencies = [ "plotters-backend", ] [[package]] name = "portable-atomic" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" [[package]] name = "powerfmt" @@ -3355,18 +3363,21 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "prettyplease" -version = "0.2.20" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -3395,11 +3406,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml_edit 0.21.1", + "toml_edit 0.22.20", ] [[package]] @@ -3443,7 +3454,7 @@ checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.5.0", + "bitflags 2.6.0", "lazy_static", "num-traits", "rand", @@ -3472,10 +3483,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -3486,16 +3497,17 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quinn" -version = "0.11.2" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ceeeeabace7857413798eb1ffa1e9c905a9946a57d81fb69b4b71c4d8eb3ad" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" dependencies = [ "bytes", "pin-project-lite", "quinn-proto", "quinn-udp", - "rustc-hash", + "rustc-hash 2.0.0", "rustls", + "socket2", "thiserror", "tokio", "tracing", @@ -3503,14 +3515,14 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.3" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddf517c03a109db8100448a4be38d498df8a210a99fe0e1b9eaf39e78c640efe" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand", "ring 0.17.8", - "rustc-hash", + "rustc-hash 2.0.0", "rustls", "slab", "thiserror", @@ -3520,22 +3532,22 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.2" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9096629c45860fc7fb143e125eb826b5e721e10be3263160c7d60ca832cf8c46" +checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" dependencies = [ "libc", "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -3616,18 +3628,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -3681,7 +3693,7 @@ dependencies = [ "h2", "http 0.2.12", "http-body 0.4.6", - "hyper 0.14.29", + "hyper 0.14.30", "ipnet", "js-sys", "log", @@ -3700,23 +3712,23 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg 0.50.0", + "winreg", ] [[package]] name = "reqwest" -version = "0.12.5" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64 0.22.1", "bytes", "futures-core", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body 1.0.1", "http-body-util", - "hyper 1.3.1", + "hyper 1.4.1", "hyper-rustls", "hyper-util", "ipnet", @@ -3744,7 +3756,7 @@ dependencies = [ "wasm-streams", "web-sys", "webpki-roots", - "winreg 0.52.0", + "windows-registry", ] [[package]] @@ -3756,7 +3768,7 @@ dependencies = [ "anyhow", "async-trait", "http 1.1.0", - "reqwest 0.12.5", + "reqwest 0.12.7", "serde", "thiserror", "tower-service", @@ -3885,6 +3897,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -3902,20 +3920,20 @@ dependencies = [ [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver 1.0.23", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -3924,9 +3942,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", "ring 0.17.8", @@ -3938,9 +3956,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ "base64 0.22.1", "rustls-pki-types", @@ -3948,15 +3966,15 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" -version = "0.102.6" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring 0.17.8", "rustls-pki-types", @@ -4023,7 +4041,7 @@ version = "2.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 1.0.109", @@ -4031,9 +4049,9 @@ dependencies = [ [[package]] name = "scc" -version = "2.1.1" +version = "2.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ad2bbb0ae5100a07b7a6f2ed7ab5fd0045551a4c507989b7a620046ea3efdc" +checksum = "0c947adb109a8afce5fc9c7bf951f87f146e9147b3a6a58413105628fb1d1e66" dependencies = [ "sdd", ] @@ -4058,9 +4076,9 @@ dependencies = [ [[package]] name = "sdd" -version = "0.2.0" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84345e4c9bd703274a082fb80caaa99b7612be48dfaa1dd9266577ec412309d" +checksum = "60a7b59a5d9b0099720b417b6325d91a52cbf5b3dcb5041d864be53eefa58abc" [[package]] name = "sec1" @@ -4117,29 +4135,29 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.207" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.207" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.124" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -4159,9 +4177,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -4188,7 +4206,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.2.6", + "indexmap 2.5.0", "serde", "serde_derive", "serde_json", @@ -4205,7 +4223,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -4230,7 +4248,7 @@ checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -4266,9 +4284,9 @@ dependencies = [ [[package]] name = "sha3-asm" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9b57fd861253bff08bb1919e995f90ba8f4889de2726091c8876f3a4e823b40" +checksum = "c28efc5e327c837aa837c59eae585fc250715ef939ac32881bcc11677cd02d46" dependencies = [ "cc", "cfg-if", @@ -4364,7 +4382,7 @@ dependencies = [ "home", "indicatif", "rand", - "reqwest 0.12.5", + "reqwest 0.12.7", "serde", "serde_json", "sphinx-core", @@ -4482,6 +4500,20 @@ dependencies = [ "serde", ] +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +source = "git+https://github.com/argumentcomputer/sphinx?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + [[package]] name = "sphinx-primitives" version = "1.0.0" @@ -4514,7 +4546,7 @@ dependencies = [ "p3-commit", "p3-field", "rayon", - "reqwest 0.12.5", + "reqwest 0.12.7", "serde", "serde_json", "serial_test", @@ -4712,7 +4744,7 @@ dependencies = [ "p3-fri", "p3-matrix", "prost", - "reqwest 0.12.5", + "reqwest 0.12.7", "reqwest-middleware", "serde", "serde_json", @@ -4744,7 +4776,7 @@ dependencies = [ "p3-field", "rand", "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "sphinx-precompiles 1.0.0", "sphinx-primitives", ] @@ -4801,14 +4833,14 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] name = "subtle" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0208408ba0c3df17ed26eb06992cb1a1268d41b2c0e12e65203fbe3972cee5" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "subtle-encoding" @@ -4832,9 +4864,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -4850,7 +4882,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -4864,6 +4896,9 @@ name = "sync_wrapper" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] [[package]] name = "system-configuration" @@ -4928,7 +4963,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -4995,9 +5030,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -5010,9 +5045,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.39.2" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", @@ -5034,7 +5069,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -5050,9 +5085,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -5063,21 +5098,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.14" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.14", + "toml_edit 0.22.20", ] [[package]] name = "toml_datetime" -version = "0.6.6" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] @@ -5088,33 +5123,22 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.5.0", "toml_datetime", "winnow 0.5.40", ] [[package]] name = "toml_edit" -version = "0.21.1" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ - "indexmap 2.2.6", - "toml_datetime", - "winnow 0.5.40", -] - -[[package]] -name = "toml_edit" -version = "0.22.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" -dependencies = [ - "indexmap 2.2.6", + "indexmap 2.5.0", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.13", + "winnow 0.6.18", ] [[package]] @@ -5135,15 +5159,15 @@ dependencies = [ [[package]] name = "tower-layer" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" @@ -5165,7 +5189,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -5262,9 +5286,9 @@ dependencies = [ "futures", "http 1.1.0", "http-body-util", - "hyper 1.3.1", + "hyper 1.4.1", "prost", - "reqwest 0.12.5", + "reqwest 0.12.7", "serde", "serde_json", "thiserror", @@ -5311,9 +5335,9 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" @@ -5332,9 +5356,9 @@ checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "unicode-xid" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" [[package]] name = "untrusted" @@ -5389,9 +5413,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vergen" -version = "8.3.1" +version = "8.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" +checksum = "2990d9ea5967266ea0ccf413a4aa5c42a93dbcfda9cb49a97de6931726b12566" dependencies = [ "anyhow", "cfg-if", @@ -5402,9 +5426,9 @@ dependencies = [ [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wait-timeout" @@ -5442,34 +5466,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if", "js-sys", @@ -5479,9 +5504,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5489,22 +5514,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasm-streams" @@ -5521,9 +5546,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ "js-sys", "wasm-bindgen", @@ -5541,9 +5566,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.3" +version = "0.26.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" dependencies = [ "rustls-pki-types", ] @@ -5578,11 +5603,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5600,6 +5625,36 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -5759,9 +5814,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.13" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] @@ -5776,16 +5831,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "ws_stream_wasm" version = "0.7.4" @@ -5797,7 +5842,7 @@ dependencies = [ "js-sys", "log", "pharos", - "rustc_version 0.4.0", + "rustc_version 0.4.1", "send_wrapper 0.6.0", "thiserror", "wasm-bindgen", @@ -5822,22 +5867,23 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] @@ -5857,7 +5903,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.77", ] [[package]] diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 50ace6dd2..4f177f8eb 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -10,7 +10,10 @@ use super::{program::Program, Opcode}; use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; -use crate::syscall::precompiles::blake2s::{Blake2sXorRotateRightChip, Blake2sXorRotateRightEvent}; +use crate::syscall::precompiles::blake2s::{ + Blake2sXorRotate16Chip, Blake2sXorRotate16Event, Blake2sXorRotateRightChip, + Blake2sXorRotateRightEvent, +}; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; use crate::syscall::precompiles::sha256::{ShaCompressEvent, ShaExtendEvent}; @@ -127,6 +130,7 @@ pub struct ExecutionRecord { pub bls12381_g2_double_events: Vec, pub blake2s_xor_rotate_right_events: Vec, + pub blake2s_xor_rotate_16_events: Vec, pub memory_initialize_events: Vec, @@ -327,6 +331,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_xor_rotate_16_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -478,6 +488,11 @@ impl MachineRecord for ExecutionRecord { "blake2s_xor_rotate_right_events".to_string(), self.blake2s_xor_rotate_right_events.len(), ); + stats.insert( + "blake2s_xor_rotate_16_events".to_string(), + self.blake2s_xor_rotate_16_events.len(), + ); + stats } @@ -525,6 +540,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.bls12381_g2_double_events); self.blake2s_xor_rotate_right_events .append(&mut other.blake2s_xor_rotate_right_events); + self.blake2s_xor_rotate_16_events + .append(&mut other.blake2s_xor_rotate_16_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -858,6 +875,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_xor_rotate_16 events + first.blake2s_xor_rotate_16_events = take(&mut self.blake2s_xor_rotate_16_events); + for (i, event) in first.blake2s_xor_rotate_16_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 2f2372564..5127148e5 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -6,7 +6,7 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; -use crate::syscall::precompiles::blake2s::Blake2sXorRotateRightChip; +use crate::syscall::precompiles::blake2s::{Blake2sXorRotate16Chip, Blake2sXorRotateRightChip}; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; use crate::syscall::precompiles::bls12_381::g2_double::Bls12381G2AffineDoubleChip; @@ -119,6 +119,8 @@ pub enum SyscallCode { HINT_READ = 0x00_00_00_F1, BLAKE_2S_XOR_ROTATE_RIGHT = 0x00_01_01_CC, + + BLAKE_2S_XOR_ROTATE_16 = 0x00_30_01_CD, } impl SyscallCode { @@ -156,6 +158,7 @@ impl SyscallCode { 0x00_01_01_80 => SyscallCode::BLS12381_G2_ADD, 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, + 0x00_30_01_CD => SyscallCode::BLAKE_2S_XOR_ROTATE_16, _ => panic!("invalid syscall number: {}", value), } } @@ -399,6 +402,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sXorRotateRightChip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_XOR_ROTATE_16, + Arc::new(Blake2sXorRotate16Chip::new()), + ); + syscall_map } @@ -519,6 +527,10 @@ mod tests { sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT ) } + + SyscallCode::BLAKE_2S_XOR_ROTATE_16 => { + assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_16) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 835709f3f..a3e9b272c 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -3,7 +3,7 @@ pub use crate::air::SphinxAirBuilder; use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; -use crate::syscall::precompiles::blake2s::Blake2sXorRotateRightChip; +use crate::syscall::precompiles::blake2s::{Blake2sXorRotate16Chip, Blake2sXorRotateRightChip}; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; use crate::syscall::precompiles::quad_field::QuadFieldChip; @@ -109,6 +109,7 @@ pub enum RiscvAir { Bls12381G1Decompress(Bls12381G1DecompressChip), Blake2sXorRotateRight(Blake2sXorRotateRightChip), + Blake2sXorRotate16(Blake2sXorRotate16Chip), } impl RiscvAir { @@ -188,6 +189,9 @@ impl RiscvAir { let blake_2s_xor_rotate_right = Blake2sXorRotateRightChip::default(); chips.push(RiscvAir::Blake2sXorRotateRight(blake_2s_xor_rotate_right)); + let blake_2s_xor_rotate_16 = Blake2sXorRotate16Chip::default(); + chips.push(RiscvAir::Blake2sXorRotate16(blake_2s_xor_rotate_16)); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index beac20a1c..2ceaa8ac7 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,3 +1,7 @@ +mod xor_rotate_16; + +pub use xor_rotate_16::*; + use crate::bytes::event::ByteRecord; use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; use crate::operations::{FixedRotateRightOperation, XorOperation}; @@ -40,7 +44,6 @@ pub struct Blake2sXorRotateRightEvent { pub channel: u32, pub a_ptr: u32, pub b_ptr: u32, - pub rot: u32, pub a_reads_writes: Vec, pub b_reads: Vec, } @@ -56,10 +59,7 @@ impl Syscall for Blake2sXorRotateRightChip { let b_ptr = arg2; let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, mut b) = ctx.mr_slice(b_ptr, 5); - - let rot = b[4].clone(); - b.truncate(4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 4); let xor = a .into_iter() @@ -69,7 +69,7 @@ impl Syscall for Blake2sXorRotateRightChip { let rotate_right = xor .into_iter() - .map(|xor_i| xor_i.rotate_right(rot)) + .map(|xor_i| xor_i.rotate_right(R_1)) .collect::>(); ctx.clk += 1; @@ -86,7 +86,6 @@ impl Syscall for Blake2sXorRotateRightChip { channel, a_ptr, b_ptr, - rot, a_reads_writes, b_reads, }); @@ -112,7 +111,7 @@ struct Blake2sXorRotateRightCols { pub b_ptr: T, pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 5], // includes rotation constant + pub b: [MemoryReadCols; 4], pub xor: [XorOperation; 4], pub rotate_right: [FixedRotateRightOperation; 4], @@ -156,10 +155,6 @@ impl MachineAir for Blake2sXorRotateRightChip { cols.a_ptr = F::from_canonical_u32(event.a_ptr); cols.b_ptr = F::from_canonical_u32(event.b_ptr); - cols.b[4].populate(event.channel, event.b_reads[4], &mut new_byte_lookup_events); // handle rotation_constant - - let rot = event.b_reads[4].value; - for i in 0..4usize { cols.a[i].populate( event.channel, @@ -172,11 +167,11 @@ impl MachineAir for Blake2sXorRotateRightChip { let a = event.a_reads_writes[i].value; let b = event.b_reads[i].value; let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - //assert_eq!(a ^ b, xor); + assert_eq!(a ^ b, xor); - let _rotate_right = - cols.rotate_right[i].populate(output, shard, event.channel, xor, rot as usize); - //assert_eq!(xor.rotate_right(rot), rotate_right); + let rotate_right = + cols.rotate_right[i].populate(output, shard, event.channel, xor, R_1 as usize); + assert_eq!(xor.rotate_right(R_1), rotate_right); } rows.push(row); @@ -225,20 +220,6 @@ where .when_transition() .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - // Eval rotation_constant (included as 4th word in b_ptr). - let i = 4usize; - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // TODO: get rotation constant from memory somehow - //let _rot = *local.b[4].value(); - for i in 0..4usize { // Eval a builder.eval_memory_access( @@ -275,7 +256,7 @@ where FixedRotateRightOperation::::eval( builder, local.xor[i].value, - R_1 as usize, // TODO use value from memory instead ! + R_1 as usize, local.rotate_right[i], local.shard, &local.channel, @@ -299,12 +280,11 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::syscall::precompiles::blake2s::R_1; use crate::utils::tests::BLAKE2S_XOR_RIGHT_ROTATE_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 5]) -> Program { + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { let mut instructions = vec![]; // memory write a for (index, word) in a.into_iter().enumerate() { @@ -359,7 +339,7 @@ mod tests { a_ptr, b_ptr, [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, R_1], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], ); let (_, memory) = run_test_with_memory_inspection(program); diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs new file mode 100644 index 000000000..3ddd0f4f7 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs @@ -0,0 +1,291 @@ +use core::borrow::Borrow; + +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::AbstractField; +use p3_matrix::Matrix; + +use super::{Blake2sXorRotate16Chip, Blake2sXorRotate16Cols, NUM_BLAKE2S_XOR_ROTATE_16_COLS}; +use crate::{ + air::{AluAirBuilder, BaseAirBuilder, MemoryAirBuilder, WordAirBuilder}, + memory::MemoryCols, + operations::{FixedRotateRightOperation, XorOperation}, + runtime::SyscallCode, +}; + +impl BaseAir for Blake2sXorRotate16Chip { + fn width(&self) -> usize { + NUM_BLAKE2S_XOR_ROTATE_16_COLS + } +} + +impl Air for Blake2sXorRotate16Chip +where + AB: MemoryAirBuilder + AluAirBuilder + WordAirBuilder, +{ + fn eval(&self, builder: &mut AB) { + // Initialize columns. + let main = builder.main(); + let (local, next) = (main.row_slice(0), main.row_slice(1)); + let local: &Blake2sXorRotate16Cols = (*local).borrow(); + let next: &Blake2sXorRotate16Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + let i_start = AB::F::from_canonical_u32(16); + + // Evaluate the control flags. + self.eval_flags(builder); + + // Copy over the inputs until the result has been computed (every 48 rows). + builder + .when_transition() + .when_not(local.cycle_16_end.result * local.cycle_48[2]) + .assert_eq(local.shard, next.shard); + builder + .when_transition() + .when_not(local.cycle_16_end.result * local.cycle_48[2]) + .assert_eq(local.clk, next.clk); + builder + .when_transition() + .when_not(local.cycle_16_end.result * local.cycle_48[2]) + .assert_eq(local.channel, next.channel); + builder + .when_transition() + .when_not(local.cycle_16_end.result * local.cycle_48[2]) + .assert_eq(local.w_ptr, next.w_ptr); + + // Read w[0]. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(0), + &local.w_0, + local.is_real, + ); + + // Read w[1] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(4), + &local.w_1, + local.is_real, + ); + + // Read w[2] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(8), + &local.w_2, + local.is_real, + ); + + // Read w[3] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(12), + &local.w_3, + local.is_real, + ); + + // Read w[4] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(16), + &local.w_4, + local.is_real, + ); + + // Read w[5] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(20), + &local.w_5, + local.is_real, + ); + + // Read w[6] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(24), + &local.w_6, + local.is_real, + ); + + // Read w[7] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(28), + &local.w_7, + local.is_real, + ); + + XorOperation::::eval( + builder, + *local.w_0.value(), + *local.w_4.value(), + local.xor_0, + local.shard, + &local.channel, + local.is_real, + ); + + FixedRotateRightOperation::::eval( + builder, + local.xor_0.value, + 16, + local.rot_0, + local.shard, + &local.channel, + local.is_real, + ); + + XorOperation::::eval( + builder, + *local.w_1.value(), + *local.w_5.value(), + local.xor_1, + local.shard, + &local.channel, + local.is_real, + ); + + FixedRotateRightOperation::::eval( + builder, + local.xor_1.value, + 16, + local.rot_1, + local.shard, + &local.channel, + local.is_real, + ); + + XorOperation::::eval( + builder, + *local.w_2.value(), + *local.w_6.value(), + local.xor_2, + local.shard, + &local.channel, + local.is_real, + ); + + FixedRotateRightOperation::::eval( + builder, + local.xor_2.value, + 16, + local.rot_2, + local.shard, + &local.channel, + local.is_real, + ); + + XorOperation::::eval( + builder, + *local.w_3.value(), + *local.w_7.value(), + local.xor_3, + local.shard, + &local.channel, + local.is_real, + ); + + FixedRotateRightOperation::::eval( + builder, + local.xor_3.value, + 16, + local.rot_3, + local.shard, + &local.channel, + local.is_real, + ); + + // Write w[16] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(64), + &local.w_16, + local.is_real, + ); + + // Write w[17] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(68), + &local.w_17, + local.is_real, + ); + + // Write w[18] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(72), + &local.w_18, + local.is_real, + ); + + // Write w[19] + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + (local.i - i_start), + local.w_ptr + AB::F::from_canonical_u32(76), + &local.w_19, + local.is_real, + ); + + builder.assert_word_eq(*local.w_16.value(), local.rot_0.value); + builder.assert_word_eq(*local.w_17.value(), local.rot_1.value); + builder.assert_word_eq(*local.w_18.value(), local.rot_2.value); + builder.assert_word_eq(*local.w_19.value(), local.rot_3.value); + + // Receive syscall event in first row of 48-cycle. + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_16.syscall_id()), + local.w_ptr, + AB::Expr::zero(), + local.cycle_48_start, + ); + + // Assert that is_real is a bool. + builder.assert_bool(local.is_real); + + // Ensure that all rows in a 48 row cycle has the same `is_real` values. + builder + .when_transition() + .when_not(local.cycle_48_end) + .assert_eq(local.is_real, next.is_real); + + // Assert that the table ends in nonreal columns. Since each extend ecall is 48 cycles and + // the table is padded to a power of 2, the last row of the table should always be padding. + builder.when_last_row().assert_zero(local.is_real); + } +} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs new file mode 100644 index 000000000..06fc34153 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs @@ -0,0 +1,71 @@ +use std::mem::size_of; + +use sphinx_derive::AlignedBorrow; + +use crate::{ + memory::{MemoryReadCols, MemoryWriteCols}, + operations::{FixedRotateRightOperation, IsZeroOperation, XorOperation}, +}; + +pub const NUM_BLAKE2S_XOR_ROTATE_16_COLS: usize = size_of::>(); + +#[derive(AlignedBorrow, Default, Debug, Clone, Copy)] +#[repr(C)] +pub struct Blake2sXorRotate16Cols { + /// Inputs. + pub shard: T, + pub channel: T, + pub nonce: T, + pub clk: T, + pub w_ptr: T, + + /// Control flags. + pub i: T, + + /// g^n where g is generator with order 16 and n is the row number. + pub cycle_16: T, + + /// Checks whether current row is start of a 16-row cycle. Bool result is stored in `result`. + pub cycle_16_start: IsZeroOperation, + + /// Checks whether current row is end of a 16-row cycle. Bool result is stored in `result`. + pub cycle_16_end: IsZeroOperation, + + /// Flags for when in the first, second, or third 16-row cycle. + pub cycle_48: [T; 3], + + /// Whether the current row is the first of a 48-row cycle and is real. + pub cycle_48_start: T, + /// Whether the current row is the end of a 48-row cycle and is real. + pub cycle_48_end: T, + + /// Inputs + pub w_0: MemoryReadCols, + pub w_1: MemoryReadCols, + pub w_2: MemoryReadCols, + pub w_3: MemoryReadCols, + pub w_4: MemoryReadCols, + pub w_5: MemoryReadCols, + pub w_6: MemoryReadCols, + pub w_7: MemoryReadCols, + + /// Operations + pub xor_0: XorOperation, + pub xor_1: XorOperation, + pub xor_2: XorOperation, + pub xor_3: XorOperation, + + pub rot_0: FixedRotateRightOperation, + pub rot_1: FixedRotateRightOperation, + pub rot_2: FixedRotateRightOperation, + pub rot_3: FixedRotateRightOperation, + + /// Result + pub w_16: MemoryWriteCols, + pub w_17: MemoryWriteCols, + pub w_18: MemoryWriteCols, + pub w_19: MemoryWriteCols, + + /// Selector. + pub is_real: T, +} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs new file mode 100644 index 000000000..8a890b9e6 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs @@ -0,0 +1,101 @@ +use super::Blake2sXorRotate16Chip; +use crate::{ + runtime::Syscall, + syscall::precompiles::{blake2s::Blake2sXorRotate16Event, SyscallContext}, +}; + +impl Syscall for Blake2sXorRotate16Chip { + fn num_extra_cycles(&self) -> u32 { + 48 + } + + fn execute(&self, rt: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = rt.clk; + let w_ptr = arg1; + assert!(arg2 == 0, "arg2 must be 0"); + + let w_ptr_init = w_ptr; + let mut w_0_reads = Vec::new(); + let mut w_1_reads = Vec::new(); + let mut w_2_reads = Vec::new(); + let mut w_3_reads = Vec::new(); + + let mut w_4_reads = Vec::new(); + let mut w_5_reads = Vec::new(); + let mut w_6_reads = Vec::new(); + let mut w_7_reads = Vec::new(); + + let mut w_16_writes = Vec::new(); + let mut w_17_writes = Vec::new(); + let mut w_18_writes = Vec::new(); + let mut w_19_writes = Vec::new(); + + for _ in 16..64 { + // read + let (record, w_0) = rt.mr(w_ptr); + w_0_reads.push(record); + + let (record, w_1) = rt.mr(w_ptr + 4); + w_1_reads.push(record); + + let (record, w_2) = rt.mr(w_ptr + 8); + w_2_reads.push(record); + + let (record, w_3) = rt.mr(w_ptr + 12); + w_3_reads.push(record); + + let (record, w_4) = rt.mr(w_ptr + 16); + w_4_reads.push(record); + + let (record, w_5) = rt.mr(w_ptr + 20); + w_5_reads.push(record); + + let (record, w_6) = rt.mr(w_ptr + 24); + w_6_reads.push(record); + + let (record, w_7) = rt.mr(w_ptr + 28); + w_7_reads.push(record); + + // compute + let w_16 = (w_0 ^ w_4).rotate_right(16); + let w_17 = (w_1 ^ w_5).rotate_right(16); + let w_18 = (w_2 ^ w_6).rotate_right(16); + let w_19 = (w_3 ^ w_7).rotate_right(16); + + // write + w_16_writes.push(rt.mw(w_ptr + 64, w_16)); + w_17_writes.push(rt.mw(w_ptr + 68, w_17)); + w_18_writes.push(rt.mw(w_ptr + 72, w_18)); + w_19_writes.push(rt.mw(w_ptr + 76, w_19)); + rt.clk += 1; + } + + // Push the Blake2sXorRotate16Event event. + let lookup_id = rt.syscall_lookup_id; + let shard = rt.current_shard(); + let channel = rt.current_channel(); + rt.record_mut() + .blake2s_xor_rotate_16_events + .push(Blake2sXorRotate16Event { + lookup_id, + shard, + channel, + clk: clk_init, + w_ptr: w_ptr_init, + w_0_reads, + w_1_reads, + w_2_reads, + w_3_reads, + w_4_reads, + w_5_reads, + w_6_reads, + w_7_reads, + w_16_writes, + w_17_writes, + w_18_writes, + w_19_writes, + }); + + None + } +} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs new file mode 100644 index 000000000..2f705b9f2 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs @@ -0,0 +1,130 @@ +use core::borrow::Borrow; + +use p3_air::AirBuilder; +use p3_baby_bear::BabyBear; +use p3_field::{AbstractField, Field, PrimeField32, TwoAdicField}; +use p3_matrix::Matrix; + +use crate::air::BaseAirBuilder; +use crate::operations::IsZeroOperation; + +use super::Blake2sXorRotate16Chip; +use super::Blake2sXorRotate16Cols; + +impl Blake2sXorRotate16Cols { + pub fn populate_flags(&mut self, i: usize) { + // The generator of the multiplicative subgroup. + let g = F::from_canonical_u32(BabyBear::two_adic_generator(4).as_canonical_u32()); + + // Populate the columns needed to keep track of cycles of 16 rows. + self.cycle_16 = g.exp_u64((i + 1) as u64); + + // Populate the columns needed to track the start of a cycle of 16 rows. + self.cycle_16_start + .populate_from_field_element(self.cycle_16 - g); + + // Populate the columns needed to track the end of a cycle of 16 rows. + self.cycle_16_end + .populate_from_field_element(self.cycle_16 - F::one()); + + // Populate the columns needed to keep track of cycles of 48 rows. + let j = 16 + (i % 48); + self.i = F::from_canonical_usize(j); + self.cycle_48[0] = F::from_bool((16..32).contains(&j)); + self.cycle_48[1] = F::from_bool((32..48).contains(&j)); + self.cycle_48[2] = F::from_bool((48..64).contains(&j)); + self.cycle_48_start = self.cycle_48[0] * self.cycle_16_start.result * self.is_real; + self.cycle_48_end = self.cycle_48[2] * self.cycle_16_end.result * self.is_real; + } +} + +impl Blake2sXorRotate16Chip { + pub fn eval_flags(&self, builder: &mut AB) { + let main = builder.main(); + let (local, next) = (main.row_slice(0), main.row_slice(1)); + let local: &Blake2sXorRotate16Cols = (*local).borrow(); + let next: &Blake2sXorRotate16Cols = (*next).borrow(); + + let one = AB::Expr::from(AB::F::one()); + + // Generator with order 16 within BabyBear. + let g = AB::F::from_canonical_u32(BabyBear::two_adic_generator(4).as_canonical_u32()); + + // First row of the table must have g^1. + builder.when_first_row().assert_eq(local.cycle_16, g); + + // First row of the table must have i = 16. + builder + .when_first_row() + .assert_eq(local.i, AB::F::from_canonical_u32(16)); + + // Every row's `cycle_16` must be previous multiplied by `g`. + builder + .when_transition() + .assert_eq(local.cycle_16 * g, next.cycle_16); + + // Constrain `cycle_16_start.result` to be `cycle_16 - g == 0`. + IsZeroOperation::::eval( + builder, + local.cycle_16 - AB::Expr::from(g), + local.cycle_16_start, + one.clone(), + ); + + // Constrain `cycle_16_end.result` to be `cycle_16 - 1 == 0`. Intuitively g^16 is 1. + IsZeroOperation::::eval( + builder, + local.cycle_16 - AB::Expr::one(), + local.cycle_16_end, + one.clone(), + ); + + // Constrain `cycle_48` to be [1, 0, 0] in the first row. + builder + .when_first_row() + .assert_eq(local.cycle_48[0], AB::F::one()); + builder + .when_first_row() + .assert_eq(local.cycle_48[1], AB::F::zero()); + builder + .when_first_row() + .assert_eq(local.cycle_48[2], AB::F::zero()); + + // Shift the indices of `cycles_48` at the end of each 16 rows. Otherwise, keep them the same. + for i in 0..3 { + builder + .when_transition() + .when(local.cycle_16_end.result) + .assert_eq(local.cycle_48[i], next.cycle_48[(i + 1) % 3]); + builder + .when_transition() + .when(one.clone() - local.cycle_16_end.result) + .assert_eq(local.cycle_48[i], next.cycle_48[i]); + builder.assert_bool(local.cycle_48[i]); + } + + // cycle_48_start == start of 16-cycle AND first 16-cycle within 48-cycle AND is_real. + builder.assert_eq( + local.cycle_16_start.result * local.cycle_48[0] * local.is_real, + local.cycle_48_start, + ); + + // cycle_48_end == end of 16-cycle AND last 16-cycle within 48-cycle AND is_real. + builder.assert_eq( + local.cycle_16_end.result * local.cycle_48[2] * local.is_real, + local.cycle_48_end, + ); + + // When it's the end of a 48-cycle, the next `i` must be 16. + builder + .when_transition() + .when(local.cycle_16_end.result * local.cycle_48[2]) + .assert_eq(next.i, AB::F::from_canonical_u32(16)); + + // When it's not the end of a 48-cycle, the next `i` must be the current plus one. + builder + .when_transition() + .when_not(local.cycle_16_end.result * local.cycle_48[2]) + .assert_eq(local.i + one.clone(), next.i); + } +} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs new file mode 100644 index 000000000..913777829 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs @@ -0,0 +1,116 @@ +mod air; +mod columns; +mod execute; +mod flags; +mod trace; + +pub use columns::*; +use serde::{Deserialize, Serialize}; + +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sXorRotate16Event { + pub lookup_id: usize, + pub shard: u32, + pub channel: u32, + pub clk: u32, + pub w_ptr: u32, + + pub w_0_reads: Vec, + pub w_1_reads: Vec, + pub w_2_reads: Vec, + pub w_3_reads: Vec, + pub w_4_reads: Vec, + pub w_5_reads: Vec, + pub w_6_reads: Vec, + pub w_7_reads: Vec, + + pub w_16_writes: Vec, + pub w_17_writes: Vec, + pub w_18_writes: Vec, + pub w_19_writes: Vec, +} + +#[derive(Default)] +pub struct Blake2sXorRotate16Chip; + +impl Blake2sXorRotate16Chip { + pub const fn new() -> Self { + Self {} + } +} + +#[cfg(test)] +pub mod blake2s_xor_rotate_tests { + use crate::utils::run_test; + use crate::utils::tests::BLAKE2S_XOR_RIGHT_16_ELF; + use crate::{ + runtime::{Instruction, Opcode, Program, SyscallCode}, + utils::{self, run_test_with_memory_inspection}, + }; + + pub fn blake2s_xor_rotate_16_program() -> Program { + let w_ptr = 100u32; + let mut words = [0u32; 64]; + words[0] = 0x6b08e647; + words[1] = 0xbb67ae85; + words[2] = 0x3c6ef372; + words[3] = 0xa54ff53a; + + words[4] = 0x510e527f; + words[5] = 0x9b05688c; + words[6] = 0x1f83d9ab; + words[7] = 0x5be0cd19; + + let mut instructions = vec![]; + for (i, word) in words.into_iter().enumerate() { + instructions.extend(vec![ + Instruction::new(Opcode::ADD, 29, 0, word, false, true), + Instruction::new(Opcode::ADD, 30, 0, w_ptr + (i * 4) as u32, false, true), + Instruction::new(Opcode::SW, 29, 30, 0, false, true), + ]); + } + instructions.extend(vec![ + Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_XOR_ROTATE_16 as u32, + false, + true, + ), + Instruction::new(Opcode::ADD, 10, 0, w_ptr, false, true), + Instruction::new(Opcode::ADD, 11, 0, 0, false, true), + Instruction::new(Opcode::ECALL, 5, 10, 11, false, false), + ]); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_xor_rotate_16_prove() { + utils::setup_logger(); + let program = blake2s_xor_rotate_16_program(); + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + for i in 0..64 { + result.push(memory.get(&(100 + i * 4)).unwrap().value); + } + assert_eq!( + result, + vec![ + 0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, + 0x5be0cd19, 0, 0, 0, 0, 0, 0, 0, 0, 0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ] + ); + } + + #[test] + fn test_blake2s_xor_rotate_16_program() { + utils::setup_logger(); + let program = Program::from(BLAKE2S_XOR_RIGHT_16_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs new file mode 100644 index 000000000..a69762463 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs @@ -0,0 +1,178 @@ +use p3_field::PrimeField32; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use std::borrow::BorrowMut; + +use super::{ + Blake2sXorRotate16Chip, Blake2sXorRotate16Cols, Blake2sXorRotate16Event, + NUM_BLAKE2S_XOR_ROTATE_16_COLS, +}; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + bytes::event::ByteRecord, + runtime::{ExecutionRecord, Program}, +}; + +impl<'a> WithEvents<'a> for Blake2sXorRotate16Chip { + type Events = &'a [Blake2sXorRotate16Event]; +} + +impl MachineAir for Blake2sXorRotate16Chip { + type Record = ExecutionRecord; + + type Program = Program; + + fn name(&self) -> String { + "Blake2sXorRotate16".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut ExecutionRecord, + ) -> RowMajorMatrix { + let mut rows = Vec::new(); + + let mut new_byte_lookup_events = Vec::new(); + for i in 0..input.events().len() { + let event = input.events()[i].clone(); + let shard = event.shard; + for j in 0..48usize { + let mut row = [F::zero(); NUM_BLAKE2S_XOR_ROTATE_16_COLS]; + let cols: &mut Blake2sXorRotate16Cols = row.as_mut_slice().borrow_mut(); + cols.is_real = F::one(); + cols.populate_flags(j); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.clk = F::from_canonical_u32(event.clk); + cols.w_ptr = F::from_canonical_u32(event.w_ptr); + + cols.w_0.populate( + event.channel, + event.w_0_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_1.populate( + event.channel, + event.w_1_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_2.populate( + event.channel, + event.w_2_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_3.populate( + event.channel, + event.w_3_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_4.populate( + event.channel, + event.w_4_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_5.populate( + event.channel, + event.w_5_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_6.populate( + event.channel, + event.w_6_reads[j], + &mut new_byte_lookup_events, + ); + cols.w_7.populate( + event.channel, + event.w_7_reads[j], + &mut new_byte_lookup_events, + ); + + let w_0 = event.w_0_reads[j].value; + let w_1 = event.w_1_reads[j].value; + let w_2 = event.w_2_reads[j].value; + let w_3 = event.w_3_reads[j].value; + let w_4 = event.w_4_reads[j].value; + let w_5 = event.w_5_reads[j].value; + let w_6 = event.w_6_reads[j].value; + let w_7 = event.w_7_reads[j].value; + + let xor_0 = cols.xor_0.populate(output, shard, event.channel, w_0, w_4); + + cols.rot_0.populate(output, shard, event.channel, xor_0, 16); + + let xor_1 = cols.xor_1.populate(output, shard, event.channel, w_1, w_5); + + cols.rot_1.populate(output, shard, event.channel, xor_1, 16); + + let xor_2 = cols.xor_2.populate(output, shard, event.channel, w_2, w_6); + + cols.rot_2.populate(output, shard, event.channel, xor_2, 16); + + let xor_3 = cols.xor_3.populate(output, shard, event.channel, w_3, w_7); + + cols.rot_3.populate(output, shard, event.channel, xor_3, 16); + + cols.w_16.populate( + event.channel, + event.w_16_writes[j], + &mut new_byte_lookup_events, + ); + + cols.w_17.populate( + event.channel, + event.w_17_writes[j], + &mut new_byte_lookup_events, + ); + + cols.w_18.populate( + event.channel, + event.w_18_writes[j], + &mut new_byte_lookup_events, + ); + + cols.w_19.populate( + event.channel, + event.w_19_writes[j], + &mut new_byte_lookup_events, + ); + + rows.push(row); + } + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + let nb_rows = rows.len(); + let mut padded_nb_rows = nb_rows.next_power_of_two(); + if padded_nb_rows == 2 || padded_nb_rows == 1 { + padded_nb_rows = 4; + } + for i in nb_rows..padded_nb_rows { + let mut row = [F::zero(); NUM_BLAKE2S_XOR_ROTATE_16_COLS]; + let cols: &mut Blake2sXorRotate16Cols = row.as_mut_slice().borrow_mut(); + cols.populate_flags(i); + rows.push(row); + } + + // Convert the trace to a row major matrix. + let mut trace = RowMajorMatrix::new( + rows.into_iter().flatten().collect::>(), + NUM_BLAKE2S_XOR_ROTATE_16_COLS, + ); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sXorRotate16Cols = trace.values + [i * NUM_BLAKE2S_XOR_ROTATE_16_COLS..(i + 1) * NUM_BLAKE2S_XOR_ROTATE_16_COLS] + .borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_xor_rotate_16_events.is_empty() + } +} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index bbaf1f342..3eb71e98c 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -124,6 +124,9 @@ pub mod tests { pub const BLAKE2S_XOR_RIGHT_ROTATE_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_XOR_RIGHT_16_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-xor-rotate-16/Cargo.lock b/tests/blake2s-xor-rotate-16/Cargo.lock new file mode 100644 index 000000000..7ab25f1f3 --- /dev/null +++ b/tests/blake2s-xor-rotate-16/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-xor-rotate-right-test" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-16/Cargo.toml b/tests/blake2s-xor-rotate-16/Cargo.toml new file mode 100644 index 000000000..8d49fdcb8 --- /dev/null +++ b/tests/blake2s-xor-rotate-16/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-xor-rotate-right-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..f01aafa22980c248238b6d8015bbc6ec5ee35854 GIT binary patch literal 22924 zcmeHvdwf*Ywf{cPnG7)m4zDWJ11AX&V@NVdCh)U%A`Cvty|qQuYkP&^WI|HIBuo+> z{(5!7WD=l!ta?DKr8W{0v9%96g!JLBH>nP&x3%^vK3cD~Hzjzj*K)-KwUoKvwa=Mk z62Z3CzkVO*4L9Ah7gLWTzOt$rtFX4EHlP+9hR7XD&9M zc~}-xL87uU)THaTc&1BsuCdZAv)1~vv?Z*w50#dr%eKlw|>HPY6 z4r6p>wtwyh#-7`#^J^BGJ&KF?qV}IV-ds(O6MwuMM2WG+ZO*)?&K&2W{yA?%{P_2= z1U{C)#}fEh0v}7@|6>W59yP~cy)2>jFwIrWy1sh&thr_=rwcSgz=e0s)yTT;1igAF zy9+eSbr&<}y?(@#P&@tF=?b(z&b;c7U)y*jWepEc_PGQ>bIr_6#E*+c=V9jUIKqsg zzO&}q5x24LFf;b!TG)3MeF;V(=rtp%(F586T;Ia=2(Gz(XN^2u1*ms=IkQf52wru> zueq6M%txDgRZ6svfbWw6jWOEq#D2bem}#nd)@oP9!TO_T)x$BP3_0tO>+pfKn&qCr zha2l5PT)htdZ6C8^>AZ7Tpz$k0oDfV(4q?FJ&K#l@;)V(%WRt>#uUiZHIqs1d63az z@HfI@iqF;?$k6Io&bnGjrjTPx0W#UJT<&?i=}dF=ZVywvMo_t*Q`nZDL03FvjXY`5x941COqUn9&A)+fc6bF(Xd2 zqbPrYb;YUf31+~CyP%gb*J);S5PxJ7s?gPu=C7R%?o{4P&*8)H#Pu)U&Uv!uyqpc* ztGwQDa`k`j*#JCf6+SuhbBt-iz;S7g!1m~jorw1Tt0o91H6@oB`h&nDTzR+(aLvcH z5LY3tB3$}|BFaUSizo*^;aZ5R5LXc{{XrS!GRkF?%P5yoE~8vVxr}lZc(T}A9u)-WVldp=nBaT^0ePAMQPKNDz*o4 z+=(cA8-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U%#j!Y=$uZDwDJ)Knt6$mlmL{ZzQi^ zJ!+n(czr`P3T;FoyIB_kAHn93-V(0c&;nDkk@T8nOZ2sM%}v-kp+}o*p@JYkMwb)~I+vei_tZi$f9k#=w>s17w@^D}9Z zY#eU5{W?2?aV|msBe*WaMY=#g;kM5+;md+>QMSl=oCR9vcT%ZkRJbfhU)G9$XAqCY zxPA`$Y@41-^gKLYjq4fEZz8Zt6SsEIw8vwfnx)9*>2% z+Hko+nzE3Wj6(}qG zaVphm*D0p9)OR)B5B&u5!!!Mew%MVPz0!}$c7k>Q^)4quhRpYa{&Ucswc!0y{YOE6 z2Xx{M^&4qCqCbas_y0?!XbnNueg=4XTTOmW+Kdqdm-j!?1W(wfprv$(h-SYElf{IZhU5u%pd zo~}~j^OlyB7nPLz7`YwhSZ77P@}lC)!W6_I#GPNdxO{EJVsCYgj;3Xo6_;LCTDE|# zs0-g3f?v5}#WKCbN5iu!VmDIPWNu`_3_QxYN@SzAw63(VWcB*e#$v{b5G6OWqDVtE zTvS#Rs$E?ZL6pFXnruST+NLH}#Q$eDtS9##m8rub_?nTrwTQA&-c*atw>h{LL;Tf0 z5<6WGH55_Dh5!8YV*jAB{O7{|soqpv{NL^c;NC}A=KRu+0f%>0ua*mW^Jv0ojsNK16wVx%>daF<XHrs literal 0 HcmV?d00001 diff --git a/tests/blake2s-xor-rotate-16/src/main.rs b/tests/blake2s-xor-rotate-16/src/main.rs new file mode 100644 index 000000000..d9b63a1e0 --- /dev/null +++ b/tests/blake2s-xor-rotate-16/src/main.rs @@ -0,0 +1,13 @@ +#![no_main] +sphinx_zkvm::entrypoint!(main); + +use sphinx_zkvm::syscalls::blake2s_xor_rotate_16::syscall_blake2s_xor_rotate_16; + +pub fn main() { + let mut w = [1u32; 64]; + for _ in 0..10000 { + syscall_blake2s_xor_rotate_16(w.as_mut_ptr()); + } +} + +// summary: cycles=40957, e2e=17694, khz=2.31, proofSize=2.07 MiB diff --git a/tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf index 77111e1412cde84eb8a5897002ba4d0f055cfc2d..7e5df46dc64f6bce33f7ca736d8674bb49d97f85 100755 GIT binary patch delta 4003 zcmai1eNa@_6~FiG-p4LM1Yg)CityOSA}q+)3QI(E0hez#R{G)mNgRF+^RTGZm|6wi8WqVQtuXH9!em3~Jl7*8?m!Fo{Yws)aQNhC~0YOVJ ztS+J7N4UZU-r;MKNNCT^PzWK~>5pdwVKkv}W)7p`ph8$q2*Z2}7RT5GZ4`1UZLuuC z%~R57SfdYKi5U{q;6P>U>yhcK7Y#=FVS>gA9w$F8-*3@af$uLd_7!(RVlw<8!3N0* zKFXjyAtTk0Q(XOF88*gcl&oO^{V^M|8imsdrNUq#1QY(u$@!TFXc;U|9HJFqPpZfN z_9QndJd{)uEe4d7Vd7bZn~Ghfa3`r6Uo4P|gx6xALr#pt4RHhRD1tX`DEvmY3)(a| zFISh0GYnImA&y(G=5T9tAqQGD?p?}JGmj-Dwcm{1hplDMko+s!I1oxM6EITBQvQer zL^zWY$?o+e5amC>gihyPYI0W5&J&s*y`WwygoVy6aoP;TSO8W+CDlxNF7uNLzy+tB zI^mjgfpBgHq^0I1BS;7~FiJUa_d(XCPXKvfU+Okm&VtG@97kBtA0v*RMbi*JlP;D5 z?37@{Ltv+5W&~6g1XV?kDUX#1!vZoD7N;E$$UV58<`TUBf)3YQs7qf=1Mo(A4Lt+@ zOn(Lcx4RArFN_VuXA}rl-}dkp&@{WD(HAtOvfx15Tg3k(=D=VGc2=&|DDAUMib|h`C7;WAID~>A7fR ziQ>R@EI^73&*f|o$PKuhv-E3G)eG}-R|;AK9LaswrjBv#Ca3zP-^PgHl4^prb%~Id zCz&$e8iC5ZL_sZq)p?1LT806U>W1#TRYIT@R?JC&i?%7C&WRn!b7xY4)ZyAjuKt5L z1zavF-!<7TwfVVH=7%HxXoi_H7!E6~6}t0n6Sq2*UmagLCcPX%Br}eeL?T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~A8l$< zr5)7X)Fr(}mz!EDueEDzD|U$80=w9~*Qb4Kt`%#n6>B@t1nWX(H&74K;oDz`(KJjrUrUJ)Bft2>y2SN2qmXzxOr*LjTTT0iIeRbD?xuNnlR$D$&c&_ zYj~V&Tbtu&(~@1IvA5}-t+@$1elRs9V2huCwgheC$ne$|l=#N=8YbX7(hrOrZE29C zY!;%z$bgS+)n9!BQ3HZ@^1*rl-nI@qS$o);s0hwrDuZ7Q8_b4Ua9`?lM7 WX)9xCl(tKy*j*0k3$%FGg8u@q^KGF3 diff --git a/tests/blake2s-xor-rotate-right/src/main.rs b/tests/blake2s-xor-rotate-right/src/main.rs index 189fad18e..3d6834f01 100644 --- a/tests/blake2s-xor-rotate-right/src/main.rs +++ b/tests/blake2s-xor-rotate-right/src/main.rs @@ -3,11 +3,9 @@ sphinx_zkvm::entrypoint!(main); use sphinx_zkvm::syscalls::blake2s_xor_rotate_right::syscall_blake2s_xor_rotate_right; -const R_1: u32 = 16; - pub fn main() { let mut a: [u32; 4] = [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a]; - let b: [u32; 5] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, R_1]; + let b: [u32; 4] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; syscall_blake2s_xor_rotate_right(a.as_mut_ptr(), b.as_ptr()); diff --git a/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_16.rs b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_16.rs new file mode 100644 index 000000000..112feab08 --- /dev/null +++ b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_16.rs @@ -0,0 +1,19 @@ +#[cfg(target_os = "zkvm")] +use core::arch::asm; + +#[allow(unused_variables)] +#[no_mangle] +pub extern "C" fn syscall_blake2s_xor_rotate_16(w: *mut u32) { + #[cfg(target_os = "zkvm")] + unsafe { + asm!( + "ecall", + in("t0") crate::syscalls::BLAKE_2S_XOR_ROTATE_16, + in("a0") w, + in("a1") 0 + ); + } + + #[cfg(not(target_os = "zkvm"))] + unreachable!() +} diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 6d02fcc35..5ae9d19bd 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -13,6 +13,7 @@ mod unconstrained; #[cfg(feature = "verify")] mod verify; +pub mod blake2s_xor_rotate_16; pub mod blake2s_xor_rotate_right; pub use bls12_381::*; @@ -110,3 +111,5 @@ pub const BLS12381_G1_DOUBLE: u32 = 0x00_00_01_72; pub const BLS12381_G1_DECOMPRESS: u32 = 0x00_01_01_F2; pub const BLAKE_2S_XOR_ROTATE_RIGHT: u32 = 0x00_01_01_CC; + +pub const BLAKE_2S_XOR_ROTATE_16: u32 = 0x00_30_01_CD; diff --git a/zkvm/precompiles/src/lib.rs b/zkvm/precompiles/src/lib.rs index 3619e4711..c98a46cfb 100644 --- a/zkvm/precompiles/src/lib.rs +++ b/zkvm/precompiles/src/lib.rs @@ -48,4 +48,5 @@ extern "C" { pub fn syscall_bls12381_g2_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g2_double(p: *mut u32); pub fn syscall_blake2s_xor_rotate_right(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_xor_rotate_16(w: *mut u32); } From 2745524df0ba4adca0dfca9371e6b5ac9f5bf0cd Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 16 Sep 2024 17:02:35 +0300 Subject: [PATCH 10/30] feat: Syscall for add2 computation --- core/src/runtime/record.rs | 24 +- core/src/runtime/syscall.rs | 16 +- core/src/stark/air.rs | 8 +- core/src/syscall/precompiles/blake2s/add_2.rs | 382 +++++++++++++ core/src/syscall/precompiles/blake2s/mod.rs | 8 +- core/src/utils/programs.rs | 3 + tests/blake2s-add2/Cargo.lock | 539 ++++++++++++++++++ tests/blake2s-add2/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25140 bytes tests/blake2s-add2/src/main.rs | 13 + zkvm/entrypoint/src/syscalls/blake2s_add_2.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 3 + 12 files changed, 1017 insertions(+), 6 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/add_2.rs create mode 100644 tests/blake2s-add2/Cargo.lock create mode 100644 tests/blake2s-add2/Cargo.toml create mode 100755 tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-add2/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_add_2.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 4f177f8eb..078c2cf6d 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -11,8 +11,8 @@ use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; use crate::syscall::precompiles::blake2s::{ - Blake2sXorRotate16Chip, Blake2sXorRotate16Event, Blake2sXorRotateRightChip, - Blake2sXorRotateRightEvent, + Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sXorRotate16Chip, Blake2sXorRotate16Event, + Blake2sXorRotateRightChip, Blake2sXorRotateRightEvent, }; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; @@ -131,6 +131,7 @@ pub struct ExecutionRecord { pub blake2s_xor_rotate_right_events: Vec, pub blake2s_xor_rotate_16_events: Vec, + pub blake2s_add_2_events: Vec, pub memory_initialize_events: Vec, @@ -337,6 +338,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_add_2_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -493,6 +500,11 @@ impl MachineRecord for ExecutionRecord { self.blake2s_xor_rotate_16_events.len(), ); + stats.insert( + "blake2s_add_2_events".to_string(), + self.blake2s_add_2_events.len(), + ); + stats } @@ -542,6 +554,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.blake2s_xor_rotate_right_events); self.blake2s_xor_rotate_16_events .append(&mut other.blake2s_xor_rotate_16_events); + self.blake2s_add_2_events + .append(&mut other.blake2s_add_2_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -881,6 +895,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); } + // blake2s_xor_rotate_16 events + first.blake2s_add_2_events = take(&mut self.blake2s_add_2_events); + for (i, event) in first.blake2s_add_2_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 5127148e5..2d1c18e59 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -6,7 +6,9 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; -use crate::syscall::precompiles::blake2s::{Blake2sXorRotate16Chip, Blake2sXorRotateRightChip}; +use crate::syscall::precompiles::blake2s::{ + Blake2sAdd2Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, +}; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; use crate::syscall::precompiles::bls12_381::g2_double::Bls12381G2AffineDoubleChip; @@ -121,6 +123,8 @@ pub enum SyscallCode { BLAKE_2S_XOR_ROTATE_RIGHT = 0x00_01_01_CC, BLAKE_2S_XOR_ROTATE_16 = 0x00_30_01_CD, + + BLAKE_2S_ADD_2 = 0x00_01_01_CE, } impl SyscallCode { @@ -159,6 +163,7 @@ impl SyscallCode { 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, 0x00_30_01_CD => SyscallCode::BLAKE_2S_XOR_ROTATE_16, + 0x00_01_01_CE => SyscallCode::BLAKE_2S_ADD_2, _ => panic!("invalid syscall number: {}", value), } } @@ -407,6 +412,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sXorRotate16Chip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_ADD_2, + Arc::new(Blake2sAdd2Chip::new()), + ); + syscall_map } @@ -531,6 +541,10 @@ mod tests { SyscallCode::BLAKE_2S_XOR_ROTATE_16 => { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_16) } + + SyscallCode::BLAKE_2S_ADD_2 => { + assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ADD_2) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index a3e9b272c..2984f4647 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -3,7 +3,9 @@ pub use crate::air::SphinxAirBuilder; use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; -use crate::syscall::precompiles::blake2s::{Blake2sXorRotate16Chip, Blake2sXorRotateRightChip}; +use crate::syscall::precompiles::blake2s::{ + Blake2sAdd2Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, +}; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; use crate::syscall::precompiles::quad_field::QuadFieldChip; @@ -110,6 +112,7 @@ pub enum RiscvAir { Blake2sXorRotateRight(Blake2sXorRotateRightChip), Blake2sXorRotate16(Blake2sXorRotate16Chip), + Blake2sAdd2(Blake2sAdd2Chip), } impl RiscvAir { @@ -192,6 +195,9 @@ impl RiscvAir { let blake_2s_xor_rotate_16 = Blake2sXorRotate16Chip::default(); chips.push(RiscvAir::Blake2sXorRotate16(blake_2s_xor_rotate_16)); + let blake2s_add_2 = Blake2sAdd2Chip::default(); + chips.push(RiscvAir::Blake2sAdd2(blake2s_add_2)); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/add_2.rs b/core/src/syscall/precompiles/blake2s/add_2.rs new file mode 100644 index 000000000..bc58eac14 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/add_2.rs @@ -0,0 +1,382 @@ +use crate::air::Word; +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::syscall::precompiles::blake2s::R_1; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +#[derive(Default)] +pub struct Blake2sAdd2Chip; + +impl Blake2sAdd2Chip { + pub fn new() -> Self { + Blake2sAdd2Chip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sAdd2Event { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + + pub a_reads_writes: Vec, + pub b_reads: Vec, + pub zero_0: Vec, + pub zero_1: Vec, +} + +impl Syscall for Blake2sAdd2Chip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, mut b) = ctx.mr_slice(b_ptr, 12); + b[4..].iter().for_each(|item| assert_eq!(*item, 0)); // expect 8 zeroes in the end of b_ptr + b.truncate(4); + + assert_eq!(a.len(), 4); + assert_eq!(b.len(), 4); + + let add2 = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| a.wrapping_add(b)) + .collect::>(); + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, add2.as_slice()); + + ctx.record_mut() + .blake2s_add_2_events + .push(Blake2sAdd2Event { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads: b_reads[0..4].to_vec(), + zero_0: b_reads[4..8].to_vec(), + zero_1: b_reads[8..12].to_vec(), + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sAdd2Cols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 4], + pub b: [MemoryReadCols; 4], + pub zero_0: [MemoryReadCols; 4], + pub zero_1: [MemoryReadCols; 4], + + pub add2: [Add4Operation; 4], +} + +impl BaseAir for Blake2sAdd2Chip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sAdd2Chip { + type Events = &'a [Blake2sAdd2Event]; +} + +impl MachineAir for Blake2sAdd2Chip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sAdd2Chip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sAdd2Cols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + for i in 0..4usize { + cols.zero_0[i].populate( + event.channel, + event.zero_0[i], + &mut new_byte_lookup_events, + ); + cols.zero_1[i].populate( + event.channel, + event.zero_1[i], + &mut new_byte_lookup_events, + ); + + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + + let a = event.a_reads_writes[i].value; + let b = event.b_reads[i].value; + + let add = cols.add2[i].populate(output, shard, event.channel, a, b, 0, 0); + assert_eq!(a + b, add); + } + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sAdd2Cols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_add_2_events.is_empty() + } +} + +impl Air for Blake2sAdd2Chip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sAdd2Cols = (*local).borrow(); + let next: &Blake2sAdd2Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + // Eval zero_0 + for i in 4..8usize { + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.zero_0[i - 4], + local.is_real, + ); + } + + // Eval zero_1 + for i in 8..12usize { + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.zero_1[i - 8], + local.is_real, + ); + } + + for i in 0..4usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + Add4Operation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + *local.zero_0[i].value(), // zero column + *local.zero_1[i].value(), // zero column + local.shard, + local.channel, + local.is_real, + local.add2[i], + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ADD_2.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::{BLAKE2S_ADD_2_ELF, BLAKE2S_XOR_RIGHT_ROTATE_ELF}; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 12]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_ADD_2 as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_add_2_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [200, 300, 400, 500], + [10, 20, 30, 40, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!(result, [210, 320, 430, 540].to_vec()); + } + + #[test] + fn test_blake2s_add_2_program() { + setup_logger(); + let program = Program::from(BLAKE2S_ADD_2_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 2ceaa8ac7..102babd65 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,5 +1,9 @@ +mod add_2; +mod add_3; mod xor_rotate_16; +pub use add_2::*; +pub use add_3::*; pub use xor_rotate_16::*; use crate::bytes::event::ByteRecord; @@ -280,7 +284,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_XOR_RIGHT_ROTATE_ELF; + use crate::utils::tests::{BLAKE2S_ADD_2_ELF, BLAKE2S_XOR_RIGHT_ROTATE_ELF}; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; @@ -358,7 +362,7 @@ mod tests { #[test] fn test_blake2s_xor_right_rotate_program() { setup_logger(); - let program = Program::from(BLAKE2S_XOR_RIGHT_ROTATE_ELF); + let program = Program::from(BLAKE2S_ADD_2_ELF); run_test(program).unwrap(); } diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index 3eb71e98c..5671f2fcc 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -127,6 +127,9 @@ pub mod tests { pub const BLAKE2S_XOR_RIGHT_16_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_ADD_2_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-add2/Cargo.lock b/tests/blake2s-add2/Cargo.lock new file mode 100644 index 000000000..b0f99b12f --- /dev/null +++ b/tests/blake2s-add2/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-add2" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-add2/Cargo.toml b/tests/blake2s-add2/Cargo.toml new file mode 100644 index 000000000..758f44ab5 --- /dev/null +++ b/tests/blake2s-add2/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-add2" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..72bd6da466349987f8f21fc79afbe3761cd08c67 GIT binary patch literal 25140 zcmeHwdwf*oo%eIDGYK&S4!0`R11AYrLy}1{fvtUKlmY3|dcmmM?G}cUfux2c%>~eP zal&MhK&e#^2wGMHAyHemD?32iUElpAtpnIkx2?5+-PhH2BZ1d;Z7L=NOquuld(N3; zf`In&*Zb-Dd=BTF-*fvtzvp*HYSR5nywfc^_gHWACa@`Z&`sqmiy*k%bnE=qmorAULU5;CzXPz%)wBqWwO4n(1n$!49*S+Ql?iKI{0#kxS;9{>%=*3;{R3HCHX`cogvR{)`U5EZ1Yq zpzo@o^qAW2)6SQm{b}Y=`+eHRqX}zpaH7{G2%2kpRxEm2G}@0aPwP=;^Q<#Q#OP#?CHbWr#S%Y2{D}IT2N_$vr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epYSv&z>^QG~9^0o~q%Q}=uwA*#^sV()r1K)cNV}5w2i(piTV1y!F z1Um#+8(_(`q58)Gdl<0KP^FZ0_$A=&fII8M$D;bffd2?^q>iY5E#W{k&ceF9c_fi& zbJpkMXzWA1qVHiYXiMX!(pU#*4ayIpe6u~yo%g5G1LZUyvU%=*8(V9_Zx3KufR*DN z{c`#e{3XE40Vn!RJ#XdKRTL7JZ85UM-wV25mVQzL?{mvv!P)2jv ziSqFAL?VoLqUr5aj#oZ^l)Zy8l7%Eb*?2t;_~utZXJU$_neD+<QTdxFuRS@|Hg#N@%LvM| zPmQMq!KWygJK*hjC;BJlb0Odd07o-^5siF+?F1|%1$GZ$I{+(6fmHzZB4BS240NNm z4+B>FMj}CSM;E~!1FQ|OB+UtiG!c6YFro+A@^$zwU^@Z3(}r<5pt?T={6{J6X+G}& z_H)4AOsUJ~5BQ#6jOqqHPa0#2iueU^2UlMz|K+1B{GX1FO5vZ|0e=|qQW^sn;qoQG z+5zKuJFr^74gi*<4dKxY*eigA@s9b8%KBcw7yh3_f)VpOV^RG>fKU0aQP~^S0Y3tK z>060Jg~Mk_ya|`HD0}SfL?RpSsn^PtI{!>QcYYq-!bEbo>M7q)P?VRS zS90@$1qiDP^Gk3SBa|*!u&%Jw%+D_g7MCtAzPVrvLimC$$tne2PhmlEUO};!k^5wh zb(ZHX&da~Knvxet0n9C2T)ehqv8Q~Uj;2L7=NH~wSTv8VtgL<@1pj#D%B6aNmxgD4 zLbtB6-rUH9X?T^hl)8JaU)ym}i@ zzqY=flm{Z4}RsZ89y%7p=%j#!Yz5-wFdq~@&nIgz5fT5djOCC literal 0 HcmV?d00001 diff --git a/tests/blake2s-add2/src/main.rs b/tests/blake2s-add2/src/main.rs new file mode 100644 index 000000000..b3bf5661e --- /dev/null +++ b/tests/blake2s-add2/src/main.rs @@ -0,0 +1,13 @@ +#![no_main] +sphinx_zkvm::entrypoint!(main); + +use sphinx_zkvm::syscalls::blake2s_add_2::syscall_blake2s_add_2; + +pub fn main() { + let mut a: [u32; 4] = [200, 300, 400, 500]; + let b: [u32; 12] = [10, 20, 30, 40, 0, 0, 0, 0, 0, 0, 0, 0]; + + syscall_blake2s_add_2(a.as_mut_ptr(), b.as_ptr()); + + assert_eq!(a, [210, 320, 430, 540]); +} diff --git a/zkvm/entrypoint/src/syscalls/blake2s_add_2.rs b/zkvm/entrypoint/src/syscalls/blake2s_add_2.rs new file mode 100644 index 000000000..01ffd1d5b --- /dev/null +++ b/zkvm/entrypoint/src/syscalls/blake2s_add_2.rs @@ -0,0 +1,19 @@ +#[cfg(target_os = "zkvm")] +use core::arch::asm; + +#[allow(unused_variables)] +#[no_mangle] +pub extern "C" fn syscall_blake2s_add_2(left: *mut u32, right: *const u32) { + #[cfg(target_os = "zkvm")] + unsafe { + asm!( + "ecall", + in("t0") crate::syscalls::BLAKE_2S_ADD_2, + in("a0") left, + in("a1") right + ); + } + + #[cfg(not(target_os = "zkvm"))] + unreachable!() +} diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 5ae9d19bd..252f5b6e9 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -13,6 +13,7 @@ mod unconstrained; #[cfg(feature = "verify")] mod verify; +pub mod blake2s_add_2; pub mod blake2s_xor_rotate_16; pub mod blake2s_xor_rotate_right; @@ -113,3 +114,5 @@ pub const BLS12381_G1_DECOMPRESS: u32 = 0x00_01_01_F2; pub const BLAKE_2S_XOR_ROTATE_RIGHT: u32 = 0x00_01_01_CC; pub const BLAKE_2S_XOR_ROTATE_16: u32 = 0x00_30_01_CD; + +pub const BLAKE_2S_ADD_2: u32 = 0x00_01_01_CE; From 856226fbb21d566424009bebc1fa253bfff5294e Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 16 Sep 2024 17:38:20 +0300 Subject: [PATCH 11/30] feat: Syscall for add3 computing --- core/src/runtime/record.rs | 26 +- core/src/runtime/syscall.rs | 14 +- core/src/stark/air.rs | 6 +- core/src/syscall/precompiles/blake2s/add_2.rs | 82 ++- core/src/syscall/precompiles/blake2s/add_3.rs | 373 ++++++++++++ core/src/utils/programs.rs | 3 + tests/blake2s-add3/Cargo.lock | 539 ++++++++++++++++++ tests/blake2s-add3/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25156 bytes tests/blake2s-add3/src/main.rs | 13 + zkvm/entrypoint/src/syscalls/blake2s_add_3.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 3 + zkvm/precompiles/src/lib.rs | 2 + 13 files changed, 1036 insertions(+), 52 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/add_3.rs create mode 100644 tests/blake2s-add3/Cargo.lock create mode 100644 tests/blake2s-add3/Cargo.toml create mode 100755 tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-add3/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_add_3.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 078c2cf6d..34aa01f2d 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -11,8 +11,8 @@ use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sXorRotate16Chip, Blake2sXorRotate16Event, - Blake2sXorRotateRightChip, Blake2sXorRotateRightEvent, + Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, Blake2sXorRotate16Chip, + Blake2sXorRotate16Event, Blake2sXorRotateRightChip, Blake2sXorRotateRightEvent, }; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; @@ -132,6 +132,7 @@ pub struct ExecutionRecord { pub blake2s_xor_rotate_right_events: Vec, pub blake2s_xor_rotate_16_events: Vec, pub blake2s_add_2_events: Vec, + pub blake2s_add_3_events: Vec, pub memory_initialize_events: Vec, @@ -344,6 +345,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_add_3_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -505,6 +512,11 @@ impl MachineRecord for ExecutionRecord { self.blake2s_add_2_events.len(), ); + stats.insert( + "blake2s_add_3_events".to_string(), + self.blake2s_add_3_events.len(), + ); + stats } @@ -556,6 +568,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.blake2s_xor_rotate_16_events); self.blake2s_add_2_events .append(&mut other.blake2s_add_2_events); + self.blake2s_add_3_events + .append(&mut other.blake2s_add_3_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -895,12 +909,18 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); } - // blake2s_xor_rotate_16 events + // blake2s_add_2 events first.blake2s_add_2_events = take(&mut self.blake2s_add_2_events); for (i, event) in first.blake2s_add_2_events.iter().enumerate() { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_add_3 events + first.blake2s_add_3_events = take(&mut self.blake2s_add_3_events); + for (i, event) in first.blake2s_add_3_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 2d1c18e59..0a361d4f9 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -7,7 +7,7 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, + Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; @@ -125,6 +125,8 @@ pub enum SyscallCode { BLAKE_2S_XOR_ROTATE_16 = 0x00_30_01_CD, BLAKE_2S_ADD_2 = 0x00_01_01_CE, + + BLAKE_2S_ADD_3 = 0x00_01_01_CF, } impl SyscallCode { @@ -164,6 +166,7 @@ impl SyscallCode { 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, 0x00_30_01_CD => SyscallCode::BLAKE_2S_XOR_ROTATE_16, 0x00_01_01_CE => SyscallCode::BLAKE_2S_ADD_2, + 0x00_01_01_CF => SyscallCode::BLAKE_2S_ADD_3, _ => panic!("invalid syscall number: {}", value), } } @@ -417,6 +420,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sAdd2Chip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_ADD_3, + Arc::new(Blake2sAdd3Chip::new()), + ); + syscall_map } @@ -545,6 +553,10 @@ mod tests { SyscallCode::BLAKE_2S_ADD_2 => { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ADD_2) } + + SyscallCode::BLAKE_2S_ADD_3 => { + assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ADD_3) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 2984f4647..eb00a385d 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -4,7 +4,7 @@ use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, + Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; @@ -113,6 +113,7 @@ pub enum RiscvAir { Blake2sXorRotateRight(Blake2sXorRotateRightChip), Blake2sXorRotate16(Blake2sXorRotate16Chip), Blake2sAdd2(Blake2sAdd2Chip), + Blake2sAdd3(Blake2sAdd3Chip), } impl RiscvAir { @@ -198,6 +199,9 @@ impl RiscvAir { let blake2s_add_2 = Blake2sAdd2Chip::default(); chips.push(RiscvAir::Blake2sAdd2(blake2s_add_2)); + let blake2s_add_3 = Blake2sAdd3Chip::default(); + chips.push(RiscvAir::Blake2sAdd3(blake2s_add_3)); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/add_2.rs b/core/src/syscall/precompiles/blake2s/add_2.rs index bc58eac14..48d70b84f 100644 --- a/core/src/syscall/precompiles/blake2s/add_2.rs +++ b/core/src/syscall/precompiles/blake2s/add_2.rs @@ -40,8 +40,6 @@ pub struct Blake2sAdd2Event { pub a_reads_writes: Vec, pub b_reads: Vec, - pub zero_0: Vec, - pub zero_1: Vec, } impl Syscall for Blake2sAdd2Chip { @@ -55,17 +53,12 @@ impl Syscall for Blake2sAdd2Chip { let b_ptr = arg2; let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, mut b) = ctx.mr_slice(b_ptr, 12); - b[4..].iter().for_each(|item| assert_eq!(*item, 0)); // expect 8 zeroes in the end of b_ptr - b.truncate(4); - - assert_eq!(a.len(), 4); - assert_eq!(b.len(), 4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 12); let add2 = a .into_iter() - .zip(b.into_iter()) - .map(|(a, b)| a.wrapping_add(b)) + .zip(b[0..4].into_iter()) + .map(|(a, b)| a.wrapping_add(*b)) .collect::>(); ctx.clk += 1; @@ -83,9 +76,7 @@ impl Syscall for Blake2sAdd2Chip { a_ptr, b_ptr, a_reads_writes, - b_reads: b_reads[0..4].to_vec(), - zero_0: b_reads[4..8].to_vec(), - zero_1: b_reads[8..12].to_vec(), + b_reads, }); None @@ -109,9 +100,7 @@ struct Blake2sAdd2Cols { pub b_ptr: T, pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], - pub zero_0: [MemoryReadCols; 4], - pub zero_1: [MemoryReadCols; 4], + pub b: [MemoryReadCols; 12], pub add2: [Add4Operation; 4], } @@ -155,17 +144,6 @@ impl MachineAir for Blake2sAdd2Chip { cols.b_ptr = F::from_canonical_u32(event.b_ptr); for i in 0..4usize { - cols.zero_0[i].populate( - event.channel, - event.zero_0[i], - &mut new_byte_lookup_events, - ); - cols.zero_1[i].populate( - event.channel, - event.zero_1[i], - &mut new_byte_lookup_events, - ); - cols.a[i].populate( event.channel, event.a_reads_writes[i], @@ -173,6 +151,16 @@ impl MachineAir for Blake2sAdd2Chip { ); cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + cols.b[i + 4].populate( + event.channel, + event.b_reads[i + 4], + &mut new_byte_lookup_events, + ); // expected to be zero + cols.b[i + 8].populate( + event.channel, + event.b_reads[i + 8], + &mut new_byte_lookup_events, + ); // expected to be zero let a = event.a_reads_writes[i].value; let b = event.b_reads[i].value; @@ -227,48 +215,48 @@ where .when_transition() .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - // Eval zero_0 - for i in 4..8usize { + for i in 0..4usize { + // Eval a builder.eval_memory_access( local.shard, local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.zero_0[i - 4], + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], local.is_real, ); - } - // Eval zero_1 - for i in 8..12usize { + // Eval b [0..4]. builder.eval_memory_access( local.shard, local.channel, local.clk, local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.zero_1[i - 8], + &local.b[i], local.is_real, ); - } - for i in 0..4usize { - // Eval a + // Eval b[4..8]. builder.eval_memory_access( local.shard, local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], + local.clk, + local.b_ptr + + ((AB::F::from_canonical_u32(4) + AB::F::from_canonical_u32(i as u32)) + * AB::F::from_canonical_u32(4)), + &local.b[i + 4], local.is_real, ); - // Eval b. + // Eval b[8..12]. builder.eval_memory_access( local.shard, local.channel, local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], + local.b_ptr + + ((AB::F::from_canonical_u32(8) + AB::F::from_canonical_u32(i as u32)) + * AB::F::from_canonical_u32(4)), + &local.b[i + 8], local.is_real, ); @@ -276,8 +264,8 @@ where builder, *local.a[i].value(), *local.b[i].value(), - *local.zero_0[i].value(), // zero column - *local.zero_1[i].value(), // zero column + *local.b[i + 4].value(), // zero + *local.b[i + 8].value(), // zero local.shard, local.channel, local.is_real, diff --git a/core/src/syscall/precompiles/blake2s/add_3.rs b/core/src/syscall/precompiles/blake2s/add_3.rs new file mode 100644 index 000000000..5fcf9737a --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/add_3.rs @@ -0,0 +1,373 @@ +use crate::air::Word; +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::syscall::precompiles::blake2s::R_1; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +#[derive(Default)] +pub struct Blake2sAdd3Chip; + +impl Blake2sAdd3Chip { + pub fn new() -> Self { + Blake2sAdd3Chip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sAdd3Event { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +impl Syscall for Blake2sAdd3Chip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 12); + let c = b[4..8].to_vec(); + + let add3 = a + .into_iter() + .zip(b[0..4].into_iter()) + .zip(c.into_iter()) + .map(|((a, b), c)| a.wrapping_add(*b).wrapping_add(c)) + .collect::>(); + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, add3.as_slice()); + + ctx.record_mut() + .blake2s_add_3_events + .push(Blake2sAdd3Event { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sAdd3Cols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 4], + pub b: [MemoryReadCols; 12], + + pub add3: [Add4Operation; 4], +} + +impl BaseAir for Blake2sAdd3Chip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sAdd3Chip { + type Events = &'a [Blake2sAdd3Event]; +} + +impl MachineAir for Blake2sAdd3Chip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sAdd3Chip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sAdd3Cols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + for i in 0..4usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + cols.b[i + 4].populate( + event.channel, + event.b_reads[i + 4], + &mut new_byte_lookup_events, + ); + cols.b[i + 8].populate( + event.channel, + event.b_reads[i + 8], + &mut new_byte_lookup_events, + ); + + let a = event.a_reads_writes[i].value; + let b = event.b_reads[i].value; + let c = event.b_reads[i + 4].value; + + let add = cols.add3[i].populate(output, shard, event.channel, a, b, c, 0); + assert_eq!(a + b + c, add); + } + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sAdd3Cols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_add_3_events.is_empty() + } +} + +impl Air for Blake2sAdd3Chip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sAdd3Cols = (*local).borrow(); + let next: &Blake2sAdd3Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..4usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b[0..4]. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // Eval b[4..8]. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + + ((AB::F::from_canonical_u32(4) + AB::F::from_canonical_u32(i as u32)) + * AB::F::from_canonical_u32(4)), + &local.b[i + 4], + local.is_real, + ); + + // Eval b[8..12]. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + + ((AB::F::from_canonical_u32(8) + AB::F::from_canonical_u32(i as u32)) + * AB::F::from_canonical_u32(4)), + &local.b[i + 8], + local.is_real, + ); + + Add4Operation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + *local.b[i + 4].value(), + *local.b[i + 8].value(), // zero + local.shard, + local.channel, + local.is_real, + local.add3[i], + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ADD_3.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::{BLAKE2S_ADD_2_ELF, BLAKE2S_ADD_3_ELF, BLAKE2S_XOR_RIGHT_ROTATE_ELF}; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 12]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_ADD_3 as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_add_3_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [200, 300, 400, 500], + [10, 20, 30, 40, 1, 2, 3, 4, 0, 0, 0, 0], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!(result, [211, 322, 433, 544].to_vec()); + } + + #[test] + fn test_blake2s_add_3_program() { + setup_logger(); + let program = Program::from(BLAKE2S_ADD_3_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index 5671f2fcc..f70840f37 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -130,6 +130,9 @@ pub mod tests { pub const BLAKE2S_ADD_2_ELF: &[u8] = include_bytes!("../../../tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_ADD_3_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-add3/Cargo.lock b/tests/blake2s-add3/Cargo.lock new file mode 100644 index 000000000..d92fcf456 --- /dev/null +++ b/tests/blake2s-add3/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-add3" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-add3/Cargo.toml b/tests/blake2s-add3/Cargo.toml new file mode 100644 index 000000000..b1777b692 --- /dev/null +++ b/tests/blake2s-add3/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-add3" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..ceef83ebba42ef5ac943d2a8ec0830351784ae26 GIT binary patch literal 25156 zcmeHwdwf*oo%eIDGYK&S4!0_+2Tl^g#gJr@Okl0=j4&X5?W%=T-_|V*Clityk~9}U zUtgSIGD%>mi#;IdS{n?BXx+BF1Ejn4v!7&j0Q>27+f~HwcD3EeW!tT#V#3A9yx-q* z&Lk6V+HU`PKRut%;hgh(ZolXE{O->);qkyd%LGASsY_(%7=7Jwlg>)zLKGMEYwm6f6<-M_#)-Li9!^+s<3n}P@3RL*h;g3C>}&hMh-jM1$S+$k@*7qHbj zzaIjO?)3KCS2MQ#ah=~Y(Cii5gcr5H|71%Qy~6pe0XM!iS0n3w0`RI+S>1qH zt{u#v@4Dg4xZ35@&X=S8N#;>c`Lqp3lGf1BM6XK_G}rW;cA$OFz`Mr&={lrUfIug4ub~jWvg8k2kVZG(7dhTGG-l~#x(CV7C&{0na`@( zRtIS1R#>!CVH(~obp|uo41wrp4S89-?0d{p(a+)+6v674&Md{nv`&=`?s1P;L*>le zqGVYvCYtrbvn|llY#*9zxpcsXZnj)G%>2gC?C2a9Gs45nI^My$!@%opmte)pnGsPj z&Ra=Kb%Ab7koGT2S|>ULYepxFKHr{sh!$~dQ_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V~@l8e-CAkCC1b60$_E3 zkxihB@W=vRh12TMcsgK>fZa`%(#ER*yo=!WynLzgW}@0El>O*PGP%QUGma)y-h%Qw zj$&?hTm8NiO;AR2*@^P-v1BrgccSUtRE}3Zf0Vt4GLnT9KDl^32Kc7eL1$u$rP*D= zH3W;=pGCc6KXrK7nGem~4F>B6ycF+r5o{)4zW|JIrinZ$MmW8Kva=|2CF@r!8W18gT?S!u9UfNck? zG!0e**vo*uO)$`n+CBzY0qil1WC)?~FzD z4+1{r-$!L{R0sSB@TKo0lQj;XrSK+P&Y*0^yUAoO-qWv#?$P;Y>bdXp_^wkuZA!_`drhT_t~qQdgq=g&u2T~btzy9}Xp@%-wN3bUxFJXlt-sOau; zdp#w^Wrf9MUPkVdIo4UBx2&+}_IgTIAO%oRvZ!or`65qMwT`Bxw-=S%UQ#-j-BVlt za0veKJ@+iti@h{F^AoyFwaw-RCQQStoTD^t@RZb+G#0O3U(#5_SRt|qEv&Gqp$e`x zD-6}Fu5LoK!wQ>iK=az>W>(1mF&oxXn1agGVIh3xrrNd0LZH0422Mmva4m-T)EAMR zZjhS)KLg~9(*HA%x>9oE0)XmKEY1JVfqP*m$SHCzQekwF&rbDd`FGUlY{!F;S>8DS zxKjOn2Jci4s?GjC3Rc^C6rcP`)zk4seN(;tkLzq7>dnG?>Pn594?wEkPn>$2Qk9%C z`karO#s$&&Mg2YNywiiq=q6srn2mVw%eQ9yxKxL(Ww;5q)D>I Date: Mon, 16 Sep 2024 18:18:17 +0300 Subject: [PATCH 12/30] feat: Syscalls for xor_right_rotate_{16, 12} --- core/src/runtime/record.rs | 51 +- core/src/runtime/syscall.rs | 32 +- core/src/stark/air.rs | 19 +- core/src/syscall/precompiles/blake2s/add_2.rs | 6 +- core/src/syscall/precompiles/blake2s/add_3.rs | 6 +- core/src/syscall/precompiles/blake2s/mod.rs | 366 +----------- .../blake2s/xor_rotate_right_12.rs | 357 ++++++++++++ .../blake2s/xor_rotate_right_16.rs | 357 ++++++++++++ core/src/utils/programs.rs | 9 +- tests/blake2s-xor-rotate-right-12/Cargo.lock | 539 ++++++++++++++++++ .../Cargo.toml | 2 +- .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25140 bytes tests/blake2s-xor-rotate-right-12/src/main.rs | 13 + .../Cargo.lock | 0 tests/blake2s-xor-rotate-right-16/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin .../src/main.rs | 6 +- ...ight.rs => blake2s_xor_rotate_right_12.rs} | 4 +- .../syscalls/blake2s_xor_rotate_right_16.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 7 +- 20 files changed, 1397 insertions(+), 404 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs create mode 100644 tests/blake2s-xor-rotate-right-12/Cargo.lock rename tests/{blake2s-xor-rotate-right => blake2s-xor-rotate-right-12}/Cargo.toml (74%) create mode 100755 tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-xor-rotate-right-12/src/main.rs rename tests/{blake2s-xor-rotate-right => blake2s-xor-rotate-right-16}/Cargo.lock (100%) create mode 100644 tests/blake2s-xor-rotate-right-16/Cargo.toml rename tests/{blake2s-xor-rotate-right => blake2s-xor-rotate-right-16}/elf/riscv32im-succinct-zkvm-elf (100%) rename tests/{blake2s-xor-rotate-right => blake2s-xor-rotate-right-16}/src/main.rs (73%) rename zkvm/entrypoint/src/syscalls/{blake2s_xor_rotate_right.rs => blake2s_xor_rotate_right_12.rs} (64%) create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_16.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 34aa01f2d..6e7b44e4a 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -12,7 +12,8 @@ use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, Blake2sXorRotate16Chip, - Blake2sXorRotate16Event, Blake2sXorRotateRightChip, Blake2sXorRotateRightEvent, + Blake2sXorRotate16Event, Blake2sXorRotateRight12Chip, Blake2sXorRotateRight12Event, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, }; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; @@ -129,10 +130,12 @@ pub struct ExecutionRecord { pub bls12381_g2_add_events: Vec, pub bls12381_g2_double_events: Vec, - pub blake2s_xor_rotate_right_events: Vec, - pub blake2s_xor_rotate_16_events: Vec, + // Blake2s + pub blake2s_xor_rotate_right_16_events: Vec, + pub blake2s_xor_rotate_16_events: Vec, // based on sha-extend pub blake2s_add_2_events: Vec, pub blake2s_add_3_events: Vec, + pub blake2s_xor_rotate_right_12_events: Vec, pub memory_initialize_events: Vec, @@ -327,9 +330,9 @@ impl EventLens> for ExecutionRecord { } } -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_xor_rotate_right_events +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_xor_rotate_right_16_events } } @@ -351,6 +354,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_xor_rotate_right_12_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -499,8 +508,8 @@ impl MachineRecord for ExecutionRecord { self.bls12381_g2_double_events.len(), ); stats.insert( - "blake2s_xor_rotate_right_events".to_string(), - self.blake2s_xor_rotate_right_events.len(), + "blake2s_xor_rotate_right_16_events".to_string(), + self.blake2s_xor_rotate_right_16_events.len(), ); stats.insert( "blake2s_xor_rotate_16_events".to_string(), @@ -517,6 +526,11 @@ impl MachineRecord for ExecutionRecord { self.blake2s_add_3_events.len(), ); + stats.insert( + "blake2s_xor_rotate_right_12_events".to_string(), + self.blake2s_xor_rotate_right_12_events.len(), + ); + stats } @@ -562,14 +576,17 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.bls12381_g2_add_events); self.bls12381_g2_double_events .append(&mut other.bls12381_g2_double_events); - self.blake2s_xor_rotate_right_events - .append(&mut other.blake2s_xor_rotate_right_events); + + self.blake2s_xor_rotate_right_16_events + .append(&mut other.blake2s_xor_rotate_right_16_events); self.blake2s_xor_rotate_16_events .append(&mut other.blake2s_xor_rotate_16_events); self.blake2s_add_2_events .append(&mut other.blake2s_add_2_events); self.blake2s_add_3_events .append(&mut other.blake2s_add_3_events); + self.blake2s_xor_rotate_right_12_events + .append(&mut other.blake2s_xor_rotate_right_12_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -897,9 +914,10 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } - // blake2s_xor_rotate_right events - first.blake2s_xor_rotate_right_events = take(&mut self.blake2s_xor_rotate_right_events); - for (i, event) in first.blake2s_xor_rotate_right_events.iter().enumerate() { + // blake2s_xor_rotate_right_16 events + first.blake2s_xor_rotate_right_16_events = + take(&mut self.blake2s_xor_rotate_right_16_events); + for (i, event) in first.blake2s_xor_rotate_right_16_events.iter().enumerate() { self.nonce_lookup.insert(event.lookup_id, i as u32); } @@ -921,6 +939,13 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_xor_rotate_right_12 events + first.blake2s_xor_rotate_right_12_events = + take(&mut self.blake2s_xor_rotate_right_12_events); + for (i, event) in first.blake2s_xor_rotate_right_12_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 0a361d4f9..25b9a0849 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -7,7 +7,8 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, + Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, + Blake2sXorRotateRight16Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; @@ -120,13 +121,15 @@ pub enum SyscallCode { /// Executes the `HINT_READ` precompile. HINT_READ = 0x00_00_00_F1, - BLAKE_2S_XOR_ROTATE_RIGHT = 0x00_01_01_CC, + BLAKE_2S_XOR_ROTATE_RIGHT_16 = 0x00_01_01_CC, - BLAKE_2S_XOR_ROTATE_16 = 0x00_30_01_CD, + BLAKE_2S_XOR_ROTATE_16 = 0x00_30_01_CD, // based on sha-extend BLAKE_2S_ADD_2 = 0x00_01_01_CE, BLAKE_2S_ADD_3 = 0x00_01_01_CF, + + BLAKE_2S_XOR_ROTATE_RIGHT_12 = 0x00_01_01_EA, } impl SyscallCode { @@ -163,10 +166,11 @@ impl SyscallCode { 0x00_01_01_F2 => SyscallCode::BLS12381_G1_DECOMPRESS, 0x00_01_01_80 => SyscallCode::BLS12381_G2_ADD, 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, - 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, + 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16, 0x00_30_01_CD => SyscallCode::BLAKE_2S_XOR_ROTATE_16, 0x00_01_01_CE => SyscallCode::BLAKE_2S_ADD_2, 0x00_01_01_CF => SyscallCode::BLAKE_2S_ADD_3, + 0x00_01_01_EA => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, _ => panic!("invalid syscall number: {}", value), } } @@ -406,8 +410,8 @@ pub fn default_syscall_map() -> HashMap> { ); syscall_map.insert( - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT, - Arc::new(Blake2sXorRotateRightChip::new()), + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16, + Arc::new(Blake2sXorRotateRight16Chip::new()), ); syscall_map.insert( @@ -425,6 +429,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sAdd3Chip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, + Arc::new(Blake2sXorRotateRight12Chip::new()), + ); + syscall_map } @@ -539,10 +548,10 @@ mod tests { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLS12381_G2_DOUBLE) } - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT => { + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16 => { assert_eq!( code as u32, - sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT + sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_16 ) } @@ -557,6 +566,13 @@ mod tests { SyscallCode::BLAKE_2S_ADD_3 => { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ADD_3) } + + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12 => { + assert_eq!( + code as u32, + sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_12 + ) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index eb00a385d..60455c427 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -4,7 +4,8 @@ use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRightChip, + Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, + Blake2sXorRotateRight16Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; @@ -110,10 +111,11 @@ pub enum RiscvAir { /// A precompile for decompressing a point on the BLS12-381 curve. Bls12381G1Decompress(Bls12381G1DecompressChip), - Blake2sXorRotateRight(Blake2sXorRotateRightChip), - Blake2sXorRotate16(Blake2sXorRotate16Chip), + Blake2sXorRotateRight16(Blake2sXorRotateRight16Chip), + Blake2sXorRotate16(Blake2sXorRotate16Chip), // based on sha-extend Blake2sAdd2(Blake2sAdd2Chip), Blake2sAdd3(Blake2sAdd3Chip), + Blake2sXorRotateRight12(Blake2sXorRotateRight12Chip), } impl RiscvAir { @@ -190,8 +192,10 @@ impl RiscvAir { let byte = ByteChip::default(); chips.push(RiscvAir::ByteLookup(byte)); - let blake_2s_xor_rotate_right = Blake2sXorRotateRightChip::default(); - chips.push(RiscvAir::Blake2sXorRotateRight(blake_2s_xor_rotate_right)); + let blake_2s_xor_rotate_right_16 = Blake2sXorRotateRight16Chip::default(); + chips.push(RiscvAir::Blake2sXorRotateRight16( + blake_2s_xor_rotate_right_16, + )); let blake_2s_xor_rotate_16 = Blake2sXorRotate16Chip::default(); chips.push(RiscvAir::Blake2sXorRotate16(blake_2s_xor_rotate_16)); @@ -202,6 +206,11 @@ impl RiscvAir { let blake2s_add_3 = Blake2sAdd3Chip::default(); chips.push(RiscvAir::Blake2sAdd3(blake2s_add_3)); + let blake_2s_xor_rotate_right_12 = Blake2sXorRotateRight12Chip::default(); + chips.push(RiscvAir::Blake2sXorRotateRight12( + blake_2s_xor_rotate_right_12, + )); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/add_2.rs b/core/src/syscall/precompiles/blake2s/add_2.rs index 48d70b84f..98879c26e 100644 --- a/core/src/syscall/precompiles/blake2s/add_2.rs +++ b/core/src/syscall/precompiles/blake2s/add_2.rs @@ -1,10 +1,8 @@ -use crate::air::Word; use crate::bytes::event::ByteRecord; use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::operations::Add4Operation; use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; use crate::stark::SphinxAirBuilder; -use crate::syscall::precompiles::blake2s::R_1; use crate::utils::pad_rows; use crate::{ air::{EventLens, MachineAir, WithEvents}, @@ -289,7 +287,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::{BLAKE2S_ADD_2_ELF, BLAKE2S_XOR_RIGHT_ROTATE_ELF}; + use crate::utils::tests::BLAKE2S_ADD_2_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; diff --git a/core/src/syscall/precompiles/blake2s/add_3.rs b/core/src/syscall/precompiles/blake2s/add_3.rs index 5fcf9737a..28506205f 100644 --- a/core/src/syscall/precompiles/blake2s/add_3.rs +++ b/core/src/syscall/precompiles/blake2s/add_3.rs @@ -1,10 +1,8 @@ -use crate::air::Word; use crate::bytes::event::ByteRecord; use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::operations::Add4Operation; use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; use crate::stark::SphinxAirBuilder; -use crate::syscall::precompiles::blake2s::R_1; use crate::utils::pad_rows; use crate::{ air::{EventLens, MachineAir, WithEvents}, @@ -292,7 +290,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::{BLAKE2S_ADD_2_ELF, BLAKE2S_ADD_3_ELF, BLAKE2S_XOR_RIGHT_ROTATE_ELF}; + use crate::utils::tests::BLAKE2S_ADD_3_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 102babd65..c7fae7c72 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,371 +1,17 @@ mod add_2; mod add_3; -mod xor_rotate_16; +mod xor_rotate_16; // based on sha-extend +mod xor_rotate_right_12; +mod xor_rotate_right_16; pub use add_2::*; pub use add_3::*; -pub use xor_rotate_16::*; - -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{FixedRotateRightOperation, XorOperation}; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -const R_1: u32 = 16; -//const R_2: u32 = 12; -//const R_3: u32 = 8; -//const R_4: u32 = 7; - -#[derive(Default)] -pub struct Blake2sXorRotateRightChip; - -impl Blake2sXorRotateRightChip { - pub fn new() -> Self { - Blake2sXorRotateRightChip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sXorRotateRightEvent { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sXorRotateRightChip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 4); - - let xor = a - .into_iter() - .zip(b.into_iter()) - .map(|(a, b)| a ^ b) - .collect::>(); - - let rotate_right = xor - .into_iter() - .map(|xor_i| xor_i.rotate_right(R_1)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); - - ctx.record_mut() - .blake2s_xor_rotate_right_events - .push(Blake2sXorRotateRightEvent { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sXorRotateRightCols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], - - pub xor: [XorOperation; 4], - pub rotate_right: [FixedRotateRightOperation; 4], -} - -impl BaseAir for Blake2sXorRotateRightChip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sXorRotateRightChip { - type Events = &'a [Blake2sXorRotateRightEvent]; -} - -impl MachineAir for Blake2sXorRotateRightChip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sXorRotateRightChip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sXorRotateRightCols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - assert_eq!(a ^ b, xor); - - let rotate_right = - cols.rotate_right[i].populate(output, shard, event.channel, xor, R_1 as usize); - assert_eq!(xor.rotate_right(R_1), rotate_right); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sXorRotateRightCols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_xor_rotate_right_events.is_empty() - } -} - -impl Air for Blake2sXorRotateRightChip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sXorRotateRightCols = (*local).borrow(); - let next: &Blake2sXorRotateRightCols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - local.xor[i], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i].value, - R_1 as usize, - local.rotate_right[i], - local.shard, - &local.channel, - local.is_real, - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} +pub use xor_rotate_16::*; // based on sha-extend +pub use xor_rotate_right_12::*; +pub use xor_rotate_right_16::*; #[cfg(test)] mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::{BLAKE2S_ADD_2_ELF, BLAKE2S_XOR_RIGHT_ROTATE_ELF}; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_xor_rotate_right_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!( - result, - [0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf].to_vec() - ); - } - - #[test] - fn test_blake2s_xor_right_rotate_program() { - setup_logger(); - let program = Program::from(BLAKE2S_ADD_2_ELF); - run_test(program).unwrap(); - } - fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] } diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs new file mode 100644 index 000000000..b0d966ba1 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs @@ -0,0 +1,357 @@ +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +const R_2: u32 = 12; + +#[derive(Default)] +pub struct Blake2sXorRotateRight12Chip; + +impl Blake2sXorRotateRight12Chip { + pub fn new() -> Self { + Blake2sXorRotateRight12Chip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sXorRotateRight12Event { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +impl Syscall for Blake2sXorRotateRight12Chip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 4); + + let xor = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| a ^ b) + .collect::>(); + + let rotate_right = xor + .into_iter() + .map(|xor_i| xor_i.rotate_right(R_2)) + .collect::>(); + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); + + ctx.record_mut() + .blake2s_xor_rotate_right_12_events + .push(Blake2sXorRotateRight12Event { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sXorRotateRight12Cols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 4], + pub b: [MemoryReadCols; 4], + + pub xor: [XorOperation; 4], + pub rotate_right: [FixedRotateRightOperation; 4], +} + +impl BaseAir for Blake2sXorRotateRight12Chip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sXorRotateRight12Chip { + type Events = &'a [Blake2sXorRotateRight12Event]; +} + +impl MachineAir for Blake2sXorRotateRight12Chip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sXorRotateRight12Chip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sXorRotateRight12Cols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + for i in 0..4usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + + let a = event.a_reads_writes[i].value; + let b = event.b_reads[i].value; + let xor = cols.xor[i].populate(output, shard, event.channel, a, b); + assert_eq!(a ^ b, xor); + + let rotate_right = + cols.rotate_right[i].populate(output, shard, event.channel, xor, R_2 as usize); + assert_eq!(xor.rotate_right(R_2), rotate_right); + } + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sXorRotateRight12Cols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_xor_rotate_right_12_events.is_empty() + } +} + +impl Air for Blake2sXorRotateRight12Chip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sXorRotateRight12Cols = (*local).borrow(); + let next: &Blake2sXorRotateRight12Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..4usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_2 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_12_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12 as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_xor_rotate_right_12_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!( + result, + [0x4383a06b, 0x6092062c, 0xad923ed2, 0x823feaf3].to_vec() + ); + } + + #[test] + fn test_blake2s_xor_rotate_right_16_program() { + setup_logger(); + let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_12_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs new file mode 100644 index 000000000..e836585e0 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs @@ -0,0 +1,357 @@ +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +const R_1: u32 = 16; + +#[derive(Default)] +pub struct Blake2sXorRotateRight16Chip; + +impl Blake2sXorRotateRight16Chip { + pub fn new() -> Self { + Blake2sXorRotateRight16Chip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sXorRotateRight16Event { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +impl Syscall for Blake2sXorRotateRight16Chip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 4); + + let xor = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| a ^ b) + .collect::>(); + + let rotate_right = xor + .into_iter() + .map(|xor_i| xor_i.rotate_right(R_1)) + .collect::>(); + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); + + ctx.record_mut() + .blake2s_xor_rotate_right_16_events + .push(Blake2sXorRotateRight16Event { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sXorRotateRight16Cols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 4], + pub b: [MemoryReadCols; 4], + + pub xor: [XorOperation; 4], + pub rotate_right: [FixedRotateRightOperation; 4], +} + +impl BaseAir for Blake2sXorRotateRight16Chip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sXorRotateRight16Chip { + type Events = &'a [Blake2sXorRotateRight16Event]; +} + +impl MachineAir for Blake2sXorRotateRight16Chip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sXorRotateRight16Chip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sXorRotateRight16Cols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + for i in 0..4usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + + let a = event.a_reads_writes[i].value; + let b = event.b_reads[i].value; + let xor = cols.xor[i].populate(output, shard, event.channel, a, b); + assert_eq!(a ^ b, xor); + + let rotate_right = + cols.rotate_right[i].populate(output, shard, event.channel, xor, R_1 as usize); + assert_eq!(xor.rotate_right(R_1), rotate_right); + } + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sXorRotateRight16Cols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_xor_rotate_right_16_events.is_empty() + } +} + +impl Air for Blake2sXorRotateRight16Chip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sXorRotateRight16Cols = (*local).borrow(); + let next: &Blake2sXorRotateRight16Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..4usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_1 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_16_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16 as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_xor_rotate_right_16_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!( + result, + [0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf].to_vec() + ); + } + + #[test] + fn test_blake2s_xor_rotate_right_16_program() { + setup_logger(); + let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_16_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index f70840f37..cfc4b3ef4 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -121,8 +121,9 @@ pub mod tests { pub const BLS12381_G2_DOUBLE_ELF: &[u8] = include_bytes!("../../../tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf"); - pub const BLAKE2S_XOR_RIGHT_ROTATE_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_XOR_ROTATE_RIGHT_16_ELF: &[u8] = include_bytes!( + "../../../tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf" + ); pub const BLAKE2S_XOR_RIGHT_16_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf"); @@ -133,6 +134,10 @@ pub mod tests { pub const BLAKE2S_ADD_3_ELF: &[u8] = include_bytes!("../../../tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_XOR_ROTATE_RIGHT_12_ELF: &[u8] = include_bytes!( + "../../../tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf" + ); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-xor-rotate-right-12/Cargo.lock b/tests/blake2s-xor-rotate-right-12/Cargo.lock new file mode 100644 index 000000000..bc27231b9 --- /dev/null +++ b/tests/blake2s-xor-rotate-right-12/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-xor-rotate-right-12-test" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right/Cargo.toml b/tests/blake2s-xor-rotate-right-12/Cargo.toml similarity index 74% rename from tests/blake2s-xor-rotate-right/Cargo.toml rename to tests/blake2s-xor-rotate-right-12/Cargo.toml index 8d49fdcb8..00618a2be 100644 --- a/tests/blake2s-xor-rotate-right/Cargo.toml +++ b/tests/blake2s-xor-rotate-right-12/Cargo.toml @@ -1,6 +1,6 @@ [workspace] [package] -name = "blake2s-xor-rotate-right-test" +name = "blake2s-xor-rotate-right-12-test" version = "0.1.0" edition = "2021" diff --git a/tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..5c00c03793a2dced10e8d0f6df6dd3790f7e8aec GIT binary patch literal 25140 zcmeHwdw3MrdH0#?u7oTE!!0(k2SyTC3rQ*=RNQJoE47-S1c6-fw`B+&NKSD<0hRI;d!vaE-7L<^RU@0 zoux4qASx?DO}c-Mce-Wg9_@|Z1U3l|x~ZIH5d@c)Zk^xyGREju2=0{Y_X4(B=l2%@ zqdT?zBdZyEg)v;mqReEf7+tC`>6pUIXHPRLHkoPaU{X^iv;IlyWevu8 zU4$`T>~w&hX1bbbu){2_b~DYB&pN+x%O*9>}% z14o!~5ck}k%jiom<^#TVP&K*%dmi_F)#zS3S6A5sLXeJZmQ57V}(tbea}*cvEd=2j)c z@-We?9h_-_mS)?)M9ZTCK5(<;$ztY{12dzuJj{p;GV4S;>x=-eH$8$CD`7^9igDgZ zTB-+hV}kVj(xi2=U9hHYW6=X`$@rNeW^@cN>%nb;ws$LwK7TYBUkBKM0ras|u%1M{ z=Tzo9D+b5hhc`4Co3YAlt)wUGyWej*srm?Kp6iypXZ%zl@r2_*Uge&O4KnLLp zIxx^dxPlH0bP%pjhbf>##Otn$_9pO*<+9EQt;cC+J+d4;uvXK&SK#5rdWcuxA!0pH zZ_Ijlu^yfq;E{{9!8$ang88K4<+R+ZWO15pQ^cqOntG-($vX=)Is*I#Syb`cd;=O< z?Mqo_3(*vGY|droUg~QKGoMmK;&-<_wbeYcoH^3k*!B7!Q--Mym8aIf)_75jCwU*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fFfp71~Zl-LK(Ey0m`js0@A=?|VVJ zeRx6}hZ}0a#t!>}df^5zRdX$LyjjHs-mI$(qYHKpc0kATn_-=m;5i95>19_ITY)Ey z^(3Buj_1#C-;LYx6GEJtSoT%6{a8V?(^tZ9gkZopo9dO#4J38M9b6Suh8tm2O`0Sd zqc`+rI(rM_kp3RTO*VsgfiB^z_cP%ULAWJDF^T7jb_G*dz%rOELpZSGV1p{`9zKGQN2e*QIZv+M6#X zll$-_+*Xa&=eP_5yz1|h$)Ct}dBteCjSIju?`$aD;X}zJz0*bWD+O!_uqFZk7n+}r z*ZTlp^-syiY5J>ft!&ceF9dnB3M=B&@h z(Kvv5cl~VPi@1pFH#8?^*0agPT*#x=>j|}itB&8mWrvp|G z*gaG!WxP_rI|y#iE8vbd9o1H$>_6@m4cAlYQHipBD3k5^W?ebo zR+LAOqkG+MJF<2}iw=~PzJ7HX;q)@f&Y{eaqx({MkILUddHoxsZBxgkxeTK``{Y+5?F6hS1y%*vi-5gJFwl+KJ_1<% zo5>`}9bE)_9I$PGxilvj(nRcWz=$4b%h%z%fb9b8J{!j6fa?AP@E@hLr}?}K*z173 zl~R|_AMm|D8_^AXo;1cJ6}|-E4z7Vz{>w*MTpya|`HD0}>!WHKA?sn?1XI{$Q^yZ#d21Ps6h^Lbsv1 z(cHj+>1QLl&Wlq7Q+Al literal 0 HcmV?d00001 diff --git a/tests/blake2s-xor-rotate-right-12/src/main.rs b/tests/blake2s-xor-rotate-right-12/src/main.rs new file mode 100644 index 000000000..75c6ac8b4 --- /dev/null +++ b/tests/blake2s-xor-rotate-right-12/src/main.rs @@ -0,0 +1,13 @@ +#![no_main] +sphinx_zkvm::entrypoint!(main); + +use sphinx_zkvm::syscalls::blake2s_xor_rotate_right_12::syscall_blake2s_xor_rotate_right_12; + +pub fn main() { + let mut a: [u32; 4] = [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a]; + let b: [u32; 4] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; + + syscall_blake2s_xor_rotate_right_12(a.as_mut_ptr(), b.as_ptr()); + + assert_eq!(a, [0x4383a06b, 0x6092062c, 0xad923ed2, 0x823feaf3]); +} diff --git a/tests/blake2s-xor-rotate-right/Cargo.lock b/tests/blake2s-xor-rotate-right-16/Cargo.lock similarity index 100% rename from tests/blake2s-xor-rotate-right/Cargo.lock rename to tests/blake2s-xor-rotate-right-16/Cargo.lock diff --git a/tests/blake2s-xor-rotate-right-16/Cargo.toml b/tests/blake2s-xor-rotate-right-16/Cargo.toml new file mode 100644 index 000000000..4787ff58f --- /dev/null +++ b/tests/blake2s-xor-rotate-right-16/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-xor-rotate-right-16-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf similarity index 100% rename from tests/blake2s-xor-rotate-right/elf/riscv32im-succinct-zkvm-elf rename to tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf diff --git a/tests/blake2s-xor-rotate-right/src/main.rs b/tests/blake2s-xor-rotate-right-16/src/main.rs similarity index 73% rename from tests/blake2s-xor-rotate-right/src/main.rs rename to tests/blake2s-xor-rotate-right-16/src/main.rs index 3d6834f01..5a6a4d658 100644 --- a/tests/blake2s-xor-rotate-right/src/main.rs +++ b/tests/blake2s-xor-rotate-right-16/src/main.rs @@ -1,19 +1,19 @@ #![no_main] sphinx_zkvm::entrypoint!(main); -use sphinx_zkvm::syscalls::blake2s_xor_rotate_right::syscall_blake2s_xor_rotate_right; +use sphinx_zkvm::syscalls::blake2s_xor_rotate_right_16::syscall_blake2s_xor_rotate_right_16; pub fn main() { let mut a: [u32; 4] = [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a]; let b: [u32; 4] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; - syscall_blake2s_xor_rotate_right(a.as_mut_ptr(), b.as_ptr()); + syscall_blake2s_xor_rotate_right_16(a.as_mut_ptr(), b.as_ptr()); assert_eq!(a, [0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf]); // precompile code //for _ in 0..10000 { - // syscall_blake2s_xor_rotate_right(a.as_mut_ptr(), b.as_ptr()); + // syscall_blake2s_xor_rotate_right_16(a.as_mut_ptr(), b.as_ptr()); //} // no-precompile code diff --git a/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right.rs b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_12.rs similarity index 64% rename from zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right.rs rename to zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_12.rs index 0c912e620..e74d0ae5c 100644 --- a/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right.rs +++ b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_12.rs @@ -3,12 +3,12 @@ use core::arch::asm; #[allow(unused_variables)] #[no_mangle] -pub extern "C" fn syscall_blake2s_xor_rotate_right(left: *mut u32, right: *const u32) { +pub extern "C" fn syscall_blake2s_xor_rotate_right_12(left: *mut u32, right: *const u32) { #[cfg(target_os = "zkvm")] unsafe { asm!( "ecall", - in("t0") crate::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT, + in("t0") crate::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_12, in("a0") left, in("a1") right ); diff --git a/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_16.rs b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_16.rs new file mode 100644 index 000000000..4d04d4057 --- /dev/null +++ b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_16.rs @@ -0,0 +1,19 @@ +#[cfg(target_os = "zkvm")] +use core::arch::asm; + +#[allow(unused_variables)] +#[no_mangle] +pub extern "C" fn syscall_blake2s_xor_rotate_right_16(left: *mut u32, right: *const u32) { + #[cfg(target_os = "zkvm")] + unsafe { + asm!( + "ecall", + in("t0") crate::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_16, + in("a0") left, + in("a1") right + ); + } + + #[cfg(not(target_os = "zkvm"))] + unreachable!() +} diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 70b605955..59837c0fd 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -16,7 +16,8 @@ mod verify; pub mod blake2s_add_2; pub mod blake2s_add_3; pub mod blake2s_xor_rotate_16; -pub mod blake2s_xor_rotate_right; +pub mod blake2s_xor_rotate_right_12; +pub mod blake2s_xor_rotate_right_16; pub use bls12_381::*; pub use bn254::*; @@ -112,10 +113,12 @@ pub const BLS12381_G1_DOUBLE: u32 = 0x00_00_01_72; /// Executes `BLS12381_G1_DECOMPRESS`. pub const BLS12381_G1_DECOMPRESS: u32 = 0x00_01_01_F2; -pub const BLAKE_2S_XOR_ROTATE_RIGHT: u32 = 0x00_01_01_CC; +pub const BLAKE_2S_XOR_ROTATE_RIGHT_16: u32 = 0x00_01_01_CC; pub const BLAKE_2S_XOR_ROTATE_16: u32 = 0x00_30_01_CD; pub const BLAKE_2S_ADD_2: u32 = 0x00_01_01_CE; pub const BLAKE_2S_ADD_3: u32 = 0x00_01_01_CF; + +pub const BLAKE_2S_XOR_ROTATE_RIGHT_12: u32 = 0x00_01_01_EA; From d176cb99551ed1baf11d628edebbcaea1ec091d5 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 16 Sep 2024 18:39:11 +0300 Subject: [PATCH 13/30] feat: Syscall for xor_right-rotate_8 computation --- core/src/runtime/record.rs | 23 +- core/src/runtime/syscall.rs | 16 +- core/src/stark/air.rs | 9 +- core/src/syscall/precompiles/blake2s/mod.rs | 2 + .../precompiles/blake2s/xor_rotate_right_8.rs | 357 ++++++++++++ core/src/utils/programs.rs | 3 + tests/blake2s-xor-rotate-right-8/Cargo.lock | 539 ++++++++++++++++++ tests/blake2s-xor-rotate-right-8/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25140 bytes tests/blake2s-xor-rotate-right-8/src/main.rs | 13 + .../syscalls/blake2s_xor_rotate_right_8.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 3 + 12 files changed, 989 insertions(+), 3 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs create mode 100644 tests/blake2s-xor-rotate-right-8/Cargo.lock create mode 100644 tests/blake2s-xor-rotate-right-8/Cargo.toml create mode 100755 tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-xor-rotate-right-8/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_8.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 6e7b44e4a..ea5cab2c9 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -13,7 +13,8 @@ use crate::stark::MachineRecord; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, Blake2sXorRotate16Chip, Blake2sXorRotate16Event, Blake2sXorRotateRight12Chip, Blake2sXorRotateRight12Event, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, Blake2sXorRotateRight8Chip, + Blake2sXorRotateRight8Event, }; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; @@ -136,6 +137,7 @@ pub struct ExecutionRecord { pub blake2s_add_2_events: Vec, pub blake2s_add_3_events: Vec, pub blake2s_xor_rotate_right_12_events: Vec, + pub blake2s_xor_rotate_right_8_events: Vec, pub memory_initialize_events: Vec, @@ -360,6 +362,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_xor_rotate_right_8_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -531,6 +539,11 @@ impl MachineRecord for ExecutionRecord { self.blake2s_xor_rotate_right_12_events.len(), ); + stats.insert( + "blake2s_xor_rotate_right_8_events".to_string(), + self.blake2s_xor_rotate_right_8_events.len(), + ); + stats } @@ -587,6 +600,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.blake2s_add_3_events); self.blake2s_xor_rotate_right_12_events .append(&mut other.blake2s_xor_rotate_right_12_events); + self.blake2s_xor_rotate_right_8_events + .append(&mut other.blake2s_xor_rotate_right_8_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -946,6 +961,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_xor_rotate_right_8 events + first.blake2s_xor_rotate_right_8_events = take(&mut self.blake2s_xor_rotate_right_8_events); + for (i, event) in first.blake2s_xor_rotate_right_8_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 25b9a0849..e07384a2a 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -8,7 +8,7 @@ use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, - Blake2sXorRotateRight16Chip, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight8Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; @@ -130,6 +130,7 @@ pub enum SyscallCode { BLAKE_2S_ADD_3 = 0x00_01_01_CF, BLAKE_2S_XOR_ROTATE_RIGHT_12 = 0x00_01_01_EA, + BLAKE_2S_XOR_ROTATE_RIGHT_8 = 0x00_01_01_EB, } impl SyscallCode { @@ -171,6 +172,7 @@ impl SyscallCode { 0x00_01_01_CE => SyscallCode::BLAKE_2S_ADD_2, 0x00_01_01_CF => SyscallCode::BLAKE_2S_ADD_3, 0x00_01_01_EA => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, + 0x00_01_01_EB => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, _ => panic!("invalid syscall number: {}", value), } } @@ -434,6 +436,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sXorRotateRight12Chip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, + Arc::new(Blake2sXorRotateRight8Chip::new()), + ); + syscall_map } @@ -573,6 +580,13 @@ mod tests { sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_12 ) } + + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8 => { + assert_eq!( + code as u32, + sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_8 + ) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 60455c427..1335ce915 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -5,7 +5,7 @@ use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, - Blake2sXorRotateRight16Chip, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight8Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; @@ -111,11 +111,13 @@ pub enum RiscvAir { /// A precompile for decompressing a point on the BLS12-381 curve. Bls12381G1Decompress(Bls12381G1DecompressChip), + // Blake2s Blake2sXorRotateRight16(Blake2sXorRotateRight16Chip), Blake2sXorRotate16(Blake2sXorRotate16Chip), // based on sha-extend Blake2sAdd2(Blake2sAdd2Chip), Blake2sAdd3(Blake2sAdd3Chip), Blake2sXorRotateRight12(Blake2sXorRotateRight12Chip), + Blake2sXorRotateRight8(Blake2sXorRotateRight8Chip), } impl RiscvAir { @@ -211,6 +213,11 @@ impl RiscvAir { blake_2s_xor_rotate_right_12, )); + let blake_2s_xor_rotate_right_8 = Blake2sXorRotateRight8Chip::default(); + chips.push(RiscvAir::Blake2sXorRotateRight8( + blake_2s_xor_rotate_right_8, + )); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index c7fae7c72..d9b77afba 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -3,12 +3,14 @@ mod add_3; mod xor_rotate_16; // based on sha-extend mod xor_rotate_right_12; mod xor_rotate_right_16; +mod xor_rotate_right_8; pub use add_2::*; pub use add_3::*; pub use xor_rotate_16::*; // based on sha-extend pub use xor_rotate_right_12::*; pub use xor_rotate_right_16::*; +pub use xor_rotate_right_8::*; #[cfg(test)] mod tests { diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs new file mode 100644 index 000000000..101a9673a --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs @@ -0,0 +1,357 @@ +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +const R_3: u32 = 8; + +#[derive(Default)] +pub struct Blake2sXorRotateRight8Chip; + +impl Blake2sXorRotateRight8Chip { + pub fn new() -> Self { + Blake2sXorRotateRight8Chip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sXorRotateRight8Event { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +impl Syscall for Blake2sXorRotateRight8Chip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 4); + + let xor = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| a ^ b) + .collect::>(); + + let rotate_right = xor + .into_iter() + .map(|xor_i| xor_i.rotate_right(R_3)) + .collect::>(); + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); + + ctx.record_mut() + .blake2s_xor_rotate_right_8_events + .push(Blake2sXorRotateRight8Event { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sXorRotateRight8Cols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 4], + pub b: [MemoryReadCols; 4], + + pub xor: [XorOperation; 4], + pub rotate_right: [FixedRotateRightOperation; 4], +} + +impl BaseAir for Blake2sXorRotateRight8Chip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sXorRotateRight8Chip { + type Events = &'a [Blake2sXorRotateRight8Event]; +} + +impl MachineAir for Blake2sXorRotateRight8Chip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sXorRotateRight8Chip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sXorRotateRight8Cols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + for i in 0..4usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + + let a = event.a_reads_writes[i].value; + let b = event.b_reads[i].value; + let xor = cols.xor[i].populate(output, shard, event.channel, a, b); + assert_eq!(a ^ b, xor); + + let rotate_right = + cols.rotate_right[i].populate(output, shard, event.channel, xor, R_3 as usize); + assert_eq!(xor.rotate_right(R_3), rotate_right); + } + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sXorRotateRight8Cols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_xor_rotate_right_8_events.is_empty() + } +} + +impl Air for Blake2sXorRotateRight8Chip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sXorRotateRight8Cols = (*local).borrow(); + let next: &Blake2sXorRotateRight8Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..4usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_3 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_8_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8 as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_xor_rotate_right_8_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!( + result, + [0x383a06b4, 0x92062c6, 0xd923ed2a, 0x23feaf38].to_vec() + ); + } + + #[test] + fn test_blake2s_xor_rotate_right_8_program() { + setup_logger(); + let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_8_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index cfc4b3ef4..f58116bf6 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -138,6 +138,9 @@ pub mod tests { "../../../tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf" ); + pub const BLAKE2S_XOR_ROTATE_RIGHT_8_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-xor-rotate-right-8/Cargo.lock b/tests/blake2s-xor-rotate-right-8/Cargo.lock new file mode 100644 index 000000000..76e896b8b --- /dev/null +++ b/tests/blake2s-xor-rotate-right-8/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-xor-rotate-right-8-test" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right-8/Cargo.toml b/tests/blake2s-xor-rotate-right-8/Cargo.toml new file mode 100644 index 000000000..82899e0ef --- /dev/null +++ b/tests/blake2s-xor-rotate-right-8/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-xor-rotate-right-8-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..a4271c1948c7a60297340f635de16d5b931fcd57 GIT binary patch literal 25140 zcmeHwdw3MrdH0#?u7oTE!!0(k2SyTC3rQUd?E!;b>Ij5nJ9V4TH7HH}^pO%T;5=!X)W$gdTsx`E<#Q5;7)uDOXusck zW=2|Zvy6(A}rLQT4Vj(56c=N{{g-UK!U54x$GWf26Imu{Wk`f|qTRtWBt>-Pe-M(6jJ z0HZs#{Ud7_d*o4_-!stcW!!`pwg3F-rb>Ff^5W$HN{rR#SB#a;!Ykd>KgVsX=udBd zqQIXh@FxoVi2{G3!2g#Nm=0sOo<*6-R57|tVbXDhna`eKR%|NM)WM{tOlAF3)DaEF zd3}U2U+hePo@Tn5X|N+Ku68rclg~Q;=IDr7aVE19FhjtNZ_QKBIv)eP@=Qi2V3y}` zX3%%dV0v8b2xu2e(Ec>@sb>P(#$!o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(DD4+u+B>GoPwM5vMY~&$ z63_pI=g)B8h1>BHLY$gd_SLriSV^?gSHWXpq6Bz43cToqJ?8(~yUnj{;i zH}vH?dkf=`{vO0lHiLM9F5zqUGvN_IxFtj6F#4OmmETMziJ$1AdJAzs1Xw-+aM4@> zxOY95OfJQfEzQ)Iw&3p#%);<*f>IJ7g-f8R?aeoNd6bUa&GXqUmx80Zi^n_`xNXfnCoS)Y%i zaRBx1_-D)oZE4(88tVX6p!{W&Z??y|@1azBpq%DIHZSX6#@3qf+XvVTz$)>MemQ*! z{vE(80Vn- zCL?$!n%+a@c;)j)*}EtsS#a^m#_I{dH@^xx6H_eB>=3RYSk(SJ>Yezh!^_TmXzpGx zSTEp3c&CeCGXeWKV1zSW)IJ}ubASa1kV21p0MGi5Wb%0%uBXzY5@q{QCfoDPx^lj) zD32gV_qyG7bnS>19Vjb({pvEp>1C9iN0}o>_oeb4mA{4Z`ZvbfrjAQ<8Af^bsqwTR z_!I?m2fPFCM1NO47Xp3=a5Uo=(I^1eZoo29V5yrUg@5h={1L!QX$)M1%a;J_0F2}9 z!0G`z1ei-3!lMq<{{_Cw*TO$-*3BA(iR5rKQhuSJC@(*+@&Uu6;NR|9IufrFwy%hG%7jZbNmW zxseIe@G5614I6!h)rIv1Yc>?t=QEavEJ72@YpAP)tIhJlRcqEYAlhMhjW(chZDS+L z2|S^`P49|C3;itw-_6 zFSnkKFY24>?R!*byHRfz-rdU`Hx~f6UawPcvs=k2qt6AnX Date: Mon, 16 Sep 2024 18:57:11 +0300 Subject: [PATCH 14/30] feat: Syscall for xor_right_rotate_7 computation --- core/src/runtime/record.rs | 24 +- core/src/runtime/syscall.rs | 16 +- core/src/stark/air.rs | 8 +- core/src/syscall/precompiles/blake2s/mod.rs | 2 + .../precompiles/blake2s/xor_rotate_right_7.rs | 357 ++++++++++++ core/src/utils/programs.rs | 3 + tests/blake2s-xor-rotate-right-7/Cargo.lock | 539 ++++++++++++++++++ tests/blake2s-xor-rotate-right-7/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25140 bytes tests/blake2s-xor-rotate-right-7/src/main.rs | 13 + .../syscalls/blake2s_xor_rotate_right_7.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 3 + zkvm/precompiles/src/lib.rs | 5 +- 13 files changed, 992 insertions(+), 5 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs create mode 100644 tests/blake2s-xor-rotate-right-7/Cargo.lock create mode 100644 tests/blake2s-xor-rotate-right-7/Cargo.toml create mode 100755 tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-xor-rotate-right-7/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_7.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index ea5cab2c9..e636402ce 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -13,8 +13,8 @@ use crate::stark::MachineRecord; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, Blake2sXorRotate16Chip, Blake2sXorRotate16Event, Blake2sXorRotateRight12Chip, Blake2sXorRotateRight12Event, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, Blake2sXorRotateRight8Chip, - Blake2sXorRotateRight8Event, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, Blake2sXorRotateRight7Chip, + Blake2sXorRotateRight7Event, Blake2sXorRotateRight8Chip, Blake2sXorRotateRight8Event, }; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; @@ -138,6 +138,7 @@ pub struct ExecutionRecord { pub blake2s_add_3_events: Vec, pub blake2s_xor_rotate_right_12_events: Vec, pub blake2s_xor_rotate_right_8_events: Vec, + pub blake2s_xor_rotate_right_7_events: Vec, pub memory_initialize_events: Vec, @@ -368,6 +369,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_xor_rotate_right_7_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -544,6 +551,11 @@ impl MachineRecord for ExecutionRecord { self.blake2s_xor_rotate_right_8_events.len(), ); + stats.insert( + "blake2s_xor_rotate_right_7_events".to_string(), + self.blake2s_xor_rotate_right_7_events.len(), + ); + stats } @@ -602,6 +614,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.blake2s_xor_rotate_right_12_events); self.blake2s_xor_rotate_right_8_events .append(&mut other.blake2s_xor_rotate_right_8_events); + self.blake2s_xor_rotate_right_7_events + .append(&mut other.blake2s_xor_rotate_right_7_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -967,6 +981,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_xor_rotate_right_7 events + first.blake2s_xor_rotate_right_7_events = take(&mut self.blake2s_xor_rotate_right_7_events); + for (i, event) in first.blake2s_xor_rotate_right_7_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index e07384a2a..89b098e23 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -8,7 +8,7 @@ use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight8Chip, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, Blake2sXorRotateRight8Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; @@ -131,6 +131,7 @@ pub enum SyscallCode { BLAKE_2S_XOR_ROTATE_RIGHT_12 = 0x00_01_01_EA, BLAKE_2S_XOR_ROTATE_RIGHT_8 = 0x00_01_01_EB, + BLAKE_2S_XOR_ROTATE_RIGHT_7 = 0x00_01_01_EC, } impl SyscallCode { @@ -173,6 +174,7 @@ impl SyscallCode { 0x00_01_01_CF => SyscallCode::BLAKE_2S_ADD_3, 0x00_01_01_EA => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, 0x00_01_01_EB => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, + 0x00_01_01_EC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7, _ => panic!("invalid syscall number: {}", value), } } @@ -441,6 +443,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sXorRotateRight8Chip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7, + Arc::new(Blake2sXorRotateRight7Chip::new()), + ); + syscall_map } @@ -587,6 +594,13 @@ mod tests { sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_8 ) } + + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7 => { + assert_eq!( + code as u32, + sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_7 + ) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 1335ce915..e8ba4907c 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -5,7 +5,7 @@ use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; use crate::syscall::precompiles::blake2s::{ Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight8Chip, + Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, Blake2sXorRotateRight8Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; @@ -118,6 +118,7 @@ pub enum RiscvAir { Blake2sAdd3(Blake2sAdd3Chip), Blake2sXorRotateRight12(Blake2sXorRotateRight12Chip), Blake2sXorRotateRight8(Blake2sXorRotateRight8Chip), + Blake2sXorRotateRight7(Blake2sXorRotateRight7Chip), } impl RiscvAir { @@ -218,6 +219,11 @@ impl RiscvAir { blake_2s_xor_rotate_right_8, )); + let blake_2s_xor_rotate_right_7 = Blake2sXorRotateRight7Chip::default(); + chips.push(RiscvAir::Blake2sXorRotateRight7( + blake_2s_xor_rotate_right_7, + )); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index d9b77afba..2d5a55ed8 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -3,6 +3,7 @@ mod add_3; mod xor_rotate_16; // based on sha-extend mod xor_rotate_right_12; mod xor_rotate_right_16; +mod xor_rotate_right_7; mod xor_rotate_right_8; pub use add_2::*; @@ -10,6 +11,7 @@ pub use add_3::*; pub use xor_rotate_16::*; // based on sha-extend pub use xor_rotate_right_12::*; pub use xor_rotate_right_16::*; +pub use xor_rotate_right_7::*; pub use xor_rotate_right_8::*; #[cfg(test)] diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs new file mode 100644 index 000000000..387dc7e5f --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs @@ -0,0 +1,357 @@ +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +const R_4: u32 = 7; + +#[derive(Default)] +pub struct Blake2sXorRotateRight7Chip; + +impl Blake2sXorRotateRight7Chip { + pub fn new() -> Self { + Blake2sXorRotateRight7Chip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sXorRotateRight7Event { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +impl Syscall for Blake2sXorRotateRight7Chip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let a = ctx.slice_unsafe(a_ptr, 4); + let (b_reads, b) = ctx.mr_slice(b_ptr, 4); + + let xor = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| a ^ b) + .collect::>(); + + let rotate_right = xor + .into_iter() + .map(|xor_i| xor_i.rotate_right(R_4)) + .collect::>(); + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); + + ctx.record_mut() + .blake2s_xor_rotate_right_7_events + .push(Blake2sXorRotateRight7Event { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sXorRotateRight7Cols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 4], + pub b: [MemoryReadCols; 4], + + pub xor: [XorOperation; 4], + pub rotate_right: [FixedRotateRightOperation; 4], +} + +impl BaseAir for Blake2sXorRotateRight7Chip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sXorRotateRight7Chip { + type Events = &'a [Blake2sXorRotateRight7Event]; +} + +impl MachineAir for Blake2sXorRotateRight7Chip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sXorRotateRight7Chip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sXorRotateRight7Cols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + for i in 0..4usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + + let a = event.a_reads_writes[i].value; + let b = event.b_reads[i].value; + let xor = cols.xor[i].populate(output, shard, event.channel, a, b); + assert_eq!(a ^ b, xor); + + let rotate_right = + cols.rotate_right[i].populate(output, shard, event.channel, xor, R_4 as usize); + assert_eq!(xor.rotate_right(R_4), rotate_right); + } + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sXorRotateRight7Cols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_xor_rotate_right_7_events.is_empty() + } +} + +impl Air for Blake2sXorRotateRight7Chip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sXorRotateRight7Cols = (*local).borrow(); + let next: &Blake2sXorRotateRight7Cols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..4usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b. + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i].value(), + *local.b[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_4 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_7_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7 as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_xor_rotate_right_7_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..4 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!( + result, + [0x70740d68, 0x1240c58c, 0xb247da55, 0x47fd5e70].to_vec() + ); + } + + #[test] + fn test_blake2s_xor_rotate_right_7_program() { + setup_logger(); + let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_7_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index f58116bf6..6cfcd9cf4 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -141,6 +141,9 @@ pub mod tests { pub const BLAKE2S_XOR_ROTATE_RIGHT_8_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_XOR_ROTATE_RIGHT_7_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-xor-rotate-right-7/Cargo.lock b/tests/blake2s-xor-rotate-right-7/Cargo.lock new file mode 100644 index 000000000..78535c876 --- /dev/null +++ b/tests/blake2s-xor-rotate-right-7/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-xor-rotate-right-7-test" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right-7/Cargo.toml b/tests/blake2s-xor-rotate-right-7/Cargo.toml new file mode 100644 index 000000000..a50846983 --- /dev/null +++ b/tests/blake2s-xor-rotate-right-7/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-xor-rotate-right-7-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..ffbd8e740a3cf08895ea2de803b385e433165ae8 GIT binary patch literal 25140 zcmeHweRx&XmG?fM_a?*;IDA#99ym$(G$gr6ZeX-?qg;>u5WXkJq-AiU|SJ-1oQk zIVZV6K-=kG@6-D{$8*j)`(y33*ZS?X*51KKf~!{ug23FL$SyE?yX^*@72$rU!v0dk zbmn36SvpH&DoFIL2qo$IIiBf~ool=`dJ@<)+~}h3EQ=`kdFj&mrLSa+E`{jMcl~bA z*6IBE5@>X#)_-^%V-G)~^J^BWy@ZSSqWWJr-Bd}BSN`~S5GBUy^DD-`&cP#H)IR5J z{L`PF{v?4vN#IWs_>%6=ptjhFP)cOjC!FnlhaY zOjAcSEY2GvjQL_`0(3Xi)l7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&H&w`?=?VRC(Y#jfd8}tbZM!YvOMoXtO}8 z#53CE@+JDWL9Yaz^b>ThSM+?sp*!QrUv2lp+kXe&9!^Y@;V@`5pwXH@KjI?;dKF12 zNB!xb)q{2y6-w!^6!cD_+v5tj{mn+PwfOeKW69)WcAW__q3=!je%o=3&91B8j~BQi|o7ox)WNi|U_8xf4He zblDjXjok|c>jS+A&-5eOY|wrV8u3g&s-F+qInV+`NRh`~plAJOGWncM*Hh(DiEsPy zO}59Ib>(b*G=u0 z#xjEM*{3GTg6Pu}j2-k&Jd^xg`&{1C8W?x_lnK1KMuT?y+gy4yf#pLH}V& zeHza@puGm#n<-`a_(9+I(=lw|OsqiI0cX$n?>R&#-MSkXBREqxG1^UCFmr@`2 z5ief?trIlPw?nH3?GR|LY>1Cm&|U^Df@h3x%+~jVzWDznlZ=$#>5Iz02>P`D8neAI z4EQ1F%il^Ss~kOZ`6gb@;oD5*q78+mW`2H2sJL`#@vQ~h5W*L1bBh%CeT4D47p&V(Rw0{*l<}f~fibSAd*R zeI>ovKi6(Nc%^a_OY{H7z};9UxKm`8BM74(`Rr7Vraw}pv&aLmS>8AZ__^(U3eQvy z&}RQX3D(&-idX(~%jtNdwyE5{M|8Fu<>uho{ki?-g5Z|xbINUX3pwBDbrCM=7eePh sYHz>uOgH*Q7wJ0stjCT2@+&6xOJ(S{0vGY-{=QHFf5Lsi-7WY30N8>U$N&HU literal 0 HcmV?d00001 diff --git a/tests/blake2s-xor-rotate-right-7/src/main.rs b/tests/blake2s-xor-rotate-right-7/src/main.rs new file mode 100644 index 000000000..800270450 --- /dev/null +++ b/tests/blake2s-xor-rotate-right-7/src/main.rs @@ -0,0 +1,13 @@ +#![no_main] +sphinx_zkvm::entrypoint!(main); + +use sphinx_zkvm::syscalls::blake2s_xor_rotate_right_7::syscall_blake2s_xor_rotate_right_7; + +pub fn main() { + let mut a: [u32; 4] = [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a]; + let b: [u32; 4] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; + + syscall_blake2s_xor_rotate_right_7(a.as_mut_ptr(), b.as_ptr()); + + assert_eq!(a, [0x70740d68, 0x1240c58c, 0xb247da55, 0x47fd5e70]); +} diff --git a/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_7.rs b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_7.rs new file mode 100644 index 000000000..be2aee1fa --- /dev/null +++ b/zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_7.rs @@ -0,0 +1,19 @@ +#[cfg(target_os = "zkvm")] +use core::arch::asm; + +#[allow(unused_variables)] +#[no_mangle] +pub extern "C" fn syscall_blake2s_xor_rotate_right_7(left: *mut u32, right: *const u32) { + #[cfg(target_os = "zkvm")] + unsafe { + asm!( + "ecall", + in("t0") crate::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_7, + in("a0") left, + in("a1") right + ); + } + + #[cfg(not(target_os = "zkvm"))] + unreachable!() +} diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 0a4737fb5..2ca7703bd 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -18,6 +18,7 @@ pub mod blake2s_add_3; pub mod blake2s_xor_rotate_16; pub mod blake2s_xor_rotate_right_12; pub mod blake2s_xor_rotate_right_16; +pub mod blake2s_xor_rotate_right_7; pub mod blake2s_xor_rotate_right_8; pub use bls12_381::*; @@ -125,3 +126,5 @@ pub const BLAKE_2S_ADD_3: u32 = 0x00_01_01_CF; pub const BLAKE_2S_XOR_ROTATE_RIGHT_12: u32 = 0x00_01_01_EA; pub const BLAKE_2S_XOR_ROTATE_RIGHT_8: u32 = 0x00_01_01_EB; + +pub const BLAKE_2S_XOR_ROTATE_RIGHT_7: u32 = 0x00_01_01_EC; diff --git a/zkvm/precompiles/src/lib.rs b/zkvm/precompiles/src/lib.rs index b0112fd9b..a99fa41d8 100644 --- a/zkvm/precompiles/src/lib.rs +++ b/zkvm/precompiles/src/lib.rs @@ -47,8 +47,11 @@ extern "C" { pub fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u8; pub fn syscall_bls12381_g2_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g2_double(p: *mut u32); - pub fn syscall_blake2s_xor_rotate_right(left: *mut u32, right: *const u32); pub fn syscall_blake2s_xor_rotate_16(w: *mut u32); pub fn syscall_blake2s_add_2(left: *mut u32, right: *const u32); pub fn syscall_blake2s_add_3(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_xor_rotate_right_16(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_xor_rotate_right_12(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_xor_rotate_right_8(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_xor_rotate_right_7(left: *mut u32, right: *const u32); } From 892bafb74ded0d6e9449f7ab9742e2b4920913b5 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Tue, 17 Sep 2024 21:25:21 +0300 Subject: [PATCH 15/30] feat: Add QuarterRound syscall --- core/src/runtime/record.rs | 23 +- core/src/runtime/syscall.rs | 16 +- core/src/stark/air.rs | 9 +- core/src/syscall/precompiles/blake2s/mod.rs | 2 + .../precompiles/blake2s/quarter_round.rs | 580 ++++++++++++++++++ core/src/utils/programs.rs | 3 + tests/blake2s-quarter-round/Cargo.lock | 539 ++++++++++++++++ tests/blake2s-quarter-round/Cargo.toml | 8 + .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25476 bytes tests/blake2s-quarter-round/src/main.rs | 13 + .../src/syscalls/blake2s_quarter_round.rs | 19 + zkvm/entrypoint/src/syscalls/mod.rs | 3 + zkvm/precompiles/src/lib.rs | 2 + 13 files changed, 1212 insertions(+), 5 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/quarter_round.rs create mode 100644 tests/blake2s-quarter-round/Cargo.lock create mode 100644 tests/blake2s-quarter-round/Cargo.toml create mode 100755 tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-quarter-round/src/main.rs create mode 100644 zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index e636402ce..85748a803 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -11,7 +11,8 @@ use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, Blake2sXorRotate16Chip, + Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, + Blake2sQuarterRound2xChip, Blake2sQuarterRound2xEvent, Blake2sXorRotate16Chip, Blake2sXorRotate16Event, Blake2sXorRotateRight12Chip, Blake2sXorRotateRight12Event, Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, Blake2sXorRotateRight7Chip, Blake2sXorRotateRight7Event, Blake2sXorRotateRight8Chip, Blake2sXorRotateRight8Event, @@ -139,6 +140,7 @@ pub struct ExecutionRecord { pub blake2s_xor_rotate_right_12_events: Vec, pub blake2s_xor_rotate_right_8_events: Vec, pub blake2s_xor_rotate_right_7_events: Vec, + pub blake2s_quarter_round_2x_events: Vec, pub memory_initialize_events: Vec, @@ -375,6 +377,12 @@ impl EventLens for ExecutionRecord { } } +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_quarter_round_2x_events + } +} + pub struct ShardingConfig { pub shard_size: usize, pub add_len: usize, @@ -556,6 +564,11 @@ impl MachineRecord for ExecutionRecord { self.blake2s_xor_rotate_right_7_events.len(), ); + stats.insert( + "blake2s_quarter_round_2x_events".to_string(), + self.blake2s_quarter_round_2x_events.len(), + ); + stats } @@ -616,6 +629,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.blake2s_xor_rotate_right_8_events); self.blake2s_xor_rotate_right_7_events .append(&mut other.blake2s_xor_rotate_right_7_events); + self.blake2s_quarter_round_2x_events + .append(&mut other.blake2s_quarter_round_2x_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -987,6 +1002,12 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } + // blake2s_quarter_round_2x events + first.blake2s_quarter_round_2x_events = take(&mut self.blake2s_quarter_round_2x_events); + for (i, event) in first.blake2s_quarter_round_2x_events.iter().enumerate() { + self.nonce_lookup.insert(event.lookup_id, i as u32); + } + // Put MemoryInit / MemoryFinalize events in the last shard. let last = shards.last_mut().unwrap(); last.memory_initialize_events diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 89b098e23..40c29982a 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -7,8 +7,9 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, Blake2sXorRotateRight8Chip, + Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sQuarterRound2xChip, Blake2sXorRotate16Chip, + Blake2sXorRotateRight12Chip, Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, + Blake2sXorRotateRight8Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; @@ -132,6 +133,7 @@ pub enum SyscallCode { BLAKE_2S_XOR_ROTATE_RIGHT_12 = 0x00_01_01_EA, BLAKE_2S_XOR_ROTATE_RIGHT_8 = 0x00_01_01_EB, BLAKE_2S_XOR_ROTATE_RIGHT_7 = 0x00_01_01_EC, + BLAKE_2S_QUARTER_ROUND = 0x00_01_01_ED, } impl SyscallCode { @@ -175,6 +177,7 @@ impl SyscallCode { 0x00_01_01_EA => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, 0x00_01_01_EB => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, 0x00_01_01_EC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7, + 0x00_01_01_ED => SyscallCode::BLAKE_2S_QUARTER_ROUND, _ => panic!("invalid syscall number: {}", value), } } @@ -448,6 +451,11 @@ pub fn default_syscall_map() -> HashMap> { Arc::new(Blake2sXorRotateRight7Chip::new()), ); + syscall_map.insert( + SyscallCode::BLAKE_2S_QUARTER_ROUND, + Arc::new(Blake2sQuarterRound2xChip::new()), + ); + syscall_map } @@ -601,6 +609,10 @@ mod tests { sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_7 ) } + + SyscallCode::BLAKE_2S_QUARTER_ROUND => { + assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_QUARTER_ROUND) + } } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index e8ba4907c..cfbc76aaf 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -4,8 +4,9 @@ use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sXorRotate16Chip, Blake2sXorRotateRight12Chip, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, Blake2sXorRotateRight8Chip, + Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sQuarterRound2xChip, Blake2sXorRotate16Chip, + Blake2sXorRotateRight12Chip, Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, + Blake2sXorRotateRight8Chip, }; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; @@ -119,6 +120,7 @@ pub enum RiscvAir { Blake2sXorRotateRight12(Blake2sXorRotateRight12Chip), Blake2sXorRotateRight8(Blake2sXorRotateRight8Chip), Blake2sXorRotateRight7(Blake2sXorRotateRight7Chip), + Blake2sQuarterRound2x(Blake2sQuarterRound2xChip), } impl RiscvAir { @@ -224,6 +226,9 @@ impl RiscvAir { blake_2s_xor_rotate_right_7, )); + let blake_2s_quarter_round_2x = Blake2sQuarterRound2xChip::default(); + chips.push(RiscvAir::Blake2sQuarterRound2x(blake_2s_quarter_round_2x)); + chips } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 2d5a55ed8..efe9f7126 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,5 +1,6 @@ mod add_2; mod add_3; +mod quarter_round; mod xor_rotate_16; // based on sha-extend mod xor_rotate_right_12; mod xor_rotate_right_16; @@ -8,6 +9,7 @@ mod xor_rotate_right_8; pub use add_2::*; pub use add_3::*; +pub use quarter_round::*; pub use xor_rotate_16::*; // based on sha-extend pub use xor_rotate_right_12::*; pub use xor_rotate_right_16::*; diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs new file mode 100644 index 000000000..c5a5ba86c --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -0,0 +1,580 @@ +use crate::bytes::event::ByteRecord; +use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; +use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, +}; +use core::borrow::{Borrow, BorrowMut}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use serde::Deserialize; +use serde::Serialize; +use sphinx_derive::AlignedBorrow; +use std::mem::size_of; + +const R_1: u32 = 16; +const R_2: u32 = 12; +//const R_3: u32 = 8; +//const R_4: u32 = 7; + +#[derive(Default)] +pub struct Blake2sQuarterRound2xChip; + +impl Blake2sQuarterRound2xChip { + pub fn new() -> Self { + Blake2sQuarterRound2xChip + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sQuarterRound2xEvent { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +impl Syscall for Blake2sQuarterRound2xChip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || + let mut a = ctx.slice_unsafe(a_ptr, 16); + let mut a_clone = a.clone(); + + // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || + let (b_reads, b) = ctx.mr_slice(b_ptr, 16); + + //for (rot_1, rot_2) in [(R_1, R_2), (R_3, R_4)].into_iter() { + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[0..4].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_1); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_2); + } + a_clone = a.clone(); + //} + + ctx.clk += 1; + + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); + + ctx.record_mut() + .blake2s_quarter_round_2x_events + .push(Blake2sQuarterRound2xEvent { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +struct Blake2sQuarterRound2xCols { + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub a: [MemoryWriteCols; 16], + pub b: [MemoryReadCols; 16], + + pub add: [Add4Operation; 8], + pub xor: [XorOperation; 8], + pub rotate_right: [FixedRotateRightOperation; 8], +} + +impl BaseAir for Blake2sQuarterRound2xChip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl<'a> WithEvents<'a> for Blake2sQuarterRound2xChip { + type Events = &'a [Blake2sQuarterRound2xEvent]; +} + +impl MachineAir for Blake2sQuarterRound2xChip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sQuarterRound2xChip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sQuarterRound2xCols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + // populate all v, m, 0 + for i in 0..16usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + } + + // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || + // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || + for i in 0..4usize { + // 1x + let v0 = event.a_reads_writes[i].value; + let v1 = event.a_reads_writes[i + 4].value; + let v2 = event.a_reads_writes[i + 8].value; + let v3 = event.a_reads_writes[i + 12].value; + let m1 = event.b_reads[i].value; + //let m2 = event.b_reads[i + 4].value; + let zero1 = event.b_reads[i + 8].value; + let zero2 = event.b_reads[i + 12].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + let v0_new = cols.add[i].populate(output, shard, event.channel, v0, v1, m1, zero1); + assert_eq!(v0 + v1 + m1 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0); + let v3_new = + cols.rotate_right[i].populate(output, shard, event.channel, temp, R_1 as usize); + assert_eq!((v3 ^ v0).rotate_right(R_1), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + let v2_new = + cols.add[i + 4].populate(output, shard, event.channel, v2, v3, zero1, zero2); + assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2); + let v1_new = cols.rotate_right[i + 4].populate( + output, + shard, + event.channel, + temp, + R_2 as usize, + ); + assert_eq!((v1 ^ v2).rotate_right(R_2), v1_new); + } + + /* + // 2x + let v0 = v0_new; + let v1 = v1_new; + let v2 = v2_new; + let v3 = v3_new; + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + let v0_new = cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); + assert_eq!(v0 + v1 + m2 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); + let v3_new = cols.rotate_right[i + 8].populate(output, shard, event.channel, temp, R_3 as usize); + assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + let v2_new = cols.add[i + 12].populate(output, shard, event.channel, v2, v3, zero1, zero2); + assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + let temp = cols.xor[i + 12].populate(output, shard, event.channel, v1, v2); + let v1_new = cols.rotate_right[i + 12].populate(output, shard, event.channel, temp, R_4 as usize); + assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); + }*/ + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sQuarterRound2xCols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_quarter_round_2x_events.is_empty() + } +} + +impl Air for Blake2sQuarterRound2xChip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sQuarterRound2xCols = (*local).borrow(); + let next: &Blake2sQuarterRound2xCols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..16usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + } + + for i in 0..4usize { + // 1x + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + *local.a[i].value(), // v0 + *local.a[i + 4].value(), // v1 + *local.b[i].value(), // m1 + *local.b[i + 8].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i + 12].value(), + *local.a[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_1 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + *local.a[i + 8].value(), // v2 + *local.a[i + 12].value(), // v3 + *local.b[i + 8].value(), // zero1 + *local.b[i + 12].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 4], + ); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i + 4].value(), + *local.a[i + 8].value(), + local.xor[i + 4], + local.shard, + &local.channel, + local.is_real, + ); + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 4].value, + R_2 as usize, + local.rotate_right[i + 4], + local.shard, + &local.channel, + local.is_real, + ); + + /* + // 2x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + *local.a[i].value(), // v0 + *local.a[i + 4].value(), // v1 + *local.b[i].value(), // m1 + *local.b[i + 8].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i + 12].value(), + *local.a[i].value(), + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_1 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + *local.a[i + 8].value(), // v2 + *local.a[i + 12].value(), // v3 + *local.b[i + 8].value(), // zero1 + *local.b[i + 12].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 4], + ); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i + 4].value(), + *local.a[i + 8].value(), + local.xor[i + 4], + local.shard, + &local.channel, + local.is_real, + ); + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 4].value, + R_2 as usize, + local.rotate_right[i + 4], + local.shard, + &local.channel, + local.is_real, + );*/ + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_QUARTER_ROUND.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} + +#[cfg(test)] +mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::utils::tests::BLAKE2S_QUARTER_ROUND_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 16]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_QUARTER_ROUND as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_quarter_round_precompile() { + setup_logger(); + + // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || + // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || + + let a_ptr = 100100100; + let b_ptr = 200200200; + let program = risc_v_program( + a_ptr, + b_ptr, + [ + 0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, + 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, + 0xe07c2654, 0x5be0cd19, + ], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..16 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!( + result, + [ + 0xbc1738c6, 0x566d1711, 0x5bf2cd1d, 0x130c253, 0x1ff85cd8, 0x361a0001, 0x6ab383b7, + 0xd13ef7a9, 0xd4c3d380, 0x3b057bed, 0x27b8af00, 0xb49a500a, 0x6ab9ed19, 0x7f9dcd68, + 0xeb49bb8e, 0xf4a5ad0, + ] + .to_vec() + ); + } + + #[test] + fn test_blake2s_quarter_round_program() { + setup_logger(); + let program = Program::from(BLAKE2S_QUARTER_ROUND_ELF); + run_test(program).unwrap(); + } +} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index 6cfcd9cf4..9b9ba7e2e 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -144,6 +144,9 @@ pub mod tests { pub const BLAKE2S_XOR_ROTATE_RIGHT_7_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_QUARTER_ROUND_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf"); + pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); } diff --git a/tests/blake2s-quarter-round/Cargo.lock b/tests/blake2s-quarter-round/Cargo.lock new file mode 100644 index 000000000..993d245f6 --- /dev/null +++ b/tests/blake2s-quarter-round/Cargo.lock @@ -0,0 +1,539 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2s-quarter_round-test" +version = "0.1.0" +dependencies = [ + "sphinx-zkvm", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" +dependencies = [ + "typenum", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signature", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "sphinx-precompiles" +version = "1.0.0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "hybrid-array", + "k256", + "serde", +] + +[[package]] +name = "sphinx-zkvm" +version = "1.0.0" +dependencies = [ + "bincode", + "cfg-if", + "getrandom", + "k256", + "lazy_static", + "libm", + "once_cell", + "rand", + "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", + "sphinx-precompiles", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-quarter-round/Cargo.toml b/tests/blake2s-quarter-round/Cargo.toml new file mode 100644 index 000000000..be741f691 --- /dev/null +++ b/tests/blake2s-quarter-round/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +[package] +name = "blake2s-quarter_round-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 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XH@~SO=&YLx9}|SPkCMFQ+fTp8>oZaNUVZ)9TT9I$%!&wvsBPjaLEqTLib~6>!I!foiv*%zG@E+-5ylM%cVO;=JmUith{roWU-k}SCRI}TWB8mtzuvw*!xFwl+Kejl)>-%KV+?&u=eZopmy%%wTOkm_MC14i^fTfPp@ z0rm=Dt8EyU1FHK9;NG8&wx{{L2UreZZ>81c^9THOz?a!@K2I8BvWkCxp29Vd&VNNH zdmd%f-d%qhcO~G@0bW6HTm<_Iz}^Ck4293kG!2s);fIV;!U`mMcK>mB$Ih~Pru&$n$ADnr~Y+(SFMA8 z+NPWJ2-(QtYN7bCxD;Vi`NH}05eAnOmE$f$=vzF0eMyB`R8$@+t5{sNu=rkt+{O30 zRf_$-lH#($;xa!YAIcoDI*b4nJMtt(&bt68t3Y3ahEl7%IubJ?wR z4R?j%AK!ZGGQHSO!?Q|4x4Evx+{6URRmeF?^Cn+OT}e~%+KnYmMT`|9>ThL*&5bp1 zwOL`fcJ2CRL_4go#RjyjYiVJH{2#M%BZVobOdS@&XKt=rhpYk0TWaA%w1(DUh|hcx z+35zU!Gt<)@HbbS1h9QhdU|kEJ&J3esn!|&-wirBMb1Skj4txosU9u=D|I@1<xpMe9yi+}>Hv9j0sJ8VeKKbR=)A2=pQ@yhh_`}tV&BVKVx#Jc9;MU7&x9e?j zD>-HKIUhHT3!?Lj`rGfk(}T+BCSJ#wO?dDt5*j-$)uC%SZo literal 0 HcmV?d00001 diff --git a/tests/blake2s-quarter-round/src/main.rs b/tests/blake2s-quarter-round/src/main.rs new file mode 100644 index 000000000..d9fd8abd3 --- /dev/null +++ b/tests/blake2s-quarter-round/src/main.rs @@ -0,0 +1,13 @@ +#![no_main] +sphinx_zkvm::entrypoint!(main); + +use sphinx_zkvm::syscalls::blake2s_quarter_round::syscall_blake2s_quarter_round; + +pub fn main() { + let mut a: [u32; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + let b: [u32; 16] = [10, 20, 30, 40, 10, 20, 30, 40, 0, 0, 0, 0, 0, 0, 0, 0]; + + syscall_blake2s_quarter_round(a.as_mut_ptr(), b.as_ptr()); + + assert_eq!(a, [0x10, 0x1c, 0x28, 0x34, 0xc00000, 0xc00000, 0xc00000, 0x400000, 0x16, 0x18, 0x1a, 0x1c, 0xc0000, 0xc0000, 0xc0000, 0x140000]); +} diff --git a/zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs b/zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs new file mode 100644 index 000000000..0ff00113b --- /dev/null +++ b/zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs @@ -0,0 +1,19 @@ +#[cfg(target_os = "zkvm")] +use core::arch::asm; + +#[allow(unused_variables)] +#[no_mangle] +pub extern "C" fn syscall_blake2s_quarter_round(left: *mut u32, right: *const u32) { + #[cfg(target_os = "zkvm")] + unsafe { + asm!( + "ecall", + in("t0") crate::syscalls::BLAKE_2S_QUARTER_ROUND, + in("a0") left, + in("a1") right + ); + } + + #[cfg(not(target_os = "zkvm"))] + unreachable!() +} diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 2ca7703bd..518870242 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -15,6 +15,7 @@ mod verify; pub mod blake2s_add_2; pub mod blake2s_add_3; +pub mod blake2s_quarter_round; pub mod blake2s_xor_rotate_16; pub mod blake2s_xor_rotate_right_12; pub mod blake2s_xor_rotate_right_16; @@ -128,3 +129,5 @@ pub const BLAKE_2S_XOR_ROTATE_RIGHT_12: u32 = 0x00_01_01_EA; pub const BLAKE_2S_XOR_ROTATE_RIGHT_8: u32 = 0x00_01_01_EB; pub const BLAKE_2S_XOR_ROTATE_RIGHT_7: u32 = 0x00_01_01_EC; + +pub const BLAKE_2S_QUARTER_ROUND: u32 = 0x00_01_01_ED; diff --git a/zkvm/precompiles/src/lib.rs b/zkvm/precompiles/src/lib.rs index a99fa41d8..1c627089a 100644 --- a/zkvm/precompiles/src/lib.rs +++ b/zkvm/precompiles/src/lib.rs @@ -48,10 +48,12 @@ extern "C" { pub fn syscall_bls12381_g2_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g2_double(p: *mut u32); pub fn syscall_blake2s_xor_rotate_16(w: *mut u32); + pub fn syscall_blake2s_add_2(left: *mut u32, right: *const u32); pub fn syscall_blake2s_add_3(left: *mut u32, right: *const u32); pub fn syscall_blake2s_xor_rotate_right_16(left: *mut u32, right: *const u32); pub fn syscall_blake2s_xor_rotate_right_12(left: *mut u32, right: *const u32); pub fn syscall_blake2s_xor_rotate_right_8(left: *mut u32, right: *const u32); pub fn syscall_blake2s_xor_rotate_right_7(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_quarter_round(left: *mut u32, right: *const u32); } From 462e28e3e6a44a0febbd8c479b9da0aaa8f09ab1 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 18 Sep 2024 17:22:35 +0300 Subject: [PATCH 16/30] feat: Update quarter_round syscall to quarter_round_2x --- core/src/runtime/syscall.rs | 13 +- core/src/syscall/precompiles/blake2s/mod.rs | 37 ++++ .../precompiles/blake2s/quarter_round.rs | 164 ++++++++++++------ core/src/utils/programs.rs | 4 +- .../Cargo.lock | 2 +- .../Cargo.toml | 2 +- .../elf/riscv32im-succinct-zkvm-elf | Bin 0 -> 25436 bytes tests/blake2s-quarter-round-2x/src/main.rs | 22 +++ .../elf/riscv32im-succinct-zkvm-elf | Bin 25476 -> 0 bytes tests/blake2s-quarter-round/src/main.rs | 13 -- ...r_round.rs => blake2s_quarter_round_2x.rs} | 4 +- zkvm/entrypoint/src/syscalls/mod.rs | 4 +- 12 files changed, 182 insertions(+), 83 deletions(-) rename tests/{blake2s-quarter-round => blake2s-quarter-round-2x}/Cargo.lock (99%) rename tests/{blake2s-quarter-round => blake2s-quarter-round-2x}/Cargo.toml (75%) create mode 100755 tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf create mode 100644 tests/blake2s-quarter-round-2x/src/main.rs delete mode 100755 tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-quarter-round/src/main.rs rename zkvm/entrypoint/src/syscalls/{blake2s_quarter_round.rs => blake2s_quarter_round_2x.rs} (65%) diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 40c29982a..3d2294103 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -133,7 +133,7 @@ pub enum SyscallCode { BLAKE_2S_XOR_ROTATE_RIGHT_12 = 0x00_01_01_EA, BLAKE_2S_XOR_ROTATE_RIGHT_8 = 0x00_01_01_EB, BLAKE_2S_XOR_ROTATE_RIGHT_7 = 0x00_01_01_EC, - BLAKE_2S_QUARTER_ROUND = 0x00_01_01_ED, + BLAKE_2S_QUARTER_ROUND_2X = 0x00_01_01_ED, } impl SyscallCode { @@ -177,7 +177,7 @@ impl SyscallCode { 0x00_01_01_EA => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, 0x00_01_01_EB => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, 0x00_01_01_EC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7, - 0x00_01_01_ED => SyscallCode::BLAKE_2S_QUARTER_ROUND, + 0x00_01_01_ED => SyscallCode::BLAKE_2S_QUARTER_ROUND_2X, _ => panic!("invalid syscall number: {}", value), } } @@ -452,7 +452,7 @@ pub fn default_syscall_map() -> HashMap> { ); syscall_map.insert( - SyscallCode::BLAKE_2S_QUARTER_ROUND, + SyscallCode::BLAKE_2S_QUARTER_ROUND_2X, Arc::new(Blake2sQuarterRound2xChip::new()), ); @@ -610,8 +610,11 @@ mod tests { ) } - SyscallCode::BLAKE_2S_QUARTER_ROUND => { - assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_QUARTER_ROUND) + SyscallCode::BLAKE_2S_QUARTER_ROUND_2X => { + assert_eq!( + code as u32, + sphinx_zkvm::syscalls::BLAKE_2S_QUARTER_ROUND_2X + ) } } } diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index efe9f7126..11052054f 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -257,4 +257,41 @@ mod tests { vec![0x6ab9ed19, 0x7f9dcd68, 0xeb49bb8e, 0xf4a5ad0] ); } + + #[test] + fn test_blake2s_quarter_round_2x_function() { + let mut v: Vec<[u32; 4]> = vec![ + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], + ]; + let m = [0, 0, 0, 0]; + let rd = 16; + let rb = 12; + + quarter_round(&mut v, rd, rb, m); + + let rd = 8; + let rb = 7; + + quarter_round(&mut v, rd, rb, m); + + assert_eq!( + v[0].to_vec(), + vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc] + ); + assert_eq!( + v[1].to_vec(), + vec![0x408705aa, 0x8d07c52d, 0xb9d6aa3a, 0x88609304] + ); + assert_eq!( + v[2].to_vec(), + vec![0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed] + ); + assert_eq!( + v[3].to_vec(), + vec![0x87b6b678, 0x7af31ada, 0x5a2defeb, 0x2cdd25e3] + ); + } } diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs index c5a5ba86c..e4fb24db7 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -20,8 +20,8 @@ use std::mem::size_of; const R_1: u32 = 16; const R_2: u32 = 12; -//const R_3: u32 = 8; -//const R_4: u32 = 7; +const R_3: u32 = 8; +const R_4: u32 = 7; #[derive(Default)] pub struct Blake2sQuarterRound2xChip; @@ -62,8 +62,8 @@ impl Syscall for Blake2sQuarterRound2xChip { // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || let (b_reads, b) = ctx.mr_slice(b_ptr, 16); - //for (rot_1, rot_2) in [(R_1, R_2), (R_3, R_4)].into_iter() { - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + // 1x (m1, R1, R2) + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) for ((v0, v1), m) in a[0..4] .iter_mut() .zip(a_clone[4..8].iter()) @@ -89,11 +89,39 @@ impl Syscall for Blake2sQuarterRound2xChip { for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { *v1 = (*v1 ^ *v2).rotate_right(R_2); } + + // 2x (m2, R3, R4) + let mut a = a.clone(); // a after 1x quarter_round + let mut a_clone = a.clone(); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[4..8].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } a_clone = a.clone(); - //} - ctx.clk += 1; + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_3); + } + a_clone = a.clone(); + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_4); + } + + ctx.clk += 1; // Write rotate_right to a_ptr. let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); @@ -133,9 +161,9 @@ struct Blake2sQuarterRound2xCols { pub a: [MemoryWriteCols; 16], pub b: [MemoryReadCols; 16], - pub add: [Add4Operation; 8], - pub xor: [XorOperation; 8], - pub rotate_right: [FixedRotateRightOperation; 8], + pub add: [Add4Operation; 8 * 2], + pub xor: [XorOperation; 8 * 2], + pub rotate_right: [FixedRotateRightOperation; 8 * 2], } impl BaseAir for Blake2sQuarterRound2xChip { @@ -189,13 +217,13 @@ impl MachineAir for Blake2sQuarterRound2xChip { // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || for i in 0..4usize { - // 1x + // 1x (m1, R1, R2) let v0 = event.a_reads_writes[i].value; let v1 = event.a_reads_writes[i + 4].value; let v2 = event.a_reads_writes[i + 8].value; let v3 = event.a_reads_writes[i + 12].value; let m1 = event.b_reads[i].value; - //let m2 = event.b_reads[i + 4].value; + let m2 = event.b_reads[i + 4].value; let zero1 = event.b_reads[i + 8].value; let zero2 = event.b_reads[i + 12].value; assert_eq!(zero1, 0); @@ -226,33 +254,52 @@ impl MachineAir for Blake2sQuarterRound2xChip { R_2 as usize, ); assert_eq!((v1 ^ v2).rotate_right(R_2), v1_new); - } - /* - // 2x + // 2x (m2, R3, R4) let v0 = v0_new; let v1 = v1_new; let v2 = v2_new; let v3 = v3_new; - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - let v0_new = cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); - assert_eq!(v0 + v1 + m2 + zero1, v0_new); + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + let v0_new = + cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); + assert_eq!(v0 + v1 + m1 + zero1, v0_new); - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); - let v3_new = cols.rotate_right[i + 8].populate(output, shard, event.channel, temp, R_3 as usize); + let v3_new = cols.rotate_right[i + 8].populate( + output, + shard, + event.channel, + temp, + R_3 as usize, + ); assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 12].populate(output, shard, event.channel, v2, v3, zero1, zero2); + let v2_new = cols.add[i + 4 + 8].populate( + output, + shard, + event.channel, + v2, + v3, + zero1, + zero2, + ); assert_eq!(v2 + v3 + zero1 + zero2, v2_new); - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - let temp = cols.xor[i + 12].populate(output, shard, event.channel, v1, v2); - let v1_new = cols.rotate_right[i + 12].populate(output, shard, event.channel, temp, R_4 as usize); + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) + let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2); + let v1_new = cols.rotate_right[i + 4 + 8].populate( + output, + shard, + event.channel, + temp, + R_4 as usize, + ); assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); - }*/ + } rows.push(row); } @@ -384,6 +431,7 @@ where &local.channel, local.is_real, ); + // Eval RotateRight FixedRotateRightOperation::::eval( builder, @@ -395,38 +443,39 @@ where local.is_real, ); - /* // 2x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, - *local.a[i].value(), // v0 - *local.a[i + 4].value(), // v1 - *local.b[i].value(), // m1 - *local.b[i + 8].value(), // zero1 + local.add[i].value, // v0 after 1x + local.rotate_right[i + 4].value, // v1 after 1x + *local.b[i + 4].value(), // m2 + *local.b[i + 8].value(), // zero1 local.shard, local.channel, local.is_real, - local.add[i], + local.add[i + 8], ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); // Eval XOR XorOperation::::eval( builder, - *local.a[i + 12].value(), - *local.a[i].value(), - local.xor[i], + local.rotate_right[i].value, // v3 after 1x + local.add[i].value, // v0 after 1x + local.xor[i + 8], local.shard, &local.channel, local.is_real, ); + // Eval RotateRight FixedRotateRightOperation::::eval( builder, - local.xor[i].value, - R_1 as usize, - local.rotate_right[i], + local.xor[i + 8].value, + R_3 as usize, + local.rotate_right[i + 8], local.shard, &local.channel, local.is_real, @@ -435,37 +484,38 @@ where // v[2] = v[2].wrapping_add(v[3]); Add4Operation::::eval( builder, - *local.a[i + 8].value(), // v2 - *local.a[i + 12].value(), // v3 - *local.b[i + 8].value(), // zero1 - *local.b[i + 12].value(), // zero2 + local.add[i + 4].value, // v2 after 1x + local.rotate_right[i].value, // v3 after 1x + *local.b[i + 8].value(), // zero1 + *local.b[i + 12].value(), // zero2 local.shard, local.channel, local.is_real, - local.add[i + 4], + local.add[i + 12], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); // Eval XOR XorOperation::::eval( builder, - *local.a[i + 4].value(), - *local.a[i + 8].value(), - local.xor[i + 4], + local.rotate_right[i + 4].value, // v1 after 1x + local.add[i + 4].value, // v2 after 1x + local.xor[i + 12], local.shard, &local.channel, local.is_real, ); + // Eval RotateRight FixedRotateRightOperation::::eval( builder, - local.xor[i + 4].value, - R_2 as usize, - local.rotate_right[i + 4], + local.xor[i + 12].value, + R_4 as usize, + local.rotate_right[i + 12], local.shard, &local.channel, local.is_real, - );*/ + ); } builder.receive_syscall( @@ -473,7 +523,7 @@ where local.channel, local.clk, local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_QUARTER_ROUND.syscall_id()), + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_QUARTER_ROUND_2X.syscall_id()), local.a_ptr, local.b_ptr, local.is_real, @@ -484,7 +534,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_QUARTER_ROUND_ELF; + use crate::utils::tests::BLAKE2S_QUARTER_ROUND_2X_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; @@ -523,7 +573,7 @@ mod tests { Opcode::ADD, 5, 0, - SyscallCode::BLAKE_2S_QUARTER_ROUND as u32, + SyscallCode::BLAKE_2S_QUARTER_ROUND_2X as u32, false, true, )); @@ -534,7 +584,7 @@ mod tests { } #[test] - fn test_blake2s_quarter_round_precompile() { + fn test_blake2s_quarter_round_2x_precompile() { setup_logger(); // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || @@ -563,18 +613,18 @@ mod tests { assert_eq!( result, [ - 0xbc1738c6, 0x566d1711, 0x5bf2cd1d, 0x130c253, 0x1ff85cd8, 0x361a0001, 0x6ab383b7, - 0xd13ef7a9, 0xd4c3d380, 0x3b057bed, 0x27b8af00, 0xb49a500a, 0x6ab9ed19, 0x7f9dcd68, - 0xeb49bb8e, 0xf4a5ad0, + 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x408705aa, 0x8d07c52d, 0xb9d6aa3a, + 0x88609304, 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, 0x87b6b678, 0x7af31ada, + 0x5a2defeb, 0x2cdd25e3, ] .to_vec() ); } #[test] - fn test_blake2s_quarter_round_program() { + fn test_blake2s_quarter_round_2x_program() { setup_logger(); - let program = Program::from(BLAKE2S_QUARTER_ROUND_ELF); + let program = Program::from(BLAKE2S_QUARTER_ROUND_2X_ELF); run_test(program).unwrap(); } } diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index 9b9ba7e2e..ae2a8665d 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -144,8 +144,8 @@ pub mod tests { pub const BLAKE2S_XOR_ROTATE_RIGHT_7_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf"); - pub const BLAKE2S_QUARTER_ROUND_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_QUARTER_ROUND_2X_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf"); pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); diff --git a/tests/blake2s-quarter-round/Cargo.lock b/tests/blake2s-quarter-round-2x/Cargo.lock similarity index 99% rename from tests/blake2s-quarter-round/Cargo.lock rename to tests/blake2s-quarter-round-2x/Cargo.lock index 993d245f6..7efd0650c 100644 --- a/tests/blake2s-quarter-round/Cargo.lock +++ b/tests/blake2s-quarter-round-2x/Cargo.lock @@ -42,7 +42,7 @@ dependencies = [ ] [[package]] -name = "blake2s-quarter_round-test" +name = "blake2s-quarter_round-2x-test" version = "0.1.0" dependencies = [ "sphinx-zkvm", diff --git a/tests/blake2s-quarter-round/Cargo.toml b/tests/blake2s-quarter-round-2x/Cargo.toml similarity index 75% rename from tests/blake2s-quarter-round/Cargo.toml rename to tests/blake2s-quarter-round-2x/Cargo.toml index be741f691..188c60950 100644 --- a/tests/blake2s-quarter-round/Cargo.toml +++ b/tests/blake2s-quarter-round-2x/Cargo.toml @@ -1,6 +1,6 @@ [workspace] [package] -name = "blake2s-quarter_round-test" +name = "blake2s-quarter_round-2x-test" version = "0.1.0" edition = "2021" diff --git a/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf new file mode 100755 index 0000000000000000000000000000000000000000..98d15aac574510f6ef7609aaaf412514415e8982 GIT binary patch literal 25436 zcmeHwe|%KsmG^Uh&SVH7aQRir>V=zx-yz8)nZV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ClX|L^ds7C&|UzI_@^Jykn&+KfkyH` zU9Jb;2kkg$x7jpq2UPYI(Am$%>eG1M0nH8C8!2V^_(A_M=&NlyA1C!OT?IaX?(phQ z)xSJ^JMwb}qf+$eX3(Dpy@cArk9heyXs?0B`F3dapuG-SQZ~d#D`=NM3*#B%8@2T( zK`;M5i3B6%clx68M?k;%7o)Z}iUB_cecPLfM3tjwNxq4fbNKesTZu##o>PB^{#@s; z$@}>);k|4l{L^OLtU<^|4p$?^kNJfNn~Ik$S%NUQAg>r#5klYmC6xswW?o)#u&883 z(X#vp5pw50m@Ja-^A_Y6<>nXp82M1?9gApW_jZv;FoOgGkB(QfHrn8th0mVHjd(z|B~f&yiwa!t{>%IC}(UQo|C_1 zzd0Zz%bjz|ZA%t%zR~LvTmmi#o&Tu4C!J@y(KotC*U@J^Zv038kBE867u=}~{np?j Q-jcujP!6IQ{Uyu&KRV(6J^%m! literal 0 HcmV?d00001 diff --git a/tests/blake2s-quarter-round-2x/src/main.rs b/tests/blake2s-quarter-round-2x/src/main.rs new file mode 100644 index 000000000..9b98e8d17 --- /dev/null +++ b/tests/blake2s-quarter-round-2x/src/main.rs @@ -0,0 +1,22 @@ +#![no_main] +sphinx_zkvm::entrypoint!(main); + +use sphinx_zkvm::syscalls::blake2s_quarter_round_2x::syscall_blake2s_quarter_round_2x; + +pub fn main() { + let mut a: [u32; 16] = [ + 0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, + 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, + 0xe07c2654, 0x5be0cd19 + ]; + let b: [u32; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + + syscall_blake2s_quarter_round_2x(a.as_mut_ptr(), b.as_ptr()); + + assert_eq!(a, [ + 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, + 0x408705aa, 0x8d07c52d, 0xb9d6aa3a, 0x88609304, + 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, + 0x87b6b678, 0x7af31ada, 0x5a2defeb, 0x2cdd25e3 + ]); +} diff --git a/tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index 917edf787d31e58358ccab560b3a60cce6443e6e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25476 zcmeHwdw3MrdH0#?u7oTkhFff64~!)4LeffFL6dY9ST2dvkYL$v(l2NkEl9DDWL*HK zdF&Odm4H%;Jz#8?I>JKorEY4zHOOiG^pR>W;5<%h*Ty)hV>^|(e9jk#7)xN6u;1@J zGqYNOz)sq~z9;iM!_2(r_MZ2=_j6X<7rb@3APCI8M0TFh*B5TkSt*_$h3t}2rZW$l z!!lV0Qvsr~Qq-jTUA)sRJNIaB^d_*$c+gGdEQcVtymagQetIQibSngR%AZ-y*fZ5S zzh?kOcY6Dms~LMaqVsz?nmv!3@S^tLIMrH1uUB5Y96*V&rbuYCbS7Turv8Od@E_m) zNP$06;ExpeBL)6Qf&XtQFb&3V1B)_~sbX}w!lYvgGao(8tk@K$sUt~EnZkx9tCuwx z=M53Ye6iC3dYYMPw!sdwxZ1}wPZ8_+neJahfEfaAd~2R2*0T%nn$uZ5fLWg1 z%%Jc3k<7T-9ndb6qx~u7Q%?u9O-GZ~@bE;xM-Vj6w48YClxTDxVZN@T%qZ-?Y_1#e z8jl@e#zEZk`Y)p|!B_zJ`VrOW1MCUhPvL$V_pJWQMjq}0)Vr{pS!cQgpE?rIyi7Fa zpiR9h#XCoU_c?*aNcDSVKR-MI8mO18PE{PLKX!@cZH<&M>&R55`KPk@>C?>IuV!0a zpp{o)(QOLT@NTKonZc$DL_cfT&*EjzFki(0i(ga(t7{sw6c5w3sch&W?tJ4*2kmmM4dq4-C(W&h{`PGQzAAU92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8abd3..000000000 --- a/tests/blake2s-quarter-round/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] -sphinx_zkvm::entrypoint!(main); - -use sphinx_zkvm::syscalls::blake2s_quarter_round::syscall_blake2s_quarter_round; - -pub fn main() { - let mut a: [u32; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let b: [u32; 16] = [10, 20, 30, 40, 10, 20, 30, 40, 0, 0, 0, 0, 0, 0, 0, 0]; - - syscall_blake2s_quarter_round(a.as_mut_ptr(), b.as_ptr()); - - assert_eq!(a, [0x10, 0x1c, 0x28, 0x34, 0xc00000, 0xc00000, 0xc00000, 0x400000, 0x16, 0x18, 0x1a, 0x1c, 0xc0000, 0xc0000, 0xc0000, 0x140000]); -} diff --git a/zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs b/zkvm/entrypoint/src/syscalls/blake2s_quarter_round_2x.rs similarity index 65% rename from zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs rename to zkvm/entrypoint/src/syscalls/blake2s_quarter_round_2x.rs index 0ff00113b..358e9615c 100644 --- a/zkvm/entrypoint/src/syscalls/blake2s_quarter_round.rs +++ b/zkvm/entrypoint/src/syscalls/blake2s_quarter_round_2x.rs @@ -3,12 +3,12 @@ use core::arch::asm; #[allow(unused_variables)] #[no_mangle] -pub extern "C" fn syscall_blake2s_quarter_round(left: *mut u32, right: *const u32) { +pub extern "C" fn syscall_blake2s_quarter_round_2x(left: *mut u32, right: *const u32) { #[cfg(target_os = "zkvm")] unsafe { asm!( "ecall", - in("t0") crate::syscalls::BLAKE_2S_QUARTER_ROUND, + in("t0") crate::syscalls::BLAKE_2S_QUARTER_ROUND_2X, in("a0") left, in("a1") right ); diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 518870242..2d1c8b0a7 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -15,7 +15,7 @@ mod verify; pub mod blake2s_add_2; pub mod blake2s_add_3; -pub mod blake2s_quarter_round; +pub mod blake2s_quarter_round_2x; pub mod blake2s_xor_rotate_16; pub mod blake2s_xor_rotate_right_12; pub mod blake2s_xor_rotate_right_16; @@ -130,4 +130,4 @@ pub const BLAKE_2S_XOR_ROTATE_RIGHT_8: u32 = 0x00_01_01_EB; pub const BLAKE_2S_XOR_ROTATE_RIGHT_7: u32 = 0x00_01_01_EC; -pub const BLAKE_2S_QUARTER_ROUND: u32 = 0x00_01_01_ED; +pub const BLAKE_2S_QUARTER_ROUND_2X: u32 = 0x00_01_01_ED; From 72a44ac1f97ace9ded4c66681263743e216b90ef Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Wed, 18 Sep 2024 20:56:58 +0300 Subject: [PATCH 17/30] feat: Add shuffle operation/constraints to quarter_round_2x chip --- core/src/syscall/precompiles/blake2s/mod.rs | 38 ++++++++++ .../precompiles/blake2s/quarter_round.rs | 65 +++++++++++++++--- .../elf/riscv32im-succinct-zkvm-elf | Bin 25436 -> 25436 bytes tests/blake2s-quarter-round-2x/src/main.rs | 6 +- 4 files changed, 97 insertions(+), 12 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 11052054f..a747c83ef 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -294,4 +294,42 @@ mod tests { vec![0x87b6b678, 0x7af31ada, 0x5a2defeb, 0x2cdd25e3] ); } + + #[test] + fn test_blake2s_quarter_round_2x_shuffle_function() { + let mut v: Vec<[u32; 4]> = vec![ + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], + ]; + let m = [0, 0, 0, 0]; + let rd = 16; + let rb = 12; + + quarter_round(&mut v, rd, rb, m); + + let rd = 8; + let rb = 7; + + quarter_round(&mut v, rd, rb, m); + shuffle(&mut v); + + assert_eq!( + v[0].to_vec(), + vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc] + ); + assert_eq!( + v[1].to_vec(), + vec![0x8d07c52d, 0xb9d6aa3a, 0x88609304, 0x408705aa] + ); + assert_eq!( + v[2].to_vec(), + vec![0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7] + ); + assert_eq!( + v[3].to_vec(), + vec![0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb] + ); + } } diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs index e4fb24db7..c463e7869 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -30,6 +30,23 @@ impl Blake2sQuarterRound2xChip { pub fn new() -> Self { Blake2sQuarterRound2xChip } + pub fn constrain_shuffled_indices( + &self, + builder: &mut AB, + shuffled_indices: &[AB::Var], + is_real: AB::Var, + ) { + for index in 0..4 { + builder + .when(is_real) + .assert_eq(shuffled_indices[index], AB::F::from_canonical_usize(0)); + } + for index in 4..shuffled_indices.len() { + builder + .when(is_real) + .assert_eq(shuffled_indices[index], AB::F::from_canonical_usize(1)); + } + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -121,6 +138,21 @@ impl Syscall for Blake2sQuarterRound2xChip { *v1 = (*v1 ^ *v2).rotate_right(R_4); } + // shuffle + // v[1] + a[4..8].swap(0, 3); + a[4..8].swap(0, 1); + a[4..8].swap(1, 2); + + // v[2] + a[8..12].swap(0, 2); + a[8..12].swap(1, 3); + + // v[3] + a[12..16].swap(2, 3); + a[12..16].swap(1, 2); + a[12..16].swap(0, 1); + ctx.clk += 1; // Write rotate_right to a_ptr. let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); @@ -158,6 +190,8 @@ struct Blake2sQuarterRound2xCols { pub a_ptr: T, pub b_ptr: T, + pub shuffled_indices: [T; 16], + pub a: [MemoryWriteCols; 16], pub b: [MemoryReadCols; 16], @@ -214,6 +248,10 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } + let v1_shuffle_lookup = vec![1, 2, 3, 0]; + let v2_shuffle_lookup = vec![2, 3, 0, 1]; + let v3_shuffle_lookup = vec![3, 0, 1, 2]; + // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || for i in 0..4usize { @@ -267,8 +305,9 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v0 + v1 + m1 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) + cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); - let v3_new = cols.rotate_right[i + 8].populate( + let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( output, shard, event.channel, @@ -278,7 +317,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 4 + 8].populate( + cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); + let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( output, shard, event.channel, @@ -290,8 +330,9 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v2 + v3 + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) + cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2); - let v1_new = cols.rotate_right[i + 4 + 8].populate( + let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( output, shard, event.channel, @@ -445,6 +486,10 @@ where // 2x + let v1_shuffle_lookup = vec![1, 2, 3, 0]; + let v2_shuffle_lookup = vec![2, 3, 0, 1]; + let v3_shuffle_lookup = vec![3, 0, 1, 2]; + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, @@ -475,7 +520,7 @@ where builder, local.xor[i + 8].value, R_3 as usize, - local.rotate_right[i + 8], + local.rotate_right[v3_shuffle_lookup[i] + 8], local.shard, &local.channel, local.is_real, @@ -491,7 +536,7 @@ where local.shard, local.channel, local.is_real, - local.add[i + 12], + local.add[v2_shuffle_lookup[i] + 12], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -511,13 +556,15 @@ where builder, local.xor[i + 12].value, R_4 as usize, - local.rotate_right[i + 12], + local.rotate_right[v1_shuffle_lookup[i] + 12], local.shard, &local.channel, local.is_real, ); } + self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); + builder.receive_syscall( local.shard, local.channel, @@ -613,9 +660,9 @@ mod tests { assert_eq!( result, [ - 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x408705aa, 0x8d07c52d, 0xb9d6aa3a, - 0x88609304, 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, 0x87b6b678, 0x7af31ada, - 0x5a2defeb, 0x2cdd25e3, + 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x8d07c52d, 0xb9d6aa3a, 0x88609304, + 0x408705aa, 0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7, 0x2cdd25e3, 0x87b6b678, + 0x7af31ada, 0x5a2defeb ] .to_vec() ); diff --git a/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf index 98d15aac574510f6ef7609aaaf412514415e8982..578cb1e8ed2114273c8e265dc27da0db9b2017af 100755 GIT binary patch delta 63 zcmV-F0Kos;#sS>M0kEi0FfGLgjXJ8M0kEi0FscQIKrO`wjXJ8+mT*sF9wd Date: Thu, 19 Sep 2024 13:53:03 +0300 Subject: [PATCH 18/30] chore: Don't update hybryd-array dependency --- Cargo.lock | 36 ++++++++++++++++++------------------ Cargo.toml | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48201fb87..fcf5f2030 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -248,9 +248,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.88" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" dependencies = [ "backtrace", ] @@ -381,9 +381,9 @@ dependencies = [ [[package]] name = "arrayref" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" [[package]] name = "arrayvec" @@ -714,9 +714,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" dependencies = [ "serde", ] @@ -761,9 +761,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.18" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ "jobserver", "libc", @@ -2228,9 +2228,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -3410,7 +3410,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml_edit 0.22.20", + "toml_edit 0.22.21", ] [[package]] @@ -5105,7 +5105,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.20", + "toml_edit 0.22.21", ] [[package]] @@ -5130,9 +5130,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" dependencies = [ "indexmap 2.5.0", "serde", @@ -5341,9 +5341,9 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] @@ -5566,9 +5566,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] diff --git a/Cargo.toml b/Cargo.toml index 274f79a71..c8a8085d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,7 @@ getrandom = "=0.2.14" # 0.2.15 depends on yanked libc 0.2.154 hashbrown = { version = "0.14.5", features = ["serde"] } hex = "0.4.3" home = "0.5.9" -hybrid-array = "0.2.0-rc" +hybrid-array = "0.2.0-rc.9" indicatif = "0.17.8" itertools = "0.12.1" k256 = "0.13.3" From 096e4d0f8d62d28c9e16e99d33f36b413d507d56 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Thu, 19 Sep 2024 14:10:57 +0300 Subject: [PATCH 19/30] chore: Revert shuffling --- .../precompiles/blake2s/quarter_round.rs | 59 +++++++++++------- .../elf/riscv32im-succinct-zkvm-elf | Bin 25436 -> 25436 bytes tests/blake2s-quarter-round-2x/src/main.rs | 9 ++- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs index c463e7869..0b50a487c 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -140,18 +140,18 @@ impl Syscall for Blake2sQuarterRound2xChip { // shuffle // v[1] - a[4..8].swap(0, 3); - a[4..8].swap(0, 1); - a[4..8].swap(1, 2); + //a[4..8].swap(0, 3); + //a[4..8].swap(0, 1); + //a[4..8].swap(1, 2); // v[2] - a[8..12].swap(0, 2); - a[8..12].swap(1, 3); + //a[8..12].swap(0, 2); + //a[8..12].swap(1, 3); // v[3] - a[12..16].swap(2, 3); - a[12..16].swap(1, 2); - a[12..16].swap(0, 1); + //a[12..16].swap(2, 3); + //a[12..16].swap(1, 2); + //a[12..16].swap(0, 1); ctx.clk += 1; // Write rotate_right to a_ptr. @@ -248,9 +248,9 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } - let v1_shuffle_lookup = vec![1, 2, 3, 0]; - let v2_shuffle_lookup = vec![2, 3, 0, 1]; - let v3_shuffle_lookup = vec![3, 0, 1, 2]; + //let v1_shuffle_lookup = vec![1, 2, 3, 0]; + //let v2_shuffle_lookup = vec![2, 3, 0, 1]; + //let v3_shuffle_lookup = vec![3, 0, 1, 2]; // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || @@ -307,7 +307,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); - let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( + //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( + let v3_new = cols.rotate_right[i + 8].populate( output, shard, event.channel, @@ -318,7 +319,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[2] = v[2].wrapping_add(v[3]); cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( + //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( + let v2_new = cols.add[i + 4 + 8].populate( output, shard, event.channel, @@ -332,7 +334,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2); - let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( + //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( + let v1_new = cols.rotate_right[i + 4 + 8].populate( output, shard, event.channel, @@ -486,9 +489,9 @@ where // 2x - let v1_shuffle_lookup = vec![1, 2, 3, 0]; - let v2_shuffle_lookup = vec![2, 3, 0, 1]; - let v3_shuffle_lookup = vec![3, 0, 1, 2]; + //let v1_shuffle_lookup = vec![1, 2, 3, 0]; + //let v2_shuffle_lookup = vec![2, 3, 0, 1]; + //let v3_shuffle_lookup = vec![3, 0, 1, 2]; // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( @@ -520,7 +523,8 @@ where builder, local.xor[i + 8].value, R_3 as usize, - local.rotate_right[v3_shuffle_lookup[i] + 8], + //local.rotate_right[v3_shuffle_lookup[i] + 8], + local.rotate_right[i + 8], local.shard, &local.channel, local.is_real, @@ -536,7 +540,8 @@ where local.shard, local.channel, local.is_real, - local.add[v2_shuffle_lookup[i] + 12], + //local.add[v2_shuffle_lookup[i] + 12], + local.add[i + 12], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -556,14 +561,15 @@ where builder, local.xor[i + 12].value, R_4 as usize, - local.rotate_right[v1_shuffle_lookup[i] + 12], + //local.rotate_right[v1_shuffle_lookup[i] + 12], + local.rotate_right[i + 12], local.shard, &local.channel, local.is_real, ); } - self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); + //self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); builder.receive_syscall( local.shard, @@ -658,6 +664,15 @@ mod tests { } assert_eq!( + result, + [ + 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x408705aa, 0x8d07c52d, 0xb9d6aa3a, + 0x88609304, 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, 0x87b6b678, 0x7af31ada, + 0x5a2defeb, 0x2cdd25e3, + ] + ); + + /*assert_eq!( result, [ 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x8d07c52d, 0xb9d6aa3a, 0x88609304, @@ -665,7 +680,7 @@ mod tests { 0x7af31ada, 0x5a2defeb ] .to_vec() - ); + );*/ } #[test] diff --git a/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf index 578cb1e8ed2114273c8e265dc27da0db9b2017af..98d15aac574510f6ef7609aaaf412514415e8982 100755 GIT binary patch delta 63 zcmV-F0Kos;#sS>M0kEi0FscQIKrO`wjXJ8+mT*sF9wdM0kEi0FfGLgjXJ8 Date: Thu, 19 Sep 2024 14:23:47 +0300 Subject: [PATCH 20/30] chore: Return shuffling --- .../precompiles/blake2s/quarter_round.rs | 61 +++++++++--------- .../elf/riscv32im-succinct-zkvm-elf | Bin 25436 -> 25436 bytes tests/blake2s-quarter-round-2x/src/main.rs | 7 +- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs index 0b50a487c..563b2c0c5 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -140,18 +140,18 @@ impl Syscall for Blake2sQuarterRound2xChip { // shuffle // v[1] - //a[4..8].swap(0, 3); - //a[4..8].swap(0, 1); - //a[4..8].swap(1, 2); + a[4..8].swap(0, 3); + a[4..8].swap(0, 1); + a[4..8].swap(1, 2); // v[2] - //a[8..12].swap(0, 2); - //a[8..12].swap(1, 3); + a[8..12].swap(0, 2); + a[8..12].swap(1, 3); // v[3] - //a[12..16].swap(2, 3); - //a[12..16].swap(1, 2); - //a[12..16].swap(0, 1); + a[12..16].swap(2, 3); + a[12..16].swap(1, 2); + a[12..16].swap(0, 1); ctx.clk += 1; // Write rotate_right to a_ptr. @@ -248,9 +248,9 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } - //let v1_shuffle_lookup = vec![1, 2, 3, 0]; - //let v2_shuffle_lookup = vec![2, 3, 0, 1]; - //let v3_shuffle_lookup = vec![3, 0, 1, 2]; + let v1_shuffle_lookup = vec![1, 2, 3, 0]; + let v2_shuffle_lookup = vec![2, 3, 0, 1]; + let v3_shuffle_lookup = vec![3, 0, 1, 2]; // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || @@ -307,8 +307,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); - //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( - let v3_new = cols.rotate_right[i + 8].populate( + let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( + //let v3_new = cols.rotate_right[i + 8].populate( output, shard, event.channel, @@ -319,8 +319,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[2] = v[2].wrapping_add(v[3]); cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( - let v2_new = cols.add[i + 4 + 8].populate( + let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( + //let v2_new = cols.add[i + 4 + 8].populate( output, shard, event.channel, @@ -334,8 +334,8 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2); - //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( - let v1_new = cols.rotate_right[i + 4 + 8].populate( + let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( + //let v1_new = cols.rotate_right[i + 4 + 8].populate( output, shard, event.channel, @@ -489,9 +489,9 @@ where // 2x - //let v1_shuffle_lookup = vec![1, 2, 3, 0]; - //let v2_shuffle_lookup = vec![2, 3, 0, 1]; - //let v3_shuffle_lookup = vec![3, 0, 1, 2]; + let v1_shuffle_lookup = vec![1, 2, 3, 0]; + let v2_shuffle_lookup = vec![2, 3, 0, 1]; + let v3_shuffle_lookup = vec![3, 0, 1, 2]; // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( @@ -523,8 +523,8 @@ where builder, local.xor[i + 8].value, R_3 as usize, - //local.rotate_right[v3_shuffle_lookup[i] + 8], - local.rotate_right[i + 8], + local.rotate_right[v3_shuffle_lookup[i] + 8], + //local.rotate_right[i + 8], local.shard, &local.channel, local.is_real, @@ -540,8 +540,8 @@ where local.shard, local.channel, local.is_real, - //local.add[v2_shuffle_lookup[i] + 12], - local.add[i + 12], + local.add[v2_shuffle_lookup[i] + 12], + //local.add[i + 12], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -561,15 +561,15 @@ where builder, local.xor[i + 12].value, R_4 as usize, - //local.rotate_right[v1_shuffle_lookup[i] + 12], - local.rotate_right[i + 12], + local.rotate_right[v1_shuffle_lookup[i] + 12], + //local.rotate_right[i + 12], local.shard, &local.channel, local.is_real, ); } - //self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); + self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); builder.receive_syscall( local.shard, @@ -663,6 +663,7 @@ mod tests { result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); } + /* assert_eq!( result, [ @@ -670,9 +671,9 @@ mod tests { 0x88609304, 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, 0x87b6b678, 0x7af31ada, 0x5a2defeb, 0x2cdd25e3, ] - ); + );*/ - /*assert_eq!( + assert_eq!( result, [ 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x8d07c52d, 0xb9d6aa3a, 0x88609304, @@ -680,7 +681,7 @@ mod tests { 0x7af31ada, 0x5a2defeb ] .to_vec() - );*/ + ); } #[test] diff --git a/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf index 98d15aac574510f6ef7609aaaf412514415e8982..03669901429a1d4c307a1683f5e168fb73653ea4 100755 GIT binary patch delta 84 zcmV-a0IUDp#sS>M0kEi0MJ>e#jXJ8M0kEi0MXCjdKrO`wjXJ8+mT*sF9wd Date: Thu, 19 Sep 2024 14:24:13 +0300 Subject: [PATCH 21/30] chore: Formatting --- core/src/syscall/precompiles/blake2s/quarter_round.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs index 563b2c0c5..2ca40d2cc 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -308,7 +308,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( - //let v3_new = cols.rotate_right[i + 8].populate( + //let v3_new = cols.rotate_right[i + 8].populate( output, shard, event.channel, @@ -320,7 +320,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { // v[2] = v[2].wrapping_add(v[3]); cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( - //let v2_new = cols.add[i + 4 + 8].populate( + //let v2_new = cols.add[i + 4 + 8].populate( output, shard, event.channel, @@ -335,7 +335,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2); let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( - //let v1_new = cols.rotate_right[i + 4 + 8].populate( + //let v1_new = cols.rotate_right[i + 4 + 8].populate( output, shard, event.channel, From 7f97a4c47ea528364557adc672434fe55cf5f309 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Thu, 19 Sep 2024 16:22:50 +0300 Subject: [PATCH 22/30] feat: Add 2 more quarter rounds --- core/src/syscall/precompiles/blake2s/mod.rs | 44 ++ .../precompiles/blake2s/quarter_round.rs | 391 +++++++++++++++++- .../elf/riscv32im-succinct-zkvm-elf | Bin 25436 -> 25436 bytes tests/blake2s-quarter-round-2x/src/main.rs | 10 +- 4 files changed, 424 insertions(+), 21 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index a747c83ef..2f29ff88c 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -332,4 +332,48 @@ mod tests { vec![0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb] ); } + + #[test] + fn test_blake2s_quarter_round_2x_shuffle_quarter_round_2x_function() { + let mut v: Vec<[u32; 4]> = vec![ + [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], + [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], + [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], + ]; + let m = [0, 0, 0, 0]; + let rd = 16; + let rb = 12; + quarter_round(&mut v, rd, rb, m); + + let rd = 8; + let rb = 7; + quarter_round(&mut v, rd, rb, m); + shuffle(&mut v); + + let rd = 16; + let rb = 12; + quarter_round(&mut v, rd, rb, m); + + let rd = 8; + let rb = 7; + quarter_round(&mut v, rd, rb, m); + + assert_eq!( + v[0].to_vec(), + vec![0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3] + ); + assert_eq!( + v[1].to_vec(), + vec![0x301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4] + ); + assert_eq!( + v[2].to_vec(), + vec![0x990c6d13, 0x76fff6f1, 0xc561666d, 0xf291605] + ); + assert_eq!( + v[3].to_vec(), + vec![0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x8e33663] + ); + } } diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/quarter_round.rs index 2ca40d2cc..d7cdab70f 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/quarter_round.rs @@ -76,8 +76,10 @@ impl Syscall for Blake2sQuarterRound2xChip { let mut a = ctx.slice_unsafe(a_ptr, 16); let mut a_clone = a.clone(); - // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || - let (b_reads, b) = ctx.mr_slice(b_ptr, 16); + // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || + // m3[0] || m3[1] || m3[2] || m3[3] || m4[0] || m4[1] || m4[2] || mr[3] || + // 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 + let (b_reads, b) = ctx.mr_slice(b_ptr, 24); // 1x (m1, R1, R2) // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) @@ -153,6 +155,71 @@ impl Syscall for Blake2sQuarterRound2xChip { a[12..16].swap(1, 2); a[12..16].swap(0, 1); + + let mut a = a.clone(); // a after 2x quarter_round + let mut a_clone = a.clone(); + + // 3x (m3, R1, R2) + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m3) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[8..12].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_1); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_2); + } + + // 4x (m4, R3, R4) + let mut a = a.clone(); // a after 3x quarter_round + let mut a_clone = a.clone(); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[12..16].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_3); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_4); + } + + // TODO unshuffle + ctx.clk += 1; // Write rotate_right to a_ptr. let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); @@ -193,11 +260,11 @@ struct Blake2sQuarterRound2xCols { pub shuffled_indices: [T; 16], pub a: [MemoryWriteCols; 16], - pub b: [MemoryReadCols; 16], + pub b: [MemoryReadCols; 24], - pub add: [Add4Operation; 8 * 2], - pub xor: [XorOperation; 8 * 2], - pub rotate_right: [FixedRotateRightOperation; 8 * 2], + pub add: [Add4Operation; 32], + pub xor: [XorOperation; 32], + pub rotate_right: [FixedRotateRightOperation; 32], } impl BaseAir for Blake2sQuarterRound2xChip { @@ -238,7 +305,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.a_ptr = F::from_canonical_u32(event.a_ptr); cols.b_ptr = F::from_canonical_u32(event.b_ptr); - // populate all v, m, 0 + // populate all v, m for i in 0..16usize { cols.a[i].populate( event.channel, @@ -248,6 +315,11 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } + // populate zeroes + for i in 16..24usize { + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + } + let v1_shuffle_lookup = vec![1, 2, 3, 0]; let v2_shuffle_lookup = vec![2, 3, 0, 1]; let v3_shuffle_lookup = vec![3, 0, 1, 2]; @@ -262,8 +334,11 @@ impl MachineAir for Blake2sQuarterRound2xChip { let v3 = event.a_reads_writes[i + 12].value; let m1 = event.b_reads[i].value; let m2 = event.b_reads[i + 4].value; - let zero1 = event.b_reads[i + 8].value; - let zero2 = event.b_reads[i + 12].value; + let m3 = event.b_reads[i + 8].value; + let m4 = event.b_reads[i + 12].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); assert_eq!(zero2, 0); @@ -343,6 +418,90 @@ impl MachineAir for Blake2sQuarterRound2xChip { R_4 as usize, ); assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); + + + // 3x (m3, R1, R2) + let v0 = v0_new; + let v1 = v1_new; + let v2 = v2_new; + let v3 = v3_new; + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + let v0_new = cols.add[i + 16].populate(output, shard, event.channel, v0, v1, m3, zero1); + assert_eq!(v0 + v1 + m3 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0); + let v3_new = + cols.rotate_right[i + 16].populate(output, shard, event.channel, temp, R_1 as usize); + assert_eq!((v3 ^ v0).rotate_right(R_1), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + let v2_new = + cols.add[i + 16 + 4].populate(output, shard, event.channel, v2, v3, zero1, zero2); + assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + let temp = cols.xor[i + 16 + 4].populate(output, shard, event.channel, v1, v2); + let v1_new = cols.rotate_right[i + 16 + 4].populate( + output, + shard, + event.channel, + temp, + R_2 as usize, + ); + assert_eq!((v1 ^ v2).rotate_right(R_2), v1_new); + + // 4x (m4, R3, R4) + let v0 = v0_new; + let v1 = v1_new; + let v2 = v2_new; + let v3 = v3_new; + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + let v0_new = + cols.add[i + 16 + 8].populate(output, shard, event.channel, v0, v1, m4, zero1); + assert_eq!(v0 + v1 + m4 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) + //cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); + let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0); + //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( + let v3_new = cols.rotate_right[i + 16 + 8].populate( + output, + shard, + event.channel, + temp, + R_3 as usize, + ); + assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + //cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); + //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( + let v2_new = cols.add[i + 16 + 4 + 8].populate( + output, + shard, + event.channel, + v2, + v3, + zero1, + zero2, + ); + assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) + //cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); + let temp = cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2); + //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( + let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( + output, + shard, + event.channel, + temp, + R_4 as usize, + ); + assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); } rows.push(row); @@ -413,6 +572,23 @@ where ); } + // zeroes + for i in 16..24usize { + // Eval b + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + } + + let v1_shuffle_lookup = vec![1, 2, 3, 0]; + let v2_shuffle_lookup = vec![2, 3, 0, 1]; + let v3_shuffle_lookup = vec![3, 0, 1, 2]; + for i in 0..4usize { // 1x @@ -489,10 +665,6 @@ where // 2x - let v1_shuffle_lookup = vec![1, 2, 3, 0]; - let v2_shuffle_lookup = vec![2, 3, 0, 1]; - let v3_shuffle_lookup = vec![3, 0, 1, 2]; - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, @@ -567,6 +739,176 @@ where &local.channel, local.is_real, ); + + + // 3x + /* + v0 : local.add[i + 8] + v1 : local.local.rotate_right[v1_shuffle_lookup[i] + 12] + v2 : local.add[v2_shuffle_lookup[i] + 12] + v3 : local.rotate_right[v3_shuffle_lookup[i] + 8] + */ + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + local.add[i + 8].value, // v0 after x2 + local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x + *local.b[i + 8].value(), // m3 + *local.b[i + 16].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i + 16], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x + local.add[i + 8].value, // v0 after x2 + local.xor[i + 16], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 16].value, + R_1 as usize, + local.rotate_right[i + 16], + local.shard, + &local.channel, + local.is_real, + ); + + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x + local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 20], + ); + + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x + local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x + local.xor[i + 20], + local.shard, + &local.channel, + local.is_real, + ); + + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 20].value, + R_2 as usize, + local.rotate_right[i + 20], + local.shard, + &local.channel, + local.is_real, + ); + + + // 4x + + /* + v0 : local.add[i + 16] + v1 : local.rotate_right[i + 20] + v2 : local.add[i + 20] + v3 : local.rotate_right[i + 16] + */ + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + local.add[i + 16].value, // v0 after 3x + local.rotate_right[i + 20].value, // v1 after 3x + *local.b[i + 12].value(), // m4 + *local.b[i + 16].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i + 24], + ); + + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[i + 16].value, // v3 after 3x + local.add[i + 16].value, // v0 after 3x + local.xor[i + 24], + local.shard, + &local.channel, + local.is_real, + ); + + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 24].value, + R_3 as usize, + local.rotate_right[i + 24], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + local.add[i + 20].value, // v2 after 3x + local.rotate_right[i + 16].value, // v3 after 3x + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 28], + ); + + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[i + 20].value, // v1 after 3x + local.add[i + 20].value, // v2 after 3x + local.xor[i + 28], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 28].value, + R_4 as usize, + local.rotate_right[i + 28], + local.shard, + &local.channel, + local.is_real, + ); + } self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); @@ -591,7 +933,7 @@ mod tests { use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 16]) -> Program { + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 24]) -> Program { let mut instructions = vec![]; // memory write a for (index, word) in a.into_iter().enumerate() { @@ -653,7 +995,12 @@ mod tests { 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19, ], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, // m1 + 0, 0, 0, 0, // m2 + 0, 0, 0, 0, // m3 + 0, 0, 0, 0, // m4 + 0, 0, 0, 0, // zero_0 + 0, 0, 0, 0], // zero_1 ); let (_, memory) = run_test_with_memory_inspection(program); @@ -673,7 +1020,7 @@ mod tests { ] );*/ - assert_eq!( + /*assert_eq!( result, [ 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x8d07c52d, 0xb9d6aa3a, 0x88609304, @@ -681,7 +1028,19 @@ mod tests { 0x7af31ada, 0x5a2defeb ] .to_vec() + );*/ + + assert_eq!( + result, + [ + 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, + 0x301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4, + 0x990c6d13, 0x76fff6f1, 0xc561666d, 0xf291605, + 0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x8e33663 + ] + .to_vec() ); + } #[test] diff --git a/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf index 03669901429a1d4c307a1683f5e168fb73653ea4..1b174b537784bf1df7862ae0773686fea4ed61bf 100755 GIT binary patch delta 122 zcmV-=0EPeD#sS>M0kE?W1@t2>5ek#I5SIZ4lTZ;q6$=vq0Ssq=001K*0SXfZK>(8l zK?<{^5%fMlT^pc+_1KFfnzf`I(<^(kTL}RJ!lO~KZ}}Hq^jcq06KxEc@%I0AZDwJ` c1r{j}UWomd8NX8=fTrYcV>aUmv)E9C5;wgr(*OVf delta 122 zcmV-=0EPeD#sS>M0kE?W1@(8l zK?t*?5%fMlo|O;W5*LSz)KI3z{JC$^EyV|oI;z&W1e0Khss)EY>z?L;?R9tI_=$R4 c$CmiD<0aiJc(%5O+8XnE>+daEv)E9C66&ipR{#J2 diff --git a/tests/blake2s-quarter-round-2x/src/main.rs b/tests/blake2s-quarter-round-2x/src/main.rs index 6bfcb9ac6..e41fe63cf 100644 --- a/tests/blake2s-quarter-round-2x/src/main.rs +++ b/tests/blake2s-quarter-round-2x/src/main.rs @@ -9,7 +9,7 @@ pub fn main() { 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19 ]; - let b: [u32; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let b: [u32; 24] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; syscall_blake2s_quarter_round_2x(a.as_mut_ptr(), b.as_ptr()); @@ -22,9 +22,9 @@ pub fn main() { assert_eq!(a, [ - 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, - 0x8d07c52d, 0xb9d6aa3a, 0x88609304, 0x408705aa, - 0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7, - 0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb + 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, + 0x301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4, + 0x990c6d13, 0x76fff6f1, 0xc561666d, 0xf291605, + 0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x8e33663 ]); } From 52637834cc5ce47c3cfcf5c2f571f0d34f45d5d0 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Thu, 19 Sep 2024 17:23:07 +0300 Subject: [PATCH 23/30] feat: Add unshuffle operation --- core/src/syscall/precompiles/blake2s/mod.rs | 11 +- .../blake2s/{quarter_round.rs => round.rs} | 193 +++++++++--------- core/src/utils/programs.rs | 4 +- .../Cargo.lock | 0 .../Cargo.toml | 0 .../elf/riscv32im-succinct-zkvm-elf | Bin 25436 -> 25436 bytes .../src/main.rs | 16 +- ...s_quarter_round_2x.rs => blake2s_round.rs} | 0 zkvm/entrypoint/src/syscalls/mod.rs | 2 +- 9 files changed, 104 insertions(+), 122 deletions(-) rename core/src/syscall/precompiles/blake2s/{quarter_round.rs => round.rs} (87%) rename tests/{blake2s-quarter-round-2x => blake2s-round}/Cargo.lock (100%) rename tests/{blake2s-quarter-round-2x => blake2s-round}/Cargo.toml (100%) rename tests/{blake2s-quarter-round-2x => blake2s-round}/elf/riscv32im-succinct-zkvm-elf (99%) rename tests/{blake2s-quarter-round-2x => blake2s-round}/src/main.rs (52%) rename zkvm/entrypoint/src/syscalls/{blake2s_quarter_round_2x.rs => blake2s_round.rs} (100%) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 2f29ff88c..83844f82c 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,6 +1,6 @@ mod add_2; mod add_3; -mod quarter_round; +mod round; mod xor_rotate_16; // based on sha-extend mod xor_rotate_right_12; mod xor_rotate_right_16; @@ -9,7 +9,7 @@ mod xor_rotate_right_8; pub use add_2::*; pub use add_3::*; -pub use quarter_round::*; +pub use round::*; pub use xor_rotate_16::*; // based on sha-extend pub use xor_rotate_right_12::*; pub use xor_rotate_right_16::*; @@ -358,6 +358,7 @@ mod tests { let rd = 8; let rb = 7; quarter_round(&mut v, rd, rb, m); + unshuffle(&mut v); assert_eq!( v[0].to_vec(), @@ -365,15 +366,15 @@ mod tests { ); assert_eq!( v[1].to_vec(), - vec![0x301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4] + vec![0x515f5af4, 0x301095b, 0xb151a3c2, 0x5e17f96f] ); assert_eq!( v[2].to_vec(), - vec![0x990c6d13, 0x76fff6f1, 0xc561666d, 0xf291605] + vec![0xc561666d, 0xf291605, 0x990c6d13, 0x76fff6f1] ); assert_eq!( v[3].to_vec(), - vec![0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x8e33663] + vec![0x1e53bf19, 0x6fe4a680, 0x8e33663, 0x97fd885e] ); } } diff --git a/core/src/syscall/precompiles/blake2s/quarter_round.rs b/core/src/syscall/precompiles/blake2s/round.rs similarity index 87% rename from core/src/syscall/precompiles/blake2s/quarter_round.rs rename to core/src/syscall/precompiles/blake2s/round.rs index d7cdab70f..834f597c4 100644 --- a/core/src/syscall/precompiles/blake2s/quarter_round.rs +++ b/core/src/syscall/precompiles/blake2s/round.rs @@ -30,21 +30,21 @@ impl Blake2sQuarterRound2xChip { pub fn new() -> Self { Blake2sQuarterRound2xChip } - pub fn constrain_shuffled_indices( + pub fn constrain_shuffled_unshuffled_indices( &self, builder: &mut AB, - shuffled_indices: &[AB::Var], + indices: &[AB::Var], is_real: AB::Var, ) { for index in 0..4 { builder .when(is_real) - .assert_eq(shuffled_indices[index], AB::F::from_canonical_usize(0)); + .assert_eq(indices[index], AB::F::from_canonical_usize(0)); } - for index in 4..shuffled_indices.len() { + for index in 4..indices.len() { builder .when(is_real) - .assert_eq(shuffled_indices[index], AB::F::from_canonical_usize(1)); + .assert_eq(indices[index], AB::F::from_canonical_usize(1)); } } } @@ -155,7 +155,6 @@ impl Syscall for Blake2sQuarterRound2xChip { a[12..16].swap(1, 2); a[12..16].swap(0, 1); - let mut a = a.clone(); // a after 2x quarter_round let mut a_clone = a.clone(); @@ -218,7 +217,20 @@ impl Syscall for Blake2sQuarterRound2xChip { *v1 = (*v1 ^ *v2).rotate_right(R_4); } - // TODO unshuffle + // unshuffle + // v[1] + a[4..8].swap(2, 3); + a[4..8].swap(1, 2); + a[4..8].swap(0, 1); + + // v[2] + a[8..12].swap(0, 2); + a[8..12].swap(1, 3); + + // v[3] + a[12..16].swap(0, 3); + a[12..16].swap(0, 1); + a[12..16].swap(1, 2); ctx.clk += 1; // Write rotate_right to a_ptr. @@ -258,6 +270,7 @@ struct Blake2sQuarterRound2xCols { pub b_ptr: T, pub shuffled_indices: [T; 16], + pub unshuffled_indices: [T; 16], pub a: [MemoryWriteCols; 16], pub b: [MemoryReadCols; 24], @@ -324,8 +337,10 @@ impl MachineAir for Blake2sQuarterRound2xChip { let v2_shuffle_lookup = vec![2, 3, 0, 1]; let v3_shuffle_lookup = vec![3, 0, 1, 2]; - // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || - // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || + let v1_unshuffle_lookup = v1_shuffle_lookup.clone(); + let v2_unshuffle_lookup = v2_shuffle_lookup.clone(); + let v3_unshuffle_lookup = v3_shuffle_lookup.clone(); + for i in 0..4usize { // 1x (m1, R1, R2) let v0 = event.a_reads_writes[i].value; @@ -419,7 +434,6 @@ impl MachineAir for Blake2sQuarterRound2xChip { ); assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); - // 3x (m3, R1, R2) let v0 = v0_new; let v1 = v1_new; @@ -427,18 +441,31 @@ impl MachineAir for Blake2sQuarterRound2xChip { let v3 = v3_new; // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - let v0_new = cols.add[i + 16].populate(output, shard, event.channel, v0, v1, m3, zero1); + let v0_new = + cols.add[i + 16].populate(output, shard, event.channel, v0, v1, m3, zero1); assert_eq!(v0 + v1 + m3 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0); - let v3_new = - cols.rotate_right[i + 16].populate(output, shard, event.channel, temp, R_1 as usize); + let v3_new = cols.rotate_right[i + 16].populate( + output, + shard, + event.channel, + temp, + R_1 as usize, + ); assert_eq!((v3 ^ v0).rotate_right(R_1), v3_new); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = - cols.add[i + 16 + 4].populate(output, shard, event.channel, v2, v3, zero1, zero2); + let v2_new = cols.add[i + 16 + 4].populate( + output, + shard, + event.channel, + v2, + v3, + zero1, + zero2, + ); assert_eq!(v2 + v3 + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -464,10 +491,10 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v0 + v1 + m4 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - //cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); + cols.unshuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0); - //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( - let v3_new = cols.rotate_right[i + 16 + 8].populate( + let v3_new = cols.rotate_right[v3_unshuffle_lookup[i] + 16 + 8].populate( + //let v3_new = cols.rotate_right[i + 16 + 8].populate( output, shard, event.channel, @@ -477,9 +504,9 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - //cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( - let v2_new = cols.add[i + 16 + 4 + 8].populate( + cols.unshuffled_indices[i + 8] = F::from_canonical_u32(1); + let v2_new = cols.add[v2_unshuffle_lookup[i] + 16 + 4 + 8].populate( + //let v2_new = cols.add[i + 16 + 4 + 8].populate( output, shard, event.channel, @@ -491,10 +518,10 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v2 + v3 + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - //cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); + cols.unshuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2); - //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( - let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( + let v1_new = cols.rotate_right[v1_unshuffle_lookup[i] + 16 + 4 + 8].populate( + //let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( output, shard, event.channel, @@ -589,6 +616,10 @@ where let v2_shuffle_lookup = vec![2, 3, 0, 1]; let v3_shuffle_lookup = vec![3, 0, 1, 2]; + let v1_unshuffle_lookup = v1_shuffle_lookup.clone(); + let v2_unshuffle_lookup = v2_shuffle_lookup.clone(); + let v3_unshuffle_lookup = v3_shuffle_lookup.clone(); + for i in 0..4usize { // 1x @@ -696,7 +727,6 @@ where local.xor[i + 8].value, R_3 as usize, local.rotate_right[v3_shuffle_lookup[i] + 8], - //local.rotate_right[i + 8], local.shard, &local.channel, local.is_real, @@ -713,7 +743,6 @@ where local.channel, local.is_real, local.add[v2_shuffle_lookup[i] + 12], - //local.add[i + 12], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -734,28 +763,23 @@ where local.xor[i + 12].value, R_4 as usize, local.rotate_right[v1_shuffle_lookup[i] + 12], - //local.rotate_right[i + 12], local.shard, &local.channel, local.is_real, ); + } + self.constrain_shuffled_unshuffled_indices(builder, &local.shuffled_indices, local.is_real); + for i in 0..4usize { // 3x - /* - v0 : local.add[i + 8] - v1 : local.local.rotate_right[v1_shuffle_lookup[i] + 12] - v2 : local.add[v2_shuffle_lookup[i] + 12] - v3 : local.rotate_right[v3_shuffle_lookup[i] + 8] - */ - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, - local.add[i + 8].value, // v0 after x2 + local.add[i + 8].value, // v0 after x2 local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x - *local.b[i + 8].value(), // m3 - *local.b[i + 16].value(), // zero1 + *local.b[i + 8].value(), // m3 + *local.b[i + 16].value(), // zero1 local.shard, local.channel, local.is_real, @@ -767,7 +791,7 @@ where XorOperation::::eval( builder, local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x - local.add[i + 8].value, // v0 after x2 + local.add[i + 8].value, // v0 after x2 local.xor[i + 16], local.shard, &local.channel, @@ -785,34 +809,31 @@ where local.is_real, ); - // v[2] = v[2].wrapping_add(v[3]); Add4Operation::::eval( builder, local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 local.shard, local.channel, local.is_real, local.add[i + 20], ); - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); // Eval XOR XorOperation::::eval( builder, local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x - local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x + local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x local.xor[i + 20], local.shard, &local.channel, local.is_real, ); - // Eval RotateRight FixedRotateRightOperation::::eval( builder, @@ -824,30 +845,20 @@ where local.is_real, ); - // 4x - - /* - v0 : local.add[i + 16] - v1 : local.rotate_right[i + 20] - v2 : local.add[i + 20] - v3 : local.rotate_right[i + 16] - */ - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, - local.add[i + 16].value, // v0 after 3x + local.add[i + 16].value, // v0 after 3x local.rotate_right[i + 20].value, // v1 after 3x - *local.b[i + 12].value(), // m4 - *local.b[i + 16].value(), // zero1 + *local.b[i + 12].value(), // m4 + *local.b[i + 16].value(), // zero1 local.shard, local.channel, local.is_real, local.add[i + 24], ); - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); // Eval XOR XorOperation::::eval( @@ -860,13 +871,12 @@ where local.is_real, ); - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 24].value, R_3 as usize, - local.rotate_right[i + 24], + local.rotate_right[v3_unshuffle_lookup[i] + 24], local.shard, &local.channel, local.is_real, @@ -875,23 +885,22 @@ where // v[2] = v[2].wrapping_add(v[3]); Add4Operation::::eval( builder, - local.add[i + 20].value, // v2 after 3x + local.add[i + 20].value, // v2 after 3x local.rotate_right[i + 16].value, // v3 after 3x - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 local.shard, local.channel, local.is_real, - local.add[i + 28], + local.add[v2_unshuffle_lookup[i] + 28], ); - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); // Eval XOR XorOperation::::eval( builder, local.rotate_right[i + 20].value, // v1 after 3x - local.add[i + 20].value, // v2 after 3x + local.add[i + 20].value, // v2 after 3x local.xor[i + 28], local.shard, &local.channel, @@ -903,15 +912,18 @@ where builder, local.xor[i + 28].value, R_4 as usize, - local.rotate_right[i + 28], + local.rotate_right[v1_unshuffle_lookup[i] + 28], local.shard, &local.channel, local.is_real, ); - } - self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); + self.constrain_shuffled_unshuffled_indices( + builder, + &local.unshuffled_indices, + local.is_real, + ); builder.receive_syscall( local.shard, @@ -929,7 +941,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_QUARTER_ROUND_2X_ELF; + use crate::utils::tests::BLAKE2S_ROUND_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; @@ -979,12 +991,9 @@ mod tests { } #[test] - fn test_blake2s_quarter_round_2x_precompile() { + fn test_blake2s_round_precompile() { setup_logger(); - // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || - // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 || - let a_ptr = 100100100; let b_ptr = 200200200; let program = risc_v_program( @@ -995,12 +1004,14 @@ mod tests { 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19, ], - [0, 0, 0, 0, // m1 + [ + 0, 0, 0, 0, // m1 0, 0, 0, 0, // m2 0, 0, 0, 0, // m3 0, 0, 0, 0, // m4 0, 0, 0, 0, // zero_0 - 0, 0, 0, 0], // zero_1 + 0, 0, 0, 0, + ], // zero_1 ); let (_, memory) = run_test_with_memory_inspection(program); @@ -1010,43 +1021,21 @@ mod tests { result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); } - /* assert_eq!( result, [ - 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x408705aa, 0x8d07c52d, 0xb9d6aa3a, - 0x88609304, 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, 0x87b6b678, 0x7af31ada, - 0x5a2defeb, 0x2cdd25e3, - ] - );*/ - - /*assert_eq!( - result, - [ - 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x8d07c52d, 0xb9d6aa3a, 0x88609304, - 0x408705aa, 0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7, 0x2cdd25e3, 0x87b6b678, - 0x7af31ada, 0x5a2defeb + 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, 0x515f5af4, 0x301095b, 0xb151a3c2, + 0x5e17f96f, 0xc561666d, 0xf291605, 0x990c6d13, 0x76fff6f1, 0x1e53bf19, 0x6fe4a680, + 0x8e33663, 0x97fd885e, ] .to_vec() - );*/ - - assert_eq!( - result, - [ - 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, - 0x301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4, - 0x990c6d13, 0x76fff6f1, 0xc561666d, 0xf291605, - 0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x8e33663 - ] - .to_vec() ); - } #[test] - fn test_blake2s_quarter_round_2x_program() { + fn test_blake2s_round_program() { setup_logger(); - let program = Program::from(BLAKE2S_QUARTER_ROUND_2X_ELF); + let program = Program::from(BLAKE2S_ROUND_ELF); run_test(program).unwrap(); } } diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index ae2a8665d..5b90fc220 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -144,8 +144,8 @@ pub mod tests { pub const BLAKE2S_XOR_ROTATE_RIGHT_7_ELF: &[u8] = include_bytes!("../../../tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf"); - pub const BLAKE2S_QUARTER_ROUND_2X_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf"); + pub const BLAKE2S_ROUND_ELF: &[u8] = + include_bytes!("../../../tests/blake2s-round/elf/riscv32im-succinct-zkvm-elf"); pub const PANIC_ELF: &[u8] = include_bytes!("../../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); diff --git a/tests/blake2s-quarter-round-2x/Cargo.lock b/tests/blake2s-round/Cargo.lock similarity index 100% rename from tests/blake2s-quarter-round-2x/Cargo.lock rename to tests/blake2s-round/Cargo.lock diff --git a/tests/blake2s-quarter-round-2x/Cargo.toml b/tests/blake2s-round/Cargo.toml similarity index 100% rename from tests/blake2s-quarter-round-2x/Cargo.toml rename to tests/blake2s-round/Cargo.toml diff --git a/tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-round/elf/riscv32im-succinct-zkvm-elf similarity index 99% rename from tests/blake2s-quarter-round-2x/elf/riscv32im-succinct-zkvm-elf rename to tests/blake2s-round/elf/riscv32im-succinct-zkvm-elf index 1b174b537784bf1df7862ae0773686fea4ed61bf..dad5a964e749b5533e34c044b8afc7f8ad93101e 100755 GIT binary patch delta 84 zcmV-a0IUDp#sS>M0kEi0Mf6%M0kEi0MOz601Hz+Gv2XboUi4aDQ4?(pneq1jc5P;1#RV2A4_=7< qml?lP9)PCgZ(}y&2y=2{FKuCIZZ2|j0N7w401E&B02s6FP;U}9z#@hK diff --git a/tests/blake2s-quarter-round-2x/src/main.rs b/tests/blake2s-round/src/main.rs similarity index 52% rename from tests/blake2s-quarter-round-2x/src/main.rs rename to tests/blake2s-round/src/main.rs index e41fe63cf..7ab5a38e0 100644 --- a/tests/blake2s-quarter-round-2x/src/main.rs +++ b/tests/blake2s-round/src/main.rs @@ -1,7 +1,7 @@ #![no_main] sphinx_zkvm::entrypoint!(main); -use sphinx_zkvm::syscalls::blake2s_quarter_round_2x::syscall_blake2s_quarter_round_2x; +use sphinx_zkvm::syscalls::blake2s_round::syscall_blake2s_quarter_round_2x; pub fn main() { let mut a: [u32; 16] = [ @@ -13,18 +13,10 @@ pub fn main() { syscall_blake2s_quarter_round_2x(a.as_mut_ptr(), b.as_ptr()); - /* - assert_eq!(a, [ - 0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc, 0x408705aa, 0x8d07c52d, 0xb9d6aa3a, - 0x88609304, 0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed, 0x87b6b678, 0x7af31ada, - 0x5a2defeb, 0x2cdd25e3, - ]);*/ - - assert_eq!(a, [ 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, - 0x301095b, 0xb151a3c2, 0x5e17f96f, 0x515f5af4, - 0x990c6d13, 0x76fff6f1, 0xc561666d, 0xf291605, - 0x97fd885e, 0x1e53bf19, 0x6fe4a680, 0x8e33663 + 0x515f5af4, 0x301095b, 0xb151a3c2, 0x5e17f96f, + 0xc561666d, 0xf291605, 0x990c6d13, 0x76fff6f1, + 0x1e53bf19, 0x6fe4a680, 0x8e33663, 0x97fd885e, ]); } diff --git a/zkvm/entrypoint/src/syscalls/blake2s_quarter_round_2x.rs b/zkvm/entrypoint/src/syscalls/blake2s_round.rs similarity index 100% rename from zkvm/entrypoint/src/syscalls/blake2s_quarter_round_2x.rs rename to zkvm/entrypoint/src/syscalls/blake2s_round.rs diff --git a/zkvm/entrypoint/src/syscalls/mod.rs b/zkvm/entrypoint/src/syscalls/mod.rs index 2d1c8b0a7..647e5202a 100644 --- a/zkvm/entrypoint/src/syscalls/mod.rs +++ b/zkvm/entrypoint/src/syscalls/mod.rs @@ -15,7 +15,7 @@ mod verify; pub mod blake2s_add_2; pub mod blake2s_add_3; -pub mod blake2s_quarter_round_2x; +pub mod blake2s_round; pub mod blake2s_xor_rotate_16; pub mod blake2s_xor_rotate_right_12; pub mod blake2s_xor_rotate_right_16; From 48f226661e613808248aac5f6acf554b99a85390 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Fri, 20 Sep 2024 21:01:09 +0300 Subject: [PATCH 24/30] feat: Blake2s round syscall testing with randomized input --- core/src/runtime/record.rs | 171 +----- core/src/runtime/syscall.rs | 115 +--- core/src/stark/air.rs | 52 +- core/src/syscall/precompiles/blake2s/add_2.rs | 368 ------------ core/src/syscall/precompiles/blake2s/add_3.rs | 371 ------------ core/src/syscall/precompiles/blake2s/mod.rs | 315 ++++------ core/src/syscall/precompiles/blake2s/round.rs | 402 +++++++------ .../precompiles/blake2s/xor_rotate_16/air.rs | 291 ---------- .../blake2s/xor_rotate_16/columns.rs | 71 --- .../blake2s/xor_rotate_16/execute.rs | 101 ---- .../blake2s/xor_rotate_16/flags.rs | 130 ----- .../precompiles/blake2s/xor_rotate_16/mod.rs | 116 ---- .../blake2s/xor_rotate_16/trace.rs | 178 ------ .../blake2s/xor_rotate_right_12.rs | 357 ------------ .../blake2s/xor_rotate_right_16.rs | 357 ------------ .../precompiles/blake2s/xor_rotate_right_7.rs | 357 ------------ .../precompiles/blake2s/xor_rotate_right_8.rs | 357 ------------ core/src/utils/programs.rs | 23 - tests/blake2s-add2/Cargo.lock | 539 ------------------ tests/blake2s-add2/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25140 -> 0 bytes tests/blake2s-add2/src/main.rs | 13 - tests/blake2s-add3/Cargo.lock | 539 ------------------ tests/blake2s-add3/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25156 -> 0 bytes tests/blake2s-add3/src/main.rs | 13 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25436 -> 22700 bytes tests/blake2s-round/src/main.rs | 11 +- tests/blake2s-xor-rotate-16/Cargo.lock | 539 ------------------ tests/blake2s-xor-rotate-16/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 22924 -> 0 bytes tests/blake2s-xor-rotate-16/src/main.rs | 13 - tests/blake2s-xor-rotate-right-12/Cargo.lock | 539 ------------------ tests/blake2s-xor-rotate-right-12/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25140 -> 0 bytes tests/blake2s-xor-rotate-right-12/src/main.rs | 13 - tests/blake2s-xor-rotate-right-16/Cargo.lock | 539 ------------------ tests/blake2s-xor-rotate-right-16/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25140 -> 0 bytes tests/blake2s-xor-rotate-right-16/src/main.rs | 29 - tests/blake2s-xor-rotate-right-7/Cargo.lock | 539 ------------------ tests/blake2s-xor-rotate-right-7/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25140 -> 0 bytes tests/blake2s-xor-rotate-right-7/src/main.rs | 13 - tests/blake2s-xor-rotate-right-8/Cargo.lock | 539 ------------------ tests/blake2s-xor-rotate-right-8/Cargo.toml | 8 - .../elf/riscv32im-succinct-zkvm-elf | Bin 25140 -> 0 bytes tests/blake2s-xor-rotate-right-8/src/main.rs | 13 - zkvm/entrypoint/src/syscalls/blake2s_add_2.rs | 19 - zkvm/entrypoint/src/syscalls/blake2s_add_3.rs | 19 - zkvm/entrypoint/src/syscalls/blake2s_round.rs | 4 +- .../src/syscalls/blake2s_xor_rotate_16.rs | 19 - .../syscalls/blake2s_xor_rotate_right_12.rs | 19 - .../syscalls/blake2s_xor_rotate_right_16.rs | 19 - .../syscalls/blake2s_xor_rotate_right_7.rs | 19 - .../syscalls/blake2s_xor_rotate_right_8.rs | 19 - zkvm/entrypoint/src/syscalls/mod.rs | 24 +- 57 files changed, 368 insertions(+), 7872 deletions(-) delete mode 100644 core/src/syscall/precompiles/blake2s/add_2.rs delete mode 100644 core/src/syscall/precompiles/blake2s/add_3.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs delete mode 100644 core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs delete mode 100644 tests/blake2s-add2/Cargo.lock delete mode 100644 tests/blake2s-add2/Cargo.toml delete mode 100755 tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-add2/src/main.rs delete mode 100644 tests/blake2s-add3/Cargo.lock delete mode 100644 tests/blake2s-add3/Cargo.toml delete mode 100755 tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-add3/src/main.rs delete mode 100644 tests/blake2s-xor-rotate-16/Cargo.lock delete mode 100644 tests/blake2s-xor-rotate-16/Cargo.toml delete mode 100755 tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-xor-rotate-16/src/main.rs delete mode 100644 tests/blake2s-xor-rotate-right-12/Cargo.lock delete mode 100644 tests/blake2s-xor-rotate-right-12/Cargo.toml delete mode 100755 tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-xor-rotate-right-12/src/main.rs delete mode 100644 tests/blake2s-xor-rotate-right-16/Cargo.lock delete mode 100644 tests/blake2s-xor-rotate-right-16/Cargo.toml delete mode 100755 tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-xor-rotate-right-16/src/main.rs delete mode 100644 tests/blake2s-xor-rotate-right-7/Cargo.lock delete mode 100644 tests/blake2s-xor-rotate-right-7/Cargo.toml delete mode 100755 tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-xor-rotate-right-7/src/main.rs delete mode 100644 tests/blake2s-xor-rotate-right-8/Cargo.lock delete mode 100644 tests/blake2s-xor-rotate-right-8/Cargo.toml delete mode 100755 tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf delete mode 100644 tests/blake2s-xor-rotate-right-8/src/main.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_add_2.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_add_3.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_16.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_12.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_16.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_7.rs delete mode 100644 zkvm/entrypoint/src/syscalls/blake2s_xor_rotate_right_8.rs diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index 85748a803..dbbbee849 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -10,13 +10,7 @@ use super::{program::Program, Opcode}; use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; -use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd2Event, Blake2sAdd3Chip, Blake2sAdd3Event, - Blake2sQuarterRound2xChip, Blake2sQuarterRound2xEvent, Blake2sXorRotate16Chip, - Blake2sXorRotate16Event, Blake2sXorRotateRight12Chip, Blake2sXorRotateRight12Event, - Blake2sXorRotateRight16Chip, Blake2sXorRotateRight16Event, Blake2sXorRotateRight7Chip, - Blake2sXorRotateRight7Event, Blake2sXorRotateRight8Chip, Blake2sXorRotateRight8Event, -}; +use crate::syscall::precompiles::blake2s::{Blake2sRoundChip, Blake2sRoundEvent}; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; use crate::syscall::precompiles::sha256::{ShaCompressEvent, ShaExtendEvent}; @@ -133,14 +127,7 @@ pub struct ExecutionRecord { pub bls12381_g2_double_events: Vec, // Blake2s - pub blake2s_xor_rotate_right_16_events: Vec, - pub blake2s_xor_rotate_16_events: Vec, // based on sha-extend - pub blake2s_add_2_events: Vec, - pub blake2s_add_3_events: Vec, - pub blake2s_xor_rotate_right_12_events: Vec, - pub blake2s_xor_rotate_right_8_events: Vec, - pub blake2s_xor_rotate_right_7_events: Vec, - pub blake2s_quarter_round_2x_events: Vec, + pub blake2s_round_events: Vec, pub memory_initialize_events: Vec, @@ -335,51 +322,9 @@ impl EventLens> for ExecutionRecord { } } -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_xor_rotate_right_16_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_xor_rotate_16_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_add_2_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_add_3_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_xor_rotate_right_12_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_xor_rotate_right_8_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_xor_rotate_right_7_events - } -} - -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.blake2s_quarter_round_2x_events +impl EventLens for ExecutionRecord { + fn events(&self) -> >::Events { + &self.blake2s_round_events } } @@ -530,43 +475,10 @@ impl MachineRecord for ExecutionRecord { "bls12381_g2_double_events".to_string(), self.bls12381_g2_double_events.len(), ); - stats.insert( - "blake2s_xor_rotate_right_16_events".to_string(), - self.blake2s_xor_rotate_right_16_events.len(), - ); - stats.insert( - "blake2s_xor_rotate_16_events".to_string(), - self.blake2s_xor_rotate_16_events.len(), - ); - - stats.insert( - "blake2s_add_2_events".to_string(), - self.blake2s_add_2_events.len(), - ); - - stats.insert( - "blake2s_add_3_events".to_string(), - self.blake2s_add_3_events.len(), - ); stats.insert( - "blake2s_xor_rotate_right_12_events".to_string(), - self.blake2s_xor_rotate_right_12_events.len(), - ); - - stats.insert( - "blake2s_xor_rotate_right_8_events".to_string(), - self.blake2s_xor_rotate_right_8_events.len(), - ); - - stats.insert( - "blake2s_xor_rotate_right_7_events".to_string(), - self.blake2s_xor_rotate_right_7_events.len(), - ); - - stats.insert( - "blake2s_quarter_round_2x_events".to_string(), - self.blake2s_quarter_round_2x_events.len(), + "blake2s_round_events".to_string(), + self.blake2s_round_events.len(), ); stats @@ -614,23 +526,8 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.bls12381_g2_add_events); self.bls12381_g2_double_events .append(&mut other.bls12381_g2_double_events); - - self.blake2s_xor_rotate_right_16_events - .append(&mut other.blake2s_xor_rotate_right_16_events); - self.blake2s_xor_rotate_16_events - .append(&mut other.blake2s_xor_rotate_16_events); - self.blake2s_add_2_events - .append(&mut other.blake2s_add_2_events); - self.blake2s_add_3_events - .append(&mut other.blake2s_add_3_events); - self.blake2s_xor_rotate_right_12_events - .append(&mut other.blake2s_xor_rotate_right_12_events); - self.blake2s_xor_rotate_right_8_events - .append(&mut other.blake2s_xor_rotate_right_8_events); - self.blake2s_xor_rotate_right_7_events - .append(&mut other.blake2s_xor_rotate_right_7_events); - self.blake2s_quarter_round_2x_events - .append(&mut other.blake2s_quarter_round_2x_events); + self.blake2s_round_events + .append(&mut other.blake2s_round_events); // Merge the byte lookups. for (shard, events_map) in take(&mut other.byte_lookups) { @@ -958,53 +855,9 @@ impl MachineRecord for ExecutionRecord { self.nonce_lookup.insert(event.lookup_id, i as u32); } - // blake2s_xor_rotate_right_16 events - first.blake2s_xor_rotate_right_16_events = - take(&mut self.blake2s_xor_rotate_right_16_events); - for (i, event) in first.blake2s_xor_rotate_right_16_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // blake2s_xor_rotate_16 events - first.blake2s_xor_rotate_16_events = take(&mut self.blake2s_xor_rotate_16_events); - for (i, event) in first.blake2s_xor_rotate_16_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); - } - - // blake2s_add_2 events - first.blake2s_add_2_events = take(&mut self.blake2s_add_2_events); - for (i, event) in first.blake2s_add_2_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // blake2s_add_3 events - first.blake2s_add_3_events = take(&mut self.blake2s_add_3_events); - for (i, event) in first.blake2s_add_3_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // blake2s_xor_rotate_right_12 events - first.blake2s_xor_rotate_right_12_events = - take(&mut self.blake2s_xor_rotate_right_12_events); - for (i, event) in first.blake2s_xor_rotate_right_12_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // blake2s_xor_rotate_right_8 events - first.blake2s_xor_rotate_right_8_events = take(&mut self.blake2s_xor_rotate_right_8_events); - for (i, event) in first.blake2s_xor_rotate_right_8_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // blake2s_xor_rotate_right_7 events - first.blake2s_xor_rotate_right_7_events = take(&mut self.blake2s_xor_rotate_right_7_events); - for (i, event) in first.blake2s_xor_rotate_right_7_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // blake2s_quarter_round_2x events - first.blake2s_quarter_round_2x_events = take(&mut self.blake2s_quarter_round_2x_events); - for (i, event) in first.blake2s_quarter_round_2x_events.iter().enumerate() { + // blake2s_round events + first.blake2s_round_events = take(&mut self.blake2s_round_events); + for (i, event) in first.blake2s_round_events.iter().enumerate() { self.nonce_lookup.insert(event.lookup_id, i as u32); } diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 3d2294103..69a9473e1 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -6,11 +6,7 @@ use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; use crate::stark::Ed25519Parameters; -use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sQuarterRound2xChip, Blake2sXorRotate16Chip, - Blake2sXorRotateRight12Chip, Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, - Blake2sXorRotateRight8Chip, -}; +use crate::syscall::precompiles::blake2s::Blake2sRoundChip; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::bls12_381::g2_add::Bls12381G2AffineAddChip; use crate::syscall::precompiles::bls12_381::g2_double::Bls12381G2AffineDoubleChip; @@ -122,18 +118,7 @@ pub enum SyscallCode { /// Executes the `HINT_READ` precompile. HINT_READ = 0x00_00_00_F1, - BLAKE_2S_XOR_ROTATE_RIGHT_16 = 0x00_01_01_CC, - - BLAKE_2S_XOR_ROTATE_16 = 0x00_30_01_CD, // based on sha-extend - - BLAKE_2S_ADD_2 = 0x00_01_01_CE, - - BLAKE_2S_ADD_3 = 0x00_01_01_CF, - - BLAKE_2S_XOR_ROTATE_RIGHT_12 = 0x00_01_01_EA, - BLAKE_2S_XOR_ROTATE_RIGHT_8 = 0x00_01_01_EB, - BLAKE_2S_XOR_ROTATE_RIGHT_7 = 0x00_01_01_EC, - BLAKE_2S_QUARTER_ROUND_2X = 0x00_01_01_ED, + BLAKE_2S_ROUND = 0x00_01_01_ED, } impl SyscallCode { @@ -170,14 +155,7 @@ impl SyscallCode { 0x00_01_01_F2 => SyscallCode::BLS12381_G1_DECOMPRESS, 0x00_01_01_80 => SyscallCode::BLS12381_G2_ADD, 0x00_00_01_81 => SyscallCode::BLS12381_G2_DOUBLE, - 0x00_01_01_CC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16, - 0x00_30_01_CD => SyscallCode::BLAKE_2S_XOR_ROTATE_16, - 0x00_01_01_CE => SyscallCode::BLAKE_2S_ADD_2, - 0x00_01_01_CF => SyscallCode::BLAKE_2S_ADD_3, - 0x00_01_01_EA => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, - 0x00_01_01_EB => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, - 0x00_01_01_EC => SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7, - 0x00_01_01_ED => SyscallCode::BLAKE_2S_QUARTER_ROUND_2X, + 0x00_01_01_ED => SyscallCode::BLAKE_2S_ROUND, _ => panic!("invalid syscall number: {}", value), } } @@ -417,43 +395,8 @@ pub fn default_syscall_map() -> HashMap> { ); syscall_map.insert( - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16, - Arc::new(Blake2sXorRotateRight16Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_XOR_ROTATE_16, - Arc::new(Blake2sXorRotate16Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_ADD_2, - Arc::new(Blake2sAdd2Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_ADD_3, - Arc::new(Blake2sAdd3Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12, - Arc::new(Blake2sXorRotateRight12Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8, - Arc::new(Blake2sXorRotateRight8Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7, - Arc::new(Blake2sXorRotateRight7Chip::new()), - ); - - syscall_map.insert( - SyscallCode::BLAKE_2S_QUARTER_ROUND_2X, - Arc::new(Blake2sQuarterRound2xChip::new()), + SyscallCode::BLAKE_2S_ROUND, + Arc::new(Blake2sRoundChip::new()), ); syscall_map @@ -569,52 +512,8 @@ mod tests { SyscallCode::BLS12381_G2_DOUBLE => { assert_eq!(code as u32, sphinx_zkvm::syscalls::BLS12381_G2_DOUBLE) } - - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16 => { - assert_eq!( - code as u32, - sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_16 - ) - } - - SyscallCode::BLAKE_2S_XOR_ROTATE_16 => { - assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_16) - } - - SyscallCode::BLAKE_2S_ADD_2 => { - assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ADD_2) - } - - SyscallCode::BLAKE_2S_ADD_3 => { - assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ADD_3) - } - - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12 => { - assert_eq!( - code as u32, - sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_12 - ) - } - - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8 => { - assert_eq!( - code as u32, - sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_8 - ) - } - - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7 => { - assert_eq!( - code as u32, - sphinx_zkvm::syscalls::BLAKE_2S_XOR_ROTATE_RIGHT_7 - ) - } - - SyscallCode::BLAKE_2S_QUARTER_ROUND_2X => { - assert_eq!( - code as u32, - sphinx_zkvm::syscalls::BLAKE_2S_QUARTER_ROUND_2X - ) + SyscallCode::BLAKE_2S_ROUND => { + assert_eq!(code as u32, sphinx_zkvm::syscalls::BLAKE_2S_ROUND) } } } diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index cfbc76aaf..3b4d61efc 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -3,11 +3,7 @@ pub use crate::air::SphinxAirBuilder; use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; use crate::memory::{MemoryChipType, MemoryProgramChip}; use crate::stark::Chip; -use crate::syscall::precompiles::blake2s::{ - Blake2sAdd2Chip, Blake2sAdd3Chip, Blake2sQuarterRound2xChip, Blake2sXorRotate16Chip, - Blake2sXorRotateRight12Chip, Blake2sXorRotateRight16Chip, Blake2sXorRotateRight7Chip, - Blake2sXorRotateRight8Chip, -}; +use crate::syscall::precompiles::blake2s::Blake2sRoundChip; use crate::syscall::precompiles::bls12_381::g1_decompress::Bls12381G1DecompressChip; use crate::syscall::precompiles::field::FieldChip; use crate::syscall::precompiles::quad_field::QuadFieldChip; @@ -111,16 +107,8 @@ pub enum RiscvAir { Bls12381Fp2Op(QuadFieldChip), /// A precompile for decompressing a point on the BLS12-381 curve. Bls12381G1Decompress(Bls12381G1DecompressChip), - - // Blake2s - Blake2sXorRotateRight16(Blake2sXorRotateRight16Chip), - Blake2sXorRotate16(Blake2sXorRotate16Chip), // based on sha-extend - Blake2sAdd2(Blake2sAdd2Chip), - Blake2sAdd3(Blake2sAdd3Chip), - Blake2sXorRotateRight12(Blake2sXorRotateRight12Chip), - Blake2sXorRotateRight8(Blake2sXorRotateRight8Chip), - Blake2sXorRotateRight7(Blake2sXorRotateRight7Chip), - Blake2sQuarterRound2x(Blake2sQuarterRound2xChip), + // A precompile for computing round function of Blake2s algorithm + Blake2sRound(Blake2sRoundChip), } impl RiscvAir { @@ -196,38 +184,8 @@ impl RiscvAir { chips.push(RiscvAir::ProgramMemory(program_memory_init)); let byte = ByteChip::default(); chips.push(RiscvAir::ByteLookup(byte)); - - let blake_2s_xor_rotate_right_16 = Blake2sXorRotateRight16Chip::default(); - chips.push(RiscvAir::Blake2sXorRotateRight16( - blake_2s_xor_rotate_right_16, - )); - - let blake_2s_xor_rotate_16 = Blake2sXorRotate16Chip::default(); - chips.push(RiscvAir::Blake2sXorRotate16(blake_2s_xor_rotate_16)); - - let blake2s_add_2 = Blake2sAdd2Chip::default(); - chips.push(RiscvAir::Blake2sAdd2(blake2s_add_2)); - - let blake2s_add_3 = Blake2sAdd3Chip::default(); - chips.push(RiscvAir::Blake2sAdd3(blake2s_add_3)); - - let blake_2s_xor_rotate_right_12 = Blake2sXorRotateRight12Chip::default(); - chips.push(RiscvAir::Blake2sXorRotateRight12( - blake_2s_xor_rotate_right_12, - )); - - let blake_2s_xor_rotate_right_8 = Blake2sXorRotateRight8Chip::default(); - chips.push(RiscvAir::Blake2sXorRotateRight8( - blake_2s_xor_rotate_right_8, - )); - - let blake_2s_xor_rotate_right_7 = Blake2sXorRotateRight7Chip::default(); - chips.push(RiscvAir::Blake2sXorRotateRight7( - blake_2s_xor_rotate_right_7, - )); - - let blake_2s_quarter_round_2x = Blake2sQuarterRound2xChip::default(); - chips.push(RiscvAir::Blake2sQuarterRound2x(blake_2s_quarter_round_2x)); + let blake_2s_round = Blake2sRoundChip::default(); + chips.push(RiscvAir::Blake2sRound(blake_2s_round)); chips } diff --git a/core/src/syscall/precompiles/blake2s/add_2.rs b/core/src/syscall/precompiles/blake2s/add_2.rs deleted file mode 100644 index 98879c26e..000000000 --- a/core/src/syscall/precompiles/blake2s/add_2.rs +++ /dev/null @@ -1,368 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::Add4Operation; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -#[derive(Default)] -pub struct Blake2sAdd2Chip; - -impl Blake2sAdd2Chip { - pub fn new() -> Self { - Blake2sAdd2Chip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sAdd2Event { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sAdd2Chip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 12); - - let add2 = a - .into_iter() - .zip(b[0..4].into_iter()) - .map(|(a, b)| a.wrapping_add(*b)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, add2.as_slice()); - - ctx.record_mut() - .blake2s_add_2_events - .push(Blake2sAdd2Event { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sAdd2Cols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 12], - - pub add2: [Add4Operation; 4], -} - -impl BaseAir for Blake2sAdd2Chip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sAdd2Chip { - type Events = &'a [Blake2sAdd2Event]; -} - -impl MachineAir for Blake2sAdd2Chip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sAdd2Chip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sAdd2Cols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - cols.b[i + 4].populate( - event.channel, - event.b_reads[i + 4], - &mut new_byte_lookup_events, - ); // expected to be zero - cols.b[i + 8].populate( - event.channel, - event.b_reads[i + 8], - &mut new_byte_lookup_events, - ); // expected to be zero - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - - let add = cols.add2[i].populate(output, shard, event.channel, a, b, 0, 0); - assert_eq!(a + b, add); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sAdd2Cols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_add_2_events.is_empty() - } -} - -impl Air for Blake2sAdd2Chip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sAdd2Cols = (*local).borrow(); - let next: &Blake2sAdd2Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b [0..4]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval b[4..8]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr - + ((AB::F::from_canonical_u32(4) + AB::F::from_canonical_u32(i as u32)) - * AB::F::from_canonical_u32(4)), - &local.b[i + 4], - local.is_real, - ); - - // Eval b[8..12]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr - + ((AB::F::from_canonical_u32(8) + AB::F::from_canonical_u32(i as u32)) - * AB::F::from_canonical_u32(4)), - &local.b[i + 8], - local.is_real, - ); - - Add4Operation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - *local.b[i + 4].value(), // zero - *local.b[i + 8].value(), // zero - local.shard, - local.channel, - local.is_real, - local.add2[i], - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ADD_2.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_ADD_2_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 12]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_ADD_2 as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_add_2_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [200, 300, 400, 500], - [10, 20, 30, 40, 0, 0, 0, 0, 0, 0, 0, 0], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!(result, [210, 320, 430, 540].to_vec()); - } - - #[test] - fn test_blake2s_add_2_program() { - setup_logger(); - let program = Program::from(BLAKE2S_ADD_2_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/add_3.rs b/core/src/syscall/precompiles/blake2s/add_3.rs deleted file mode 100644 index 28506205f..000000000 --- a/core/src/syscall/precompiles/blake2s/add_3.rs +++ /dev/null @@ -1,371 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::Add4Operation; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -#[derive(Default)] -pub struct Blake2sAdd3Chip; - -impl Blake2sAdd3Chip { - pub fn new() -> Self { - Blake2sAdd3Chip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sAdd3Event { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sAdd3Chip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 12); - let c = b[4..8].to_vec(); - - let add3 = a - .into_iter() - .zip(b[0..4].into_iter()) - .zip(c.into_iter()) - .map(|((a, b), c)| a.wrapping_add(*b).wrapping_add(c)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, add3.as_slice()); - - ctx.record_mut() - .blake2s_add_3_events - .push(Blake2sAdd3Event { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sAdd3Cols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 12], - - pub add3: [Add4Operation; 4], -} - -impl BaseAir for Blake2sAdd3Chip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sAdd3Chip { - type Events = &'a [Blake2sAdd3Event]; -} - -impl MachineAir for Blake2sAdd3Chip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sAdd3Chip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sAdd3Cols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - cols.b[i + 4].populate( - event.channel, - event.b_reads[i + 4], - &mut new_byte_lookup_events, - ); - cols.b[i + 8].populate( - event.channel, - event.b_reads[i + 8], - &mut new_byte_lookup_events, - ); - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - let c = event.b_reads[i + 4].value; - - let add = cols.add3[i].populate(output, shard, event.channel, a, b, c, 0); - assert_eq!(a + b + c, add); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sAdd3Cols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_add_3_events.is_empty() - } -} - -impl Air for Blake2sAdd3Chip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sAdd3Cols = (*local).borrow(); - let next: &Blake2sAdd3Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b[0..4]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval b[4..8]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr - + ((AB::F::from_canonical_u32(4) + AB::F::from_canonical_u32(i as u32)) - * AB::F::from_canonical_u32(4)), - &local.b[i + 4], - local.is_real, - ); - - // Eval b[8..12]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr - + ((AB::F::from_canonical_u32(8) + AB::F::from_canonical_u32(i as u32)) - * AB::F::from_canonical_u32(4)), - &local.b[i + 8], - local.is_real, - ); - - Add4Operation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - *local.b[i + 4].value(), - *local.b[i + 8].value(), // zero - local.shard, - local.channel, - local.is_real, - local.add3[i], - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ADD_3.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_ADD_3_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 12]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_ADD_3 as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_add_3_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [200, 300, 400, 500], - [10, 20, 30, 40, 1, 2, 3, 4, 0, 0, 0, 0], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!(result, [211, 322, 433, 544].to_vec()); - } - - #[test] - fn test_blake2s_add_3_program() { - setup_logger(); - let program = Program::from(BLAKE2S_ADD_3_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 83844f82c..a9229b40b 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,103 +1,112 @@ -mod add_2; -mod add_3; mod round; -mod xor_rotate_16; // based on sha-extend -mod xor_rotate_right_12; -mod xor_rotate_right_16; -mod xor_rotate_right_7; -mod xor_rotate_right_8; - -pub use add_2::*; -pub use add_3::*; pub use round::*; -pub use xor_rotate_16::*; // based on sha-extend -pub use xor_rotate_right_12::*; -pub use xor_rotate_right_16::*; -pub use xor_rotate_right_7::*; -pub use xor_rotate_right_8::*; - -#[cfg(test)] -mod tests { - fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { - [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] - } - - fn shuffle_left_1_u32x4(a: [u32; 4]) -> [u32; 4] { - [a[1], a[2], a[3], a[0]] - } - - fn shuffle_left_2_u32x4(a: [u32; 4]) -> [u32; 4] { - [a[2], a[3], a[0], a[1]] - } - - fn shuffle_left_3_u32x4(a: [u32; 4]) -> [u32; 4] { - [a[3], a[0], a[1], a[2]] - } - - fn shuffle_right_1_u32x4(a: [u32; 4]) -> [u32; 4] { - shuffle_left_3_u32x4(a) - } - fn shuffle_right_2_u32x4(a: [u32; 4]) -> [u32; 4] { - shuffle_left_2_u32x4(a) - } - fn shuffle_right_3_u32x4(a: [u32; 4]) -> [u32; 4] { - shuffle_left_1_u32x4(a) - } - - fn wrapping_add_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { - [ - a[0].wrapping_add(b[0]), - a[1].wrapping_add(b[1]), - a[2].wrapping_add(b[2]), - a[3].wrapping_add(b[3]), - ] - } - - fn rotate_right_const(a: [u32; 4], n: u32) -> [u32; 4] { - [ - a[0].rotate_right(n), - a[1].rotate_right(n), - a[2].rotate_right(n), - a[3].rotate_right(n), - ] - } - fn quarter_round(v: &mut Vec<[u32; 4]>, rd: u32, rb: u32, m: [u32; 4]) { - v[0] = wrapping_add_u32x4(wrapping_add_u32x4(v[0], v[1]), m); // m.from_le (?) - v[3] = rotate_right_const(xor_u32x4(v[3], v[0]), rd); - v[2] = wrapping_add_u32x4(v[2], v[3]); - v[1] = rotate_right_const(xor_u32x4(v[1], v[2]), rb); - } - - fn shuffle(v: &mut Vec<[u32; 4]>) { - v[1] = shuffle_left_1_u32x4(v[1]); - v[2] = shuffle_left_2_u32x4(v[2]); - v[3] = shuffle_left_3_u32x4(v[3]); - } - - fn unshuffle(v: &mut Vec<[u32; 4]>) { - v[1] = shuffle_right_1_u32x4(v[1]); - v[2] = shuffle_right_2_u32x4(v[2]); - v[3] = shuffle_right_3_u32x4(v[3]); - } +fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { + [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] +} +fn shuffle_left_1_u32x4(a: [u32; 4]) -> [u32; 4] { + [a[1], a[2], a[3], a[0]] +} +fn shuffle_left_2_u32x4(a: [u32; 4]) -> [u32; 4] { + [a[2], a[3], a[0], a[1]] +} +fn shuffle_left_3_u32x4(a: [u32; 4]) -> [u32; 4] { + [a[3], a[0], a[1], a[2]] +} +fn shuffle_right_1_u32x4(a: [u32; 4]) -> [u32; 4] { + shuffle_left_3_u32x4(a) +} +fn shuffle_right_2_u32x4(a: [u32; 4]) -> [u32; 4] { + shuffle_left_2_u32x4(a) +} +fn shuffle_right_3_u32x4(a: [u32; 4]) -> [u32; 4] { + shuffle_left_1_u32x4(a) +} +fn wrapping_add_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { + [ + a[0].wrapping_add(b[0]), + a[1].wrapping_add(b[1]), + a[2].wrapping_add(b[2]), + a[3].wrapping_add(b[3]), + ] +} +fn rotate_right_const(a: [u32; 4], n: u32) -> [u32; 4] { + [ + a[0].rotate_right(n), + a[1].rotate_right(n), + a[2].rotate_right(n), + a[3].rotate_right(n), + ] +} +fn quarter_round(v: &mut Vec<[u32; 4]>, rd: u32, rb: u32, m: [u32; 4]) { + v[0] = wrapping_add_u32x4(wrapping_add_u32x4(v[0], v[1]), m); // m.from_le (?) + v[3] = rotate_right_const(xor_u32x4(v[3], v[0]), rd); + v[2] = wrapping_add_u32x4(v[2], v[3]); + v[1] = rotate_right_const(xor_u32x4(v[1], v[2]), rb); +} +fn shuffle(v: &mut Vec<[u32; 4]>) { + v[1] = shuffle_left_1_u32x4(v[1]); + v[2] = shuffle_left_2_u32x4(v[2]); + v[3] = shuffle_left_3_u32x4(v[3]); +} +fn unshuffle(v: &mut Vec<[u32; 4]>) { + v[1] = shuffle_right_1_u32x4(v[1]); + v[2] = shuffle_right_2_u32x4(v[2]); + v[3] = shuffle_right_3_u32x4(v[3]); +} +fn gather(m: [u32; 16], i0: usize, i1: usize, i2: usize, i3: usize) -> [u32; 4] { + [m[i0], m[i1], m[i2], m[i3]] +} +fn round(v: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16]) { + let r1 = 16; + let r2 = 12; + let r3 = 8; + let r4 = 7; + + quarter_round(v, r1, r2, gather(m, s[0], s[2], s[4], s[6])); + quarter_round(v, r3, r4, gather(m, s[1], s[3], s[5], s[7])); + shuffle(v); + quarter_round(v, r1, r2, gather(m, s[8], s[10], s[12], s[14])); + quarter_round(v, r3, r4, gather(m, s[9], s[11], s[13], s[15])); + unshuffle(v); +} - fn gather(m: [u32; 16], i0: usize, i1: usize, i2: usize, i3: usize) -> [u32; 4] { - [m[i0], m[i1], m[i2], m[i3]] +pub fn blake2s_round(v: &mut [u32], m: &[u32]) { + assert_eq!(v.len(), 16); + assert_eq!(m.len(), 24); + for item in m[16..24].iter() { + assert_eq!(*item, 0u32); } - fn round(v: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16]) { - let r1 = 16; - let r2 = 12; - let r3 = 8; - let r4 = 7; + let r1 = 16; + let r2 = 12; + let r3 = 8; + let r4 = 7; + + let mut v0 = [0u32; 4]; + v0.copy_from_slice(&v[0..4]); + let mut v1 = [0u32; 4]; + v1.copy_from_slice(&v[4..8]); + let mut v2 = [0u32; 4]; + v2.copy_from_slice(&v[8..12]); + let mut v3 = [0u32; 4]; + v3.copy_from_slice(&v[12..16]); + + let mut input = vec![v0, v1, v2, v3]; + quarter_round(&mut input, r1, r2, m[0..4].try_into().unwrap()); + quarter_round(&mut input, r3, r4, m[4..8].try_into().unwrap()); + shuffle(&mut input); + quarter_round(&mut input, r1, r2, m[8..12].try_into().unwrap()); + quarter_round(&mut input, r3, r4, m[12..16].try_into().unwrap()); + unshuffle(&mut input); + + let input = input.into_iter().flatten().collect::>(); + v.copy_from_slice(input.as_slice()); +} - quarter_round(v, r1, r2, gather(m, s[0], s[2], s[4], s[6])); - quarter_round(v, r3, r4, gather(m, s[1], s[3], s[5], s[7])); - shuffle(v); - quarter_round(v, r1, r2, gather(m, s[8], s[10], s[12], s[14])); - quarter_round(v, r3, r4, gather(m, s[9], s[11], s[13], s[15])); - unshuffle(v); - } +#[cfg(test)] +mod tests { + use crate::syscall::precompiles::blake2s::{quarter_round, round, shuffle, unshuffle}; #[test] fn test_blake2s_round_function() { @@ -257,124 +266,4 @@ mod tests { vec![0x6ab9ed19, 0x7f9dcd68, 0xeb49bb8e, 0xf4a5ad0] ); } - - #[test] - fn test_blake2s_quarter_round_2x_function() { - let mut v: Vec<[u32; 4]> = vec![ - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], - ]; - let m = [0, 0, 0, 0]; - let rd = 16; - let rb = 12; - - quarter_round(&mut v, rd, rb, m); - - let rd = 8; - let rb = 7; - - quarter_round(&mut v, rd, rb, m); - - assert_eq!( - v[0].to_vec(), - vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc] - ); - assert_eq!( - v[1].to_vec(), - vec![0x408705aa, 0x8d07c52d, 0xb9d6aa3a, 0x88609304] - ); - assert_eq!( - v[2].to_vec(), - vec![0x5c7a89f8, 0xb5f896c7, 0x81e69eeb, 0xe17775ed] - ); - assert_eq!( - v[3].to_vec(), - vec![0x87b6b678, 0x7af31ada, 0x5a2defeb, 0x2cdd25e3] - ); - } - - #[test] - fn test_blake2s_quarter_round_2x_shuffle_function() { - let mut v: Vec<[u32; 4]> = vec![ - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], - ]; - let m = [0, 0, 0, 0]; - let rd = 16; - let rb = 12; - - quarter_round(&mut v, rd, rb, m); - - let rd = 8; - let rb = 7; - - quarter_round(&mut v, rd, rb, m); - shuffle(&mut v); - - assert_eq!( - v[0].to_vec(), - vec![0xdc0f959e, 0x8c871712, 0xc6a650d4, 0xd26fb9fc] - ); - assert_eq!( - v[1].to_vec(), - vec![0x8d07c52d, 0xb9d6aa3a, 0x88609304, 0x408705aa] - ); - assert_eq!( - v[2].to_vec(), - vec![0x81e69eeb, 0xe17775ed, 0x5c7a89f8, 0xb5f896c7] - ); - assert_eq!( - v[3].to_vec(), - vec![0x2cdd25e3, 0x87b6b678, 0x7af31ada, 0x5a2defeb] - ); - } - - #[test] - fn test_blake2s_quarter_round_2x_shuffle_quarter_round_2x_function() { - let mut v: Vec<[u32; 4]> = vec![ - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19], - ]; - let m = [0, 0, 0, 0]; - let rd = 16; - let rb = 12; - quarter_round(&mut v, rd, rb, m); - - let rd = 8; - let rb = 7; - quarter_round(&mut v, rd, rb, m); - shuffle(&mut v); - - let rd = 16; - let rb = 12; - quarter_round(&mut v, rd, rb, m); - - let rd = 8; - let rb = 7; - quarter_round(&mut v, rd, rb, m); - unshuffle(&mut v); - - assert_eq!( - v[0].to_vec(), - vec![0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3] - ); - assert_eq!( - v[1].to_vec(), - vec![0x515f5af4, 0x301095b, 0xb151a3c2, 0x5e17f96f] - ); - assert_eq!( - v[2].to_vec(), - vec![0xc561666d, 0xf291605, 0x990c6d13, 0x76fff6f1] - ); - assert_eq!( - v[3].to_vec(), - vec![0x1e53bf19, 0x6fe4a680, 0x8e33663, 0x97fd885e] - ); - } } diff --git a/core/src/syscall/precompiles/blake2s/round.rs b/core/src/syscall/precompiles/blake2s/round.rs index 834f597c4..2661514cc 100644 --- a/core/src/syscall/precompiles/blake2s/round.rs +++ b/core/src/syscall/precompiles/blake2s/round.rs @@ -24,13 +24,13 @@ const R_3: u32 = 8; const R_4: u32 = 7; #[derive(Default)] -pub struct Blake2sQuarterRound2xChip; +pub struct Blake2sRoundChip; -impl Blake2sQuarterRound2xChip { +impl Blake2sRoundChip { pub fn new() -> Self { - Blake2sQuarterRound2xChip + Blake2sRoundChip } - pub fn constrain_shuffled_unshuffled_indices( + pub fn constrain_shuffled_indices( &self, builder: &mut AB, indices: &[AB::Var], @@ -50,7 +50,7 @@ impl Blake2sQuarterRound2xChip { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sQuarterRound2xEvent { +pub struct Blake2sRoundEvent { pub lookup_id: usize, pub clk: u32, pub shard: u32, @@ -62,7 +62,7 @@ pub struct Blake2sQuarterRound2xEvent { pub b_reads: Vec, } -impl Syscall for Blake2sQuarterRound2xChip { +impl Syscall for Blake2sRoundChip { fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { let clk_init = ctx.clk; let shard = ctx.current_shard(); @@ -80,6 +80,14 @@ impl Syscall for Blake2sQuarterRound2xChip { // m3[0] || m3[1] || m3[2] || m3[3] || m4[0] || m4[1] || m4[2] || mr[3] || // 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 let (b_reads, b) = ctx.mr_slice(b_ptr, 24); + assert_eq!(b[16], 0u32); + assert_eq!(b[17], 0u32); + assert_eq!(b[18], 0u32); + assert_eq!(b[19], 0u32); + assert_eq!(b[20], 0u32); + assert_eq!(b[21], 0u32); + assert_eq!(b[22], 0u32); + assert_eq!(b[23], 0u32); // 1x (m1, R1, R2) // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) @@ -237,8 +245,8 @@ impl Syscall for Blake2sQuarterRound2xChip { let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); ctx.record_mut() - .blake2s_quarter_round_2x_events - .push(Blake2sQuarterRound2xEvent { + .blake2s_round_events + .push(Blake2sRoundEvent { lookup_id, clk: clk_init, shard, @@ -259,7 +267,7 @@ impl Syscall for Blake2sQuarterRound2xChip { #[derive(Debug, Clone, AlignedBorrow)] #[repr(C)] -struct Blake2sQuarterRound2xCols { +struct Blake2sRoundCols { pub clk: T, pub shard: T, pub channel: T, @@ -270,7 +278,6 @@ struct Blake2sQuarterRound2xCols { pub b_ptr: T, pub shuffled_indices: [T; 16], - pub unshuffled_indices: [T; 16], pub a: [MemoryWriteCols; 16], pub b: [MemoryReadCols; 24], @@ -280,22 +287,22 @@ struct Blake2sQuarterRound2xCols { pub rotate_right: [FixedRotateRightOperation; 32], } -impl BaseAir for Blake2sQuarterRound2xChip { +impl BaseAir for Blake2sRoundChip { fn width(&self) -> usize { - size_of::>() + size_of::>() } } -impl<'a> WithEvents<'a> for Blake2sQuarterRound2xChip { - type Events = &'a [Blake2sQuarterRound2xEvent]; +impl<'a> WithEvents<'a> for Blake2sRoundChip { + type Events = &'a [Blake2sRoundEvent]; } -impl MachineAir for Blake2sQuarterRound2xChip { +impl MachineAir for Blake2sRoundChip { type Record = ExecutionRecord; type Program = Program; fn name(&self) -> String { - "Blake2sQuarterRound2xChip".to_string() + "Blake2sRoundChip".to_string() } fn generate_trace>( @@ -304,12 +311,12 @@ impl MachineAir for Blake2sQuarterRound2xChip { output: &mut Self::Record, ) -> RowMajorMatrix { let mut rows = vec![]; - let width = >::width(self); + let width = >::width(self); let mut new_byte_lookup_events = Vec::new(); for event in input.events() { let shard = event.shard; let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sQuarterRound2xCols = row.as_mut_slice().borrow_mut(); + let cols: &mut Blake2sRoundCols = row.as_mut_slice().borrow_mut(); cols.clk = F::from_canonical_u32(event.clk); cols.is_real = F::one(); @@ -333,27 +340,20 @@ impl MachineAir for Blake2sQuarterRound2xChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } - let v1_shuffle_lookup = vec![1, 2, 3, 0]; - let v2_shuffle_lookup = vec![2, 3, 0, 1]; - let v3_shuffle_lookup = vec![3, 0, 1, 2]; - - let v1_unshuffle_lookup = v1_shuffle_lookup.clone(); - let v2_unshuffle_lookup = v2_shuffle_lookup.clone(); - let v3_unshuffle_lookup = v3_shuffle_lookup.clone(); + let mut v0_outer = vec![0u32; 4]; + let mut v1_outer = vec![0u32; 4]; + let mut v2_outer = vec![0u32; 4]; + let mut v3_outer = vec![0u32; 4]; + // 1x (m1, R1, R2) for i in 0..4usize { - // 1x (m1, R1, R2) - let v0 = event.a_reads_writes[i].value; - let v1 = event.a_reads_writes[i + 4].value; - let v2 = event.a_reads_writes[i + 8].value; - let v3 = event.a_reads_writes[i + 12].value; + let v0 = event.a_reads_writes[i].prev_value; + let v1 = event.a_reads_writes[i + 4].prev_value; + let v2 = event.a_reads_writes[i + 8].prev_value; + let v3 = event.a_reads_writes[i + 12].prev_value; let m1 = event.b_reads[i].value; - let m2 = event.b_reads[i + 4].value; - let m3 = event.b_reads[i + 8].value; - let m4 = event.b_reads[i + 12].value; let zero1 = event.b_reads[i + 16].value; let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); assert_eq!(zero2, 0); @@ -362,18 +362,25 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v0 + v1 + m1 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0); + let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0_new); let v3_new = cols.rotate_right[i].populate(output, shard, event.channel, temp, R_1 as usize); - assert_eq!((v3 ^ v0).rotate_right(R_1), v3_new); + assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = - cols.add[i + 4].populate(output, shard, event.channel, v2, v3, zero1, zero2); - assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + let v2_new = cols.add[i + 4].populate( + output, + shard, + event.channel, + v2, + v3_new, + zero1, + zero2, + ); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2); + let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2_new); let v1_new = cols.rotate_right[i + 4].populate( output, shard, @@ -381,64 +388,107 @@ impl MachineAir for Blake2sQuarterRound2xChip { temp, R_2 as usize, ); - assert_eq!((v1 ^ v2).rotate_right(R_2), v1_new); + assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); + + v0_outer[i] = v0_new; + v1_outer[i] = v1_new; + v2_outer[i] = v2_new; + v3_outer[i] = v3_new; + } - // 2x (m2, R3, R4) - let v0 = v0_new; - let v1 = v1_new; - let v2 = v2_new; - let v3 = v3_new; + // 2x (m2, R3, R4) + for i in 0..4usize { + let v0 = v0_outer[i]; + let v1 = v1_outer[i]; + let v2 = v2_outer[i]; + let v3 = v3_outer[i]; + let m2 = event.b_reads[i + 4].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) let v0_new = cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); - assert_eq!(v0 + v1 + m1 + zero1, v0_new); + assert_eq!(v0 + v1 + m2 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); - let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0); - let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( - //let v3_new = cols.rotate_right[i + 8].populate( + //cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); + let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0_new); + //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( + let v3_new = cols.rotate_right[i + 8].populate( output, shard, event.channel, temp, R_3 as usize, ); - assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); + assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( - //let v2_new = cols.add[i + 4 + 8].populate( + //cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); + //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( + let v2_new = cols.add[i + 4 + 8].populate( output, shard, event.channel, v2, - v3, + v3_new, zero1, zero2, ); - assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); - let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2); - let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( - //let v1_new = cols.rotate_right[i + 4 + 8].populate( + //cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); + let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2_new); + //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( + let v1_new = cols.rotate_right[i + 4 + 8].populate( output, shard, event.channel, temp, R_4 as usize, ); - assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); + assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); + + v0_outer[i] = v0_new; + v1_outer[i] = v1_new; + v2_outer[i] = v2_new; + v3_outer[i] = v3_new; + } - // 3x (m3, R1, R2) - let v0 = v0_new; - let v1 = v1_new; - let v2 = v2_new; - let v3 = v3_new; + // shuffle + // v[1] + v1_outer.swap(0, 3); + v1_outer.swap(0, 1); + v1_outer.swap(1, 2); + + // v[2] + v2_outer.swap(0, 2); + v2_outer.swap(1, 3); + + // v[3] + v3_outer.swap(2, 3); + v3_outer.swap(1, 2); + v3_outer.swap(0, 1); + + // 3x (m3, R1, R2) + for i in 0..4usize { + cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); + cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); + cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); + + let v0 = v0_outer[i]; + let v1 = v1_outer[i]; + let v2 = v2_outer[i]; + let v3 = v3_outer[i]; + let m3 = event.b_reads[i + 8].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); let v0_new = @@ -446,7 +496,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v0 + v1 + m3 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0); + let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0_new); let v3_new = cols.rotate_right[i + 16].populate( output, shard, @@ -454,7 +504,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { temp, R_1 as usize, ); - assert_eq!((v3 ^ v0).rotate_right(R_1), v3_new); + assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); // v[2] = v[2].wrapping_add(v[3]); let v2_new = cols.add[i + 16 + 4].populate( @@ -462,14 +512,14 @@ impl MachineAir for Blake2sQuarterRound2xChip { shard, event.channel, v2, - v3, + v3_new, zero1, zero2, ); - assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - let temp = cols.xor[i + 16 + 4].populate(output, shard, event.channel, v1, v2); + let temp = cols.xor[i + 16 + 4].populate(output, shard, event.channel, v1, v2_new); let v1_new = cols.rotate_right[i + 16 + 4].populate( output, shard, @@ -477,13 +527,25 @@ impl MachineAir for Blake2sQuarterRound2xChip { temp, R_2 as usize, ); - assert_eq!((v1 ^ v2).rotate_right(R_2), v1_new); + assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); - // 4x (m4, R3, R4) - let v0 = v0_new; - let v1 = v1_new; - let v2 = v2_new; - let v3 = v3_new; + v0_outer[i] = v0_new; + v1_outer[i] = v1_new; + v2_outer[i] = v2_new; + v3_outer[i] = v3_new; + } + + // 4x (m4, R3, R4) + for i in 0..4usize { + let v0 = v0_outer[i]; + let v1 = v1_outer[i]; + let v2 = v2_outer[i]; + let v3 = v3_outer[i]; + let m4 = event.b_reads[i + 12].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) let v0_new = @@ -491,46 +553,70 @@ impl MachineAir for Blake2sQuarterRound2xChip { assert_eq!(v0 + v1 + m4 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - cols.unshuffled_indices[i + 12] = F::from_canonical_u32(1); - let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0); - let v3_new = cols.rotate_right[v3_unshuffle_lookup[i] + 16 + 8].populate( - //let v3_new = cols.rotate_right[i + 16 + 8].populate( + //cols.unshuffled_indices[i + 12] = F::from_canonical_u32(1); + let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0_new); + //let v3_new = cols.rotate_right[v3_unshuffle_lookup[i] + 16 + 8].populate( + let v3_new = cols.rotate_right[i + 16 + 8].populate( output, shard, event.channel, temp, R_3 as usize, ); - assert_eq!((v3 ^ v0).rotate_right(R_3), v3_new); + assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - cols.unshuffled_indices[i + 8] = F::from_canonical_u32(1); - let v2_new = cols.add[v2_unshuffle_lookup[i] + 16 + 4 + 8].populate( - //let v2_new = cols.add[i + 16 + 4 + 8].populate( + //cols.unshuffled_indices[i + 8] = F::from_canonical_u32(1); + //let v2_new = cols.add[v2_unshuffle_lookup[i] + 16 + 4 + 8].populate( + let v2_new = cols.add[i + 16 + 4 + 8].populate( output, shard, event.channel, v2, - v3, + v3_new, zero1, zero2, ); - assert_eq!(v2 + v3 + zero1 + zero2, v2_new); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - cols.unshuffled_indices[i + 4] = F::from_canonical_u32(1); - let temp = cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2); - let v1_new = cols.rotate_right[v1_unshuffle_lookup[i] + 16 + 4 + 8].populate( - //let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( + //cols.unshuffled_indices[i + 4] = F::from_canonical_u32(1); + let temp = + cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2_new); + //let v1_new = cols.rotate_right[v1_unshuffle_lookup[i] + 16 + 4 + 8].populate( + let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( output, shard, event.channel, temp, R_4 as usize, ); - assert_eq!((v1 ^ v2).rotate_right(R_4), v1_new); + assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); + + //v0_outer[i] = v0_new; + //v1_outer[i] = v1_new; + //v2_outer[i] = v2_new; + //v3_outer[i] = v3_new; } + /* + // unshuffle + // v[1] + v1_outer.swap(2, 3); + v1_outer.swap(1, 2); + v1_outer.swap(0, 1); + + // v[2] + v2_outer.swap(0, 2); + v2_outer.swap(1, 3); + + // v[3] + v3_outer.swap(0, 3); + v3_outer.swap(0, 1); + v3_outer.swap(1, 2);*/ + + //println!("4x traces: {:02x?}", [v0_outer, v1_outer, v2_outer, v3_outer].concat().to_vec()); + rows.push(row); } @@ -547,7 +633,7 @@ impl MachineAir for Blake2sQuarterRound2xChip { // Write the nonces to the trace. for i in 0..trace.height() { - let cols: &mut Blake2sQuarterRound2xCols = + let cols: &mut Blake2sRoundCols = trace.values[i * width..(i + 1) * width].borrow_mut(); cols.nonce = F::from_canonical_usize(i); } @@ -556,11 +642,11 @@ impl MachineAir for Blake2sQuarterRound2xChip { } fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_quarter_round_2x_events.is_empty() + !shard.blake2s_round_events.is_empty() } } -impl Air for Blake2sQuarterRound2xChip +impl Air for Blake2sRoundChip where AB::F: PrimeField32, { @@ -568,8 +654,8 @@ where let main = builder.main(); let local = main.row_slice(0); let next = main.row_slice(1); - let local: &Blake2sQuarterRound2xCols = (*local).borrow(); - let next: &Blake2sQuarterRound2xCols = (*next).borrow(); + let local: &Blake2sRoundCols = (*local).borrow(); + let next: &Blake2sRoundCols = (*next).borrow(); // Constrain the incrementing nonce. builder.when_first_row().assert_zero(local.nonce); @@ -616,20 +702,16 @@ where let v2_shuffle_lookup = vec![2, 3, 0, 1]; let v3_shuffle_lookup = vec![3, 0, 1, 2]; - let v1_unshuffle_lookup = v1_shuffle_lookup.clone(); - let v2_unshuffle_lookup = v2_shuffle_lookup.clone(); - let v3_unshuffle_lookup = v3_shuffle_lookup.clone(); - for i in 0..4usize { // 1x // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, - *local.a[i].value(), // v0 - *local.a[i + 4].value(), // v1 - *local.b[i].value(), // m1 - *local.b[i + 8].value(), // zero1 + *local.a[i].prev_value(), // v0 + *local.a[i + 4].prev_value(), // v1 + *local.b[i].value(), // m1 + *local.b[i + 20].value(), // zero1 local.shard, local.channel, local.is_real, @@ -640,13 +722,14 @@ where // Eval XOR XorOperation::::eval( builder, - *local.a[i + 12].value(), - *local.a[i].value(), + *local.a[i + 12].prev_value(), + local.add[i].value, local.xor[i], local.shard, &local.channel, local.is_real, ); + // Eval RotateRight FixedRotateRightOperation::::eval( builder, @@ -661,10 +744,10 @@ where // v[2] = v[2].wrapping_add(v[3]); Add4Operation::::eval( builder, - *local.a[i + 8].value(), // v2 - *local.a[i + 12].value(), // v3 - *local.b[i + 8].value(), // zero1 - *local.b[i + 12].value(), // zero2 + *local.a[i + 8].prev_value(), // v2 + local.rotate_right[i].value, // v3 from previous operation + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 local.shard, local.channel, local.is_real, @@ -675,8 +758,8 @@ where // Eval XOR XorOperation::::eval( builder, - *local.a[i + 4].value(), - *local.a[i + 8].value(), + *local.a[i + 4].prev_value(), + local.add[i + 4].value, local.xor[i + 4], local.shard, &local.channel, @@ -695,14 +778,13 @@ where ); // 2x - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, local.add[i].value, // v0 after 1x local.rotate_right[i + 4].value, // v1 after 1x *local.b[i + 4].value(), // m2 - *local.b[i + 8].value(), // zero1 + *local.b[i + 16].value(), // zero1 local.shard, local.channel, local.is_real, @@ -714,7 +796,7 @@ where XorOperation::::eval( builder, local.rotate_right[i].value, // v3 after 1x - local.add[i].value, // v0 after 1x + local.add[i + 8].value, // v0 after 1x local.xor[i + 8], local.shard, &local.channel, @@ -726,7 +808,7 @@ where builder, local.xor[i + 8].value, R_3 as usize, - local.rotate_right[v3_shuffle_lookup[i] + 8], + local.rotate_right[i + 8], local.shard, &local.channel, local.is_real, @@ -735,14 +817,14 @@ where // v[2] = v[2].wrapping_add(v[3]); Add4Operation::::eval( builder, - local.add[i + 4].value, // v2 after 1x - local.rotate_right[i].value, // v3 after 1x - *local.b[i + 8].value(), // zero1 - *local.b[i + 12].value(), // zero2 + local.add[i + 4].value, // v2 after 1x + local.rotate_right[i + 8].value, // v3 after previous operation + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 local.shard, local.channel, local.is_real, - local.add[v2_shuffle_lookup[i] + 12], + local.add[i + 12], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -750,7 +832,7 @@ where XorOperation::::eval( builder, local.rotate_right[i + 4].value, // v1 after 1x - local.add[i + 4].value, // v2 after 1x + local.add[i + 12].value, // v2 after previous operation local.xor[i + 12], local.shard, &local.channel, @@ -762,21 +844,21 @@ where builder, local.xor[i + 12].value, R_4 as usize, - local.rotate_right[v1_shuffle_lookup[i] + 12], + local.rotate_right[i + 12], local.shard, &local.channel, local.is_real, ); } - self.constrain_shuffled_unshuffled_indices(builder, &local.shuffled_indices, local.is_real); + self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); for i in 0..4usize { // 3x // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, - local.add[i + 8].value, // v0 after x2 + local.add[i + 8].value, // v0 after 2x local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x *local.b[i + 8].value(), // m3 *local.b[i + 16].value(), // zero1 @@ -791,7 +873,7 @@ where XorOperation::::eval( builder, local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x - local.add[i + 8].value, // v0 after x2 + local.add[i + 16].value, // v0 after previous operation local.xor[i + 16], local.shard, &local.channel, @@ -813,7 +895,7 @@ where Add4Operation::::eval( builder, local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x - local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x + local.rotate_right[i + 16].value, // v3 after previous operation *local.b[i + 16].value(), // zero1 *local.b[i + 20].value(), // zero2 local.shard, @@ -827,7 +909,7 @@ where XorOperation::::eval( builder, local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x - local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x + local.add[i + 20].value, // v2 after previous operation local.xor[i + 20], local.shard, &local.channel, @@ -864,7 +946,7 @@ where XorOperation::::eval( builder, local.rotate_right[i + 16].value, // v3 after 3x - local.add[i + 16].value, // v0 after 3x + local.add[i + 24].value, // v0 after previous operation local.xor[i + 24], local.shard, &local.channel, @@ -876,7 +958,7 @@ where builder, local.xor[i + 24].value, R_3 as usize, - local.rotate_right[v3_unshuffle_lookup[i] + 24], + local.rotate_right[i + 24], local.shard, &local.channel, local.is_real, @@ -886,13 +968,13 @@ where Add4Operation::::eval( builder, local.add[i + 20].value, // v2 after 3x - local.rotate_right[i + 16].value, // v3 after 3x + local.rotate_right[i + 24].value, // v3 after previous operation *local.b[i + 16].value(), // zero1 *local.b[i + 20].value(), // zero2 local.shard, local.channel, local.is_real, - local.add[v2_unshuffle_lookup[i] + 28], + local.add[i + 28], ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); @@ -900,7 +982,7 @@ where XorOperation::::eval( builder, local.rotate_right[i + 20].value, // v1 after 3x - local.add[i + 20].value, // v2 after 3x + local.add[i + 28].value, // v2 after previous operation local.xor[i + 28], local.shard, &local.channel, @@ -912,25 +994,25 @@ where builder, local.xor[i + 28].value, R_4 as usize, - local.rotate_right[v1_unshuffle_lookup[i] + 28], + local.rotate_right[i + 28], local.shard, &local.channel, local.is_real, ); } - self.constrain_shuffled_unshuffled_indices( + /*self.constrain_shuffled_unshuffled_indices( builder, &local.unshuffled_indices, local.is_real, - ); + );*/ builder.receive_syscall( local.shard, local.channel, local.clk, local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_QUARTER_ROUND_2X.syscall_id()), + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ROUND.syscall_id()), local.a_ptr, local.b_ptr, local.is_real, @@ -941,9 +1023,11 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::syscall::precompiles::blake2s::blake2s_round; use crate::utils::tests::BLAKE2S_ROUND_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; use crate::Program; + use rand::Rng; fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 24]) -> Program { let mut instructions = vec![]; @@ -980,7 +1064,7 @@ mod tests { Opcode::ADD, 5, 0, - SyscallCode::BLAKE_2S_QUARTER_ROUND_2X as u32, + SyscallCode::BLAKE_2S_ROUND as u32, false, true, )); @@ -996,23 +1080,17 @@ mod tests { let a_ptr = 100100100; let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [ - 0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, - 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, - 0xe07c2654, 0x5be0cd19, - ], - [ - 0, 0, 0, 0, // m1 - 0, 0, 0, 0, // m2 - 0, 0, 0, 0, // m3 - 0, 0, 0, 0, // m4 - 0, 0, 0, 0, // zero_0 - 0, 0, 0, 0, - ], // zero_1 - ); + + let a = rand::thread_rng().gen::<[u32; 16]>(); + let mut a_clone = a.clone(); + let mut b = rand::thread_rng().gen::<[u32; 24]>(); + for item in b[0..24].iter_mut() { + *item = 0; + } + + blake2s_round(&mut a_clone, &b); + + let program = risc_v_program(a_ptr, b_ptr, a, b); let (_, memory) = run_test_with_memory_inspection(program); let mut result = vec![]; @@ -1021,15 +1099,7 @@ mod tests { result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); } - assert_eq!( - result, - [ - 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, 0x515f5af4, 0x301095b, 0xb151a3c2, - 0x5e17f96f, 0xc561666d, 0xf291605, 0x990c6d13, 0x76fff6f1, 0x1e53bf19, 0x6fe4a680, - 0x8e33663, 0x97fd885e, - ] - .to_vec() - ); + assert_eq!(result, a_clone.to_vec()); } #[test] diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs deleted file mode 100644 index 3ddd0f4f7..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_16/air.rs +++ /dev/null @@ -1,291 +0,0 @@ -use core::borrow::Borrow; - -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::AbstractField; -use p3_matrix::Matrix; - -use super::{Blake2sXorRotate16Chip, Blake2sXorRotate16Cols, NUM_BLAKE2S_XOR_ROTATE_16_COLS}; -use crate::{ - air::{AluAirBuilder, BaseAirBuilder, MemoryAirBuilder, WordAirBuilder}, - memory::MemoryCols, - operations::{FixedRotateRightOperation, XorOperation}, - runtime::SyscallCode, -}; - -impl BaseAir for Blake2sXorRotate16Chip { - fn width(&self) -> usize { - NUM_BLAKE2S_XOR_ROTATE_16_COLS - } -} - -impl Air for Blake2sXorRotate16Chip -where - AB: MemoryAirBuilder + AluAirBuilder + WordAirBuilder, -{ - fn eval(&self, builder: &mut AB) { - // Initialize columns. - let main = builder.main(); - let (local, next) = (main.row_slice(0), main.row_slice(1)); - let local: &Blake2sXorRotate16Cols = (*local).borrow(); - let next: &Blake2sXorRotate16Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - let i_start = AB::F::from_canonical_u32(16); - - // Evaluate the control flags. - self.eval_flags(builder); - - // Copy over the inputs until the result has been computed (every 48 rows). - builder - .when_transition() - .when_not(local.cycle_16_end.result * local.cycle_48[2]) - .assert_eq(local.shard, next.shard); - builder - .when_transition() - .when_not(local.cycle_16_end.result * local.cycle_48[2]) - .assert_eq(local.clk, next.clk); - builder - .when_transition() - .when_not(local.cycle_16_end.result * local.cycle_48[2]) - .assert_eq(local.channel, next.channel); - builder - .when_transition() - .when_not(local.cycle_16_end.result * local.cycle_48[2]) - .assert_eq(local.w_ptr, next.w_ptr); - - // Read w[0]. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(0), - &local.w_0, - local.is_real, - ); - - // Read w[1] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(4), - &local.w_1, - local.is_real, - ); - - // Read w[2] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(8), - &local.w_2, - local.is_real, - ); - - // Read w[3] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(12), - &local.w_3, - local.is_real, - ); - - // Read w[4] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(16), - &local.w_4, - local.is_real, - ); - - // Read w[5] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(20), - &local.w_5, - local.is_real, - ); - - // Read w[6] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(24), - &local.w_6, - local.is_real, - ); - - // Read w[7] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(28), - &local.w_7, - local.is_real, - ); - - XorOperation::::eval( - builder, - *local.w_0.value(), - *local.w_4.value(), - local.xor_0, - local.shard, - &local.channel, - local.is_real, - ); - - FixedRotateRightOperation::::eval( - builder, - local.xor_0.value, - 16, - local.rot_0, - local.shard, - &local.channel, - local.is_real, - ); - - XorOperation::::eval( - builder, - *local.w_1.value(), - *local.w_5.value(), - local.xor_1, - local.shard, - &local.channel, - local.is_real, - ); - - FixedRotateRightOperation::::eval( - builder, - local.xor_1.value, - 16, - local.rot_1, - local.shard, - &local.channel, - local.is_real, - ); - - XorOperation::::eval( - builder, - *local.w_2.value(), - *local.w_6.value(), - local.xor_2, - local.shard, - &local.channel, - local.is_real, - ); - - FixedRotateRightOperation::::eval( - builder, - local.xor_2.value, - 16, - local.rot_2, - local.shard, - &local.channel, - local.is_real, - ); - - XorOperation::::eval( - builder, - *local.w_3.value(), - *local.w_7.value(), - local.xor_3, - local.shard, - &local.channel, - local.is_real, - ); - - FixedRotateRightOperation::::eval( - builder, - local.xor_3.value, - 16, - local.rot_3, - local.shard, - &local.channel, - local.is_real, - ); - - // Write w[16] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(64), - &local.w_16, - local.is_real, - ); - - // Write w[17] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(68), - &local.w_17, - local.is_real, - ); - - // Write w[18] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(72), - &local.w_18, - local.is_real, - ); - - // Write w[19] - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + (local.i - i_start), - local.w_ptr + AB::F::from_canonical_u32(76), - &local.w_19, - local.is_real, - ); - - builder.assert_word_eq(*local.w_16.value(), local.rot_0.value); - builder.assert_word_eq(*local.w_17.value(), local.rot_1.value); - builder.assert_word_eq(*local.w_18.value(), local.rot_2.value); - builder.assert_word_eq(*local.w_19.value(), local.rot_3.value); - - // Receive syscall event in first row of 48-cycle. - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_16.syscall_id()), - local.w_ptr, - AB::Expr::zero(), - local.cycle_48_start, - ); - - // Assert that is_real is a bool. - builder.assert_bool(local.is_real); - - // Ensure that all rows in a 48 row cycle has the same `is_real` values. - builder - .when_transition() - .when_not(local.cycle_48_end) - .assert_eq(local.is_real, next.is_real); - - // Assert that the table ends in nonreal columns. Since each extend ecall is 48 cycles and - // the table is padded to a power of 2, the last row of the table should always be padding. - builder.when_last_row().assert_zero(local.is_real); - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs deleted file mode 100644 index 06fc34153..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_16/columns.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::mem::size_of; - -use sphinx_derive::AlignedBorrow; - -use crate::{ - memory::{MemoryReadCols, MemoryWriteCols}, - operations::{FixedRotateRightOperation, IsZeroOperation, XorOperation}, -}; - -pub const NUM_BLAKE2S_XOR_ROTATE_16_COLS: usize = size_of::>(); - -#[derive(AlignedBorrow, Default, Debug, Clone, Copy)] -#[repr(C)] -pub struct Blake2sXorRotate16Cols { - /// Inputs. - pub shard: T, - pub channel: T, - pub nonce: T, - pub clk: T, - pub w_ptr: T, - - /// Control flags. - pub i: T, - - /// g^n where g is generator with order 16 and n is the row number. - pub cycle_16: T, - - /// Checks whether current row is start of a 16-row cycle. Bool result is stored in `result`. - pub cycle_16_start: IsZeroOperation, - - /// Checks whether current row is end of a 16-row cycle. Bool result is stored in `result`. - pub cycle_16_end: IsZeroOperation, - - /// Flags for when in the first, second, or third 16-row cycle. - pub cycle_48: [T; 3], - - /// Whether the current row is the first of a 48-row cycle and is real. - pub cycle_48_start: T, - /// Whether the current row is the end of a 48-row cycle and is real. - pub cycle_48_end: T, - - /// Inputs - pub w_0: MemoryReadCols, - pub w_1: MemoryReadCols, - pub w_2: MemoryReadCols, - pub w_3: MemoryReadCols, - pub w_4: MemoryReadCols, - pub w_5: MemoryReadCols, - pub w_6: MemoryReadCols, - pub w_7: MemoryReadCols, - - /// Operations - pub xor_0: XorOperation, - pub xor_1: XorOperation, - pub xor_2: XorOperation, - pub xor_3: XorOperation, - - pub rot_0: FixedRotateRightOperation, - pub rot_1: FixedRotateRightOperation, - pub rot_2: FixedRotateRightOperation, - pub rot_3: FixedRotateRightOperation, - - /// Result - pub w_16: MemoryWriteCols, - pub w_17: MemoryWriteCols, - pub w_18: MemoryWriteCols, - pub w_19: MemoryWriteCols, - - /// Selector. - pub is_real: T, -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs deleted file mode 100644 index 8a890b9e6..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_16/execute.rs +++ /dev/null @@ -1,101 +0,0 @@ -use super::Blake2sXorRotate16Chip; -use crate::{ - runtime::Syscall, - syscall::precompiles::{blake2s::Blake2sXorRotate16Event, SyscallContext}, -}; - -impl Syscall for Blake2sXorRotate16Chip { - fn num_extra_cycles(&self) -> u32 { - 48 - } - - fn execute(&self, rt: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = rt.clk; - let w_ptr = arg1; - assert!(arg2 == 0, "arg2 must be 0"); - - let w_ptr_init = w_ptr; - let mut w_0_reads = Vec::new(); - let mut w_1_reads = Vec::new(); - let mut w_2_reads = Vec::new(); - let mut w_3_reads = Vec::new(); - - let mut w_4_reads = Vec::new(); - let mut w_5_reads = Vec::new(); - let mut w_6_reads = Vec::new(); - let mut w_7_reads = Vec::new(); - - let mut w_16_writes = Vec::new(); - let mut w_17_writes = Vec::new(); - let mut w_18_writes = Vec::new(); - let mut w_19_writes = Vec::new(); - - for _ in 16..64 { - // read - let (record, w_0) = rt.mr(w_ptr); - w_0_reads.push(record); - - let (record, w_1) = rt.mr(w_ptr + 4); - w_1_reads.push(record); - - let (record, w_2) = rt.mr(w_ptr + 8); - w_2_reads.push(record); - - let (record, w_3) = rt.mr(w_ptr + 12); - w_3_reads.push(record); - - let (record, w_4) = rt.mr(w_ptr + 16); - w_4_reads.push(record); - - let (record, w_5) = rt.mr(w_ptr + 20); - w_5_reads.push(record); - - let (record, w_6) = rt.mr(w_ptr + 24); - w_6_reads.push(record); - - let (record, w_7) = rt.mr(w_ptr + 28); - w_7_reads.push(record); - - // compute - let w_16 = (w_0 ^ w_4).rotate_right(16); - let w_17 = (w_1 ^ w_5).rotate_right(16); - let w_18 = (w_2 ^ w_6).rotate_right(16); - let w_19 = (w_3 ^ w_7).rotate_right(16); - - // write - w_16_writes.push(rt.mw(w_ptr + 64, w_16)); - w_17_writes.push(rt.mw(w_ptr + 68, w_17)); - w_18_writes.push(rt.mw(w_ptr + 72, w_18)); - w_19_writes.push(rt.mw(w_ptr + 76, w_19)); - rt.clk += 1; - } - - // Push the Blake2sXorRotate16Event event. - let lookup_id = rt.syscall_lookup_id; - let shard = rt.current_shard(); - let channel = rt.current_channel(); - rt.record_mut() - .blake2s_xor_rotate_16_events - .push(Blake2sXorRotate16Event { - lookup_id, - shard, - channel, - clk: clk_init, - w_ptr: w_ptr_init, - w_0_reads, - w_1_reads, - w_2_reads, - w_3_reads, - w_4_reads, - w_5_reads, - w_6_reads, - w_7_reads, - w_16_writes, - w_17_writes, - w_18_writes, - w_19_writes, - }); - - None - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs deleted file mode 100644 index 2f705b9f2..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_16/flags.rs +++ /dev/null @@ -1,130 +0,0 @@ -use core::borrow::Borrow; - -use p3_air::AirBuilder; -use p3_baby_bear::BabyBear; -use p3_field::{AbstractField, Field, PrimeField32, TwoAdicField}; -use p3_matrix::Matrix; - -use crate::air::BaseAirBuilder; -use crate::operations::IsZeroOperation; - -use super::Blake2sXorRotate16Chip; -use super::Blake2sXorRotate16Cols; - -impl Blake2sXorRotate16Cols { - pub fn populate_flags(&mut self, i: usize) { - // The generator of the multiplicative subgroup. - let g = F::from_canonical_u32(BabyBear::two_adic_generator(4).as_canonical_u32()); - - // Populate the columns needed to keep track of cycles of 16 rows. - self.cycle_16 = g.exp_u64((i + 1) as u64); - - // Populate the columns needed to track the start of a cycle of 16 rows. - self.cycle_16_start - .populate_from_field_element(self.cycle_16 - g); - - // Populate the columns needed to track the end of a cycle of 16 rows. - self.cycle_16_end - .populate_from_field_element(self.cycle_16 - F::one()); - - // Populate the columns needed to keep track of cycles of 48 rows. - let j = 16 + (i % 48); - self.i = F::from_canonical_usize(j); - self.cycle_48[0] = F::from_bool((16..32).contains(&j)); - self.cycle_48[1] = F::from_bool((32..48).contains(&j)); - self.cycle_48[2] = F::from_bool((48..64).contains(&j)); - self.cycle_48_start = self.cycle_48[0] * self.cycle_16_start.result * self.is_real; - self.cycle_48_end = self.cycle_48[2] * self.cycle_16_end.result * self.is_real; - } -} - -impl Blake2sXorRotate16Chip { - pub fn eval_flags(&self, builder: &mut AB) { - let main = builder.main(); - let (local, next) = (main.row_slice(0), main.row_slice(1)); - let local: &Blake2sXorRotate16Cols = (*local).borrow(); - let next: &Blake2sXorRotate16Cols = (*next).borrow(); - - let one = AB::Expr::from(AB::F::one()); - - // Generator with order 16 within BabyBear. - let g = AB::F::from_canonical_u32(BabyBear::two_adic_generator(4).as_canonical_u32()); - - // First row of the table must have g^1. - builder.when_first_row().assert_eq(local.cycle_16, g); - - // First row of the table must have i = 16. - builder - .when_first_row() - .assert_eq(local.i, AB::F::from_canonical_u32(16)); - - // Every row's `cycle_16` must be previous multiplied by `g`. - builder - .when_transition() - .assert_eq(local.cycle_16 * g, next.cycle_16); - - // Constrain `cycle_16_start.result` to be `cycle_16 - g == 0`. - IsZeroOperation::::eval( - builder, - local.cycle_16 - AB::Expr::from(g), - local.cycle_16_start, - one.clone(), - ); - - // Constrain `cycle_16_end.result` to be `cycle_16 - 1 == 0`. Intuitively g^16 is 1. - IsZeroOperation::::eval( - builder, - local.cycle_16 - AB::Expr::one(), - local.cycle_16_end, - one.clone(), - ); - - // Constrain `cycle_48` to be [1, 0, 0] in the first row. - builder - .when_first_row() - .assert_eq(local.cycle_48[0], AB::F::one()); - builder - .when_first_row() - .assert_eq(local.cycle_48[1], AB::F::zero()); - builder - .when_first_row() - .assert_eq(local.cycle_48[2], AB::F::zero()); - - // Shift the indices of `cycles_48` at the end of each 16 rows. Otherwise, keep them the same. - for i in 0..3 { - builder - .when_transition() - .when(local.cycle_16_end.result) - .assert_eq(local.cycle_48[i], next.cycle_48[(i + 1) % 3]); - builder - .when_transition() - .when(one.clone() - local.cycle_16_end.result) - .assert_eq(local.cycle_48[i], next.cycle_48[i]); - builder.assert_bool(local.cycle_48[i]); - } - - // cycle_48_start == start of 16-cycle AND first 16-cycle within 48-cycle AND is_real. - builder.assert_eq( - local.cycle_16_start.result * local.cycle_48[0] * local.is_real, - local.cycle_48_start, - ); - - // cycle_48_end == end of 16-cycle AND last 16-cycle within 48-cycle AND is_real. - builder.assert_eq( - local.cycle_16_end.result * local.cycle_48[2] * local.is_real, - local.cycle_48_end, - ); - - // When it's the end of a 48-cycle, the next `i` must be 16. - builder - .when_transition() - .when(local.cycle_16_end.result * local.cycle_48[2]) - .assert_eq(next.i, AB::F::from_canonical_u32(16)); - - // When it's not the end of a 48-cycle, the next `i` must be the current plus one. - builder - .when_transition() - .when_not(local.cycle_16_end.result * local.cycle_48[2]) - .assert_eq(local.i + one.clone(), next.i); - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs deleted file mode 100644 index 913777829..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_16/mod.rs +++ /dev/null @@ -1,116 +0,0 @@ -mod air; -mod columns; -mod execute; -mod flags; -mod trace; - -pub use columns::*; -use serde::{Deserialize, Serialize}; - -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sXorRotate16Event { - pub lookup_id: usize, - pub shard: u32, - pub channel: u32, - pub clk: u32, - pub w_ptr: u32, - - pub w_0_reads: Vec, - pub w_1_reads: Vec, - pub w_2_reads: Vec, - pub w_3_reads: Vec, - pub w_4_reads: Vec, - pub w_5_reads: Vec, - pub w_6_reads: Vec, - pub w_7_reads: Vec, - - pub w_16_writes: Vec, - pub w_17_writes: Vec, - pub w_18_writes: Vec, - pub w_19_writes: Vec, -} - -#[derive(Default)] -pub struct Blake2sXorRotate16Chip; - -impl Blake2sXorRotate16Chip { - pub const fn new() -> Self { - Self {} - } -} - -#[cfg(test)] -pub mod blake2s_xor_rotate_tests { - use crate::utils::run_test; - use crate::utils::tests::BLAKE2S_XOR_RIGHT_16_ELF; - use crate::{ - runtime::{Instruction, Opcode, Program, SyscallCode}, - utils::{self, run_test_with_memory_inspection}, - }; - - pub fn blake2s_xor_rotate_16_program() -> Program { - let w_ptr = 100u32; - let mut words = [0u32; 64]; - words[0] = 0x6b08e647; - words[1] = 0xbb67ae85; - words[2] = 0x3c6ef372; - words[3] = 0xa54ff53a; - - words[4] = 0x510e527f; - words[5] = 0x9b05688c; - words[6] = 0x1f83d9ab; - words[7] = 0x5be0cd19; - - let mut instructions = vec![]; - for (i, word) in words.into_iter().enumerate() { - instructions.extend(vec![ - Instruction::new(Opcode::ADD, 29, 0, word, false, true), - Instruction::new(Opcode::ADD, 30, 0, w_ptr + (i * 4) as u32, false, true), - Instruction::new(Opcode::SW, 29, 30, 0, false, true), - ]); - } - instructions.extend(vec![ - Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_XOR_ROTATE_16 as u32, - false, - true, - ), - Instruction::new(Opcode::ADD, 10, 0, w_ptr, false, true), - Instruction::new(Opcode::ADD, 11, 0, 0, false, true), - Instruction::new(Opcode::ECALL, 5, 10, 11, false, false), - ]); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_xor_rotate_16_prove() { - utils::setup_logger(); - let program = blake2s_xor_rotate_16_program(); - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - for i in 0..64 { - result.push(memory.get(&(100 + i * 4)).unwrap().value); - } - assert_eq!( - result, - vec![ - 0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, - 0x5be0cd19, 0, 0, 0, 0, 0, 0, 0, 0, 0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - ] - ); - } - - #[test] - fn test_blake2s_xor_rotate_16_program() { - utils::setup_logger(); - let program = Program::from(BLAKE2S_XOR_RIGHT_16_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs deleted file mode 100644 index a69762463..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_16/trace.rs +++ /dev/null @@ -1,178 +0,0 @@ -use p3_field::PrimeField32; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use std::borrow::BorrowMut; - -use super::{ - Blake2sXorRotate16Chip, Blake2sXorRotate16Cols, Blake2sXorRotate16Event, - NUM_BLAKE2S_XOR_ROTATE_16_COLS, -}; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - bytes::event::ByteRecord, - runtime::{ExecutionRecord, Program}, -}; - -impl<'a> WithEvents<'a> for Blake2sXorRotate16Chip { - type Events = &'a [Blake2sXorRotate16Event]; -} - -impl MachineAir for Blake2sXorRotate16Chip { - type Record = ExecutionRecord; - - type Program = Program; - - fn name(&self) -> String { - "Blake2sXorRotate16".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut ExecutionRecord, - ) -> RowMajorMatrix { - let mut rows = Vec::new(); - - let mut new_byte_lookup_events = Vec::new(); - for i in 0..input.events().len() { - let event = input.events()[i].clone(); - let shard = event.shard; - for j in 0..48usize { - let mut row = [F::zero(); NUM_BLAKE2S_XOR_ROTATE_16_COLS]; - let cols: &mut Blake2sXorRotate16Cols = row.as_mut_slice().borrow_mut(); - cols.is_real = F::one(); - cols.populate_flags(j); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.clk = F::from_canonical_u32(event.clk); - cols.w_ptr = F::from_canonical_u32(event.w_ptr); - - cols.w_0.populate( - event.channel, - event.w_0_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_1.populate( - event.channel, - event.w_1_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_2.populate( - event.channel, - event.w_2_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_3.populate( - event.channel, - event.w_3_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_4.populate( - event.channel, - event.w_4_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_5.populate( - event.channel, - event.w_5_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_6.populate( - event.channel, - event.w_6_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_7.populate( - event.channel, - event.w_7_reads[j], - &mut new_byte_lookup_events, - ); - - let w_0 = event.w_0_reads[j].value; - let w_1 = event.w_1_reads[j].value; - let w_2 = event.w_2_reads[j].value; - let w_3 = event.w_3_reads[j].value; - let w_4 = event.w_4_reads[j].value; - let w_5 = event.w_5_reads[j].value; - let w_6 = event.w_6_reads[j].value; - let w_7 = event.w_7_reads[j].value; - - let xor_0 = cols.xor_0.populate(output, shard, event.channel, w_0, w_4); - - cols.rot_0.populate(output, shard, event.channel, xor_0, 16); - - let xor_1 = cols.xor_1.populate(output, shard, event.channel, w_1, w_5); - - cols.rot_1.populate(output, shard, event.channel, xor_1, 16); - - let xor_2 = cols.xor_2.populate(output, shard, event.channel, w_2, w_6); - - cols.rot_2.populate(output, shard, event.channel, xor_2, 16); - - let xor_3 = cols.xor_3.populate(output, shard, event.channel, w_3, w_7); - - cols.rot_3.populate(output, shard, event.channel, xor_3, 16); - - cols.w_16.populate( - event.channel, - event.w_16_writes[j], - &mut new_byte_lookup_events, - ); - - cols.w_17.populate( - event.channel, - event.w_17_writes[j], - &mut new_byte_lookup_events, - ); - - cols.w_18.populate( - event.channel, - event.w_18_writes[j], - &mut new_byte_lookup_events, - ); - - cols.w_19.populate( - event.channel, - event.w_19_writes[j], - &mut new_byte_lookup_events, - ); - - rows.push(row); - } - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - let nb_rows = rows.len(); - let mut padded_nb_rows = nb_rows.next_power_of_two(); - if padded_nb_rows == 2 || padded_nb_rows == 1 { - padded_nb_rows = 4; - } - for i in nb_rows..padded_nb_rows { - let mut row = [F::zero(); NUM_BLAKE2S_XOR_ROTATE_16_COLS]; - let cols: &mut Blake2sXorRotate16Cols = row.as_mut_slice().borrow_mut(); - cols.populate_flags(i); - rows.push(row); - } - - // Convert the trace to a row major matrix. - let mut trace = RowMajorMatrix::new( - rows.into_iter().flatten().collect::>(), - NUM_BLAKE2S_XOR_ROTATE_16_COLS, - ); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sXorRotate16Cols = trace.values - [i * NUM_BLAKE2S_XOR_ROTATE_16_COLS..(i + 1) * NUM_BLAKE2S_XOR_ROTATE_16_COLS] - .borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_xor_rotate_16_events.is_empty() - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs deleted file mode 100644 index b0d966ba1..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_right_12.rs +++ /dev/null @@ -1,357 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{FixedRotateRightOperation, XorOperation}; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -const R_2: u32 = 12; - -#[derive(Default)] -pub struct Blake2sXorRotateRight12Chip; - -impl Blake2sXorRotateRight12Chip { - pub fn new() -> Self { - Blake2sXorRotateRight12Chip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sXorRotateRight12Event { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sXorRotateRight12Chip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 4); - - let xor = a - .into_iter() - .zip(b.into_iter()) - .map(|(a, b)| a ^ b) - .collect::>(); - - let rotate_right = xor - .into_iter() - .map(|xor_i| xor_i.rotate_right(R_2)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); - - ctx.record_mut() - .blake2s_xor_rotate_right_12_events - .push(Blake2sXorRotateRight12Event { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sXorRotateRight12Cols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], - - pub xor: [XorOperation; 4], - pub rotate_right: [FixedRotateRightOperation; 4], -} - -impl BaseAir for Blake2sXorRotateRight12Chip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sXorRotateRight12Chip { - type Events = &'a [Blake2sXorRotateRight12Event]; -} - -impl MachineAir for Blake2sXorRotateRight12Chip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sXorRotateRight12Chip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sXorRotateRight12Cols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - assert_eq!(a ^ b, xor); - - let rotate_right = - cols.rotate_right[i].populate(output, shard, event.channel, xor, R_2 as usize); - assert_eq!(xor.rotate_right(R_2), rotate_right); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sXorRotateRight12Cols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_xor_rotate_right_12_events.is_empty() - } -} - -impl Air for Blake2sXorRotateRight12Chip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sXorRotateRight12Cols = (*local).borrow(); - let next: &Blake2sXorRotateRight12Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - local.xor[i], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i].value, - R_2 as usize, - local.rotate_right[i], - local.shard, - &local.channel, - local.is_real, - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_12_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_12 as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_xor_rotate_right_12_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!( - result, - [0x4383a06b, 0x6092062c, 0xad923ed2, 0x823feaf3].to_vec() - ); - } - - #[test] - fn test_blake2s_xor_rotate_right_16_program() { - setup_logger(); - let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_12_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs deleted file mode 100644 index e836585e0..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_right_16.rs +++ /dev/null @@ -1,357 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{FixedRotateRightOperation, XorOperation}; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -const R_1: u32 = 16; - -#[derive(Default)] -pub struct Blake2sXorRotateRight16Chip; - -impl Blake2sXorRotateRight16Chip { - pub fn new() -> Self { - Blake2sXorRotateRight16Chip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sXorRotateRight16Event { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sXorRotateRight16Chip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 4); - - let xor = a - .into_iter() - .zip(b.into_iter()) - .map(|(a, b)| a ^ b) - .collect::>(); - - let rotate_right = xor - .into_iter() - .map(|xor_i| xor_i.rotate_right(R_1)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); - - ctx.record_mut() - .blake2s_xor_rotate_right_16_events - .push(Blake2sXorRotateRight16Event { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sXorRotateRight16Cols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], - - pub xor: [XorOperation; 4], - pub rotate_right: [FixedRotateRightOperation; 4], -} - -impl BaseAir for Blake2sXorRotateRight16Chip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sXorRotateRight16Chip { - type Events = &'a [Blake2sXorRotateRight16Event]; -} - -impl MachineAir for Blake2sXorRotateRight16Chip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sXorRotateRight16Chip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sXorRotateRight16Cols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - assert_eq!(a ^ b, xor); - - let rotate_right = - cols.rotate_right[i].populate(output, shard, event.channel, xor, R_1 as usize); - assert_eq!(xor.rotate_right(R_1), rotate_right); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sXorRotateRight16Cols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_xor_rotate_right_16_events.is_empty() - } -} - -impl Air for Blake2sXorRotateRight16Chip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sXorRotateRight16Cols = (*local).borrow(); - let next: &Blake2sXorRotateRight16Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - local.xor[i], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i].value, - R_1 as usize, - local.rotate_right[i], - local.shard, - &local.channel, - local.is_real, - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_16_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_16 as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_xor_rotate_right_16_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!( - result, - [0xb4383a06, 0xc6092062, 0x2ad923ed, 0x3823feaf].to_vec() - ); - } - - #[test] - fn test_blake2s_xor_rotate_right_16_program() { - setup_logger(); - let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_16_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs deleted file mode 100644 index 387dc7e5f..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_right_7.rs +++ /dev/null @@ -1,357 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{FixedRotateRightOperation, XorOperation}; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -const R_4: u32 = 7; - -#[derive(Default)] -pub struct Blake2sXorRotateRight7Chip; - -impl Blake2sXorRotateRight7Chip { - pub fn new() -> Self { - Blake2sXorRotateRight7Chip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sXorRotateRight7Event { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sXorRotateRight7Chip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 4); - - let xor = a - .into_iter() - .zip(b.into_iter()) - .map(|(a, b)| a ^ b) - .collect::>(); - - let rotate_right = xor - .into_iter() - .map(|xor_i| xor_i.rotate_right(R_4)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); - - ctx.record_mut() - .blake2s_xor_rotate_right_7_events - .push(Blake2sXorRotateRight7Event { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sXorRotateRight7Cols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], - - pub xor: [XorOperation; 4], - pub rotate_right: [FixedRotateRightOperation; 4], -} - -impl BaseAir for Blake2sXorRotateRight7Chip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sXorRotateRight7Chip { - type Events = &'a [Blake2sXorRotateRight7Event]; -} - -impl MachineAir for Blake2sXorRotateRight7Chip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sXorRotateRight7Chip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sXorRotateRight7Cols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - assert_eq!(a ^ b, xor); - - let rotate_right = - cols.rotate_right[i].populate(output, shard, event.channel, xor, R_4 as usize); - assert_eq!(xor.rotate_right(R_4), rotate_right); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sXorRotateRight7Cols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_xor_rotate_right_7_events.is_empty() - } -} - -impl Air for Blake2sXorRotateRight7Chip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sXorRotateRight7Cols = (*local).borrow(); - let next: &Blake2sXorRotateRight7Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - local.xor[i], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i].value, - R_4 as usize, - local.rotate_right[i], - local.shard, - &local.channel, - local.is_real, - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_7_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_7 as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_xor_rotate_right_7_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!( - result, - [0x70740d68, 0x1240c58c, 0xb247da55, 0x47fd5e70].to_vec() - ); - } - - #[test] - fn test_blake2s_xor_rotate_right_7_program() { - setup_logger(); - let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_7_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs b/core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs deleted file mode 100644 index 101a9673a..000000000 --- a/core/src/syscall/precompiles/blake2s/xor_rotate_right_8.rs +++ /dev/null @@ -1,357 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{FixedRotateRightOperation, XorOperation}; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -const R_3: u32 = 8; - -#[derive(Default)] -pub struct Blake2sXorRotateRight8Chip; - -impl Blake2sXorRotateRight8Chip { - pub fn new() -> Self { - Blake2sXorRotateRight8Chip - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sXorRotateRight8Event { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sXorRotateRight8Chip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - let a = ctx.slice_unsafe(a_ptr, 4); - let (b_reads, b) = ctx.mr_slice(b_ptr, 4); - - let xor = a - .into_iter() - .zip(b.into_iter()) - .map(|(a, b)| a ^ b) - .collect::>(); - - let rotate_right = xor - .into_iter() - .map(|xor_i| xor_i.rotate_right(R_3)) - .collect::>(); - - ctx.clk += 1; - - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, rotate_right.as_slice()); - - ctx.record_mut() - .blake2s_xor_rotate_right_8_events - .push(Blake2sXorRotateRight8Event { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sXorRotateRight8Cols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub a: [MemoryWriteCols; 4], - pub b: [MemoryReadCols; 4], - - pub xor: [XorOperation; 4], - pub rotate_right: [FixedRotateRightOperation; 4], -} - -impl BaseAir for Blake2sXorRotateRight8Chip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sXorRotateRight8Chip { - type Events = &'a [Blake2sXorRotateRight8Event]; -} - -impl MachineAir for Blake2sXorRotateRight8Chip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sXorRotateRight8Chip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sXorRotateRight8Cols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - for i in 0..4usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - - let a = event.a_reads_writes[i].value; - let b = event.b_reads[i].value; - let xor = cols.xor[i].populate(output, shard, event.channel, a, b); - assert_eq!(a ^ b, xor); - - let rotate_right = - cols.rotate_right[i].populate(output, shard, event.channel, xor, R_3 as usize); - assert_eq!(xor.rotate_right(R_3), rotate_right); - } - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sXorRotateRight8Cols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_xor_rotate_right_8_events.is_empty() - } -} - -impl Air for Blake2sXorRotateRight8Chip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sXorRotateRight8Cols = (*local).borrow(); - let next: &Blake2sXorRotateRight8Cols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..4usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b. - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i].value(), - *local.b[i].value(), - local.xor[i], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i].value, - R_3 as usize, - local.rotate_right[i], - local.shard, - &local.channel, - local.is_real, - ); - } - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::utils::tests::BLAKE2S_XOR_ROTATE_RIGHT_8_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 4], b: [u32; 4]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_XOR_ROTATE_RIGHT_8 as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_xor_rotate_right_8_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - let program = risc_v_program( - a_ptr, - b_ptr, - [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a], - [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19], - ); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..4 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!( - result, - [0x383a06b4, 0x92062c6, 0xd923ed2a, 0x23feaf38].to_vec() - ); - } - - #[test] - fn test_blake2s_xor_rotate_right_8_program() { - setup_logger(); - let program = Program::from(BLAKE2S_XOR_ROTATE_RIGHT_8_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/utils/programs.rs b/core/src/utils/programs.rs index 5b90fc220..8e5b3dd3c 100644 --- a/core/src/utils/programs.rs +++ b/core/src/utils/programs.rs @@ -121,29 +121,6 @@ pub mod tests { pub const BLS12381_G2_DOUBLE_ELF: &[u8] = include_bytes!("../../../tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf"); - pub const BLAKE2S_XOR_ROTATE_RIGHT_16_ELF: &[u8] = include_bytes!( - "../../../tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf" - ); - - pub const BLAKE2S_XOR_RIGHT_16_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf"); - - pub const BLAKE2S_ADD_2_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf"); - - pub const BLAKE2S_ADD_3_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf"); - - pub const BLAKE2S_XOR_ROTATE_RIGHT_12_ELF: &[u8] = include_bytes!( - "../../../tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf" - ); - - pub const BLAKE2S_XOR_ROTATE_RIGHT_8_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf"); - - pub const BLAKE2S_XOR_ROTATE_RIGHT_7_ELF: &[u8] = - include_bytes!("../../../tests/blake2s-xor-rotate-right-7/elf/riscv32im-succinct-zkvm-elf"); - pub const BLAKE2S_ROUND_ELF: &[u8] = include_bytes!("../../../tests/blake2s-round/elf/riscv32im-succinct-zkvm-elf"); diff --git a/tests/blake2s-add2/Cargo.lock b/tests/blake2s-add2/Cargo.lock deleted file mode 100644 index b0f99b12f..000000000 --- a/tests/blake2s-add2/Cargo.lock +++ /dev/null @@ -1,539 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2s-add2" -version = "0.1.0" -dependencies = [ - "sphinx-zkvm", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "hybrid-array" -version = "0.2.0-rc.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" -dependencies = [ - "typenum", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "once_cell" -version = "1.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" -version = "1.0.0" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "hybrid-array", - "k256", - "serde", -] - -[[package]] -name = "sphinx-zkvm" -version = "1.0.0" -dependencies = [ - "bincode", - "cfg-if", - "getrandom", - "k256", - "lazy_static", - "libm", - "once_cell", - "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-add2/Cargo.toml b/tests/blake2s-add2/Cargo.toml deleted file mode 100644 index 758f44ab5..000000000 --- a/tests/blake2s-add2/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -[package] -name = "blake2s-add2" -version = "0.1.0" -edition = "2021" - -[dependencies] -sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-add2/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index 72bd6da466349987f8f21fc79afbe3761cd08c67..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25140 zcmeHwdwf*oo%eIDGYK&S4!0`R11AYrLy}1{fvtUKlmY3|dcmmM?G}cUfux2c%>~eP zal&MhK&e#^2wGMHAyHemD?32iUElpAtpnIkx2?5+-PhH2BZ1d;Z7L=NOquuld(N3; zf`In&*Zb-Dd=BTF-*fvtzvp*HYSR5nywfc^_gHWACa@`Z&`sqmiy*k%bnE=q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rs b/tests/blake2s-add2/src/main.rs deleted file mode 100644 index b3bf5661e..000000000 --- a/tests/blake2s-add2/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] -sphinx_zkvm::entrypoint!(main); - -use sphinx_zkvm::syscalls::blake2s_add_2::syscall_blake2s_add_2; - -pub fn main() { - let mut a: [u32; 4] = [200, 300, 400, 500]; - let b: [u32; 12] = [10, 20, 30, 40, 0, 0, 0, 0, 0, 0, 0, 0]; - - syscall_blake2s_add_2(a.as_mut_ptr(), b.as_ptr()); - - assert_eq!(a, [210, 320, 430, 540]); -} diff --git a/tests/blake2s-add3/Cargo.lock b/tests/blake2s-add3/Cargo.lock deleted file mode 100644 index d92fcf456..000000000 --- a/tests/blake2s-add3/Cargo.lock +++ /dev/null @@ -1,539 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2s-add3" -version = "0.1.0" -dependencies = [ - "sphinx-zkvm", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "hybrid-array" -version = "0.2.0-rc.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" -dependencies = [ - "typenum", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "once_cell" -version = "1.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" -version = "1.0.0" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "hybrid-array", - "k256", - "serde", -] - -[[package]] -name = "sphinx-zkvm" -version = "1.0.0" -dependencies = [ - "bincode", - "cfg-if", - "getrandom", - "k256", - "lazy_static", - "libm", - "once_cell", - "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-add3/Cargo.toml b/tests/blake2s-add3/Cargo.toml deleted file mode 100644 index b1777b692..000000000 --- a/tests/blake2s-add3/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -[package] -name = "blake2s-add3" -version = "0.1.0" -edition = "2021" - -[dependencies] -sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-add3/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index ceef83ebba42ef5ac943d2a8ec0830351784ae26..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25156 zcmeHwdwf*oo%eIDGYK&S4!0_+2Tl^g#gJr@Okl0=j4&X5?W%=T-_|V*Clityk~9}U zUtgSIGD%>mi#;IdS{n?BXx+BF1Ejn4v!7&j0Q>27+f~HwcD3EeW!tT#V#3A9yx-q* z&Lk6V+HU`PKRut%;hgh(ZolXE{O->);qkyd%LGASsY_(%7=7Jwlg>)zLKGMEYwm6f6<-M_#)-Li9!^+s<3n}P@3RL*h;g3C>}&hMh-jM1$S+$k@*7qHbj zzaIjO?)3KCS2MQ#ah=~Y(Cii5gcr5H|71%Qy~6pe0XM!iS0n3w0`RI+S>1qH zt{u#v@4Dg4xZ35@&X=S8N#;>c`Lqp3lGf1BM6XK_G}rW;cA$OFz`Mr&={lrUfIug4ub~jWvg8k2kVZG(7dhTGG-l~#x(CV7C&{0na`@( zRtIS1R#>!CVH(~obp|uo41wrp4S89-?0d{p(a+)+6v674&Md{nv`&=`?s1P;L*>le zqGVYvCYtrbvn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00 zdD@cu#ELci!6mn4c4AN>I(ye>#-IT_MZ6za!~b*1Z55+(MB&MHjJh4X|QhtpwD#ytJf-W*zX(*ZE)TvIDJXF54fCcH@a5Wi*6HJc0LP z2cl6TLloF%zD?*9AC-34 zxcsa_WN_2=sQJw$)e@gC09yuZ4cZ`YsE6=jsujgm4ifP6tc zB2#HabJJmdFPhJyx&H`%ctu+FJ~T7liAKqRVnoT`jsSo49sc?Xci;?~7k_X0jI}QD zm13rhQ;vy^ySjxXnRA3pfEMQ(56vuZh@EYKIOTofc+@Wj+v85%ZAX@*Nwgn$N0}zrYQ%}%sI|~y)sidfo9Kp{EsU$0~gV(e}AGx zq~R19UJtz6Bx-C*lByW^C~!g1G_q5Wt?% zXq4QSE+W_k>>w~Q8(oC;0DBu4NrlPAHh2Tr5ny#DX80YAJqn!t+oky=&_}=$ft`pO zn}YS(MRdH2jvBMWkdzil!A=+hZgK0aCAAWcy9|B%|7dOYI6tTbz7O~{L<<)&b2qSK zzzoJMY!k3iU~`N@1RxP@2RH^Wh&Ch~-(4>OU;XdVD5KS_#c2F~;I$u&JNx*qdl&e& z|A{*?w@qZSm zS)){7U9kvu72atnVsGzyjqSYyO69-2eY(;U)L74I{=3`V_F*&+u4ZfopHZ)JXT4MT f)IfN4y+=H_nlHqozJYJ7_sBnKfa~!e*Q@^rpaxsg diff --git a/tests/blake2s-round/src/main.rs b/tests/blake2s-round/src/main.rs index 7ab5a38e0..c67c53605 100644 --- a/tests/blake2s-round/src/main.rs +++ b/tests/blake2s-round/src/main.rs @@ -1,7 +1,7 @@ #![no_main] sphinx_zkvm::entrypoint!(main); -use sphinx_zkvm::syscalls::blake2s_round::syscall_blake2s_quarter_round_2x; +use sphinx_zkvm::syscalls::blake2s_round::syscall_blake2s_round; pub fn main() { let mut a: [u32; 16] = [ @@ -11,12 +11,5 @@ pub fn main() { ]; let b: [u32; 24] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - syscall_blake2s_quarter_round_2x(a.as_mut_ptr(), b.as_ptr()); - - assert_eq!(a, [ - 0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3, - 0x515f5af4, 0x301095b, 0xb151a3c2, 0x5e17f96f, - 0xc561666d, 0xf291605, 0x990c6d13, 0x76fff6f1, - 0x1e53bf19, 0x6fe4a680, 0x8e33663, 0x97fd885e, - ]); + syscall_blake2s_round(a.as_mut_ptr(), b.as_ptr()); } diff --git a/tests/blake2s-xor-rotate-16/Cargo.lock b/tests/blake2s-xor-rotate-16/Cargo.lock deleted file mode 100644 index 7ab25f1f3..000000000 --- a/tests/blake2s-xor-rotate-16/Cargo.lock +++ /dev/null @@ -1,539 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2s-xor-rotate-right-test" -version = "0.1.0" -dependencies = [ - "sphinx-zkvm", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "hybrid-array" -version = "0.2.0-rc.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" -dependencies = [ - "typenum", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" -version = "1.0.0" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "hybrid-array", - "k256", - "serde", -] - -[[package]] -name = "sphinx-zkvm" -version = "1.0.0" -dependencies = [ - "bincode", - "cfg-if", - "getrandom", - "k256", - "lazy_static", - "libm", - "once_cell", - "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-16/Cargo.toml b/tests/blake2s-xor-rotate-16/Cargo.toml deleted file mode 100644 index 8d49fdcb8..000000000 --- a/tests/blake2s-xor-rotate-16/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -[package] -name = "blake2s-xor-rotate-right-test" -version = "0.1.0" -edition = "2021" - -[dependencies] -sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-16/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index f01aafa22980c248238b6d8015bbc6ec5ee35854..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22924 zcmeHvdwf*Ywf{cPnG7)m4zDWJ11AX&V@NVdCh)U%A`Cvty|qQuYkP&^WI|HIBuo+> z{(5!7WD=l!ta?DKr8W{0v9%96g!JLBH>nP&x3%^vK3cD~Hzjzj*K)-KwUoKvwa=Mk z62Z3CzkVO*4L9Ah7gLWTzOt$rtFX4EHlP+9hR7XD&9M zc~}-xL87uU)THaTc&1BsuCdZAv)1~vv?Z*w50#dr%eKlw|>HPY6 z4r6p>wtwyh#-7`#^J^BGJ&KF?qV}IV-ds(O6MwuMM2WG+ZO*)?&K&2W{yA?%{P_2= z1U{C)#}fEh0v}7@|6>W59yP~cy)2>jFwIrWy1sh&thr_=rwcSgz=e0s)yTT;1igAF zy9+eSbr&<}y?(@#P&@tF=?b(z&b;c7U)y*jWepEc_PGQ>bIr_6#E*+c=V9jUIKqsg zzO&}q5x24LFf;b!TG)3MeF;V(=rtp%(F586T;Ia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$eDtS9##m8rub_?nTrwTQA&-c*atw>h{LL;Tf0 z5<6WGH55_Dh5!8YV*jAB{O7{|soqpv{NL^c;NC}A=KRu+0f%>0ua*mW^Jv0ojsNK16wVx%>daF<XHrs diff --git a/tests/blake2s-xor-rotate-16/src/main.rs b/tests/blake2s-xor-rotate-16/src/main.rs deleted file mode 100644 index d9b63a1e0..000000000 --- a/tests/blake2s-xor-rotate-16/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] -sphinx_zkvm::entrypoint!(main); - -use sphinx_zkvm::syscalls::blake2s_xor_rotate_16::syscall_blake2s_xor_rotate_16; - -pub fn main() { - let mut w = [1u32; 64]; - for _ in 0..10000 { - syscall_blake2s_xor_rotate_16(w.as_mut_ptr()); - } -} - -// summary: cycles=40957, e2e=17694, khz=2.31, proofSize=2.07 MiB diff --git a/tests/blake2s-xor-rotate-right-12/Cargo.lock b/tests/blake2s-xor-rotate-right-12/Cargo.lock deleted file mode 100644 index bc27231b9..000000000 --- a/tests/blake2s-xor-rotate-right-12/Cargo.lock +++ /dev/null @@ -1,539 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2s-xor-rotate-right-12-test" -version = "0.1.0" -dependencies = [ - "sphinx-zkvm", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "hybrid-array" -version = "0.2.0-rc.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" -dependencies = [ - "typenum", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "once_cell" -version = "1.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" -version = "1.0.0" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "hybrid-array", - "k256", - "serde", -] - -[[package]] -name = "sphinx-zkvm" -version = "1.0.0" -dependencies = [ - "bincode", - "cfg-if", - "getrandom", - "k256", - "lazy_static", - "libm", - "once_cell", - "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right-12/Cargo.toml b/tests/blake2s-xor-rotate-right-12/Cargo.toml deleted file mode 100644 index 00618a2be..000000000 --- a/tests/blake2s-xor-rotate-right-12/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -[package] -name = "blake2s-xor-rotate-right-12-test" -version = "0.1.0" -edition = "2021" - -[dependencies] -sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-12/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index 5c00c03793a2dced10e8d0f6df6dd3790f7e8aec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25140 zcmeHwdw3MrdH0#?u7oTE!!0(k2SyTC3rQ*=RNQJoE47-S1c6-fw`B+&NKSD<0hRI;d!vaE-7L<^RU@0 zoux4qASx?DO}c-Mce-Wg9_@|Z1U3l|x~ZIH5d@c)Zk^xyGREju2=0{Y_X4(B=l2%@ zqdT?zBdZyEg)v;mqReEf7+tC`>6pUIXHPRLHkoPaU{X^iv;IlyWevu8 zU4$`T>~w&hX1bbbu){2_b~DYB&pN+x%O*9>}% z14o!~5ck}k%jiom<^#TVP&K*%dmi_F)#z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1cJ6}|-E4z7Vz{>w*MTpya|`HD0}>!WHKA?sn?1XI{$Q^yZ#d21Ps6h^Lbsv1 z(cHj+>1QLl&Wlq7Q+Al diff --git a/tests/blake2s-xor-rotate-right-12/src/main.rs b/tests/blake2s-xor-rotate-right-12/src/main.rs deleted file mode 100644 index 75c6ac8b4..000000000 --- a/tests/blake2s-xor-rotate-right-12/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] -sphinx_zkvm::entrypoint!(main); - -use sphinx_zkvm::syscalls::blake2s_xor_rotate_right_12::syscall_blake2s_xor_rotate_right_12; - -pub fn main() { - let mut a: [u32; 4] = [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a]; - let b: [u32; 4] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; - - syscall_blake2s_xor_rotate_right_12(a.as_mut_ptr(), b.as_ptr()); - - assert_eq!(a, [0x4383a06b, 0x6092062c, 0xad923ed2, 0x823feaf3]); -} diff --git a/tests/blake2s-xor-rotate-right-16/Cargo.lock b/tests/blake2s-xor-rotate-right-16/Cargo.lock deleted file mode 100644 index 733b51ebb..000000000 --- a/tests/blake2s-xor-rotate-right-16/Cargo.lock +++ /dev/null @@ -1,539 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2s-xor-rotate-right-test" -version = "0.1.0" -dependencies = [ - "sphinx-zkvm", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "hybrid-array" -version = "0.2.0-rc.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" -dependencies = [ - "typenum", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" -version = "1.0.0" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "hybrid-array", - "k256", - "serde", -] - -[[package]] -name = "sphinx-zkvm" -version = "1.0.0" -dependencies = [ - "bincode", - "cfg-if", - "getrandom", - "k256", - "lazy_static", - "libm", - "once_cell", - "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right-16/Cargo.toml b/tests/blake2s-xor-rotate-right-16/Cargo.toml deleted file mode 100644 index 4787ff58f..000000000 --- a/tests/blake2s-xor-rotate-right-16/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -[package] -name = "blake2s-xor-rotate-right-16-test" -version = "0.1.0" -edition = "2021" - -[dependencies] -sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-16/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index 7e5df46dc64f6bce33f7ca736d8674bb49d97f85..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25140 zcmeHwdw3MrdH0#?u7oTE!!0(k2SyTC3rQUd?E!;b>Ij5nJ9V4TH7HH}^pO%T;5=!X)W$gdTsx`E<#Q5;7)uDOXusck zW=2|Zvy6(A}rLQT4Vj(56c=N{{g-UK!U54x$GWf26Imu{Wk`f|qTRtWBt>-Pe-M(6jJ z0HZs#{Ud7_d*o4_-!stcW!!`pwg3F-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2lp+kXe&9!^Y@;V@`5pwXH@KjI?;dKF12 zNB!xb)q{2y6-w!^6!cD_+v5tj{mn+PwfOeKW69)WcAW__q3=!je%o=3&91B8j~BQi|o7ox)WNi|U_8xf4He zblDjXjok|c>jS+A&-5eOY|wrV8u3g&s-F+qInV+`NRh`~plAJOGWncM*Hh(DiEsPy zO}59Ib>(b*G=u0 z#xjEM*{3GTg6Pu}j2-k&Jd^xg`&{1C8W?x_lnK1KMuT?y+gy4yf#pLH}V& zeHza@puGm#n<-`a_(9+I(=lw|OsqiI0cX$n?>R&#-MSkXBREqxG1^UCFmr@`2 z5ief?trIlPw?nH3?GR|LY>1Cm&|U^Df@h3x%+~jVzWDznlZ=$#>5Iz02>P`D8neAI z4EQ1F%il^Ss~kOZ`6gb@;oD5*q78+mW`2H2sJL`#@vQ~h5W*L1bBh%CeT4D47p&V(Rw0{*l<}f~fibSAd*R zeI>ovKi6(Nc%^a_OY{H7z};9UxKm`8BM74(`Rr7Vraw}pv&aLmS>8AZ__^(U3eQvy z&}RQX3D(&-idX(~%jtNdwyE5{M|8Fu<>uho{ki?-g5Z|xbINUX3pwBDbrCM=7eePh sYHz>uOgH*Q7wJ0stjCT2@+&6xOJ(S{0vGY-{=QHFf5Lsi-7WY30N8>U$N&HU diff --git a/tests/blake2s-xor-rotate-right-7/src/main.rs b/tests/blake2s-xor-rotate-right-7/src/main.rs deleted file mode 100644 index 800270450..000000000 --- a/tests/blake2s-xor-rotate-right-7/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] -sphinx_zkvm::entrypoint!(main); - -use sphinx_zkvm::syscalls::blake2s_xor_rotate_right_7::syscall_blake2s_xor_rotate_right_7; - -pub fn main() { - let mut a: [u32; 4] = [0x6b08e647, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a]; - let b: [u32; 4] = [0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]; - - syscall_blake2s_xor_rotate_right_7(a.as_mut_ptr(), b.as_ptr()); - - assert_eq!(a, [0x70740d68, 0x1240c58c, 0xb247da55, 0x47fd5e70]); -} diff --git a/tests/blake2s-xor-rotate-right-8/Cargo.lock b/tests/blake2s-xor-rotate-right-8/Cargo.lock deleted file mode 100644 index 76e896b8b..000000000 --- a/tests/blake2s-xor-rotate-right-8/Cargo.lock +++ /dev/null @@ -1,539 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2s-xor-rotate-right-8-test" -version = "0.1.0" -dependencies = [ - "sphinx-zkvm", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "cpufeatures" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "hybrid-array" -version = "0.2.0-rc.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" -dependencies = [ - "typenum", -] - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "once_cell" -version = "1.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" -version = "1.0.0" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "hybrid-array", - "k256", - "serde", -] - -[[package]] -name = "sphinx-zkvm" -version = "1.0.0" -dependencies = [ - "bincode", - "cfg-if", - "getrandom", - "k256", - "lazy_static", - "libm", - "once_cell", - "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/blake2s-xor-rotate-right-8/Cargo.toml b/tests/blake2s-xor-rotate-right-8/Cargo.toml deleted file mode 100644 index 82899e0ef..000000000 --- a/tests/blake2s-xor-rotate-right-8/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -[package] -name = "blake2s-xor-rotate-right-8-test" -version = "0.1.0" -edition = "2021" - -[dependencies] -sphinx-zkvm = { path = "../../zkvm/entrypoint" } diff --git a/tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-xor-rotate-right-8/elf/riscv32im-succinct-zkvm-elf deleted file mode 100755 index a4271c1948c7a60297340f635de16d5b931fcd57..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25140 zcmeHwdw3MrdH0#?u7oTE!!0(k2SyTC3rQUd?E!;b>Ij5nJ9V4TH7HH}^pO%T;5=!X)W$gdTsx`E<#Q5;7)uDOXusck zW=2|Zvy6(A}rLQT4Vj(56c=N{{g-UK!U54x$GWf26Imu{Wk`f|qTRtWBt>-Pe-M(6jJ z0HZs#{Ud7_d*o4_-!stcW!!`pwg3F-rb>Ff^5W$HN{rR#SB#a;!Ykd>KgVsX=udBd zqQIXh@FxoVi2{G3!2g#Nm=0sOo<*6-R57|tVbXDhna`eKR%|NM)WM{tOlAF3)DaEF zd3}U2U+hePo@Tn5X|N+Ku68rclg~Q;=IDr7aVE19FhjtNZ_QKBIv)eP@=Qi2V3y}` zX3%%dV0v8b2xu2e(Ec>@sb>P(#$!oqU|^!(BM6#jdR9DkS~NP2GGF^KX5{sZm}>{U z#=)b^ID~tC&j|VwjD>)&8&r*Mz@EqbE!;2Sp4~HIWaG|7y^G73b+%pbse=K{%S2-? z+SI60yloJ8pBHG1(SEP&=O2%P2I`2_ri%SF$A@X&)?hKSj!t8me;SLQIm68TYNpi= zT6q-~-L5bV@0L1)8El3?^s@&1EMEK_<}2-G@gYU9+NU#1@i1+>%KGOOkbreacd4t_mak`=3-k zv=k8{~nwJrcrcpVSS#8SzU(SHXR2s{QP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+XvVTz$)>MemQ*! z{vE(80Vn- zCL?$!n%+a@c;)j)*}EtsS#a^m#_I{dH@^xx6H_eB>=3RYSk(SJ>Yezh!^_TmXzpGx zSTEp3c&CeCGXeWKV1zSW)IJ}ubASa1kV21p0MGi5Wb%0%uBXzY5@q{QCfoDPx^lj) zD32gV_qyG7bnS>19Vjb({pvEp>1C9iN0}o>_oeb4mA{4Z`ZvbfrjAQ<8Af^bsqwTR z_!I?m2fPFCM1NO47Xp3=a5Uo=(I^1eZoo29V5yrUg@5h={1L!QX$)M1%a;J_0F2}9 z!0G`z1ei-3!lMq<{{_Cw*TO$-*3BA(iR5rKQhuSJC@(*+@&Uu6;NR|9IufrFwy%hG%7jZbNmW zxseIe@G5614I6!h)rIv1Yc>?t=QEavEJ72@YpAP)tIhJlRcqEYAlhMhjW(chZDS+L z2|S^`P49|C3;itw-_6 zFSnkKFY24>?R!*byHRfz-rdU`Hx~f6UawPcvs=k2qt6AnX Date: Mon, 23 Sep 2024 14:44:28 +0300 Subject: [PATCH 25/30] chore: Split round syscall implementation to multiple source files --- core/src/syscall/precompiles/blake2s/air.rs | 385 ++++++ .../syscall/precompiles/blake2s/columns.rs | 39 + .../syscall/precompiles/blake2s/execute.rs | 195 +++ core/src/syscall/precompiles/blake2s/mod.rs | 158 ++- core/src/syscall/precompiles/blake2s/round.rs | 1111 ----------------- core/src/syscall/precompiles/blake2s/trace.rs | 368 ++++++ 6 files changed, 1143 insertions(+), 1113 deletions(-) create mode 100644 core/src/syscall/precompiles/blake2s/air.rs create mode 100644 core/src/syscall/precompiles/blake2s/columns.rs create mode 100644 core/src/syscall/precompiles/blake2s/execute.rs delete mode 100644 core/src/syscall/precompiles/blake2s/round.rs create mode 100644 core/src/syscall/precompiles/blake2s/trace.rs diff --git a/core/src/syscall/precompiles/blake2s/air.rs b/core/src/syscall/precompiles/blake2s/air.rs new file mode 100644 index 000000000..0a0e57759 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/air.rs @@ -0,0 +1,385 @@ +use crate::memory::MemoryCols; +use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::runtime::SyscallCode; +use crate::stark::SphinxAirBuilder; +use crate::syscall::precompiles::blake2s::columns::Blake2sRoundCols; +use crate::syscall::precompiles::blake2s::{Blake2sRoundChip, R_1, R_2, R_3, R_4}; +use core::borrow::Borrow; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; +use p3_matrix::Matrix; +use std::mem::size_of; + +impl BaseAir for Blake2sRoundChip { + fn width(&self) -> usize { + size_of::>() + } +} + +impl Air for Blake2sRoundChip +where + AB::F: PrimeField32, +{ + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let next = main.row_slice(1); + let local: &Blake2sRoundCols = (*local).borrow(); + let next: &Blake2sRoundCols = (*next).borrow(); + + // Constrain the incrementing nonce. + builder.when_first_row().assert_zero(local.nonce); + builder + .when_transition() + .assert_eq(local.nonce + AB::Expr::one(), next.nonce); + + for i in 0..16usize { + // Eval a + builder.eval_memory_access( + local.shard, + local.channel, + local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, + local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.a[i], + local.is_real, + ); + + // Eval b + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + } + + // zeroes + for i in 16..24usize { + // Eval b + builder.eval_memory_access( + local.shard, + local.channel, + local.clk, + local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), + &local.b[i], + local.is_real, + ); + } + + let v1_shuffle_lookup = vec![1, 2, 3, 0]; + let v2_shuffle_lookup = vec![2, 3, 0, 1]; + let v3_shuffle_lookup = vec![3, 0, 1, 2]; + + for i in 0..4usize { + // 1x + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + *local.a[i].prev_value(), // v0 + *local.a[i + 4].prev_value(), // v1 + *local.b[i].value(), // m1 + *local.b[i + 20].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i + 12].prev_value(), + local.add[i].value, + local.xor[i], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i].value, + R_1 as usize, + local.rotate_right[i], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + *local.a[i + 8].prev_value(), // v2 + local.rotate_right[i].value, // v3 from previous operation + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 4], + ); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + *local.a[i + 4].prev_value(), + local.add[i + 4].value, + local.xor[i + 4], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 4].value, + R_2 as usize, + local.rotate_right[i + 4], + local.shard, + &local.channel, + local.is_real, + ); + + // 2x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + local.add[i].value, // v0 after 1x + local.rotate_right[i + 4].value, // v1 after 1x + *local.b[i + 4].value(), // m2 + *local.b[i + 16].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i + 8], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[i].value, // v3 after 1x + local.add[i + 8].value, // v0 after 1x + local.xor[i + 8], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 8].value, + R_3 as usize, + local.rotate_right[i + 8], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + local.add[i + 4].value, // v2 after 1x + local.rotate_right[i + 8].value, // v3 after previous operation + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 12], + ); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[i + 4].value, // v1 after 1x + local.add[i + 12].value, // v2 after previous operation + local.xor[i + 12], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 12].value, + R_4 as usize, + local.rotate_right[i + 12], + local.shard, + &local.channel, + local.is_real, + ); + } + + self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); + + for i in 0..4usize { + // 3x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + local.add[i + 8].value, // v0 after 2x + local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x + *local.b[i + 8].value(), // m3 + *local.b[i + 16].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i + 16], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x + local.add[i + 16].value, // v0 after previous operation + local.xor[i + 16], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 16].value, + R_1 as usize, + local.rotate_right[i + 16], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x + local.rotate_right[i + 16].value, // v3 after previous operation + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 20], + ); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x + local.add[i + 20].value, // v2 after previous operation + local.xor[i + 20], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 20].value, + R_2 as usize, + local.rotate_right[i + 20], + local.shard, + &local.channel, + local.is_real, + ); + + // 4x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + Add4Operation::::eval( + builder, + local.add[i + 16].value, // v0 after 3x + local.rotate_right[i + 20].value, // v1 after 3x + *local.b[i + 12].value(), // m4 + *local.b[i + 16].value(), // zero1 + local.shard, + local.channel, + local.is_real, + local.add[i + 24], + ); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[i + 16].value, // v3 after 3x + local.add[i + 24].value, // v0 after previous operation + local.xor[i + 24], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 24].value, + R_3 as usize, + local.rotate_right[i + 24], + local.shard, + &local.channel, + local.is_real, + ); + + // v[2] = v[2].wrapping_add(v[3]); + Add4Operation::::eval( + builder, + local.add[i + 20].value, // v2 after 3x + local.rotate_right[i + 24].value, // v3 after previous operation + *local.b[i + 16].value(), // zero1 + *local.b[i + 20].value(), // zero2 + local.shard, + local.channel, + local.is_real, + local.add[i + 28], + ); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + // Eval XOR + XorOperation::::eval( + builder, + local.rotate_right[i + 20].value, // v1 after 3x + local.add[i + 28].value, // v2 after previous operation + local.xor[i + 28], + local.shard, + &local.channel, + local.is_real, + ); + + // Eval RotateRight + FixedRotateRightOperation::::eval( + builder, + local.xor[i + 28].value, + R_4 as usize, + local.rotate_right[i + 28], + local.shard, + &local.channel, + local.is_real, + ); + } + + builder.receive_syscall( + local.shard, + local.channel, + local.clk, + local.nonce, + AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ROUND.syscall_id()), + local.a_ptr, + local.b_ptr, + local.is_real, + ) + } +} diff --git a/core/src/syscall/precompiles/blake2s/columns.rs b/core/src/syscall/precompiles/blake2s/columns.rs new file mode 100644 index 000000000..a684fd9f0 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/columns.rs @@ -0,0 +1,39 @@ +use crate::memory::{MemoryReadCols, MemoryWriteCols}; +use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use sphinx_derive::AlignedBorrow; + +#[derive(Debug, Clone, AlignedBorrow)] +#[repr(C)] +pub struct Blake2sRoundCols { + /// Inputs. + pub clk: T, + pub shard: T, + pub channel: T, + pub nonce: T, + pub is_real: T, + + pub a_ptr: T, + pub b_ptr: T, + + pub shuffled_indices: [T; 16], + + /// Memory layout: + /// a: v0[0] || v0[1] || v0[2] || v0[3] || + /// v1[0] || v1[1] || v1[2] || v1[3] || + /// v2[0] || v2[1] || v2[2] || v2[3] || + /// v3[0] || v3[1] || v3[2] || v3[3] || + /// + /// b: m0[0] || m0[1] || m0[2] || m0[3] || + /// m1[0] || m1[1] || m1[2] || m1[3] || + /// m2[0] || m2[1] || m2[2] || m2[3] || + /// m3[0] || m3[1] || m3[2] || m3[3] || + /// 0 || 0 || 0 || 0 || + /// 0 || 0 || 0 || 0 || + /// + pub a: [MemoryWriteCols; 16], + pub b: [MemoryReadCols; 24], + + pub add: [Add4Operation; 32], + pub xor: [XorOperation; 32], + pub rotate_right: [FixedRotateRightOperation; 32], +} diff --git a/core/src/syscall/precompiles/blake2s/execute.rs b/core/src/syscall/precompiles/blake2s/execute.rs new file mode 100644 index 000000000..06f415bf7 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/execute.rs @@ -0,0 +1,195 @@ +use crate::runtime::{Syscall, SyscallContext}; +use crate::syscall::precompiles::blake2s::{ + Blake2sRoundChip, Blake2sRoundEvent, R_1, R_2, R_3, R_4, +}; + +impl Syscall for Blake2sRoundChip { + fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { + let clk_init = ctx.clk; + let shard = ctx.current_shard(); + let lookup_id = ctx.syscall_lookup_id; + let channel = ctx.current_channel(); + + let a_ptr = arg1; + let b_ptr = arg2; + + let mut a = ctx.slice_unsafe(a_ptr, 16); + let mut a_clone = a.clone(); + + let (b_reads, b) = ctx.mr_slice(b_ptr, 24); + + // 1x (m1, R1, R2) + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[0..4].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_1); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_2); + } + + // 2x (m2, R3, R4) + let mut a = a.clone(); // a after 1x quarter_round + let mut a_clone = a.clone(); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[4..8].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_3); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_4); + } + + // shuffle + // v[1] + a[4..8].swap(0, 3); + a[4..8].swap(0, 1); + a[4..8].swap(1, 2); + + // v[2] + a[8..12].swap(0, 2); + a[8..12].swap(1, 3); + + // v[3] + a[12..16].swap(2, 3); + a[12..16].swap(1, 2); + a[12..16].swap(0, 1); + + let mut a = a.clone(); // a after 2x quarter_round + let mut a_clone = a.clone(); + + // 3x (m3, R1, R2) + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m3) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[8..12].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_1); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_2); + } + + // 4x (m4, R3, R4) + let mut a = a.clone(); // a after 3x quarter_round + let mut a_clone = a.clone(); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + for ((v0, v1), m) in a[0..4] + .iter_mut() + .zip(a_clone[4..8].iter()) + .zip(b[12..16].iter()) + { + *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); + } + a_clone = a.clone(); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { + *v3 = (*v3 ^ *v0).rotate_right(R_3); + } + a_clone = a.clone(); + + // v[2] = v[2].wrapping_add(v[3]); + for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { + *v2 = (*v2).wrapping_add(*v3); + } + a_clone = a.clone(); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { + *v1 = (*v1 ^ *v2).rotate_right(R_4); + } + + // unshuffle + // v[1] + a[4..8].swap(2, 3); + a[4..8].swap(1, 2); + a[4..8].swap(0, 1); + + // v[2] + a[8..12].swap(0, 2); + a[8..12].swap(1, 3); + + // v[3] + a[12..16].swap(0, 3); + a[12..16].swap(0, 1); + a[12..16].swap(1, 2); + + ctx.clk += 1; + // Write rotate_right to a_ptr. + let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); + + ctx.record_mut() + .blake2s_round_events + .push(Blake2sRoundEvent { + lookup_id, + clk: clk_init, + shard, + channel, + a_ptr, + b_ptr, + a_reads_writes, + b_reads, + }); + + None + } + + fn num_extra_cycles(&self) -> u32 { + 1 + } +} diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index a9229b40b..1d7cd20c2 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -1,5 +1,73 @@ -mod round; -pub use round::*; +mod air; +mod columns; +mod execute; +mod trace; + +pub use columns::*; + +use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; +use crate::stark::SphinxAirBuilder; +use p3_air::AirBuilder; +use p3_field::AbstractField; +use serde::Deserialize; +use serde::Serialize; + +/// Implements the single round function of Blake2s hashing algorithm. +/// The correspondent syscall expects two arguments, where the first argument is 4 arrays, each +/// consists from 4 u32 words one by one and the second is 4 arrays properly constructed from the +/// message of the Blake2s block: +/// +/// let m1 = $vec::gather(m, s[0], s[2], s[4], s[6]).from_le(); +/// let m2 = $vec::gather(m, s[1], s[3], s[5], s[7]).from_le(); +/// let m3 = $vec::gather(m, s[8], s[10], s[12], s[14]).from_le(); +/// let m4 = $vec::gather(m, s[9], s[11], s[13], s[15]).from_le(); +/// +/// where s is a SIGMA constant (https://www.rfc-editor.org/rfc/rfc7693.txt). + +#[derive(Default)] +pub struct Blake2sRoundChip; + +impl Blake2sRoundChip { + pub fn new() -> Self { + Blake2sRoundChip + } + pub fn constrain_shuffled_indices( + &self, + builder: &mut AB, + indices: &[AB::Var], + is_real: AB::Var, + ) { + for index in 0..4 { + builder + .when(is_real) + .assert_eq(indices[index], AB::F::from_canonical_usize(0)); + } + for index in 4..indices.len() { + builder + .when(is_real) + .assert_eq(indices[index], AB::F::from_canonical_usize(1)); + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Blake2sRoundEvent { + pub lookup_id: usize, + pub clk: u32, + pub shard: u32, + pub channel: u32, + pub a_ptr: u32, + pub b_ptr: u32, + + pub a_reads_writes: Vec, + pub b_reads: Vec, +} + +/// Rotation constants +pub const R_1: u32 = 16; +pub const R_2: u32 = 12; +pub const R_3: u32 = 8; +pub const R_4: u32 = 7; fn xor_u32x4(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] @@ -106,7 +174,93 @@ pub fn blake2s_round(v: &mut [u32], m: &[u32]) { #[cfg(test)] mod tests { + use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::syscall::precompiles::blake2s::blake2s_round; use crate::syscall::precompiles::blake2s::{quarter_round, round, shuffle, unshuffle}; + use crate::utils::tests::BLAKE2S_ROUND_ELF; + use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; + use crate::Program; + use rand::Rng; + + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 24]) -> Program { + let mut instructions = vec![]; + // memory write a + for (index, word) in a.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + a_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // memory write b + for (index, word) in b.into_iter().enumerate() { + instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); + instructions.push(Instruction::new( + Opcode::ADD, + 30, + 0, + b_ptr + (index * 4) as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); + } + + // Syscall invocation + instructions.push(Instruction::new( + Opcode::ADD, + 5, + 0, + SyscallCode::BLAKE_2S_ROUND as u32, + false, + true, + )); + instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); + instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); + Program::new(instructions, 0, 0) + } + + #[test] + fn test_blake2s_round_precompile() { + setup_logger(); + + let a_ptr = 100100100; + let b_ptr = 200200200; + + let a = rand::thread_rng().gen::<[u32; 16]>(); + let mut a_clone = a.clone(); + let mut b = rand::thread_rng().gen::<[u32; 24]>(); + for item in b[0..24].iter_mut() { + *item = 0; + } + + blake2s_round(&mut a_clone, &b); + + let program = risc_v_program(a_ptr, b_ptr, a, b); + + let (_, memory) = run_test_with_memory_inspection(program); + let mut result = vec![]; + // result is 4 words, written to a_ptr + for i in 0..16 { + result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); + } + + assert_eq!(result, a_clone.to_vec()); + } + + #[test] + fn test_blake2s_round_program() { + setup_logger(); + let program = Program::from(BLAKE2S_ROUND_ELF); + run_test(program).unwrap(); + } #[test] fn test_blake2s_round_function() { diff --git a/core/src/syscall/precompiles/blake2s/round.rs b/core/src/syscall/precompiles/blake2s/round.rs deleted file mode 100644 index 2661514cc..000000000 --- a/core/src/syscall/precompiles/blake2s/round.rs +++ /dev/null @@ -1,1111 +0,0 @@ -use crate::bytes::event::ByteRecord; -use crate::memory::{MemoryCols, MemoryReadCols, MemoryWriteCols}; -use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; -use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use crate::utils::pad_rows; -use crate::{ - air::{EventLens, MachineAir, WithEvents}, - runtime::{ExecutionRecord, Program, Syscall, SyscallCode, SyscallContext}, -}; -use core::borrow::{Borrow, BorrowMut}; -use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{AbstractField, PrimeField32}; -use p3_matrix::dense::RowMajorMatrix; -use p3_matrix::Matrix; -use serde::Deserialize; -use serde::Serialize; -use sphinx_derive::AlignedBorrow; -use std::mem::size_of; - -const R_1: u32 = 16; -const R_2: u32 = 12; -const R_3: u32 = 8; -const R_4: u32 = 7; - -#[derive(Default)] -pub struct Blake2sRoundChip; - -impl Blake2sRoundChip { - pub fn new() -> Self { - Blake2sRoundChip - } - pub fn constrain_shuffled_indices( - &self, - builder: &mut AB, - indices: &[AB::Var], - is_real: AB::Var, - ) { - for index in 0..4 { - builder - .when(is_real) - .assert_eq(indices[index], AB::F::from_canonical_usize(0)); - } - for index in 4..indices.len() { - builder - .when(is_real) - .assert_eq(indices[index], AB::F::from_canonical_usize(1)); - } - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Blake2sRoundEvent { - pub lookup_id: usize, - pub clk: u32, - pub shard: u32, - pub channel: u32, - pub a_ptr: u32, - pub b_ptr: u32, - - pub a_reads_writes: Vec, - pub b_reads: Vec, -} - -impl Syscall for Blake2sRoundChip { - fn execute(&self, ctx: &mut SyscallContext<'_, '_>, arg1: u32, arg2: u32) -> Option { - let clk_init = ctx.clk; - let shard = ctx.current_shard(); - let lookup_id = ctx.syscall_lookup_id; - let channel = ctx.current_channel(); - - let a_ptr = arg1; - let b_ptr = arg2; - - // a: v[0] || v[1] || v[2] || v[3] || v[4] || v[5] || v[6] || v[7] || v[8] || v[9] || v[10] || v[11] || v[12] || v[13] || v[14] || v[15] || - let mut a = ctx.slice_unsafe(a_ptr, 16); - let mut a_clone = a.clone(); - - // b: m1[0] || m1[1] || m1[2] || m1[3] || || m2[0] || m2[1] || m2[2] || m2[3] || - // m3[0] || m3[1] || m3[2] || m3[3] || m4[0] || m4[1] || m4[2] || mr[3] || - // 0 || 0 || 0 || 0 || 0 || 0 || 0 || 0 - let (b_reads, b) = ctx.mr_slice(b_ptr, 24); - assert_eq!(b[16], 0u32); - assert_eq!(b[17], 0u32); - assert_eq!(b[18], 0u32); - assert_eq!(b[19], 0u32); - assert_eq!(b[20], 0u32); - assert_eq!(b[21], 0u32); - assert_eq!(b[22], 0u32); - assert_eq!(b[23], 0u32); - - // 1x (m1, R1, R2) - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) - for ((v0, v1), m) in a[0..4] - .iter_mut() - .zip(a_clone[4..8].iter()) - .zip(b[0..4].iter()) - { - *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); - } - a_clone = a.clone(); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { - *v3 = (*v3 ^ *v0).rotate_right(R_1); - } - a_clone = a.clone(); - - // v[2] = v[2].wrapping_add(v[3]); - for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { - *v2 = (*v2).wrapping_add(*v3); - } - a_clone = a.clone(); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { - *v1 = (*v1 ^ *v2).rotate_right(R_2); - } - - // 2x (m2, R3, R4) - let mut a = a.clone(); // a after 1x quarter_round - let mut a_clone = a.clone(); - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) - for ((v0, v1), m) in a[0..4] - .iter_mut() - .zip(a_clone[4..8].iter()) - .zip(b[4..8].iter()) - { - *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); - } - a_clone = a.clone(); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { - *v3 = (*v3 ^ *v0).rotate_right(R_3); - } - a_clone = a.clone(); - - // v[2] = v[2].wrapping_add(v[3]); - for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { - *v2 = (*v2).wrapping_add(*v3); - } - a_clone = a.clone(); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { - *v1 = (*v1 ^ *v2).rotate_right(R_4); - } - - // shuffle - // v[1] - a[4..8].swap(0, 3); - a[4..8].swap(0, 1); - a[4..8].swap(1, 2); - - // v[2] - a[8..12].swap(0, 2); - a[8..12].swap(1, 3); - - // v[3] - a[12..16].swap(2, 3); - a[12..16].swap(1, 2); - a[12..16].swap(0, 1); - - let mut a = a.clone(); // a after 2x quarter_round - let mut a_clone = a.clone(); - - // 3x (m3, R1, R2) - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m3) - for ((v0, v1), m) in a[0..4] - .iter_mut() - .zip(a_clone[4..8].iter()) - .zip(b[8..12].iter()) - { - *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); - } - a_clone = a.clone(); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { - *v3 = (*v3 ^ *v0).rotate_right(R_1); - } - a_clone = a.clone(); - - // v[2] = v[2].wrapping_add(v[3]); - for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { - *v2 = (*v2).wrapping_add(*v3); - } - a_clone = a.clone(); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { - *v1 = (*v1 ^ *v2).rotate_right(R_2); - } - - // 4x (m4, R3, R4) - let mut a = a.clone(); // a after 3x quarter_round - let mut a_clone = a.clone(); - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) - for ((v0, v1), m) in a[0..4] - .iter_mut() - .zip(a_clone[4..8].iter()) - .zip(b[12..16].iter()) - { - *v0 = (*v0).wrapping_add(*v1).wrapping_add(*m); - } - a_clone = a.clone(); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - for (v3, v0) in a[12..16].iter_mut().zip(a_clone[0..4].iter()) { - *v3 = (*v3 ^ *v0).rotate_right(R_3); - } - a_clone = a.clone(); - - // v[2] = v[2].wrapping_add(v[3]); - for (v2, v3) in a[8..12].iter_mut().zip(a_clone[12..16].iter()) { - *v2 = (*v2).wrapping_add(*v3); - } - a_clone = a.clone(); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - for (v1, v2) in a[4..8].iter_mut().zip(a_clone[8..12].iter()) { - *v1 = (*v1 ^ *v2).rotate_right(R_4); - } - - // unshuffle - // v[1] - a[4..8].swap(2, 3); - a[4..8].swap(1, 2); - a[4..8].swap(0, 1); - - // v[2] - a[8..12].swap(0, 2); - a[8..12].swap(1, 3); - - // v[3] - a[12..16].swap(0, 3); - a[12..16].swap(0, 1); - a[12..16].swap(1, 2); - - ctx.clk += 1; - // Write rotate_right to a_ptr. - let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); - - ctx.record_mut() - .blake2s_round_events - .push(Blake2sRoundEvent { - lookup_id, - clk: clk_init, - shard, - channel, - a_ptr, - b_ptr, - a_reads_writes, - b_reads, - }); - - None - } - - fn num_extra_cycles(&self) -> u32 { - 1 - } -} - -#[derive(Debug, Clone, AlignedBorrow)] -#[repr(C)] -struct Blake2sRoundCols { - pub clk: T, - pub shard: T, - pub channel: T, - pub nonce: T, - pub is_real: T, - - pub a_ptr: T, - pub b_ptr: T, - - pub shuffled_indices: [T; 16], - - pub a: [MemoryWriteCols; 16], - pub b: [MemoryReadCols; 24], - - pub add: [Add4Operation; 32], - pub xor: [XorOperation; 32], - pub rotate_right: [FixedRotateRightOperation; 32], -} - -impl BaseAir for Blake2sRoundChip { - fn width(&self) -> usize { - size_of::>() - } -} - -impl<'a> WithEvents<'a> for Blake2sRoundChip { - type Events = &'a [Blake2sRoundEvent]; -} - -impl MachineAir for Blake2sRoundChip { - type Record = ExecutionRecord; - type Program = Program; - - fn name(&self) -> String { - "Blake2sRoundChip".to_string() - } - - fn generate_trace>( - &self, - input: &EL, - output: &mut Self::Record, - ) -> RowMajorMatrix { - let mut rows = vec![]; - let width = >::width(self); - let mut new_byte_lookup_events = Vec::new(); - for event in input.events() { - let shard = event.shard; - let mut row = vec![F::zero(); width]; - let cols: &mut Blake2sRoundCols = row.as_mut_slice().borrow_mut(); - - cols.clk = F::from_canonical_u32(event.clk); - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a_ptr = F::from_canonical_u32(event.a_ptr); - cols.b_ptr = F::from_canonical_u32(event.b_ptr); - - // populate all v, m - for i in 0..16usize { - cols.a[i].populate( - event.channel, - event.a_reads_writes[i], - &mut new_byte_lookup_events, - ); - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - } - - // populate zeroes - for i in 16..24usize { - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - } - - let mut v0_outer = vec![0u32; 4]; - let mut v1_outer = vec![0u32; 4]; - let mut v2_outer = vec![0u32; 4]; - let mut v3_outer = vec![0u32; 4]; - - // 1x (m1, R1, R2) - for i in 0..4usize { - let v0 = event.a_reads_writes[i].prev_value; - let v1 = event.a_reads_writes[i + 4].prev_value; - let v2 = event.a_reads_writes[i + 8].prev_value; - let v3 = event.a_reads_writes[i + 12].prev_value; - let m1 = event.b_reads[i].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - let v0_new = cols.add[i].populate(output, shard, event.channel, v0, v1, m1, zero1); - assert_eq!(v0 + v1 + m1 + zero1, v0_new); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0_new); - let v3_new = - cols.rotate_right[i].populate(output, shard, event.channel, temp, R_1 as usize); - assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); - - // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 4].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2_new); - let v1_new = cols.rotate_right[i + 4].populate( - output, - shard, - event.channel, - temp, - R_2 as usize, - ); - assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); - - v0_outer[i] = v0_new; - v1_outer[i] = v1_new; - v2_outer[i] = v2_new; - v3_outer[i] = v3_new; - } - - // 2x (m2, R3, R4) - for i in 0..4usize { - let v0 = v0_outer[i]; - let v1 = v1_outer[i]; - let v2 = v2_outer[i]; - let v3 = v3_outer[i]; - let m2 = event.b_reads[i + 4].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) - let v0_new = - cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); - assert_eq!(v0 + v1 + m2 + zero1, v0_new); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - //cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); - let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0_new); - //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( - let v3_new = cols.rotate_right[i + 8].populate( - output, - shard, - event.channel, - temp, - R_3 as usize, - ); - assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); - - // v[2] = v[2].wrapping_add(v[3]); - //cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( - let v2_new = cols.add[i + 4 + 8].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - //cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); - let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2_new); - //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( - let v1_new = cols.rotate_right[i + 4 + 8].populate( - output, - shard, - event.channel, - temp, - R_4 as usize, - ); - assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); - - v0_outer[i] = v0_new; - v1_outer[i] = v1_new; - v2_outer[i] = v2_new; - v3_outer[i] = v3_new; - } - - // shuffle - // v[1] - v1_outer.swap(0, 3); - v1_outer.swap(0, 1); - v1_outer.swap(1, 2); - - // v[2] - v2_outer.swap(0, 2); - v2_outer.swap(1, 3); - - // v[3] - v3_outer.swap(2, 3); - v3_outer.swap(1, 2); - v3_outer.swap(0, 1); - - // 3x (m3, R1, R2) - for i in 0..4usize { - cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); - cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); - - let v0 = v0_outer[i]; - let v1 = v1_outer[i]; - let v2 = v2_outer[i]; - let v3 = v3_outer[i]; - let m3 = event.b_reads[i + 8].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - let v0_new = - cols.add[i + 16].populate(output, shard, event.channel, v0, v1, m3, zero1); - assert_eq!(v0 + v1 + m3 + zero1, v0_new); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0_new); - let v3_new = cols.rotate_right[i + 16].populate( - output, - shard, - event.channel, - temp, - R_1 as usize, - ); - assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); - - // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 16 + 4].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - let temp = cols.xor[i + 16 + 4].populate(output, shard, event.channel, v1, v2_new); - let v1_new = cols.rotate_right[i + 16 + 4].populate( - output, - shard, - event.channel, - temp, - R_2 as usize, - ); - assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); - - v0_outer[i] = v0_new; - v1_outer[i] = v1_new; - v2_outer[i] = v2_new; - v3_outer[i] = v3_new; - } - - // 4x (m4, R3, R4) - for i in 0..4usize { - let v0 = v0_outer[i]; - let v1 = v1_outer[i]; - let v2 = v2_outer[i]; - let v3 = v3_outer[i]; - let m4 = event.b_reads[i + 12].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) - let v0_new = - cols.add[i + 16 + 8].populate(output, shard, event.channel, v0, v1, m4, zero1); - assert_eq!(v0 + v1 + m4 + zero1, v0_new); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - //cols.unshuffled_indices[i + 12] = F::from_canonical_u32(1); - let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0_new); - //let v3_new = cols.rotate_right[v3_unshuffle_lookup[i] + 16 + 8].populate( - let v3_new = cols.rotate_right[i + 16 + 8].populate( - output, - shard, - event.channel, - temp, - R_3 as usize, - ); - assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); - - // v[2] = v[2].wrapping_add(v[3]); - //cols.unshuffled_indices[i + 8] = F::from_canonical_u32(1); - //let v2_new = cols.add[v2_unshuffle_lookup[i] + 16 + 4 + 8].populate( - let v2_new = cols.add[i + 16 + 4 + 8].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - //cols.unshuffled_indices[i + 4] = F::from_canonical_u32(1); - let temp = - cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2_new); - //let v1_new = cols.rotate_right[v1_unshuffle_lookup[i] + 16 + 4 + 8].populate( - let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( - output, - shard, - event.channel, - temp, - R_4 as usize, - ); - assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); - - //v0_outer[i] = v0_new; - //v1_outer[i] = v1_new; - //v2_outer[i] = v2_new; - //v3_outer[i] = v3_new; - } - - /* - // unshuffle - // v[1] - v1_outer.swap(2, 3); - v1_outer.swap(1, 2); - v1_outer.swap(0, 1); - - // v[2] - v2_outer.swap(0, 2); - v2_outer.swap(1, 3); - - // v[3] - v3_outer.swap(0, 3); - v3_outer.swap(0, 1); - v3_outer.swap(1, 2);*/ - - //println!("4x traces: {:02x?}", [v0_outer, v1_outer, v2_outer, v3_outer].concat().to_vec()); - - rows.push(row); - } - - output.add_byte_lookup_events(new_byte_lookup_events); - - pad_rows(&mut rows, || { - let row = vec![F::zero(); width]; - - row - }); - - let mut trace = - RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); - - // Write the nonces to the trace. - for i in 0..trace.height() { - let cols: &mut Blake2sRoundCols = - trace.values[i * width..(i + 1) * width].borrow_mut(); - cols.nonce = F::from_canonical_usize(i); - } - - trace - } - - fn included(&self, shard: &Self::Record) -> bool { - !shard.blake2s_round_events.is_empty() - } -} - -impl Air for Blake2sRoundChip -where - AB::F: PrimeField32, -{ - fn eval(&self, builder: &mut AB) { - let main = builder.main(); - let local = main.row_slice(0); - let next = main.row_slice(1); - let local: &Blake2sRoundCols = (*local).borrow(); - let next: &Blake2sRoundCols = (*next).borrow(); - - // Constrain the incrementing nonce. - builder.when_first_row().assert_zero(local.nonce); - builder - .when_transition() - .assert_eq(local.nonce + AB::Expr::one(), next.nonce); - - for i in 0..16usize { - // Eval a - builder.eval_memory_access( - local.shard, - local.channel, - local.clk + AB::F::from_canonical_u32(1), // We eval 'a' pointer access at clk+1 since 'a', 'b' could be the same, - local.a_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.a[i], - local.is_real, - ); - - // Eval b - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - } - - // zeroes - for i in 16..24usize { - // Eval b - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - } - - let v1_shuffle_lookup = vec![1, 2, 3, 0]; - let v2_shuffle_lookup = vec![2, 3, 0, 1]; - let v3_shuffle_lookup = vec![3, 0, 1, 2]; - - for i in 0..4usize { - // 1x - - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( - builder, - *local.a[i].prev_value(), // v0 - *local.a[i + 4].prev_value(), // v1 - *local.b[i].value(), // m1 - *local.b[i + 20].value(), // zero1 - local.shard, - local.channel, - local.is_real, - local.add[i], - ); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i + 12].prev_value(), - local.add[i].value, - local.xor[i], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i].value, - R_1 as usize, - local.rotate_right[i], - local.shard, - &local.channel, - local.is_real, - ); - - // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( - builder, - *local.a[i + 8].prev_value(), // v2 - local.rotate_right[i].value, // v3 from previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 - local.shard, - local.channel, - local.is_real, - local.add[i + 4], - ); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR - XorOperation::::eval( - builder, - *local.a[i + 4].prev_value(), - local.add[i + 4].value, - local.xor[i + 4], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 4].value, - R_2 as usize, - local.rotate_right[i + 4], - local.shard, - &local.channel, - local.is_real, - ); - - // 2x - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( - builder, - local.add[i].value, // v0 after 1x - local.rotate_right[i + 4].value, // v1 after 1x - *local.b[i + 4].value(), // m2 - *local.b[i + 16].value(), // zero1 - local.shard, - local.channel, - local.is_real, - local.add[i + 8], - ); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR - XorOperation::::eval( - builder, - local.rotate_right[i].value, // v3 after 1x - local.add[i + 8].value, // v0 after 1x - local.xor[i + 8], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 8].value, - R_3 as usize, - local.rotate_right[i + 8], - local.shard, - &local.channel, - local.is_real, - ); - - // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( - builder, - local.add[i + 4].value, // v2 after 1x - local.rotate_right[i + 8].value, // v3 after previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 - local.shard, - local.channel, - local.is_real, - local.add[i + 12], - ); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR - XorOperation::::eval( - builder, - local.rotate_right[i + 4].value, // v1 after 1x - local.add[i + 12].value, // v2 after previous operation - local.xor[i + 12], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 12].value, - R_4 as usize, - local.rotate_right[i + 12], - local.shard, - &local.channel, - local.is_real, - ); - } - - self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); - - for i in 0..4usize { - // 3x - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( - builder, - local.add[i + 8].value, // v0 after 2x - local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x - *local.b[i + 8].value(), // m3 - *local.b[i + 16].value(), // zero1 - local.shard, - local.channel, - local.is_real, - local.add[i + 16], - ); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR - XorOperation::::eval( - builder, - local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x - local.add[i + 16].value, // v0 after previous operation - local.xor[i + 16], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 16].value, - R_1 as usize, - local.rotate_right[i + 16], - local.shard, - &local.channel, - local.is_real, - ); - - // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( - builder, - local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x - local.rotate_right[i + 16].value, // v3 after previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 - local.shard, - local.channel, - local.is_real, - local.add[i + 20], - ); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR - XorOperation::::eval( - builder, - local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x - local.add[i + 20].value, // v2 after previous operation - local.xor[i + 20], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 20].value, - R_2 as usize, - local.rotate_right[i + 20], - local.shard, - &local.channel, - local.is_real, - ); - - // 4x - // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( - builder, - local.add[i + 16].value, // v0 after 3x - local.rotate_right[i + 20].value, // v1 after 3x - *local.b[i + 12].value(), // m4 - *local.b[i + 16].value(), // zero1 - local.shard, - local.channel, - local.is_real, - local.add[i + 24], - ); - - // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR - XorOperation::::eval( - builder, - local.rotate_right[i + 16].value, // v3 after 3x - local.add[i + 24].value, // v0 after previous operation - local.xor[i + 24], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 24].value, - R_3 as usize, - local.rotate_right[i + 24], - local.shard, - &local.channel, - local.is_real, - ); - - // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( - builder, - local.add[i + 20].value, // v2 after 3x - local.rotate_right[i + 24].value, // v3 after previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 - local.shard, - local.channel, - local.is_real, - local.add[i + 28], - ); - - // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR - XorOperation::::eval( - builder, - local.rotate_right[i + 20].value, // v1 after 3x - local.add[i + 28].value, // v2 after previous operation - local.xor[i + 28], - local.shard, - &local.channel, - local.is_real, - ); - - // Eval RotateRight - FixedRotateRightOperation::::eval( - builder, - local.xor[i + 28].value, - R_4 as usize, - local.rotate_right[i + 28], - local.shard, - &local.channel, - local.is_real, - ); - } - - /*self.constrain_shuffled_unshuffled_indices( - builder, - &local.unshuffled_indices, - local.is_real, - );*/ - - builder.receive_syscall( - local.shard, - local.channel, - local.clk, - local.nonce, - AB::F::from_canonical_u32(SyscallCode::BLAKE_2S_ROUND.syscall_id()), - local.a_ptr, - local.b_ptr, - local.is_real, - ) - } -} - -#[cfg(test)] -mod tests { - use crate::runtime::{Instruction, Opcode, SyscallCode}; - use crate::syscall::precompiles::blake2s::blake2s_round; - use crate::utils::tests::BLAKE2S_ROUND_ELF; - use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; - use crate::Program; - use rand::Rng; - - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 24]) -> Program { - let mut instructions = vec![]; - // memory write a - for (index, word) in a.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - a_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // memory write b - for (index, word) in b.into_iter().enumerate() { - instructions.push(Instruction::new(Opcode::ADD, 29, 0, word, false, true)); - instructions.push(Instruction::new( - Opcode::ADD, - 30, - 0, - b_ptr + (index * 4) as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::SW, 29, 30, 0, false, true)); - } - - // Syscall invocation - instructions.push(Instruction::new( - Opcode::ADD, - 5, - 0, - SyscallCode::BLAKE_2S_ROUND as u32, - false, - true, - )); - instructions.push(Instruction::new(Opcode::ADD, 10, 0, a_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ADD, 11, 0, b_ptr, false, true)); - instructions.push(Instruction::new(Opcode::ECALL, 5, 10, 11, false, false)); - Program::new(instructions, 0, 0) - } - - #[test] - fn test_blake2s_round_precompile() { - setup_logger(); - - let a_ptr = 100100100; - let b_ptr = 200200200; - - let a = rand::thread_rng().gen::<[u32; 16]>(); - let mut a_clone = a.clone(); - let mut b = rand::thread_rng().gen::<[u32; 24]>(); - for item in b[0..24].iter_mut() { - *item = 0; - } - - blake2s_round(&mut a_clone, &b); - - let program = risc_v_program(a_ptr, b_ptr, a, b); - - let (_, memory) = run_test_with_memory_inspection(program); - let mut result = vec![]; - // result is 4 words, written to a_ptr - for i in 0..16 { - result.push(memory.get(&(a_ptr + i * 4)).unwrap().value); - } - - assert_eq!(result, a_clone.to_vec()); - } - - #[test] - fn test_blake2s_round_program() { - setup_logger(); - let program = Program::from(BLAKE2S_ROUND_ELF); - run_test(program).unwrap(); - } -} diff --git a/core/src/syscall/precompiles/blake2s/trace.rs b/core/src/syscall/precompiles/blake2s/trace.rs new file mode 100644 index 000000000..06d67e014 --- /dev/null +++ b/core/src/syscall/precompiles/blake2s/trace.rs @@ -0,0 +1,368 @@ +use crate::bytes::event::ByteRecord; +use crate::syscall::precompiles::blake2s::Blake2sRoundCols; +use crate::syscall::precompiles::blake2s::{ + Blake2sRoundChip, Blake2sRoundEvent, R_1, R_2, R_3, R_4, +}; +use crate::utils::pad_rows; +use crate::{ + air::{EventLens, MachineAir, WithEvents}, + runtime::{ExecutionRecord, Program}, +}; +use core::borrow::BorrowMut; +use p3_air::BaseAir; +use p3_field::PrimeField32; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; + +impl<'a> WithEvents<'a> for Blake2sRoundChip { + type Events = &'a [Blake2sRoundEvent]; +} + +impl MachineAir for Blake2sRoundChip { + type Record = ExecutionRecord; + type Program = Program; + + fn name(&self) -> String { + "Blake2sRoundChip".to_string() + } + + fn generate_trace>( + &self, + input: &EL, + output: &mut Self::Record, + ) -> RowMajorMatrix { + let mut rows = vec![]; + let width = >::width(self); + let mut new_byte_lookup_events = Vec::new(); + for event in input.events() { + let shard = event.shard; + let mut row = vec![F::zero(); width]; + let cols: &mut Blake2sRoundCols = row.as_mut_slice().borrow_mut(); + + cols.clk = F::from_canonical_u32(event.clk); + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a_ptr = F::from_canonical_u32(event.a_ptr); + cols.b_ptr = F::from_canonical_u32(event.b_ptr); + + // populate all v, m + for i in 0..16usize { + cols.a[i].populate( + event.channel, + event.a_reads_writes[i], + &mut new_byte_lookup_events, + ); + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + } + + // populate zeroes + for i in 16..24usize { + cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); + } + + let mut v0_outer = vec![0u32; 4]; + let mut v1_outer = vec![0u32; 4]; + let mut v2_outer = vec![0u32; 4]; + let mut v3_outer = vec![0u32; 4]; + + // 1x (m1, R1, R2) + for i in 0..4usize { + let v0 = event.a_reads_writes[i].prev_value; + let v1 = event.a_reads_writes[i + 4].prev_value; + let v2 = event.a_reads_writes[i + 8].prev_value; + let v3 = event.a_reads_writes[i + 12].prev_value; + let m1 = event.b_reads[i].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + let v0_new = cols.add[i].populate(output, shard, event.channel, v0, v1, m1, zero1); + assert_eq!(v0 + v1 + m1 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0_new); + let v3_new = + cols.rotate_right[i].populate(output, shard, event.channel, temp, R_1 as usize); + assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + let v2_new = cols.add[i + 4].populate( + output, + shard, + event.channel, + v2, + v3_new, + zero1, + zero2, + ); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2_new); + let v1_new = cols.rotate_right[i + 4].populate( + output, + shard, + event.channel, + temp, + R_2 as usize, + ); + assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); + + v0_outer[i] = v0_new; + v1_outer[i] = v1_new; + v2_outer[i] = v2_new; + v3_outer[i] = v3_new; + } + + // 2x (m2, R3, R4) + for i in 0..4usize { + let v0 = v0_outer[i]; + let v1 = v1_outer[i]; + let v2 = v2_outer[i]; + let v3 = v3_outer[i]; + let m2 = event.b_reads[i + 4].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + let v0_new = + cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); + assert_eq!(v0 + v1 + m2 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) + //cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); + let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0_new); + //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( + let v3_new = cols.rotate_right[i + 8].populate( + output, + shard, + event.channel, + temp, + R_3 as usize, + ); + assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + //cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); + //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( + let v2_new = cols.add[i + 4 + 8].populate( + output, + shard, + event.channel, + v2, + v3_new, + zero1, + zero2, + ); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) + //cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); + let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2_new); + //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( + let v1_new = cols.rotate_right[i + 4 + 8].populate( + output, + shard, + event.channel, + temp, + R_4 as usize, + ); + assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); + + v0_outer[i] = v0_new; + v1_outer[i] = v1_new; + v2_outer[i] = v2_new; + v3_outer[i] = v3_new; + } + + // shuffle + // v[1] + v1_outer.swap(0, 3); + v1_outer.swap(0, 1); + v1_outer.swap(1, 2); + + // v[2] + v2_outer.swap(0, 2); + v2_outer.swap(1, 3); + + // v[3] + v3_outer.swap(2, 3); + v3_outer.swap(1, 2); + v3_outer.swap(0, 1); + + // 3x (m3, R1, R2) + for i in 0..4usize { + cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); + cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); + cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); + + let v0 = v0_outer[i]; + let v1 = v1_outer[i]; + let v2 = v2_outer[i]; + let v3 = v3_outer[i]; + let m3 = event.b_reads[i + 8].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); + let v0_new = + cols.add[i + 16].populate(output, shard, event.channel, v0, v1, m3, zero1); + assert_eq!(v0 + v1 + m3 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); + let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0_new); + let v3_new = cols.rotate_right[i + 16].populate( + output, + shard, + event.channel, + temp, + R_1 as usize, + ); + assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + let v2_new = cols.add[i + 16 + 4].populate( + output, + shard, + event.channel, + v2, + v3_new, + zero1, + zero2, + ); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); + let temp = cols.xor[i + 16 + 4].populate(output, shard, event.channel, v1, v2_new); + let v1_new = cols.rotate_right[i + 16 + 4].populate( + output, + shard, + event.channel, + temp, + R_2 as usize, + ); + assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); + + v0_outer[i] = v0_new; + v1_outer[i] = v1_new; + v2_outer[i] = v2_new; + v3_outer[i] = v3_new; + } + + // 4x (m4, R3, R4) + for i in 0..4usize { + let v0 = v0_outer[i]; + let v1 = v1_outer[i]; + let v2 = v2_outer[i]; + let v3 = v3_outer[i]; + let m4 = event.b_reads[i + 12].value; + let zero1 = event.b_reads[i + 16].value; + let zero2 = event.b_reads[i + 20].value; + assert_eq!(zero1, 0); + assert_eq!(zero2, 0); + + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) + let v0_new = + cols.add[i + 16 + 8].populate(output, shard, event.channel, v0, v1, m4, zero1); + assert_eq!(v0 + v1 + m4 + zero1, v0_new); + + // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) + //cols.unshuffled_indices[i + 12] = F::from_canonical_u32(1); + let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0_new); + //let v3_new = cols.rotate_right[v3_unshuffle_lookup[i] + 16 + 8].populate( + let v3_new = cols.rotate_right[i + 16 + 8].populate( + output, + shard, + event.channel, + temp, + R_3 as usize, + ); + assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); + + // v[2] = v[2].wrapping_add(v[3]); + //cols.unshuffled_indices[i + 8] = F::from_canonical_u32(1); + //let v2_new = cols.add[v2_unshuffle_lookup[i] + 16 + 4 + 8].populate( + let v2_new = cols.add[i + 16 + 4 + 8].populate( + output, + shard, + event.channel, + v2, + v3_new, + zero1, + zero2, + ); + assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); + + // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) + //cols.unshuffled_indices[i + 4] = F::from_canonical_u32(1); + let temp = + cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2_new); + //let v1_new = cols.rotate_right[v1_unshuffle_lookup[i] + 16 + 4 + 8].populate( + let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( + output, + shard, + event.channel, + temp, + R_4 as usize, + ); + assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); + + //v0_outer[i] = v0_new; + //v1_outer[i] = v1_new; + //v2_outer[i] = v2_new; + //v3_outer[i] = v3_new; + } + + /* + // unshuffle + // v[1] + v1_outer.swap(2, 3); + v1_outer.swap(1, 2); + v1_outer.swap(0, 1); + + // v[2] + v2_outer.swap(0, 2); + v2_outer.swap(1, 3); + + // v[3] + v3_outer.swap(0, 3); + v3_outer.swap(0, 1); + v3_outer.swap(1, 2);*/ + + //println!("4x traces: {:02x?}", [v0_outer, v1_outer, v2_outer, v3_outer].concat().to_vec()); + + rows.push(row); + } + + output.add_byte_lookup_events(new_byte_lookup_events); + + pad_rows(&mut rows, || { + let row = vec![F::zero(); width]; + + row + }); + + let mut trace = + RowMajorMatrix::::new(rows.into_iter().flatten().collect::>(), width); + + // Write the nonces to the trace. + for i in 0..trace.height() { + let cols: &mut Blake2sRoundCols = + trace.values[i * width..(i + 1) * width].borrow_mut(); + cols.nonce = F::from_canonical_usize(i); + } + + trace + } + + fn included(&self, shard: &Self::Record) -> bool { + !shard.blake2s_round_events.is_empty() + } +} From 04fa3d1caa83c21d7a6acaaa64f17ec41ee3665e Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 23 Sep 2024 14:51:39 +0300 Subject: [PATCH 26/30] chore: Cleanup --- core/src/syscall/precompiles/blake2s/air.rs | 29 +-------- .../syscall/precompiles/blake2s/execute.rs | 9 +-- core/src/syscall/precompiles/blake2s/trace.rs | 61 +++---------------- 3 files changed, 15 insertions(+), 84 deletions(-) diff --git a/core/src/syscall/precompiles/blake2s/air.rs b/core/src/syscall/precompiles/blake2s/air.rs index 0a0e57759..15ab346ce 100644 --- a/core/src/syscall/precompiles/blake2s/air.rs +++ b/core/src/syscall/precompiles/blake2s/air.rs @@ -55,9 +55,8 @@ where ); } - // zeroes + // Eval extra-zeroes for i in 16..24usize { - // Eval b builder.eval_memory_access( local.shard, local.channel, @@ -89,7 +88,6 @@ where ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR XorOperation::::eval( builder, *local.a[i + 12].prev_value(), @@ -99,8 +97,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i].value, @@ -125,7 +121,6 @@ where ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR XorOperation::::eval( builder, *local.a[i + 4].prev_value(), @@ -135,8 +130,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 4].value, @@ -148,6 +141,7 @@ where ); // 2x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, @@ -162,7 +156,6 @@ where ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR XorOperation::::eval( builder, local.rotate_right[i].value, // v3 after 1x @@ -172,8 +165,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 8].value, @@ -198,7 +189,6 @@ where ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR XorOperation::::eval( builder, local.rotate_right[i + 4].value, // v1 after 1x @@ -208,8 +198,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 12].value, @@ -225,6 +213,7 @@ where for i in 0..4usize { // 3x + // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); Add4Operation::::eval( builder, @@ -239,7 +228,6 @@ where ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR XorOperation::::eval( builder, local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x @@ -249,8 +237,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 16].value, @@ -275,7 +261,6 @@ where ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR XorOperation::::eval( builder, local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x @@ -285,8 +270,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 20].value, @@ -312,7 +295,6 @@ where ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); - // Eval XOR XorOperation::::eval( builder, local.rotate_right[i + 16].value, // v3 after 3x @@ -322,8 +304,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 24].value, @@ -348,7 +328,6 @@ where ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); - // Eval XOR XorOperation::::eval( builder, local.rotate_right[i + 20].value, // v1 after 3x @@ -358,8 +337,6 @@ where &local.channel, local.is_real, ); - - // Eval RotateRight FixedRotateRightOperation::::eval( builder, local.xor[i + 28].value, diff --git a/core/src/syscall/precompiles/blake2s/execute.rs b/core/src/syscall/precompiles/blake2s/execute.rs index 06f415bf7..c4e7b5d0d 100644 --- a/core/src/syscall/precompiles/blake2s/execute.rs +++ b/core/src/syscall/precompiles/blake2s/execute.rs @@ -18,7 +18,7 @@ impl Syscall for Blake2sRoundChip { let (b_reads, b) = ctx.mr_slice(b_ptr, 24); - // 1x (m1, R1, R2) + // 1x (m0, R1, R2) // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) for ((v0, v1), m) in a[0..4] .iter_mut() @@ -46,7 +46,7 @@ impl Syscall for Blake2sRoundChip { *v1 = (*v1 ^ *v2).rotate_right(R_2); } - // 2x (m2, R3, R4) + // 2x (m1, R3, R4) let mut a = a.clone(); // a after 1x quarter_round let mut a_clone = a.clone(); @@ -95,7 +95,7 @@ impl Syscall for Blake2sRoundChip { let mut a = a.clone(); // a after 2x quarter_round let mut a_clone = a.clone(); - // 3x (m3, R1, R2) + // 3x (m2, R1, R2) // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m3) for ((v0, v1), m) in a[0..4] .iter_mut() @@ -123,7 +123,7 @@ impl Syscall for Blake2sRoundChip { *v1 = (*v1 ^ *v2).rotate_right(R_2); } - // 4x (m4, R3, R4) + // 4x (m3, R3, R4) let mut a = a.clone(); // a after 3x quarter_round let mut a_clone = a.clone(); @@ -170,6 +170,7 @@ impl Syscall for Blake2sRoundChip { a[12..16].swap(1, 2); ctx.clk += 1; + // Write rotate_right to a_ptr. let a_reads_writes = ctx.mw_slice(a_ptr, a.as_slice()); diff --git a/core/src/syscall/precompiles/blake2s/trace.rs b/core/src/syscall/precompiles/blake2s/trace.rs index 06d67e014..ec95db0eb 100644 --- a/core/src/syscall/precompiles/blake2s/trace.rs +++ b/core/src/syscall/precompiles/blake2s/trace.rs @@ -56,7 +56,8 @@ impl MachineAir for Blake2sRoundChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } - // populate zeroes + // populate extra-zeroes + // TODO: replace Add4 with Add3 operation and avoid this for i in 16..24usize { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } @@ -66,7 +67,7 @@ impl MachineAir for Blake2sRoundChip { let mut v2_outer = vec![0u32; 4]; let mut v3_outer = vec![0u32; 4]; - // 1x (m1, R1, R2) + // 1x (m0, R1, R2) for i in 0..4usize { let v0 = event.a_reads_writes[i].prev_value; let v1 = event.a_reads_writes[i + 4].prev_value; @@ -80,13 +81,11 @@ impl MachineAir for Blake2sRoundChip { // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); let v0_new = cols.add[i].populate(output, shard, event.channel, v0, v1, m1, zero1); - assert_eq!(v0 + v1 + m1 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0_new); let v3_new = cols.rotate_right[i].populate(output, shard, event.channel, temp, R_1 as usize); - assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); // v[2] = v[2].wrapping_add(v[3]); let v2_new = cols.add[i + 4].populate( @@ -98,7 +97,6 @@ impl MachineAir for Blake2sRoundChip { zero1, zero2, ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2_new); @@ -109,7 +107,6 @@ impl MachineAir for Blake2sRoundChip { temp, R_2 as usize, ); - assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); v0_outer[i] = v0_new; v1_outer[i] = v1_new; @@ -117,7 +114,7 @@ impl MachineAir for Blake2sRoundChip { v3_outer[i] = v3_new; } - // 2x (m2, R3, R4) + // 2x (m1, R3, R4) for i in 0..4usize { let v0 = v0_outer[i]; let v1 = v1_outer[i]; @@ -126,18 +123,13 @@ impl MachineAir for Blake2sRoundChip { let m2 = event.b_reads[i + 4].value; let zero1 = event.b_reads[i + 16].value; let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) let v0_new = cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); - assert_eq!(v0 + v1 + m2 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - //cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0_new); - //let v3_new = cols.rotate_right[v3_shuffle_lookup[i] + 8].populate( let v3_new = cols.rotate_right[i + 8].populate( output, shard, @@ -145,11 +137,8 @@ impl MachineAir for Blake2sRoundChip { temp, R_3 as usize, ); - assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - //cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - //let v2_new = cols.add[v2_shuffle_lookup[i] + 4 + 8].populate( let v2_new = cols.add[i + 4 + 8].populate( output, shard, @@ -159,12 +148,9 @@ impl MachineAir for Blake2sRoundChip { zero1, zero2, ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - //cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2_new); - //let v1_new = cols.rotate_right[v1_shuffle_lookup[i] + 4 + 8].populate( let v1_new = cols.rotate_right[i + 4 + 8].populate( output, shard, @@ -172,7 +158,6 @@ impl MachineAir for Blake2sRoundChip { temp, R_4 as usize, ); - assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); v0_outer[i] = v0_new; v1_outer[i] = v1_new; @@ -195,7 +180,7 @@ impl MachineAir for Blake2sRoundChip { v3_outer.swap(1, 2); v3_outer.swap(0, 1); - // 3x (m3, R1, R2) + // 3x (m2, R1, R2) for i in 0..4usize { cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); @@ -256,7 +241,7 @@ impl MachineAir for Blake2sRoundChip { v3_outer[i] = v3_new; } - // 4x (m4, R3, R4) + // 4x (m3, R3, R4) for i in 0..4usize { let v0 = v0_outer[i]; let v1 = v1_outer[i]; @@ -274,9 +259,7 @@ impl MachineAir for Blake2sRoundChip { assert_eq!(v0 + v1 + m4 + zero1, v0_new); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) - //cols.unshuffled_indices[i + 12] = F::from_canonical_u32(1); let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0_new); - //let v3_new = cols.rotate_right[v3_unshuffle_lookup[i] + 16 + 8].populate( let v3_new = cols.rotate_right[i + 16 + 8].populate( output, shard, @@ -287,8 +270,6 @@ impl MachineAir for Blake2sRoundChip { assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - //cols.unshuffled_indices[i + 8] = F::from_canonical_u32(1); - //let v2_new = cols.add[v2_unshuffle_lookup[i] + 16 + 4 + 8].populate( let v2_new = cols.add[i + 16 + 4 + 8].populate( output, shard, @@ -298,46 +279,18 @@ impl MachineAir for Blake2sRoundChip { zero1, zero2, ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) - //cols.unshuffled_indices[i + 4] = F::from_canonical_u32(1); let temp = cols.xor[i + 16 + 4 + 8].populate(output, shard, event.channel, v1, v2_new); - //let v1_new = cols.rotate_right[v1_unshuffle_lookup[i] + 16 + 4 + 8].populate( - let v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( + let _v1_new = cols.rotate_right[i + 16 + 4 + 8].populate( output, shard, event.channel, temp, R_4 as usize, ); - assert_eq!((v1 ^ v2_new).rotate_right(R_4), v1_new); - - //v0_outer[i] = v0_new; - //v1_outer[i] = v1_new; - //v2_outer[i] = v2_new; - //v3_outer[i] = v3_new; } - - /* - // unshuffle - // v[1] - v1_outer.swap(2, 3); - v1_outer.swap(1, 2); - v1_outer.swap(0, 1); - - // v[2] - v2_outer.swap(0, 2); - v2_outer.swap(1, 3); - - // v[3] - v3_outer.swap(0, 3); - v3_outer.swap(0, 1); - v3_outer.swap(1, 2);*/ - - //println!("4x traces: {:02x?}", [v0_outer, v1_outer, v2_outer, v3_outer].concat().to_vec()); - rows.push(row); } From b4c74f8f6fc735c57feb0a36c0aeb6b8d537996a Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 23 Sep 2024 15:15:33 +0300 Subject: [PATCH 27/30] chore: Clippy --- core/src/stark/air.rs | 2 +- core/src/syscall/precompiles/blake2s/air.rs | 6 ++--- core/src/syscall/precompiles/blake2s/mod.rs | 27 +++++++++---------- core/src/syscall/precompiles/blake2s/trace.rs | 8 +++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 3b4d61efc..af094bb27 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -184,7 +184,7 @@ impl RiscvAir { chips.push(RiscvAir::ProgramMemory(program_memory_init)); let byte = ByteChip::default(); chips.push(RiscvAir::ByteLookup(byte)); - let blake_2s_round = Blake2sRoundChip::default(); + let blake_2s_round = Blake2sRoundChip::new(); chips.push(RiscvAir::Blake2sRound(blake_2s_round)); chips diff --git a/core/src/syscall/precompiles/blake2s/air.rs b/core/src/syscall/precompiles/blake2s/air.rs index 15ab346ce..d70f0d6f2 100644 --- a/core/src/syscall/precompiles/blake2s/air.rs +++ b/core/src/syscall/precompiles/blake2s/air.rs @@ -67,9 +67,9 @@ where ); } - let v1_shuffle_lookup = vec![1, 2, 3, 0]; - let v2_shuffle_lookup = vec![2, 3, 0, 1]; - let v3_shuffle_lookup = vec![3, 0, 1, 2]; + let v1_shuffle_lookup = [1, 2, 3, 0]; + let v2_shuffle_lookup = [2, 3, 0, 1]; + let v3_shuffle_lookup = [3, 0, 1, 2]; for i in 0..4usize { // 1x diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index 1d7cd20c2..db178b42f 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -106,26 +106,30 @@ fn rotate_right_const(a: [u32; 4], n: u32) -> [u32; 4] { a[3].rotate_right(n), ] } -fn quarter_round(v: &mut Vec<[u32; 4]>, rd: u32, rb: u32, m: [u32; 4]) { +fn quarter_round(v: &mut [[u32; 4]], rd: u32, rb: u32, m: [u32; 4]) { v[0] = wrapping_add_u32x4(wrapping_add_u32x4(v[0], v[1]), m); // m.from_le (?) v[3] = rotate_right_const(xor_u32x4(v[3], v[0]), rd); v[2] = wrapping_add_u32x4(v[2], v[3]); v[1] = rotate_right_const(xor_u32x4(v[1], v[2]), rb); } -fn shuffle(v: &mut Vec<[u32; 4]>) { +fn shuffle(v: &mut [[u32; 4]]) { v[1] = shuffle_left_1_u32x4(v[1]); v[2] = shuffle_left_2_u32x4(v[2]); v[3] = shuffle_left_3_u32x4(v[3]); } -fn unshuffle(v: &mut Vec<[u32; 4]>) { +fn unshuffle(v: &mut [[u32; 4]]) { v[1] = shuffle_right_1_u32x4(v[1]); v[2] = shuffle_right_2_u32x4(v[2]); v[3] = shuffle_right_3_u32x4(v[3]); } + +#[allow(dead_code)] fn gather(m: [u32; 16], i0: usize, i1: usize, i2: usize, i3: usize) -> [u32; 4] { [m[i0], m[i1], m[i2], m[i3]] } -fn round(v: &mut Vec<[u32; 4]>, m: [u32; 16], s: [usize; 16]) { + +#[allow(dead_code)] +fn round(v: &mut [[u32; 4]], m: [u32; 16], s: [usize; 16]) { let r1 = 16; let r2 = 12; let r3 = 8; @@ -235,7 +239,7 @@ mod tests { let b_ptr = 200200200; let a = rand::thread_rng().gen::<[u32; 16]>(); - let mut a_clone = a.clone(); + let mut a_clone = a; let mut b = rand::thread_rng().gen::<[u32; 24]>(); for item in b[0..24].iter_mut() { *item = 0; @@ -264,14 +268,9 @@ mod tests { #[test] fn test_blake2s_round_function() { - fn test_inner( - input: &mut Vec<[u32; 4]>, - m: [u32; 16], - s: [usize; 16], - output: Vec<[u32; 4]>, - ) { + fn test_inner(input: &mut [[u32; 4]], m: [u32; 16], s: [usize; 16], output: &[[u32; 4]]) { round(input, m, s); - assert_eq!(input.clone(), output); + assert_eq!(input.to_vec(), output.to_vec()); } let mut v: Vec<[u32; 4]> = vec![ @@ -294,7 +293,7 @@ mod tests { &mut v, m, s, - vec![ + &[ [0x82a01b5d, 0x248bd8f5, 0x1da4b59a, 0xb37b2bd3], [0x515f5af4, 0x0301095b, 0xb151a3c2, 0x5e17f96f], [0xc561666d, 0x0f291605, 0x990c6d13, 0x76fff6f1], @@ -322,7 +321,7 @@ mod tests { &mut v, m, s, - vec![ + &[ [0x071e8a60, 0x071e8a60, 0x071e8a60, 0x071e8a60], [0x072df44c, 0x072df44c, 0x072df44c, 0x072df44c], [0x522ca035, 0x522ca035, 0x522ca035, 0x522ca035], diff --git a/core/src/syscall/precompiles/blake2s/trace.rs b/core/src/syscall/precompiles/blake2s/trace.rs index ec95db0eb..d710f0fd8 100644 --- a/core/src/syscall/precompiles/blake2s/trace.rs +++ b/core/src/syscall/precompiles/blake2s/trace.rs @@ -62,10 +62,10 @@ impl MachineAir for Blake2sRoundChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } - let mut v0_outer = vec![0u32; 4]; - let mut v1_outer = vec![0u32; 4]; - let mut v2_outer = vec![0u32; 4]; - let mut v3_outer = vec![0u32; 4]; + let mut v0_outer = [0u32; 4]; + let mut v1_outer = [0u32; 4]; + let mut v2_outer = [0u32; 4]; + let mut v3_outer = [0u32; 4]; // 1x (m0, R1, R2) for i in 0..4usize { From 6c41a9bba9a432fde2e0efff22935b49ee6b30d7 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 23 Sep 2024 16:49:14 +0300 Subject: [PATCH 28/30] ci: Fixing check-downstream-compile(loam) job --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d7bb335b..da45141a4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -171,7 +171,7 @@ jobs: - repo: zk-light-clients path: ethereum features: ethereum - - repo: loam + - repo: lurk path: "" steps: - uses: actions/checkout@v4 From 35085fbe647b64787a94e0d0ede355a69ae5081b Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 23 Sep 2024 16:51:21 +0300 Subject: [PATCH 29/30] feat: Introduce Add3 operation --- core/src/operations/add3.rs | 134 ++++++++++++++++++ core/src/operations/mod.rs | 2 + core/src/syscall/precompiles/blake2s/air.rs | 94 +++++------- .../syscall/precompiles/blake2s/columns.rs | 9 +- .../syscall/precompiles/blake2s/execute.rs | 2 +- core/src/syscall/precompiles/blake2s/mod.rs | 12 +- core/src/syscall/precompiles/blake2s/trace.rs | 77 ++-------- tests/blake2s-round/Cargo.lock | 2 +- tests/blake2s-round/Cargo.toml | 2 +- .../elf/riscv32im-succinct-zkvm-elf | Bin 22700 -> 22700 bytes tests/blake2s-round/src/main.rs | 2 +- 11 files changed, 190 insertions(+), 146 deletions(-) create mode 100644 core/src/operations/add3.rs diff --git a/core/src/operations/add3.rs b/core/src/operations/add3.rs new file mode 100644 index 000000000..0366f79ae --- /dev/null +++ b/core/src/operations/add3.rs @@ -0,0 +1,134 @@ +use p3_air::AirBuilder; +use p3_field::{AbstractField, Field}; +use sphinx_derive::AlignedBorrow; + +use crate::air::Word; +use crate::air::WordAirBuilder; +use crate::air::WORD_SIZE; +use crate::bytes::event::ByteRecord; + +/// A set of columns needed to compute the add of three words. +#[derive(AlignedBorrow, Default, Debug, Clone, Copy)] +#[repr(C)] +pub struct Add3Operation { + /// The result of `a + b + c`. + pub value: Word, + + /// Indicates if the carry for the `i`th digit is 0. + pub is_carry_0: Word, + + /// Indicates if the carry for the `i`th digit is 1. + pub is_carry_1: Word, + + /// Indicates if the carry for the `i`th digit is 2. The carry when adding 3 words is at most 2. + pub is_carry_2: Word, + + /// The carry for the `i`th digit. + pub carry: Word, +} + +impl Add3Operation { + pub fn populate( + &mut self, + record: &mut impl ByteRecord, + shard: u32, + channel: u32, + a_u32: u32, + b_u32: u32, + c_u32: u32, + ) -> u32 { + let expected = a_u32.wrapping_add(b_u32).wrapping_add(c_u32); + + self.value = Word::from(expected); + let a = a_u32.to_le_bytes(); + let b = b_u32.to_le_bytes(); + let c = c_u32.to_le_bytes(); + + let base = 256; + let mut carry = [0u8, 0u8, 0u8, 0u8]; + for i in 0..WORD_SIZE { + let mut res = u32::from(a[i]) + u32::from(b[i]) + u32::from(c[i]); + if i > 0 { + res += u32::from(carry[i - 1]); + } + carry[i] = (res / base) as u8; + self.is_carry_0[i] = F::from_bool(carry[i] == 0); + self.is_carry_1[i] = F::from_bool(carry[i] == 1); + self.is_carry_2[i] = F::from_bool(carry[i] == 2); + self.carry[i] = F::from_canonical_u8(carry[i]); + debug_assert!(carry[i] <= 2); + debug_assert_eq!(self.value[i], F::from_canonical_u32(res % base)); + } + + // Range check. + { + record.add_u8_range_checks(shard, channel, &a); + record.add_u8_range_checks(shard, channel, &b); + record.add_u8_range_checks(shard, channel, &c); + record.add_u8_range_checks(shard, channel, &expected.to_le_bytes()); + } + expected + } + + pub fn eval>( + builder: &mut AB, + a: Word, + b: Word, + c: Word, + shard: AB::Var, + channel: impl Into + Copy, + is_real: AB::Var, + cols: Add3Operation, + ) { + // Range check each byte. + { + builder.slice_range_check_u8(&a.0, shard, channel, is_real); + builder.slice_range_check_u8(&b.0, shard, channel, is_real); + builder.slice_range_check_u8(&c.0, shard, channel, is_real); + builder.slice_range_check_u8(&cols.value.0, shard, channel, is_real); + } + + builder.assert_bool(is_real); + let mut builder_is_real = builder.when(is_real); + + // Each value in is_carry_{0,1,2,3} is 0 or 1, and exactly one of them is 1 per digit. + { + for i in 0..WORD_SIZE { + builder_is_real.assert_bool(cols.is_carry_0[i]); + builder_is_real.assert_bool(cols.is_carry_1[i]); + builder_is_real.assert_bool(cols.is_carry_2[i]); + builder_is_real.assert_eq( + cols.is_carry_0[i] + cols.is_carry_1[i] + cols.is_carry_2[i], + AB::Expr::one(), + ); + } + } + + // Calculates carry from is_carry_{0,1,2}. + { + let one = AB::Expr::one(); + let two = AB::F::from_canonical_u32(2); + + for i in 0..WORD_SIZE { + builder_is_real.assert_eq( + cols.carry[i], + cols.is_carry_1[i] * one.clone() + cols.is_carry_2[i] * two, + ); + } + } + + // Compare the sum and summands by looking at carry. + { + let base = AB::F::from_canonical_u32(256); + // For each limb, assert that difference between the carried result and the non-carried + // result is the product of carry and base. + for i in 0..WORD_SIZE { + let mut overflow = a[i] + b[i] + c[i] - cols.value[i]; + if i > 0 { + overflow += cols.carry[i - 1].into(); + } + builder_is_real.assert_eq(cols.carry[i] * base, overflow.clone()); + } + } + } +} diff --git a/core/src/operations/mod.rs b/core/src/operations/mod.rs index e3fbcc78b..52a17847d 100644 --- a/core/src/operations/mod.rs +++ b/core/src/operations/mod.rs @@ -5,6 +5,7 @@ //! the constraints. mod add; +mod add3; mod add4; mod add5; mod and; @@ -21,6 +22,7 @@ mod or; mod xor; pub use add::*; +pub use add3::*; pub use add4::*; pub use add5::*; pub use and::*; diff --git a/core/src/syscall/precompiles/blake2s/air.rs b/core/src/syscall/precompiles/blake2s/air.rs index d70f0d6f2..d054431dc 100644 --- a/core/src/syscall/precompiles/blake2s/air.rs +++ b/core/src/syscall/precompiles/blake2s/air.rs @@ -1,5 +1,5 @@ use crate::memory::MemoryCols; -use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::operations::{Add3Operation, AddOperation, FixedRotateRightOperation, XorOperation}; use crate::runtime::SyscallCode; use crate::stark::SphinxAirBuilder; use crate::syscall::precompiles::blake2s::columns::Blake2sRoundCols; @@ -55,18 +55,6 @@ where ); } - // Eval extra-zeroes - for i in 16..24usize { - builder.eval_memory_access( - local.shard, - local.channel, - local.clk, - local.b_ptr + AB::F::from_canonical_u32((i as u32) * 4), - &local.b[i], - local.is_real, - ); - } - let v1_shuffle_lookup = [1, 2, 3, 0]; let v2_shuffle_lookup = [2, 3, 0, 1]; let v3_shuffle_lookup = [3, 0, 1, 2]; @@ -75,23 +63,22 @@ where // 1x // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( + Add3Operation::::eval( builder, *local.a[i].prev_value(), // v0 *local.a[i + 4].prev_value(), // v1 *local.b[i].value(), // m1 - *local.b[i + 20].value(), // zero1 local.shard, local.channel, local.is_real, - local.add[i], + local.add3[i], ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); XorOperation::::eval( builder, *local.a[i + 12].prev_value(), - local.add[i].value, + local.add3[i].value, local.xor[i], local.shard, &local.channel, @@ -108,23 +95,21 @@ where ); // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( + AddOperation::::eval( builder, *local.a[i + 8].prev_value(), // v2 local.rotate_right[i].value, // v3 from previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 + local.add2[i], local.shard, local.channel, - local.is_real, - local.add[i + 4], + local.is_real.into(), ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); XorOperation::::eval( builder, *local.a[i + 4].prev_value(), - local.add[i + 4].value, + local.add2[i].value, local.xor[i + 4], local.shard, &local.channel, @@ -143,23 +128,22 @@ where // 2x // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( + Add3Operation::::eval( builder, - local.add[i].value, // v0 after 1x + local.add3[i].value, // v0 after 1x local.rotate_right[i + 4].value, // v1 after 1x *local.b[i + 4].value(), // m2 - *local.b[i + 16].value(), // zero1 local.shard, local.channel, local.is_real, - local.add[i + 8], + local.add3[i + 4], ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); XorOperation::::eval( builder, local.rotate_right[i].value, // v3 after 1x - local.add[i + 8].value, // v0 after 1x + local.add3[i + 4].value, // v0 after 1x local.xor[i + 8], local.shard, &local.channel, @@ -176,23 +160,21 @@ where ); // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( + AddOperation::::eval( builder, - local.add[i + 4].value, // v2 after 1x + local.add2[i].value, // v2 after 1x local.rotate_right[i + 8].value, // v3 after previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 + local.add2[i + 4], local.shard, local.channel, - local.is_real, - local.add[i + 12], + local.is_real.into(), ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); XorOperation::::eval( builder, local.rotate_right[i + 4].value, // v1 after 1x - local.add[i + 12].value, // v2 after previous operation + local.add2[i + 4].value, // v2 after previous operation local.xor[i + 12], local.shard, &local.channel, @@ -215,23 +197,22 @@ where // 3x // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( + Add3Operation::::eval( builder, - local.add[i + 8].value, // v0 after 2x + local.add3[i + 4].value, // v0 after 2x local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x *local.b[i + 8].value(), // m3 - *local.b[i + 16].value(), // zero1 local.shard, local.channel, local.is_real, - local.add[i + 16], + local.add3[i + 8], ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); XorOperation::::eval( builder, local.rotate_right[v3_shuffle_lookup[i] + 8].value, // v3 after 2x - local.add[i + 16].value, // v0 after previous operation + local.add3[i + 8].value, // v0 after previous operation local.xor[i + 16], local.shard, &local.channel, @@ -248,23 +229,21 @@ where ); // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( + AddOperation::::eval( builder, - local.add[v2_shuffle_lookup[i] + 12].value, // v2 after 2x + local.add2[v2_shuffle_lookup[i] + 4].value, // v2 after 2x local.rotate_right[i + 16].value, // v3 after previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 + local.add2[i + 8], local.shard, local.channel, - local.is_real, - local.add[i + 20], + local.is_real.into(), ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); XorOperation::::eval( builder, local.rotate_right[v1_shuffle_lookup[i] + 12].value, // v1 after 2x - local.add[i + 20].value, // v2 after previous operation + local.add2[i + 8].value, // v2 after previous operation local.xor[i + 20], local.shard, &local.channel, @@ -282,23 +261,22 @@ where // 4x // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - Add4Operation::::eval( + Add3Operation::::eval( builder, - local.add[i + 16].value, // v0 after 3x + local.add3[i + 8].value, // v0 after 3x local.rotate_right[i + 20].value, // v1 after 3x *local.b[i + 12].value(), // m4 - *local.b[i + 16].value(), // zero1 local.shard, local.channel, local.is_real, - local.add[i + 24], + local.add3[i + 12], ); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); XorOperation::::eval( builder, local.rotate_right[i + 16].value, // v3 after 3x - local.add[i + 24].value, // v0 after previous operation + local.add3[i + 12].value, // v0 after previous operation local.xor[i + 24], local.shard, &local.channel, @@ -315,23 +293,21 @@ where ); // v[2] = v[2].wrapping_add(v[3]); - Add4Operation::::eval( + AddOperation::::eval( builder, - local.add[i + 20].value, // v2 after 3x + local.add2[i + 8].value, // v2 after 3x local.rotate_right[i + 24].value, // v3 after previous operation - *local.b[i + 16].value(), // zero1 - *local.b[i + 20].value(), // zero2 + local.add2[i + 12], local.shard, local.channel, - local.is_real, - local.add[i + 28], + local.is_real.into(), ); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); XorOperation::::eval( builder, local.rotate_right[i + 20].value, // v1 after 3x - local.add[i + 28].value, // v2 after previous operation + local.add2[i + 12].value, // v2 after previous operation local.xor[i + 28], local.shard, &local.channel, diff --git a/core/src/syscall/precompiles/blake2s/columns.rs b/core/src/syscall/precompiles/blake2s/columns.rs index a684fd9f0..1d17a2108 100644 --- a/core/src/syscall/precompiles/blake2s/columns.rs +++ b/core/src/syscall/precompiles/blake2s/columns.rs @@ -1,5 +1,5 @@ use crate::memory::{MemoryReadCols, MemoryWriteCols}; -use crate::operations::{Add4Operation, FixedRotateRightOperation, XorOperation}; +use crate::operations::{Add3Operation, AddOperation, FixedRotateRightOperation, XorOperation}; use sphinx_derive::AlignedBorrow; #[derive(Debug, Clone, AlignedBorrow)] @@ -27,13 +27,12 @@ pub struct Blake2sRoundCols { /// m1[0] || m1[1] || m1[2] || m1[3] || /// m2[0] || m2[1] || m2[2] || m2[3] || /// m3[0] || m3[1] || m3[2] || m3[3] || - /// 0 || 0 || 0 || 0 || - /// 0 || 0 || 0 || 0 || /// pub a: [MemoryWriteCols; 16], - pub b: [MemoryReadCols; 24], + pub b: [MemoryReadCols; 16], - pub add: [Add4Operation; 32], + pub add3: [Add3Operation; 16], + pub add2: [AddOperation; 16], pub xor: [XorOperation; 32], pub rotate_right: [FixedRotateRightOperation; 32], } diff --git a/core/src/syscall/precompiles/blake2s/execute.rs b/core/src/syscall/precompiles/blake2s/execute.rs index c4e7b5d0d..6a568a1a5 100644 --- a/core/src/syscall/precompiles/blake2s/execute.rs +++ b/core/src/syscall/precompiles/blake2s/execute.rs @@ -16,7 +16,7 @@ impl Syscall for Blake2sRoundChip { let mut a = ctx.slice_unsafe(a_ptr, 16); let mut a_clone = a.clone(); - let (b_reads, b) = ctx.mr_slice(b_ptr, 24); + let (b_reads, b) = ctx.mr_slice(b_ptr, 16); // 1x (m0, R1, R2) // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m1) diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index db178b42f..ca52c776d 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -145,10 +145,7 @@ fn round(v: &mut [[u32; 4]], m: [u32; 16], s: [usize; 16]) { pub fn blake2s_round(v: &mut [u32], m: &[u32]) { assert_eq!(v.len(), 16); - assert_eq!(m.len(), 24); - for item in m[16..24].iter() { - assert_eq!(*item, 0u32); - } + assert_eq!(m.len(), 16); let r1 = 16; let r2 = 12; @@ -186,7 +183,7 @@ mod tests { use crate::Program; use rand::Rng; - fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 24]) -> Program { + fn risc_v_program(a_ptr: u32, b_ptr: u32, a: [u32; 16], b: [u32; 16]) -> Program { let mut instructions = vec![]; // memory write a for (index, word) in a.into_iter().enumerate() { @@ -240,10 +237,7 @@ mod tests { let a = rand::thread_rng().gen::<[u32; 16]>(); let mut a_clone = a; - let mut b = rand::thread_rng().gen::<[u32; 24]>(); - for item in b[0..24].iter_mut() { - *item = 0; - } + let b = rand::thread_rng().gen::<[u32; 16]>(); blake2s_round(&mut a_clone, &b); diff --git a/core/src/syscall/precompiles/blake2s/trace.rs b/core/src/syscall/precompiles/blake2s/trace.rs index d710f0fd8..8159d8c73 100644 --- a/core/src/syscall/precompiles/blake2s/trace.rs +++ b/core/src/syscall/precompiles/blake2s/trace.rs @@ -56,12 +56,6 @@ impl MachineAir for Blake2sRoundChip { cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); } - // populate extra-zeroes - // TODO: replace Add4 with Add3 operation and avoid this - for i in 16..24usize { - cols.b[i].populate(event.channel, event.b_reads[i], &mut new_byte_lookup_events); - } - let mut v0_outer = [0u32; 4]; let mut v1_outer = [0u32; 4]; let mut v2_outer = [0u32; 4]; @@ -74,13 +68,9 @@ impl MachineAir for Blake2sRoundChip { let v2 = event.a_reads_writes[i + 8].prev_value; let v3 = event.a_reads_writes[i + 12].prev_value; let m1 = event.b_reads[i].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - let v0_new = cols.add[i].populate(output, shard, event.channel, v0, v1, m1, zero1); + let v0_new = cols.add3[i].populate(output, shard, event.channel, v0, v1, m1); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); let temp = cols.xor[i].populate(output, shard, event.channel, v3, v0_new); @@ -88,15 +78,7 @@ impl MachineAir for Blake2sRoundChip { cols.rotate_right[i].populate(output, shard, event.channel, temp, R_1 as usize); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 4].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); + let v2_new = cols.add2[i].populate(output, shard, event.channel, v2, v3_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); let temp = cols.xor[i + 4].populate(output, shard, event.channel, v1, v2_new); @@ -121,12 +103,9 @@ impl MachineAir for Blake2sRoundChip { let v2 = v2_outer[i]; let v3 = v3_outer[i]; let m2 = event.b_reads[i + 4].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) - let v0_new = - cols.add[i + 8].populate(output, shard, event.channel, v0, v1, m2, zero1); + let v0_new = cols.add3[i + 4].populate(output, shard, event.channel, v0, v1, m2); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) let temp = cols.xor[i + 8].populate(output, shard, event.channel, v3, v0_new); @@ -139,15 +118,7 @@ impl MachineAir for Blake2sRoundChip { ); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 4 + 8].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); + let v2_new = cols.add2[i + 4].populate(output, shard, event.channel, v2, v3_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) let temp = cols.xor[i + 4 + 8].populate(output, shard, event.channel, v1, v2_new); @@ -191,15 +162,9 @@ impl MachineAir for Blake2sRoundChip { let v2 = v2_outer[i]; let v3 = v3_outer[i]; let m3 = event.b_reads[i + 8].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); - let v0_new = - cols.add[i + 16].populate(output, shard, event.channel, v0, v1, m3, zero1); - assert_eq!(v0 + v1 + m3 + zero1, v0_new); + let v0_new = cols.add3[i + 8].populate(output, shard, event.channel, v0, v1, m3); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); let temp = cols.xor[i + 16].populate(output, shard, event.channel, v3, v0_new); @@ -210,19 +175,9 @@ impl MachineAir for Blake2sRoundChip { temp, R_1 as usize, ); - assert_eq!((v3 ^ v0_new).rotate_right(R_1), v3_new); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 16 + 4].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); - assert_eq!(v2 + v3_new + zero1 + zero2, v2_new); + let v2_new = cols.add2[i + 8].populate(output, shard, event.channel, v2, v3_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); let temp = cols.xor[i + 16 + 4].populate(output, shard, event.channel, v1, v2_new); @@ -233,7 +188,6 @@ impl MachineAir for Blake2sRoundChip { temp, R_2 as usize, ); - assert_eq!((v1 ^ v2_new).rotate_right(R_2), v1_new); v0_outer[i] = v0_new; v1_outer[i] = v1_new; @@ -248,15 +202,9 @@ impl MachineAir for Blake2sRoundChip { let v2 = v2_outer[i]; let v3 = v3_outer[i]; let m4 = event.b_reads[i + 12].value; - let zero1 = event.b_reads[i + 16].value; - let zero2 = event.b_reads[i + 20].value; - assert_eq!(zero1, 0); - assert_eq!(zero2, 0); // v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le()); (m2) - let v0_new = - cols.add[i + 16 + 8].populate(output, shard, event.channel, v0, v1, m4, zero1); - assert_eq!(v0 + v1 + m4 + zero1, v0_new); + let v0_new = cols.add3[i + 12].populate(output, shard, event.channel, v0, v1, m4); // v[3] = (v[3] ^ v[0]).rotate_right_const(rd); (R3) let temp = cols.xor[i + 16 + 8].populate(output, shard, event.channel, v3, v0_new); @@ -267,18 +215,9 @@ impl MachineAir for Blake2sRoundChip { temp, R_3 as usize, ); - assert_eq!((v3 ^ v0_new).rotate_right(R_3), v3_new); // v[2] = v[2].wrapping_add(v[3]); - let v2_new = cols.add[i + 16 + 4 + 8].populate( - output, - shard, - event.channel, - v2, - v3_new, - zero1, - zero2, - ); + let v2_new = cols.add2[i + 12].populate(output, shard, event.channel, v2, v3_new); // v[1] = (v[1] ^ v[2]).rotate_right_const(rb); (R4) let temp = diff --git a/tests/blake2s-round/Cargo.lock b/tests/blake2s-round/Cargo.lock index 7efd0650c..e2a3cc14e 100644 --- a/tests/blake2s-round/Cargo.lock +++ b/tests/blake2s-round/Cargo.lock @@ -42,7 +42,7 @@ dependencies = [ ] [[package]] -name = "blake2s-quarter_round-2x-test" +name = "blake2s-round-test" version = "0.1.0" dependencies = [ "sphinx-zkvm", diff --git a/tests/blake2s-round/Cargo.toml b/tests/blake2s-round/Cargo.toml index 188c60950..98d23e472 100644 --- a/tests/blake2s-round/Cargo.toml +++ b/tests/blake2s-round/Cargo.toml @@ -1,6 +1,6 @@ [workspace] [package] -name = "blake2s-quarter_round-2x-test" +name = "blake2s-round-test" version = "0.1.0" edition = "2021" diff --git a/tests/blake2s-round/elf/riscv32im-succinct-zkvm-elf b/tests/blake2s-round/elf/riscv32im-succinct-zkvm-elf index d20fc7e4394539b95ec58368a5f2c68ef66e49f8..fef04f7e418a7cf1d0be9ce6d562ef6bd302e8f0 100755 GIT binary patch delta 36 scmZ3pk#WsN#tq86tlyQ@1UV*a@J?rBnS6j(nUzDBk&$!r3*IAM0Mzsf!vFvP delta 36 scmZ3pk#WsN#tq86tY4MY1i2<_@J?rBn|y#*nUzbJk&%1z3*IAM0M#rC$p8QV diff --git a/tests/blake2s-round/src/main.rs b/tests/blake2s-round/src/main.rs index c67c53605..1fec17136 100644 --- a/tests/blake2s-round/src/main.rs +++ b/tests/blake2s-round/src/main.rs @@ -9,7 +9,7 @@ pub fn main() { 0x5be0cd19, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0xe07c2654, 0x5be0cd19 ]; - let b: [u32; 24] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let b: [u32; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; syscall_blake2s_round(a.as_mut_ptr(), b.as_ptr()); } From 430087acd357f09b56ad41e56caf5aa46ca949fc Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Tue, 24 Sep 2024 18:15:55 +0300 Subject: [PATCH 30/30] chore: Address feedback --- Cargo.lock | 54 +++++++++---------- Cargo.toml | 2 +- core/src/stark/air.rs | 5 +- core/src/syscall/precompiles/blake2s/air.rs | 2 - .../syscall/precompiles/blake2s/columns.rs | 2 - core/src/syscall/precompiles/blake2s/mod.rs | 20 ------- core/src/syscall/precompiles/blake2s/trace.rs | 4 -- core/src/utils/prove.rs | 10 ++-- zkvm/precompiles/src/lib.rs | 10 +--- 9 files changed, 37 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcf5f2030..6e41ea19c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -466,9 +466,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +checksum = "5e6b8ba012a258d63c9adfa28b9ddcf66149da6f986c5b5452e629d5ee64bf00" dependencies = [ "async-trait", "bytes", @@ -479,7 +479,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 0.1.2", + "sync_wrapper 1.0.1", "tower-layer", "tower-service", "tracing", @@ -848,9 +848,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" dependencies = [ "clap_builder", "clap_derive", @@ -858,9 +858,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" dependencies = [ "anstream", "anstyle", @@ -870,9 +870,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", @@ -2457,9 +2457,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", @@ -2505,9 +2505,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libgit2-sys" @@ -3254,9 +3254,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" +checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", "thiserror", @@ -3317,9 +3317,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plotters" @@ -3351,9 +3351,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "d30538d42559de6b034bc76fd6dd4c38961b1ee5c6c56e3808c50128fdbc22ce" [[package]] name = "powerfmt" @@ -4948,18 +4948,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -5350,15 +5350,15 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "untrusted" diff --git a/Cargo.toml b/Cargo.toml index c8a8085d6..274f79a71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,7 @@ getrandom = "=0.2.14" # 0.2.15 depends on yanked libc 0.2.154 hashbrown = { version = "0.14.5", features = ["serde"] } hex = "0.4.3" home = "0.5.9" -hybrid-array = "0.2.0-rc.9" +hybrid-array = "0.2.0-rc" indicatif = "0.17.8" itertools = "0.12.1" k256 = "0.13.3" diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index af094bb27..31fe0b1e0 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -161,6 +161,9 @@ impl RiscvAir { chips.push(RiscvAir::Bls12381Fp2Op(bls12381_fp2_op)); let bls12381_g1_decompress = Bls12381G1DecompressChip::new(); chips.push(RiscvAir::Bls12381G1Decompress(bls12381_g1_decompress)); + let blake_2s_round = Blake2sRoundChip::new(); + chips.push(RiscvAir::Blake2sRound(blake_2s_round)); + let div_rem = DivRemChip; chips.push(RiscvAir::DivRem(div_rem)); @@ -184,8 +187,6 @@ impl RiscvAir { chips.push(RiscvAir::ProgramMemory(program_memory_init)); let byte = ByteChip::default(); chips.push(RiscvAir::ByteLookup(byte)); - let blake_2s_round = Blake2sRoundChip::new(); - chips.push(RiscvAir::Blake2sRound(blake_2s_round)); chips } diff --git a/core/src/syscall/precompiles/blake2s/air.rs b/core/src/syscall/precompiles/blake2s/air.rs index d054431dc..8b519501e 100644 --- a/core/src/syscall/precompiles/blake2s/air.rs +++ b/core/src/syscall/precompiles/blake2s/air.rs @@ -191,8 +191,6 @@ where ); } - self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); - for i in 0..4usize { // 3x diff --git a/core/src/syscall/precompiles/blake2s/columns.rs b/core/src/syscall/precompiles/blake2s/columns.rs index 1d17a2108..897f41598 100644 --- a/core/src/syscall/precompiles/blake2s/columns.rs +++ b/core/src/syscall/precompiles/blake2s/columns.rs @@ -15,8 +15,6 @@ pub struct Blake2sRoundCols { pub a_ptr: T, pub b_ptr: T, - pub shuffled_indices: [T; 16], - /// Memory layout: /// a: v0[0] || v0[1] || v0[2] || v0[3] || /// v1[0] || v1[1] || v1[2] || v1[3] || diff --git a/core/src/syscall/precompiles/blake2s/mod.rs b/core/src/syscall/precompiles/blake2s/mod.rs index ca52c776d..d4beb98fa 100644 --- a/core/src/syscall/precompiles/blake2s/mod.rs +++ b/core/src/syscall/precompiles/blake2s/mod.rs @@ -6,9 +6,6 @@ mod trace; pub use columns::*; use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; -use crate::stark::SphinxAirBuilder; -use p3_air::AirBuilder; -use p3_field::AbstractField; use serde::Deserialize; use serde::Serialize; @@ -31,23 +28,6 @@ impl Blake2sRoundChip { pub fn new() -> Self { Blake2sRoundChip } - pub fn constrain_shuffled_indices( - &self, - builder: &mut AB, - indices: &[AB::Var], - is_real: AB::Var, - ) { - for index in 0..4 { - builder - .when(is_real) - .assert_eq(indices[index], AB::F::from_canonical_usize(0)); - } - for index in 4..indices.len() { - builder - .when(is_real) - .assert_eq(indices[index], AB::F::from_canonical_usize(1)); - } - } } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/core/src/syscall/precompiles/blake2s/trace.rs b/core/src/syscall/precompiles/blake2s/trace.rs index 8159d8c73..3061fb669 100644 --- a/core/src/syscall/precompiles/blake2s/trace.rs +++ b/core/src/syscall/precompiles/blake2s/trace.rs @@ -153,10 +153,6 @@ impl MachineAir for Blake2sRoundChip { // 3x (m2, R1, R2) for i in 0..4usize { - cols.shuffled_indices[i + 4] = F::from_canonical_u32(1); - cols.shuffled_indices[i + 8] = F::from_canonical_u32(1); - cols.shuffled_indices[i + 12] = F::from_canonical_u32(1); - let v0 = v0_outer[i]; let v1 = v1_outer[i]; let v2 = v2_outer[i]; diff --git a/core/src/utils/prove.rs b/core/src/utils/prove.rs index 1f223cdcf..dee783732 100644 --- a/core/src/utils/prove.rs +++ b/core/src/utils/prove.rs @@ -356,11 +356,11 @@ where OpeningProof: Send + Sync, ShardMainData: Serialize + DeserializeOwned, { - //#[cfg(debug_assertions)] - //{ - let record_clone = record.clone(); - machine.debug_constraints(pk, record_clone); - //} + #[cfg(debug_assertions)] + { + let record_clone = record.clone(); + machine.debug_constraints(pk, record_clone); + } let stats = record.stats().clone(); let cycles = stats.get("cpu_events").unwrap(); diff --git a/zkvm/precompiles/src/lib.rs b/zkvm/precompiles/src/lib.rs index 1c627089a..a5a1d7aa9 100644 --- a/zkvm/precompiles/src/lib.rs +++ b/zkvm/precompiles/src/lib.rs @@ -47,13 +47,5 @@ extern "C" { pub fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u8; pub fn syscall_bls12381_g2_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g2_double(p: *mut u32); - pub fn syscall_blake2s_xor_rotate_16(w: *mut u32); - - pub fn syscall_blake2s_add_2(left: *mut u32, right: *const u32); - pub fn syscall_blake2s_add_3(left: *mut u32, right: *const u32); - pub fn syscall_blake2s_xor_rotate_right_16(left: *mut u32, right: *const u32); - pub fn syscall_blake2s_xor_rotate_right_12(left: *mut u32, right: *const u32); - pub fn syscall_blake2s_xor_rotate_right_8(left: *mut u32, right: *const u32); - pub fn syscall_blake2s_xor_rotate_right_7(left: *mut u32, right: *const u32); - pub fn syscall_blake2s_quarter_round(left: *mut u32, right: *const u32); + pub fn syscall_blake2s_round(left: *mut u32, right: *const u32); }