From 41879d86c1a3f9f6dad6d8ac6e4279253867de04 Mon Sep 17 00:00:00 2001 From: Stephen <81497928+eigmax@users.noreply.github.com> Date: Sun, 19 Nov 2023 11:29:06 +0800 Subject: [PATCH] fix: logic offset (#43) * chore: fix kernel * chore: fix kernel * chore: fix kernel * chore: fix kernel * chore: fix kernel * chore: fix bootstrap --- src/all_stark.rs | 37 ++++++---- src/cpu/bootstrap_kernel.rs | 30 +++++--- src/cpu/columns/ops.rs | 2 +- src/cpu/cpu_stark.rs | 18 +++-- src/cpu/decode.rs | 92 +---------------------- src/cpu/jumps.rs | 12 +-- src/cpu/kernel/assembler.rs | 2 +- src/cross_table_lookup.rs | 3 +- src/generation/mod.rs | 2 +- src/logic.rs | 141 +----------------------------------- src/prover.rs | 6 +- src/verifier.rs | 9 ++- src/witness/traces.rs | 36 +++++---- src/witness/util.rs | 2 + 14 files changed, 96 insertions(+), 296 deletions(-) diff --git a/src/all_stark.rs b/src/all_stark.rs index 69445da4..308dda46 100644 --- a/src/all_stark.rs +++ b/src/all_stark.rs @@ -26,8 +26,8 @@ pub struct AllStark, const D: usize> { pub arithmetic_stark: ArithmeticStark, // pub byte_packing_stark: BytePackingStark, pub cpu_stark: CpuStark, - pub keccak_stark: KeccakStark, - pub keccak_sponge_stark: KeccakSpongeStark, + //pub keccak_stark: KeccakStark, + //pub keccak_sponge_stark: KeccakSpongeStark, pub logic_stark: LogicStark, pub memory_stark: MemoryStark, pub cross_table_lookups: Vec>, @@ -39,8 +39,8 @@ impl, const D: usize> Default for AllStark { arithmetic_stark: ArithmeticStark::default(), // byte_packing_stark: BytePackingStark::default(), cpu_stark: CpuStark::default(), - keccak_stark: KeccakStark::default(), - keccak_sponge_stark: KeccakSpongeStark::default(), + //keccak_stark: KeccakStark::default(), + //keccak_sponge_stark: KeccakSpongeStark::default(), logic_stark: LogicStark::default(), memory_stark: MemoryStark::default(), cross_table_lookups: all_cross_table_lookups(), @@ -49,13 +49,13 @@ impl, const D: usize> Default for AllStark { } impl, const D: usize> AllStark { - pub(crate) fn num_lookups_helper_columns(&self, config: &StarkConfig) -> [usize; 6] { + pub(crate) fn num_lookups_helper_columns(&self, config: &StarkConfig) -> [usize; NUM_TABLES] { [ self.arithmetic_stark.num_lookup_helper_columns(config), // self.byte_packing_stark.num_lookup_helper_columns(config), self.cpu_stark.num_lookup_helper_columns(config), - self.keccak_stark.num_lookup_helper_columns(config), - self.keccak_sponge_stark.num_lookup_helper_columns(config), + //self.keccak_stark.num_lookup_helper_columns(config), + //self.keccak_sponge_stark.num_lookup_helper_columns(config), self.logic_stark.num_lookup_helper_columns(config), self.memory_stark.num_lookup_helper_columns(config), ] @@ -66,10 +66,10 @@ impl, const D: usize> AllStark { pub enum Table { Arithmetic = 0, Cpu = 1, - Keccak = 2, - KeccakSponge = 3, - Logic = 4, - Memory = 5, + //Keccak = 2, + //KeccakSponge = 3, + Logic = 2, + Memory = 3, } pub(crate) const NUM_TABLES: usize = Table::Memory as usize + 1; @@ -79,8 +79,8 @@ impl Table { [ Self::Arithmetic, Self::Cpu, - Self::Keccak, - Self::KeccakSponge, + //Self::Keccak, + //Self::KeccakSponge, Self::Logic, Self::Memory, ] @@ -90,9 +90,9 @@ impl Table { pub(crate) fn all_cross_table_lookups() -> Vec> { vec![ ctl_arithmetic(), - ctl_keccak_sponge(), - ctl_keccak_inputs(), - ctl_keccak_outputs(), + //ctl_keccak_sponge(), + //ctl_keccak_inputs(), + //ctl_keccak_outputs(), ctl_logic(), ctl_memory(), ] @@ -108,6 +108,7 @@ fn ctl_arithmetic() -> CrossTableLookup { // We now need two different looked tables for `KeccakStark`: // one for the inputs and one for the outputs. // They are linked with the timestamp. +/* fn ctl_keccak_inputs() -> CrossTableLookup { let keccak_sponge_looking = TableWithColumns::new( Table::KeccakSponge, @@ -149,6 +150,7 @@ fn ctl_keccak_sponge() -> CrossTableLookup { ); CrossTableLookup::new(vec![cpu_looking], keccak_sponge_looked) } +*/ pub(crate) fn ctl_logic() -> CrossTableLookup { let cpu_looking = TableWithColumns::new( @@ -185,6 +187,7 @@ fn ctl_memory() -> CrossTableLookup { Some(cpu_stark::ctl_filter_gp_memory(channel)), ) }); + /* let keccak_sponge_reads = (0..KECCAK_RATE_BYTES).map(|i| { TableWithColumns::new( Table::KeccakSponge, @@ -196,6 +199,8 @@ fn ctl_memory() -> CrossTableLookup { .into_iter() .chain(keccak_sponge_reads) .collect(); + */ + let all_lookers = cpu_memory_gp_ops.collect(); let memory_looked = TableWithColumns::new( Table::Memory, memory_stark::ctl_data(), diff --git a/src/cpu/bootstrap_kernel.rs b/src/cpu/bootstrap_kernel.rs index 730c014e..71450c13 100644 --- a/src/cpu/bootstrap_kernel.rs +++ b/src/cpu/bootstrap_kernel.rs @@ -14,12 +14,13 @@ use crate::generation::state::GenerationState; use crate::memory::segments::Segment; use crate::witness::memory::MemoryAddress; -use crate::witness::util::{keccak_sponge_log, mem_write_gp_log_and_fill}; +use crate::witness::util::mem_write_gp_log_and_fill; pub(crate) fn generate_bootstrap_kernel(state: &mut GenerationState) { // Iterate through chunks of the code, such that we can write one chunk to memory per row. for chunk in &KERNEL.program.image.iter().chunks(NUM_GP_CHANNELS) { let mut cpu_row = CpuColumnsView::default(); + println!("trace: {:?}", state.traces.clock()); cpu_row.clock = F::from_canonical_usize(state.traces.clock()); cpu_row.is_bootstrap_kernel = F::ONE; @@ -27,6 +28,7 @@ pub(crate) fn generate_bootstrap_kernel(state: &mut GenerationState for (channel, (addr, val)) in chunk.enumerate() { // FIXMEBoth instruction and memory data are located in // code section for MIPS + println!("addr: {}", *addr); let address = MemoryAddress::new(0, Segment::Code, *addr as usize); let write = mem_write_gp_log_and_fill(channel, address, state, &mut cpu_row, (*val).to_be()); @@ -53,11 +55,13 @@ pub(crate) fn generate_bootstrap_kernel(state: &mut GenerationState // FIXME: store all the hash final_cpu_row.mem_channels[4].value = KERNEL.code_hash.map(F::from_canonical_u32)[0]; //final_cpu_row.mem_channels[4].value.reverse(); + /* keccak_sponge_log( state, MemoryAddress::new(0, Segment::Code, 0), KERNEL.code.clone(), ); + */ state.traces.push_cpu(final_cpu_row); state.traces.push_cpu(final_cpu_row); @@ -79,15 +83,17 @@ pub(crate) fn eval_bootstrap_kernel_packed> yield_constr.constraint_transition(delta_is_bootstrap * (delta_is_bootstrap + P::ONES)); // If this is a bootloading row and the i'th memory channel is used, it must have the right - // address, name context = 0, segment = Code, virt = clock * NUM_GP_CHANNELS + i. + // address, name context = 0, segment = Code, virt + 4 = next_virt let code_segment = F::from_canonical_usize(Segment::Code as usize); for (i, channel) in local_values.mem_channels.iter().enumerate() { let filter = local_is_bootstrap * channel.used; yield_constr.constraint(filter * channel.addr_context); yield_constr.constraint(filter * (channel.addr_segment - code_segment)); - let expected_virt = local_values.clock * F::from_canonical_usize(NUM_GP_CHANNELS) - + F::from_canonical_usize(i); - yield_constr.constraint(filter * (channel.addr_virtual - expected_virt)); + /* FIXME + let delta_virt = channel.addr_virtual + P::from(F::from_canonical_u32(32)) - next_values.mem_channels[i].addr_virtual; + println!("virt {:?} {:?} {:?} {:?} {}", channel.addr_virtual, delta_virt, local_values.clock, NUM_GP_CHANNELS, i); + yield_constr.constraint_transition(filter * delta_virt); + */ } // If this is the final bootstrap row (i.e. delta_is_bootstrap = 1), check that @@ -130,7 +136,7 @@ pub(crate) fn eval_bootstrap_kernel_ext_circuit, co yield_constr.constraint_transition(builder, constraint); // If this is a bootloading row and the i'th memory channel is used, it must have the right - // address, name context = 0, segment = Code, virt = clock * NUM_GP_CHANNELS + i. + // address, name context = 0, segment = Code, virt + 4 = next_virt let code_segment = builder.constant_extension(F::Extension::from_canonical_usize(Segment::Code as usize)); for (i, channel) in local_values.mem_channels.iter().enumerate() { @@ -142,13 +148,13 @@ pub(crate) fn eval_bootstrap_kernel_ext_circuit, co let constraint = builder.mul_extension(filter, segment_diff); yield_constr.constraint(builder, constraint); - let i_ext = builder.constant_extension(F::Extension::from_canonical_usize(i)); - let num_gp_channels_f = F::from_canonical_usize(NUM_GP_CHANNELS); - let expected_virt = - builder.mul_const_add_extension(num_gp_channels_f, local_values.clock, i_ext); - let virt_diff = builder.sub_extension(channel.addr_virtual, expected_virt); + /* + let i_ext = builder.constant_extension(F::Extension::from_canonical_u32(32)); + let prev_virt = builder.add_extension(channel.addr_virtual, i_ext); + let virt_diff = builder.sub_extension(prev_virt, next_values.mem_channels[i].addr_virtual); let constraint = builder.mul_extension(filter, virt_diff); - yield_constr.constraint(builder, constraint); + yield_constr.constraint_transition(builder, constraint); + */ } // If this is the final bootstrap row (i.e. delta_is_bootstrap = 1), check that diff --git a/src/cpu/columns/ops.rs b/src/cpu/columns/ops.rs index b4a31b90..921ee1e2 100644 --- a/src/cpu/columns/ops.rs +++ b/src/cpu/columns/ops.rs @@ -10,7 +10,7 @@ pub struct OpsColumnsView { pub binary_op: T, // Combines ADD, MUL, SUB, DIV, SLL, ... flags. pub binary_imm_op: T, // Combines ADDI, ADDIU pub eq_iszero: T, // Combines EQ and ISZERO flags. - pub logic_op: T, // Combines AND, OR and XOR flags. + pub logic_op: T, // Combines AND, OR, XOR, Nor flags. pub condmov_op: T, pub count_op: T, pub not: T, diff --git a/src/cpu/cpu_stark.rs b/src/cpu/cpu_stark.rs index f0e43cac..6e7eadfd 100644 --- a/src/cpu/cpu_stark.rs +++ b/src/cpu/cpu_stark.rs @@ -57,9 +57,9 @@ pub fn ctl_filter_keccak_sponge() -> Column { /// 36, out 68. But the looking table offers in0 77, in1 83, out 89. fn ctl_data_binops() -> Vec> { println!("{:?}", COL_MAP.mem_channels); - let mut res = Column::singles(vec![COL_MAP.mem_channels[0].value - 73]).collect_vec(); - res.extend(Column::singles(vec![COL_MAP.mem_channels[1].value - 47])); - res.extend(Column::singles(vec![COL_MAP.mem_channels[2].value - 21])); + let mut res = Column::singles(vec![COL_MAP.mem_channels[0].value]).collect_vec(); + res.extend(Column::singles(vec![COL_MAP.mem_channels[1].value])); + res.extend(Column::singles(vec![COL_MAP.mem_channels[2].value])); res } @@ -194,17 +194,19 @@ impl, const D: usize> Stark for CpuStark, const D: usize> Stark for CpuStark usize { diff --git a/src/cpu/decode.rs b/src/cpu/decode.rs index ea1dafbf..c8db4bf8 100644 --- a/src/cpu/decode.rs +++ b/src/cpu/decode.rs @@ -97,45 +97,7 @@ pub fn eval_packed_generic( yield_constr.constraint(flag_sum * (flag_sum - P::ONES)); // Finally, classify all opcodes, together with the kernel flag, into blocks - for (oc, block_length, kernel_only, col) in OPCODES { - // 0 if the block/flag is available to us (is always available or we are in kernel mode) and - // 1 otherwise. - let unavailable = match kernel_only { - false => P::ZEROS, - true => P::ONES - kernel_mode, - }; - // 0 if all the opcode bits match, and something in {1, ..., 8}, otherwise. - let opcode_mismatch: P = lv - .opcode_bits - .into_iter() - .zip(bits_from_opcode(oc)) - .rev() - .take(8 - block_length) - .map(|(row_bit, flag_bit)| match flag_bit { - // 1 if the bit does not match, and 0 otherwise - false => row_bit, - true => P::ONES - row_bit, - }) - .sum(); - - // If unavailable + opcode_mismatch is 0, then the opcode bits all match and we are in the - // correct mode. - yield_constr.constraint(lv[col] * (unavailable + opcode_mismatch)); - } - - // Manually check lv.op.m_op_constr - let opcode: P = lv - .opcode_bits - .into_iter() - .enumerate() - .map(|(i, bit)| bit * P::Scalar::from_canonical_u64(1 << i)) - .sum(); - yield_constr.constraint((P::ONES - kernel_mode) * lv.op.m_op_general); - - let m_op_constr = (opcode - P::Scalar::from_canonical_usize(0xfb_usize)) - * (opcode - P::Scalar::from_canonical_usize(0xfc_usize)) - * lv.op.m_op_general; - yield_constr.constraint(m_op_constr); + // TODO } pub fn eval_ext_circuit, const D: usize>( @@ -186,56 +148,4 @@ pub fn eval_ext_circuit, const D: usize>( } // Finally, classify all opcodes, together with the kernel flag, into blocks - for (oc, block_length, kernel_only, col) in OPCODES { - // 0 if the block/flag is available to us (is always available or we are in kernel mode) and - // 1 otherwise. - let unavailable = match kernel_only { - false => builder.zero_extension(), - true => builder.sub_extension(one, kernel_mode), - }; - // 0 if all the opcode bits match, and something in {1, ..., 8}, otherwise. - let opcode_mismatch = lv - .opcode_bits - .into_iter() - .zip(bits_from_opcode(oc)) - .rev() - .take(8 - block_length) - .fold(builder.zero_extension(), |cumul, (row_bit, flag_bit)| { - let to_add = match flag_bit { - false => row_bit, - true => builder.sub_extension(one, row_bit), - }; - builder.add_extension(cumul, to_add) - }); - - // If unavailable + opcode_mismatch is 0, then the opcode bits all match and we are in the - // correct mode. - let constr = builder.add_extension(unavailable, opcode_mismatch); - let constr = builder.mul_extension(lv[col], constr); - yield_constr.constraint(builder, constr); - } - - // Manually check lv.op.m_op_constr - let opcode = lv - .opcode_bits - .into_iter() - .rev() - .fold(builder.zero_extension(), |cumul, bit| { - builder.mul_const_add_extension(F::TWO, cumul, bit) - }); - - let mload_opcode = builder.constant_extension(F::Extension::from_canonical_usize(0xfb_usize)); - let mstore_opcode = builder.constant_extension(F::Extension::from_canonical_usize(0xfc_usize)); - - let one_extension = builder.constant_extension(F::Extension::ONE); - let is_not_kernel_mode = builder.sub_extension(one_extension, kernel_mode); - let constr = builder.mul_extension(is_not_kernel_mode, lv.op.m_op_general); - yield_constr.constraint(builder, constr); - - let mload_constr = builder.sub_extension(opcode, mload_opcode); - let mstore_constr = builder.sub_extension(opcode, mstore_opcode); - let mut m_op_constr = builder.mul_extension(mload_constr, mstore_constr); - m_op_constr = builder.mul_extension(m_op_constr, lv.op.m_op_general); - - yield_constr.constraint(builder, m_op_constr); } diff --git a/src/cpu/jumps.rs b/src/cpu/jumps.rs index a9231fb9..52109bf9 100644 --- a/src/cpu/jumps.rs +++ b/src/cpu/jumps.rs @@ -644,9 +644,9 @@ pub fn eval_packed( yield_constr: &mut ConstraintConsumer

, ) { eval_packed_exit_kernel(lv, nv, yield_constr); - eval_packed_jump_jumpi(lv, nv, yield_constr); - eval_packed_branch(lv, nv, yield_constr); - eval_packed_condmov(lv, nv, yield_constr); + //eval_packed_jump_jumpi(lv, nv, yield_constr); + //eval_packed_branch(lv, nv, yield_constr); + //eval_packed_condmov(lv, nv, yield_constr); } pub fn eval_ext_circuit, const D: usize>( @@ -656,7 +656,7 @@ pub fn eval_ext_circuit, const D: usize>( yield_constr: &mut RecursiveConstraintConsumer, ) { eval_ext_circuit_exit_kernel(builder, lv, nv, yield_constr); - eval_ext_circuit_jump_jumpi(builder, lv, nv, yield_constr); - eval_ext_circuit_branch(builder, lv, nv, yield_constr); - eval_ext_circuit_condmov(builder, lv, nv, yield_constr); + //eval_ext_circuit_jump_jumpi(builder, lv, nv, yield_constr); + //eval_ext_circuit_branch(builder, lv, nv, yield_constr); + //eval_ext_circuit_condmov(builder, lv, nv, yield_constr); } diff --git a/src/cpu/kernel/assembler.rs b/src/cpu/kernel/assembler.rs index c79f7ef4..68e60301 100644 --- a/src/cpu/kernel/assembler.rs +++ b/src/cpu/kernel/assembler.rs @@ -33,7 +33,7 @@ pub(crate) fn combined_kernel() -> Kernel { let max_mem = 0x80000000; let mut p: Program = Program::load_elf(&code, max_mem).unwrap(); let real_blockpath = Program::get_block_path("13284491", "input"); - println!("real block path: {}", real_blockpath); + println!("real block path: {}, entry: {}", real_blockpath, p.entry); let test_blockpath: &str = "test-vectors/0_13284491/input"; p.load_block(test_blockpath).unwrap(); diff --git a/src/cross_table_lookup.rs b/src/cross_table_lookup.rs index 3918cd8d..d8d2498e 100644 --- a/src/cross_table_lookup.rs +++ b/src/cross_table_lookup.rs @@ -182,6 +182,7 @@ impl Column { .sum::() + self.constant; + //log::debug!("lc: {:?}\ntable: {:?}, len = {}, \nrow: {}, res: {}", self, table, table.len(), row, res); // If we access the next row at the last row, for sanity, we consider the next row's values to be 0. // If CTLs are correctly written, the filter should be 0 in that case anyway. if !self.next_row_linear_combination.is_empty() && row < table[0].values.len() - 1 { @@ -1055,7 +1056,7 @@ pub(crate) mod testutils { Some(Column::single(2)), // f: (0, 1) )]; - // select_f * f = trace[looking_col[row]][row] * \sum_{row=0..n, i=0..m} ([trace[looking_col[i]][row] ...]), where n is domain size, m is the looking_col.size, + // select_f * f = trace[looking_col[i]][row] * \sum_{row=0..n, i=0..m}, where n is domain size, m is the looking_col.size, // check select_f * f \in select_t * t let cross_tables = CrossTableLookup::new(lookings, looked); diff --git a/src/generation/mod.rs b/src/generation/mod.rs index 5c8ca55d..be0c08e5 100644 --- a/src/generation/mod.rs +++ b/src/generation/mod.rs @@ -41,7 +41,7 @@ pub fn generate_traces, const D: usize>( // Decode the trace record // 1. Decode instruction and fill in cpu columns // 2. Decode memory and fill in memory columns - let mut state = GenerationState::::new(inputs.clone(), &KERNEL.code, 4000000).unwrap(); + let mut state = GenerationState::::new(inputs.clone(), &KERNEL.code, 400000).unwrap(); generate_bootstrap_kernel::(&mut state); timed!(timing, "simulate CPU", simulate_cpu(&mut state)?); diff --git a/src/logic.rs b/src/logic.rs index 128ce867..af2f4cae 100644 --- a/src/logic.rs +++ b/src/logic.rs @@ -350,10 +350,13 @@ mod tests { cross_table_lookup_data_ex, get_grand_product_challenge_set, CtlCheckVars, }; use crate::logic::{LogicStark, Op, Operation}; + use crate::memory::memory_stark::MemoryStark; + use crate::memory::segments::Segment; use crate::prover::prove_single_table; use crate::stark::Stark; use crate::stark_testing::{test_stark_circuit_constraints, test_stark_low_degree}; use crate::verifier::verify_stark_proof_with_challenges; + use crate::witness::memory::{MemoryAddress, MemoryChannel, MemoryOp, MemoryOpKind}; use anyhow::Result; use plonky2::fri::oracle::PolynomialBatch; use plonky2::iop::challenger::Challenger; @@ -386,142 +389,4 @@ mod tests { }; test_stark_circuit_constraints::(stark) } - - #[test] - fn test_stark_verifier() { - env_logger::try_init().unwrap_or_default(); - const D: usize = 2; - type C = PoseidonGoldilocksConfig; - type F = >::F; - type S = LogicStark; - - let config = StarkConfig::standard_fast_config(); - let stark = S { - f: Default::default(), - }; - let ops = vec![ - Operation::new(Op::Nor, 0, 1), - Operation::new(Op::Nor, 1, 1), - Operation::new(Op::Nor, 0, 0), - Operation::new(Op::Nor, 1283818, 219218), - Operation::new(Op::And, 0, 1), - Operation::new(Op::And, 1, 1), - Operation::new(Op::And, 0, 0), - Operation::new(Op::Or, 0, 1), - Operation::new(Op::Or, 1, 1), - Operation::new(Op::Or, 0, 0), - Operation::new(Op::Xor, 0, 1), - Operation::new(Op::And, 0, 1), - Operation::new(Op::And, 1, 1), - Operation::new(Op::And, 0, 0), - Operation::new(Op::And, 12112, 313131), - Operation::new(Op::Or, 0, 1), - Operation::new(Op::Or, 1, 1), - Operation::new(Op::Or, 0, 0), - Operation::new(Op::Or, 12121, 21211), - Operation::new(Op::Xor, 0, 1), - Operation::new(Op::Xor, 1, 1), - Operation::new(Op::Xor, 0, 0), - Operation::new(Op::Xor, 218219, 9828121), - Operation::new(Op::Xor, 1, 1), - Operation::new(Op::Xor, 0, 0), - ]; - let num_rows = 1 << 10; - - let mut timing = TimingTree::new("Logic", log::Level::Debug); - log::debug!("generate trace"); - let trace_poly_values = stark.generate_trace(ops, num_rows, &mut timing); - - let rate_bits = config.fri_config.rate_bits; - let cap_height = config.fri_config.cap_height; - - log::debug!("trace commit"); - let trace_commitments = timed!( - timing, - "compute all trace commitments", - PolynomialBatch::::from_values( - // TODO: Cloning this isn't great; consider having `from_values` accept a reference, - // or having `compute_permutation_z_polys` read trace values from the `PolynomialBatch`. - trace_poly_values.clone(), - rate_bits, - false, - cap_height, - &mut timing, - None, - ) - ); - - log::debug!("observe cap"); - let mut challenger = Challenger::>::Hasher>::new(); - - log::debug!("cross_table_lookup"); - let cross_table_lookups = ctl_logic(); - - log::debug!("ctl_challenges"); - let ctl_challenges = - get_grand_product_challenge_set(&mut challenger, config.num_challenges); - log::debug!( - "ctl_challenges: {:?}, num_challenges: {}", - ctl_challenges, - config.num_challenges - ); - - log::debug!("ctl data per table"); - let ctl_data_per_table = timed!( - timing, - "compute CTL data", - cross_table_lookup_data_ex::( - &trace_poly_values, - &[cross_table_lookups.clone()], - &ctl_challenges, - ) - ); - - log::debug!("prove single table"); - let proof = prove_single_table::( - &stark, - &config, - &trace_poly_values, - &trace_commitments, - &ctl_data_per_table, - &ctl_challenges, - &mut challenger, - &mut timing, - ) - .unwrap(); - log::debug!("prove done"); - - let num_lookup_columns = stark.num_lookup_helper_columns(&config); - let ctl_vars_per_table = CtlCheckVars::from_proof( - &proof, - &cross_table_lookups, - &ctl_challenges, - num_lookup_columns, - ); - - let mut challenger = Challenger::>::Hasher>::new(); - - let ctl_challenges = - get_grand_product_challenge_set(&mut challenger, config.num_challenges); - log::debug!( - "ctl_challenges v: {:?}, num_challenges: {}", - ctl_challenges, - config.num_challenges - ); - - let stark_challenger: crate::proof::StarkProofChallenges = { - challenger.compact(); - proof.proof.get_challenges(&mut challenger, &config) - }; - - verify_stark_proof_with_challenges::( - &stark, - &proof.proof, - &stark_challenger, - &ctl_vars_per_table, - &ctl_challenges, - &config, - ) - .unwrap(); - } } diff --git a/src/prover.rs b/src/prover.rs index d8bfab94..5ca4d7ab 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -243,6 +243,7 @@ where )? ); + /* let keccak_proof = timed!( timing, "prove Keccak STARK", @@ -271,6 +272,7 @@ where timing, )? ); + */ let logic_proof = timed!( timing, "prove logic STARK", @@ -304,8 +306,8 @@ where arithmetic_proof, //byte_packing_proof, cpu_proof, - keccak_proof, - keccak_sponge_proof, + //keccak_proof, + //keccak_sponge_proof, logic_proof, memory_proof, ]) diff --git a/src/verifier.rs b/src/verifier.rs index 5baf0f26..85ce8694 100644 --- a/src/verifier.rs +++ b/src/verifier.rs @@ -41,8 +41,8 @@ where let AllStark { arithmetic_stark, cpu_stark, - keccak_stark, - keccak_sponge_stark, + //keccak_stark, + //keccak_sponge_stark, logic_stark, memory_stark, cross_table_lookups, @@ -81,6 +81,7 @@ where &ctl_challenges, config, )?; + /* verify_stark_proof_with_challenges( keccak_stark, &all_proof.stark_proofs[Table::Keccak as usize].proof, @@ -97,6 +98,7 @@ where &ctl_challenges, config, )?; + */ verify_stark_proof_with_challenges( logic_stark, &all_proof.stark_proofs[Table::Logic as usize].proof, @@ -530,7 +532,6 @@ mod tests { } #[test] - #[ignore] fn test_mips_prove_and_verify() { env_logger::try_init().unwrap_or_default(); const D: usize = 2; @@ -539,7 +540,7 @@ mod tests { let allstark: AllStark = AllStark::default(); let mut config = StarkConfig::standard_fast_config(); - config.fri_config.rate_bits = 2; + config.fri_config.rate_bits = 3; let input = GenerationInputs {}; diff --git a/src/witness/traces.rs b/src/witness/traces.rs index d317162a..8d979fbb 100644 --- a/src/witness/traces.rs +++ b/src/witness/traces.rs @@ -23,8 +23,8 @@ pub struct TraceCheckpoint { pub(self) arithmetic_len: usize, // pub(self) byte_packing_len: usize, pub(self) cpu_len: usize, - pub(self) keccak_len: usize, - pub(self) keccak_sponge_len: usize, + //pub(self) keccak_len: usize, + //pub(self) keccak_sponge_len: usize, pub(self) logic_len: usize, pub(self) memory_len: usize, } @@ -36,8 +36,8 @@ pub(crate) struct Traces { pub(crate) cpu: Vec>, pub(crate) logic_ops: Vec, pub(crate) memory_ops: Vec, - pub(crate) keccak_inputs: Vec<([u64; keccak::keccak_stark::NUM_INPUTS], usize)>, - pub(crate) keccak_sponge_ops: Vec, + //pub(crate) keccak_inputs: Vec<([u64; keccak::keccak_stark::NUM_INPUTS], usize)>, + //pub(crate) keccak_sponge_ops: Vec, } impl Traces { @@ -48,8 +48,8 @@ impl Traces { cpu: vec![], logic_ops: vec![], memory_ops: vec![], - keccak_inputs: vec![], - keccak_sponge_ops: vec![], + // keccak_inputs: vec![], + // keccak_sponge_ops: vec![], } } @@ -69,12 +69,14 @@ impl Traces { .sum(), // byte_packing_len: self.byte_packing_ops.iter().map(|op| op.bytes.len()).sum(), cpu_len: self.cpu.len(), + /* keccak_len: self.keccak_inputs.len() * keccak::keccak_stark::NUM_ROUNDS, keccak_sponge_len: self .keccak_sponge_ops .iter() .map(|op| op.input.len() / keccak_sponge::columns::KECCAK_RATE_BYTES + 1) .sum(), + */ logic_len: self.logic_ops.len(), // This is technically a lower-bound, as we may fill gaps, // but this gives a relatively good estimate. @@ -88,8 +90,8 @@ impl Traces { arithmetic_len: self.arithmetic_ops.len(), // byte_packing_len: self.byte_packing_ops.len(), cpu_len: self.cpu.len(), - keccak_len: self.keccak_inputs.len(), - keccak_sponge_len: self.keccak_sponge_ops.len(), + //keccak_len: self.keccak_inputs.len(), + //keccak_sponge_len: self.keccak_sponge_ops.len(), logic_len: self.logic_ops.len(), memory_len: self.memory_ops.len(), } @@ -99,9 +101,9 @@ impl Traces { self.arithmetic_ops.truncate(checkpoint.arithmetic_len); //self.byte_packing_ops.truncate(checkpoint.byte_packing_len); self.cpu.truncate(checkpoint.cpu_len); - self.keccak_inputs.truncate(checkpoint.keccak_len); - self.keccak_sponge_ops - .truncate(checkpoint.keccak_sponge_len); + //self.keccak_inputs.truncate(checkpoint.keccak_len); + //self.keccak_sponge_ops + // .truncate(checkpoint.keccak_sponge_len); self.logic_ops.truncate(checkpoint.logic_len); self.memory_ops.truncate(checkpoint.memory_len); } @@ -130,7 +132,6 @@ impl Traces { pub fn push_byte_packing(&mut self, op: BytePackingOp) { self.byte_packing_ops.push(op); } - */ pub fn push_keccak(&mut self, input: [u64; keccak::keccak_stark::NUM_INPUTS], clock: usize) { self.keccak_inputs.push((input, clock)); @@ -149,6 +150,7 @@ impl Traces { pub fn push_keccak_sponge(&mut self, op: KeccakSpongeOp) { self.keccak_sponge_ops.push(op); } + */ pub fn clock(&self) -> usize { self.cpu.len() @@ -170,8 +172,8 @@ impl Traces { cpu, logic_ops, memory_ops, - keccak_inputs, - keccak_sponge_ops, + // keccak_inputs, + // keccak_sponge_ops, } = self; let arithmetic_trace = timed!( @@ -190,6 +192,7 @@ impl Traces { */ let cpu_rows = cpu.into_iter().map(|x| x.into()).collect(); let cpu_trace = trace_rows_to_poly_values(cpu_rows); + /* let keccak_trace = timed!( timing, "generate Keccak trace", @@ -204,6 +207,7 @@ impl Traces { .keccak_sponge_stark .generate_trace(keccak_sponge_ops, cap_elements, timing) ); + */ let logic_trace = timed!( timing, "generate logic trace", @@ -221,8 +225,8 @@ impl Traces { arithmetic_trace, //byte_packing_trace, cpu_trace, - keccak_trace, - keccak_sponge_trace, + //keccak_trace, + //keccak_sponge_trace, logic_trace, memory_trace, ] diff --git a/src/witness/util.rs b/src/witness/util.rs index 618632e6..89f2effc 100644 --- a/src/witness/util.rs +++ b/src/witness/util.rs @@ -264,6 +264,7 @@ pub(crate) fn mem_write_log( ) } +/* pub(crate) fn keccak_sponge_log( state: &mut GenerationState, base_address: MemoryAddress, @@ -342,6 +343,7 @@ fn xor_into_sponge( sponge_state[i] ^= block[i]; } } +*/ pub(crate) fn u32_from_u64(v: u64) -> (u32, u32) { ((v >> 32) as u32, v as u32)