From c42c63baff6a28cce7b7bc6500df4dd3132000d8 Mon Sep 17 00:00:00 2001 From: Hadas Date: Sat, 16 Dec 2023 19:48:10 -0500 Subject: [PATCH 01/11] start of manual implementation of Machine trait for BasicMachine --- basic/Cargo.toml | 3 +- basic/src/lib.rs | 173 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 137 insertions(+), 39 deletions(-) diff --git a/basic/Cargo.toml b/basic/Cargo.toml index bd0968e1..1ec0512e 100644 --- a/basic/Cargo.toml +++ b/basic/Cargo.toml @@ -25,7 +25,7 @@ p3-baby-bear = { path = "../../Plonky3/baby-bear" } p3-field = { path = "../../Plonky3/field" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } p3-util = { path = "../../Plonky3/util" } - +p3-goldilocks = {path = "../../Plonky3/goldilocks" } [dev-dependencies] p3-challenger = { path = "../../Plonky3/challenger" } p3-commit = { path = "../../Plonky3/commit" } @@ -38,4 +38,5 @@ p3-mds = { path = "../../Plonky3/mds" } p3-merkle-tree = { path = "../../Plonky3/merkle-tree" } p3-poseidon = { path = "../../Plonky3/poseidon" } p3-symmetric = { path = "../../Plonky3/symmetric" } + rand = "0.8.5" diff --git a/basic/src/lib.rs b/basic/src/lib.rs index 0f3d3c7b..cff1148e 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -2,8 +2,10 @@ #![allow(unused)] extern crate alloc; - -use p3_field::TwoAdicField; +use alloc::vec::Vec; +use core::marker::PhantomData; +use p3_field::{extension::BinomialExtensionField, TwoAdicField}; +use p3_goldilocks::Goldilocks; use valida_alu_u32::{ add::{Add32Chip, Add32Instruction, MachineWithAdd32Chip}, bitwise::{ @@ -26,8 +28,8 @@ use valida_cpu::{ use valida_cpu::{CpuChip, MachineWithCpuChip}; use valida_derive::Machine; use valida_machine::{ - AbstractExtensionField, AbstractField, BusArgument, Chip, ExtensionField, Instruction, Machine, - PrimeField64, ProgramROM, ValidaAirBuilder, + config::StarkConfig, proof::MachineProof, AbstractExtensionField, AbstractField, BusArgument, + Chip, ExtensionField, Instruction, Machine, PrimeField64, ProgramROM, ValidaAirBuilder, }; use valida_memory::{MachineWithMemoryChip, MemoryChip}; use valida_output::{MachineWithOutputChip, OutputChip, WriteInstruction}; @@ -36,78 +38,73 @@ use valida_range::{MachineWithRangeChip, RangeCheckerChip}; use p3_maybe_rayon::*; -#[derive(Machine, Default)] -#[machine_fields(F, EF)] +#[derive(Default)] pub struct BasicMachine> { // Core instructions - #[instruction] load32: Load32Instruction, - #[instruction] + store32: Store32Instruction, - #[instruction] + jal: JalInstruction, - #[instruction] + jalv: JalvInstruction, - #[instruction] + beq: BeqInstruction, - #[instruction] + bne: BneInstruction, - #[instruction] + imm32: Imm32Instruction, - #[instruction] + stop: StopInstruction, // ALU instructions - #[instruction(add_u32)] add32: Add32Instruction, - #[instruction(add_u32)] + sub32: Sub32Instruction, - #[instruction(mul_u32)] + mul32: Mul32Instruction, - #[instruction(div_u32)] + div32: Div32Instruction, - #[instruction(shift_u32)] + shl32: Shl32Instruction, - #[instruction(shift_u32)] + shr32: Shr32Instruction, - #[instruction(lt_u32)] + lt32: Lt32Instruction, - #[instruction(bitwise_u32)] + and32: And32Instruction, - #[instruction(bitwise_u32)] + or32: Or32Instruction, - #[instruction(bitwise_u32)] + xor32: Xor32Instruction, // Input/output instructions - #[instruction] read: ReadAdviceInstruction, - #[instruction(output)] + write: WriteInstruction, - #[chip] cpu: CpuChip, - #[chip] + program: ProgramChip, - #[chip] + mem: MemoryChip, - #[chip] + add_u32: Add32Chip, - #[chip] + sub_u32: Sub32Chip, - #[chip] + mul_u32: Mul32Chip, - #[chip] + div_u32: Div32Chip, - #[chip] + shift_u32: Shift32Chip, - #[chip] + lt_u32: Lt32Chip, - #[chip] + bitwise_u32: Bitwise32Chip, - #[chip] + output: OutputChip, - #[chip] + range: RangeCheckerChip<256>, _phantom_base: core::marker::PhantomData, @@ -289,3 +286,103 @@ impl> MachineWithRangeChip &mut self.range } } + +impl> Machine for BasicMachine { + type F = F; + type EF = EF; + fn run(&mut self, program: &ProgramROM) { + loop { + let pc = self.cpu().pc; + let instruction = program.get_instruction(pc); + let opcode = instruction.opcode; + let ops = instruction.operands; + match opcode { + >::OPCODE => { + Load32Instruction::execute(self, ops); + } + >::OPCODE => { + JalInstruction::execute(self, ops); + } + >::OPCODE => { + JalvInstruction::execute(self, ops); + } + >::OPCODE => { + BeqInstruction::execute(self, ops); + } + >::OPCODE => { + BneInstruction::execute(self, ops); + } + >::OPCODE => { + Imm32Instruction::execute(self, ops); + } + >::OPCODE => { + Add32Instruction::execute(self, ops); + } + >::OPCODE => { + Sub32Instruction::execute(self, ops); + } + >::OPCODE => { + Mul32Instruction::execute(self, ops); + } + >::OPCODE => { + Div32Instruction::execute(self, ops); + } + >::OPCODE => { + Shl32Instruction::execute(self, ops); + } + >::OPCODE => { + Shr32Instruction::execute(self, ops); + } + >::OPCODE => { + Lt32Instruction::execute(self, ops); + } + >::OPCODE => { + And32Instruction::execute(self, ops); + } + >::OPCODE => { + Or32Instruction::execute(self, ops); + } + >::OPCODE => { + Xor32Instruction::execute(self, ops); + } + >::OPCODE => { + ReadAdviceInstruction::execute(self, ops); + } + >::OPCODE => { + WriteInstruction::execute(self, ops); + } + >::OPCODE => { + StopInstruction::execute(self, ops); + } + _ => {} + } + + self.read_word(pc as usize); + + if opcode == >::OPCODE { + break; + } + } + let n = self.cpu().clock.next_power_of_two() - self.cpu().clock; + for _ in 0..n { + self.read_word(self.cpu().pc as usize); + } + } + + fn prove(&self, config: &SC) -> MachineProof + where + SC: StarkConfig, + { + MachineProof { + chip_proofs: Vec::new(), + phantom: PhantomData::default(), + } + } + + fn verify(proof: &MachineProof) -> Result<(), ()> + where + SC: StarkConfig, + { + Ok(()) + } +} From 669aacead03bebac6e609b1604995d7dc76933c9 Mon Sep 17 00:00:00 2001 From: Hadas Date: Sun, 17 Dec 2023 17:52:22 -0500 Subject: [PATCH 02/11] implemented chip proof function, generalized Machine trait so it can be explicitly implemented, began explicit implementation for BasicMachine --- basic/Cargo.toml | 1 + basic/src/lib.rs | 5 ++++- basic/tests/test_prover.rs | 9 +++++---- machine/Cargo.toml | 2 +- machine/src/__internal/prove.rs | 20 ++++++++++++-------- machine/src/lib.rs | 2 +- machine/src/proof.rs | 10 ++++++---- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/basic/Cargo.toml b/basic/Cargo.toml index 1ec0512e..c0d0b406 100644 --- a/basic/Cargo.toml +++ b/basic/Cargo.toml @@ -26,6 +26,7 @@ p3-field = { path = "../../Plonky3/field" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } p3-util = { path = "../../Plonky3/util" } p3-goldilocks = {path = "../../Plonky3/goldilocks" } +p3-uni-stark = {path = "../../Plonky3/uni-stark" } [dev-dependencies] p3-challenger = { path = "../../Plonky3/challenger" } p3-commit = { path = "../../Plonky3/commit" } diff --git a/basic/src/lib.rs b/basic/src/lib.rs index cff1148e..876bc4eb 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -27,8 +27,9 @@ use valida_cpu::{ }; use valida_cpu::{CpuChip, MachineWithCpuChip}; use valida_derive::Machine; +use p3_uni_stark::StarkConfig; use valida_machine::{ - config::StarkConfig, proof::MachineProof, AbstractExtensionField, AbstractField, BusArgument, + proof::MachineProof, AbstractExtensionField, AbstractField, BusArgument, Chip, ExtensionField, Instruction, Machine, PrimeField64, ProgramROM, ValidaAirBuilder, }; use valida_memory::{MachineWithMemoryChip, MemoryChip}; @@ -373,6 +374,8 @@ impl> Machine for BasicMac where SC: StarkConfig, { + + MachineProof { chip_proofs: Vec::new(), phantom: PhantomData::default(), diff --git a/basic/tests/test_prover.rs b/basic/tests/test_prover.rs index 1e958030..e7f3ba1b 100644 --- a/basic/tests/test_prover.rs +++ b/basic/tests/test_prover.rs @@ -5,7 +5,7 @@ use valida_cpu::{ BeqInstruction, BneInstruction, Imm32Instruction, JalInstruction, JalvInstruction, MachineWithCpuChip, StopInstruction, }; -use valida_machine::config::StarkConfigImpl; +use p3_uni_stark::{StarkConfigImpl}; use valida_machine::{Instruction, InstructionWord, Machine, Operands, ProgramROM, Word}; use valida_memory::MachineWithMemoryChip; use valida_program::MachineWithProgramChip; @@ -222,9 +222,10 @@ fn prove_fibonacci() { type MyConfig = StarkConfigImpl; let pcs = Pcs::new(dft, val_mmcs, ldt); - let challenger = DuplexChallenger::new(perm16); - let config = MyConfig::new(pcs, challenger); - machine.prove(&config); + + let config = MyConfig::new(pcs); + let out = machine.prove(&config); + assert_eq!(machine.cpu().clock, 192); assert_eq!(machine.cpu().operations.len(), 192); diff --git a/machine/Cargo.toml b/machine/Cargo.toml index 19fea207..81a77d6c 100644 --- a/machine/Cargo.toml +++ b/machine/Cargo.toml @@ -17,6 +17,6 @@ p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } p3-util = { path = "../../Plonky3/util" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark" } valida-util = { path = "../util" } diff --git a/machine/src/__internal/prove.rs b/machine/src/__internal/prove.rs index 4565f5d1..b3c4d81d 100644 --- a/machine/src/__internal/prove.rs +++ b/machine/src/__internal/prove.rs @@ -1,20 +1,24 @@ use crate::__internal::ConstraintFolder; -use crate::config::StarkConfig; use crate::proof::ChipProof; use crate::{Chip, Machine}; use p3_air::Air; +use p3_uni_stark::{prove as stark_prove,StarkConfig,SymbolicAirBuilder,ProverConstraintFolder}; pub fn prove( - _machine: &M, - _config: &SC, - _air: &A, - _challenger: &mut SC::Challenger, -) -> ChipProof + machine: &M, + config: &SC, + air: &A, + challenger: &mut SC::Challenger, +) -> ChipProof where M: Machine, - A: for<'a> Air> + Chip, + A: for<'a> Air> + Chip + Air>, SC: StarkConfig, { + let trace = air.generate_trace(&machine); + let proof = stark_prove(config,air,challenger,trace); // TODO: Sumcheck - ChipProof + ChipProof{ + proof + } } diff --git a/machine/src/lib.rs b/machine/src/lib.rs index def670b9..000d2410 100644 --- a/machine/src/lib.rs +++ b/machine/src/lib.rs @@ -10,7 +10,7 @@ use byteorder::{ByteOrder, LittleEndian}; pub use crate::core::Word; pub use chip::{BusArgument, Chip, Interaction, InteractionType, ValidaAirBuilder}; -use crate::config::StarkConfig; +use p3_uni_stark::{StarkConfig}; use crate::proof::MachineProof; pub use p3_field::{ AbstractExtensionField, AbstractField, ExtensionField, Field, PrimeField, PrimeField64, diff --git a/machine/src/proof.rs b/machine/src/proof.rs index 9584627f..13ddb589 100644 --- a/machine/src/proof.rs +++ b/machine/src/proof.rs @@ -1,10 +1,12 @@ -use crate::config::StarkConfig; use alloc::vec::Vec; - +use p3_uni_stark::{Proof,StarkConfig}; +use crate::{Chip,Machine}; pub struct MachineProof { //pub opening_proof: >>::Proof, - pub chip_proofs: Vec, + pub chip_proofs: Vec>, pub phantom: core::marker::PhantomData, } -pub struct ChipProof; +pub struct ChipProof{ + pub proof: Proof +} From f509c9ae7ca19b6c01053e76d8b6f9a71461d786 Mon Sep 17 00:00:00 2001 From: Hadas Date: Sun, 17 Dec 2023 17:55:15 -0500 Subject: [PATCH 03/11] removed sumcheck --- machine/src/__internal/prove.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine/src/__internal/prove.rs b/machine/src/__internal/prove.rs index b3c4d81d..4233a6ea 100644 --- a/machine/src/__internal/prove.rs +++ b/machine/src/__internal/prove.rs @@ -17,7 +17,7 @@ where { let trace = air.generate_trace(&machine); let proof = stark_prove(config,air,challenger,trace); - // TODO: Sumcheck + ChipProof{ proof } From 014c195704abe1b22ef0b2f3f3114e3cf149ec31 Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 20 Dec 2023 17:31:02 -0500 Subject: [PATCH 04/11] prove in machine implementation for basic machine --- basic/src/lib.rs | 43 ++++++++++++++++++++++++++++++-------- basic/tests/test_prover.rs | 7 ++++--- machine/src/lib.rs | 2 +- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/basic/src/lib.rs b/basic/src/lib.rs index 876bc4eb..8bf1f7e9 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +//#![no_std] #![allow(unused)] extern crate alloc; @@ -6,6 +6,8 @@ use alloc::vec::Vec; use core::marker::PhantomData; use p3_field::{extension::BinomialExtensionField, TwoAdicField}; use p3_goldilocks::Goldilocks; +use p3_maybe_rayon::*; +use p3_uni_stark::StarkConfig; use valida_alu_u32::{ add::{Add32Chip, Add32Instruction, MachineWithAdd32Chip}, bitwise::{ @@ -27,18 +29,15 @@ use valida_cpu::{ }; use valida_cpu::{CpuChip, MachineWithCpuChip}; use valida_derive::Machine; -use p3_uni_stark::StarkConfig; use valida_machine::{ - proof::MachineProof, AbstractExtensionField, AbstractField, BusArgument, - Chip, ExtensionField, Instruction, Machine, PrimeField64, ProgramROM, ValidaAirBuilder, + proof::MachineProof, AbstractExtensionField, AbstractField, BusArgument, Chip, ExtensionField, + Instruction, Machine, PrimeField64, ProgramROM, ValidaAirBuilder, }; use valida_memory::{MachineWithMemoryChip, MemoryChip}; use valida_output::{MachineWithOutputChip, OutputChip, WriteInstruction}; use valida_program::{MachineWithProgramChip, ProgramChip}; use valida_range::{MachineWithRangeChip, RangeCheckerChip}; -use p3_maybe_rayon::*; - #[derive(Default)] pub struct BasicMachine> { // Core instructions @@ -370,14 +369,40 @@ impl> Machine for BasicMac } } - fn prove(&self, config: &SC) -> MachineProof + fn prove(&self, config: &SC, challenger: &mut SC::Challenger) -> MachineProof where SC: StarkConfig, { + use valida_machine::__internal::prove; + let mut chip_proofs = Vec::new(); + + if self.cpu.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.cpu, challenger)); + } + if self.add_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.add_u32, challenger)); + } + if self.sub_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.sub_u32, challenger)); + } + if self.mul_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.mul_u32, challenger)); + } + if self.div_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.div_u32, challenger)); + } + if self.shift_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.shift_u32, challenger)); + } + if self.lt_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.lt_u32, challenger)); + } + if self.bitwise_u32.operations.len() > 0 { + chip_proofs.push(prove(self, config, &self.bitwise_u32, challenger)); + } - MachineProof { - chip_proofs: Vec::new(), + chip_proofs: chip_proofs, phantom: PhantomData::default(), } } diff --git a/basic/tests/test_prover.rs b/basic/tests/test_prover.rs index e7f3ba1b..1c1d5c99 100644 --- a/basic/tests/test_prover.rs +++ b/basic/tests/test_prover.rs @@ -20,8 +20,7 @@ use p3_ldt::QuotientMmcs; use p3_mds::coset_mds::CosetMds; use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon::Poseidon; -use p3_symmetric::CompressionFunctionFromHasher; -use p3_symmetric::SerializingHasher32; +use p3_symmetric::{CompressionFunctionFromHasher,CryptographicPermutation, SerializingHasher32}; use rand::thread_rng; use valida_machine::__internal::p3_commit::ExtensionMmcs; @@ -224,7 +223,9 @@ fn prove_fibonacci() { let pcs = Pcs::new(dft, val_mmcs, ldt); let config = MyConfig::new(pcs); - let out = machine.prove(&config); + + let mut challenger = Challenger::new(perm16); + let out = machine.prove(&config,&mut challenger); assert_eq!(machine.cpu().clock, 192); diff --git a/machine/src/lib.rs b/machine/src/lib.rs index 000d2410..ee58b39c 100644 --- a/machine/src/lib.rs +++ b/machine/src/lib.rs @@ -125,7 +125,7 @@ pub trait Machine { fn run(&mut self, program: &ProgramROM); - fn prove(&self, config: &SC) -> MachineProof + fn prove(&self, config: &SC, challenger: &mut SC::Challenger) -> MachineProof where SC: StarkConfig; From 9abe475b71ed525ed80fa1d443b77a7c8cd1061d Mon Sep 17 00:00:00 2001 From: Hadas Date: Sun, 7 Jan 2024 21:28:23 -0500 Subject: [PATCH 05/11] prover done except for accessing commitments to put in proof object --- basic/Cargo.toml | 5 +- basic/src/lib.rs | 118 +++++++++++++++++++++++++++++++++++++------ machine/Cargo.toml | 2 +- machine/src/proof.rs | 2 +- 4 files changed, 109 insertions(+), 18 deletions(-) diff --git a/basic/Cargo.toml b/basic/Cargo.toml index c0d0b406..ef8b4e4c 100644 --- a/basic/Cargo.toml +++ b/basic/Cargo.toml @@ -27,9 +27,11 @@ p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } p3-util = { path = "../../Plonky3/util" } p3-goldilocks = {path = "../../Plonky3/goldilocks" } p3-uni-stark = {path = "../../Plonky3/uni-stark" } +p3-commit = { path = "../../Plonky3/commit" } [dev-dependencies] + p3-challenger = { path = "../../Plonky3/challenger" } -p3-commit = { path = "../../Plonky3/commit" } + p3-dft = { path = "../../Plonky3/dft" } p3-field = { path = "../../Plonky3/field" } p3-fri = { path = "../../Plonky3/fri" } @@ -40,4 +42,5 @@ p3-merkle-tree = { path = "../../Plonky3/merkle-tree" } p3-poseidon = { path = "../../Plonky3/poseidon" } p3-symmetric = { path = "../../Plonky3/symmetric" } + rand = "0.8.5" diff --git a/basic/src/lib.rs b/basic/src/lib.rs index 8bf1f7e9..c21716b8 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -4,10 +4,15 @@ extern crate alloc; use alloc::vec::Vec; use core::marker::PhantomData; +use p3_commit::{Pcs, UnivariatePcs, UnivariatePcsWithLde}; use p3_field::{extension::BinomialExtensionField, TwoAdicField}; use p3_goldilocks::Goldilocks; use p3_maybe_rayon::*; -use p3_uni_stark::StarkConfig; +use p3_uni_stark::{ + get_max_constraint_degree, get_trace_and_quotient_ldes, open, ProverConstraintFolder, + StarkConfig, SymbolicAirBuilder, Commitments, Proof +}; +use p3_util::log2_ceil_usize; use valida_alu_u32::{ add::{Add32Chip, Add32Instruction, MachineWithAdd32Chip}, bitwise::{ @@ -30,7 +35,7 @@ use valida_cpu::{ use valida_cpu::{CpuChip, MachineWithCpuChip}; use valida_derive::Machine; use valida_machine::{ - proof::MachineProof, AbstractExtensionField, AbstractField, BusArgument, Chip, ExtensionField, + proof::{MachineProof, ChipProof}, AbstractExtensionField, AbstractField, BusArgument, Chip, ExtensionField, Instruction, Machine, PrimeField64, ProgramROM, ValidaAirBuilder, }; use valida_memory::{MachineWithMemoryChip, MemoryChip}; @@ -373,36 +378,119 @@ impl> Machine for BasicMac where SC: StarkConfig, { - use valida_machine::__internal::prove; - let mut chip_proofs = Vec::new(); - + let mut trace_commitments = Vec::new(); + let mut quotient_commitments = Vec::new(); + let mut log_degrees = Vec::new(); + let mut log_quotient_degrees = Vec::new(); if self.cpu.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.cpu, challenger)); - } + let air = &self.cpu; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); + } if self.add_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.add_u32, challenger)); + let air = &self.add_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } if self.sub_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.sub_u32, challenger)); + let air = &self.sub_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } if self.mul_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.mul_u32, challenger)); + let air = &self.mul_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } if self.div_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.div_u32, challenger)); + let air = &self.div_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } if self.shift_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.shift_u32, challenger)); + let air = &self.shift_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } if self.lt_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.lt_u32, challenger)); + let air = &self.lt_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } + if self.bitwise_u32.operations.len() > 0 { - chip_proofs.push(prove(self, config, &self.bitwise_u32, challenger)); + let air = &self.bitwise_u32; + let trace = air.generate_trace(self); + let (trace_lde, quotient_lde, log_degree, log_quotient_degree) = + get_trace_and_quotient_ldes(config, trace, air, challenger); + trace_commitments.push(trace_lde); + quotient_commitments.push(quotient_lde); + log_degrees.push(log_degree); + log_quotient_degrees.push(log_quotient_degree); } + let pcs = config.pcs(); + let aggregated_trace = pcs.combine(&trace_commitments); + let aggregated_quotient = pcs.combine("ient_commitments); + let max_log_degree = log_degrees.iter().max().unwrap(); + let max_quotient_degree = log_quotient_degrees.iter().max().unwrap(); + let (opening_proof, opened_values) = open( + config, + &aggregated_trace, + &aggregated_quotient, + *max_log_degree, + *max_quotient_degree, + challenger, + ); + + let commitments = Commitments { + trace: aggregated_trace.root(), + quotient_chunks: aggregated_quotient.root() + }; MachineProof { - chip_proofs: chip_proofs, + chip_proof: ChipProof{ + proof: Proof{ + commitments, + opened_values, + opening_proof, + degree_bits:max_log_degree + } + }, phantom: PhantomData::default(), } } diff --git a/machine/Cargo.toml b/machine/Cargo.toml index 81a77d6c..54867a74 100644 --- a/machine/Cargo.toml +++ b/machine/Cargo.toml @@ -19,4 +19,4 @@ p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } p3-util = { path = "../../Plonky3/util" } p3-uni-stark = { path = "../../Plonky3/uni-stark" } valida-util = { path = "../util" } - +serde = { version = "1.0", default-features = false, features = ["derive"] } diff --git a/machine/src/proof.rs b/machine/src/proof.rs index 13ddb589..1743d1bf 100644 --- a/machine/src/proof.rs +++ b/machine/src/proof.rs @@ -3,7 +3,7 @@ use p3_uni_stark::{Proof,StarkConfig}; use crate::{Chip,Machine}; pub struct MachineProof { //pub opening_proof: >>::Proof, - pub chip_proofs: Vec>, + pub chip_proof: ChipProof, pub phantom: core::marker::PhantomData, } From 6bc2cd242a7617a83fd0c2967ac532a2f25aa37a Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 10 Jan 2024 14:41:55 -0500 Subject: [PATCH 06/11] prover for basic machine --- basic/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/basic/src/lib.rs b/basic/src/lib.rs index c21716b8..f62c5ba8 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -465,22 +465,22 @@ impl> Machine for BasicMac } let pcs = config.pcs(); - let aggregated_trace = pcs.combine(&trace_commitments); - let aggregated_quotient = pcs.combine("ient_commitments); + let (aggregated_commitment, aggregated_trace) = pcs.combine(&trace_commitments); + let (aggregated_quotient_commitment, aggregated_quotient_trace) = pcs.combine("ient_commitments); let max_log_degree = log_degrees.iter().max().unwrap(); let max_quotient_degree = log_quotient_degrees.iter().max().unwrap(); let (opening_proof, opened_values) = open( config, &aggregated_trace, - &aggregated_quotient, + &aggregated_quotient_trace, *max_log_degree, *max_quotient_degree, challenger, ); let commitments = Commitments { - trace: aggregated_trace.root(), - quotient_chunks: aggregated_quotient.root() + trace: aggregated_commitment, + quotient_chunks: aggregated_quotient_commitment }; MachineProof { chip_proof: ChipProof{ @@ -488,7 +488,7 @@ impl> Machine for BasicMac commitments, opened_values, opening_proof, - degree_bits:max_log_degree + degree_bits:*max_log_degree } }, phantom: PhantomData::default(), From 563419f3e00c92f90720c0145971a1d018ba3a44 Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 17 Jan 2024 16:00:24 -0500 Subject: [PATCH 07/11] lint --- basic/tests/test_prover.rs | 8 +++----- machine/src/__internal/prove.rs | 4 ++-- machine/src/lib.rs | 11 +++++------ machine/src/proof.rs | 8 ++++---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/basic/tests/test_prover.rs b/basic/tests/test_prover.rs index 3abcf5fb..2c1a2dae 100644 --- a/basic/tests/test_prover.rs +++ b/basic/tests/test_prover.rs @@ -8,8 +8,7 @@ use valida_cpu::{ MachineWithCpuChip, StopInstruction, }; -use p3_uni_stark::{StarkConfigImpl}; - +use p3_uni_stark::StarkConfigImpl; use valida_machine::{ FixedAdviceProvider, Instruction, InstructionWord, Machine, Operands, ProgramROM, Word, @@ -29,7 +28,7 @@ use p3_ldt::QuotientMmcs; use p3_mds::coset_mds::CosetMds; use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon::Poseidon; -use p3_symmetric::{CompressionFunctionFromHasher,CryptographicPermutation, SerializingHasher32}; +use p3_symmetric::{CompressionFunctionFromHasher, CryptographicPermutation, SerializingHasher32}; use rand::thread_rng; use valida_machine::__internal::p3_commit::ExtensionMmcs; @@ -235,8 +234,7 @@ fn prove_fibonacci() { let config = MyConfig::new(pcs); let mut challenger = Challenger::new(perm16); - let out = machine.prove(&config,&mut challenger); - + let out = machine.prove(&config, &mut challenger); assert_eq!(machine.cpu().clock, 192); assert_eq!(machine.cpu().operations.len(), 192); diff --git a/machine/src/__internal/prove.rs b/machine/src/__internal/prove.rs index 2b3ce047..dbfdf295 100644 --- a/machine/src/__internal/prove.rs +++ b/machine/src/__internal/prove.rs @@ -2,7 +2,7 @@ use crate::__internal::ConstraintFolder; use crate::proof::ChipProof; use crate::{Chip, Machine}; use p3_air::Air; -use p3_uni_stark::{prove as stark_prove,StarkConfig,SymbolicAirBuilder,ProverConstraintFolder}; +use p3_uni_stark::{prove as stark_prove, ProverConstraintFolder, StarkConfig, SymbolicAirBuilder}; /* pub fn prove( machine: &M, @@ -19,7 +19,7 @@ where let proof = stark_prove(config,air,challenger,trace); ChipProof{ - proof + proof } } */ diff --git a/machine/src/lib.rs b/machine/src/lib.rs index 7d544d9b..676ae70a 100644 --- a/machine/src/lib.rs +++ b/machine/src/lib.rs @@ -9,16 +9,15 @@ use byteorder::{ByteOrder, LittleEndian}; pub use crate::core::Word; pub use chip::{BusArgument, Chip, Interaction, InteractionType, ValidaAirBuilder}; -use p3_matrix::dense::{RowMajorMatrix}; +use p3_matrix::dense::RowMajorMatrix; -use p3_air::Air; use crate::proof::MachineProof; +use p3_air::Air; pub use p3_field::{ AbstractExtensionField, AbstractField, ExtensionField, Field, PrimeField, PrimeField64, }; use p3_uni_stark::{ - ProverConstraintFolder, - StarkConfig, SymbolicAirBuilder, Commitments, Proof, ProverData + Commitments, Proof, ProverConstraintFolder, ProverData, StarkConfig, SymbolicAirBuilder, }; // TODO: some are also re-exported, so they shouldn't be pub? pub mod __internal; @@ -173,8 +172,8 @@ pub trait Machine { quotient_commitments: &mut Vec>, log_degree: &mut Vec, log_quotient_degrees: &mut Vec, - chip:&A, - trace:RowMajorMatrix<::Val> + chip: &A, + trace: RowMajorMatrix<::Val>, ) where SC: StarkConfig, A: Air> + for<'a> Air>; diff --git a/machine/src/proof.rs b/machine/src/proof.rs index 1743d1bf..0975020b 100644 --- a/machine/src/proof.rs +++ b/machine/src/proof.rs @@ -1,12 +1,12 @@ +use crate::{Chip, Machine}; use alloc::vec::Vec; -use p3_uni_stark::{Proof,StarkConfig}; -use crate::{Chip,Machine}; +use p3_uni_stark::{Proof, StarkConfig}; pub struct MachineProof { //pub opening_proof: >>::Proof, pub chip_proof: ChipProof, pub phantom: core::marker::PhantomData, } -pub struct ChipProof{ - pub proof: Proof +pub struct ChipProof { + pub proof: Proof, } From e2262b14d87dead32852e12c6c7c8b1a116a84dd Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 17 Jan 2024 16:13:13 -0500 Subject: [PATCH 08/11] smoke test for prover --- basic/tests/test_prover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basic/tests/test_prover.rs b/basic/tests/test_prover.rs index 6af5fbcb..c394eec6 100644 --- a/basic/tests/test_prover.rs +++ b/basic/tests/test_prover.rs @@ -235,7 +235,7 @@ fn prove_fibonacci() { let mut challenger = Challenger::new(perm16); let out = machine.prove(&config, &mut challenger); - + assert_eq!(out.chip_proof.proof.opened_values.trace_local.len() > 0, true); assert_eq!(machine.cpu().clock, 192); assert_eq!(machine.cpu().operations.len(), 192); assert_eq!(machine.mem().operations.values().flatten().count(), 401); From 009d80198571e24c3cb0a92d97a1f0ab61a4d6d2 Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 17 Jan 2024 17:06:44 -0500 Subject: [PATCH 09/11] clippy --- basic/tests/test_prover.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/basic/tests/test_prover.rs b/basic/tests/test_prover.rs index c394eec6..9b6818f1 100644 --- a/basic/tests/test_prover.rs +++ b/basic/tests/test_prover.rs @@ -235,7 +235,10 @@ fn prove_fibonacci() { let mut challenger = Challenger::new(perm16); let out = machine.prove(&config, &mut challenger); - assert_eq!(out.chip_proof.proof.opened_values.trace_local.len() > 0, true); + assert_eq!( + out.chip_proof.proof.opened_values.trace_local.len() > 0, + true + ); assert_eq!(machine.cpu().clock, 192); assert_eq!(machine.cpu().operations.len(), 192); assert_eq!(machine.mem().operations.values().flatten().count(), 401); From 23ecec162e9339b401711449a5fe13f96365aaf1 Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 17 Jan 2024 17:10:41 -0500 Subject: [PATCH 10/11] fmt --- basic/src/lib.rs | 2 -- machine/src/__internal/prove.rs | 1 - machine/src/lib.rs | 1 - 3 files changed, 4 deletions(-) diff --git a/basic/src/lib.rs b/basic/src/lib.rs index d237baaa..1dcacee2 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -52,10 +52,8 @@ use valida_output::{MachineWithOutputChip, OutputChip, WriteInstruction}; use valida_program::{MachineWithProgramChip, ProgramChip}; use valida_range::{MachineWithRangeChip, RangeCheckerChip}; - #[derive(Default)] pub struct BasicMachine> { - // Core instructions load32: Load32Instruction, diff --git a/machine/src/__internal/prove.rs b/machine/src/__internal/prove.rs index 356f38af..3a9042cb 100644 --- a/machine/src/__internal/prove.rs +++ b/machine/src/__internal/prove.rs @@ -1,4 +1,3 @@ - use crate::__internal::ConstraintFolder; use crate::proof::ChipProof; use crate::{Chip, Machine}; diff --git a/machine/src/lib.rs b/machine/src/lib.rs index 61101771..bdc1e6c9 100644 --- a/machine/src/lib.rs +++ b/machine/src/lib.rs @@ -179,6 +179,5 @@ pub trait Machine { where SC: StarkConfig; - fn verify>(proof: &MachineProof) -> Result<(), ()>; } From 9e911a1be9be6f032a8ab38690f9841b413cedc7 Mon Sep 17 00:00:00 2001 From: Hadas Date: Wed, 17 Jan 2024 19:33:41 -0500 Subject: [PATCH 11/11] merge conflicts --- alu_u32/Cargo.toml | 2 +- alu_u32/src/add/mod.rs | 2 +- alu_u32/src/bitwise/mod.rs | 2 +- alu_u32/src/div/mod.rs | 4 +- alu_u32/src/lt/mod.rs | 4 +- alu_u32/src/mul/mod.rs | 2 +- alu_u32/src/shift/mod.rs | 2 +- alu_u32/src/sub/mod.rs | 3 +- basic/src/lib.rs | 98 +++++++++++---------- cpu/Cargo.toml | 2 +- cpu/src/lib.rs | 2 +- machine/src/__internal/check_constraints.rs | 3 +- machine/src/__internal/debug_builder.rs | 3 +- machine/src/__internal/folding_builder.rs | 2 +- machine/src/chip.rs | 3 +- machine/src/lib.rs | 2 +- memory/Cargo.toml | 2 +- memory/src/lib.rs | 4 +- native_field/Cargo.toml | 2 +- native_field/src/lib.rs | 3 +- output/Cargo.toml | 2 +- output/src/lib.rs | 2 +- program/Cargo.toml | 2 +- program/src/lib.rs | 2 +- range/Cargo.toml | 2 +- range/src/lib.rs | 3 +- 26 files changed, 85 insertions(+), 75 deletions(-) diff --git a/alu_u32/Cargo.toml b/alu_u32/Cargo.toml index 52b96966..7123abb7 100644 --- a/alu_u32/Cargo.toml +++ b/alu_u32/Cargo.toml @@ -12,7 +12,7 @@ p3-baby-bear = { path = "../../Plonky3/baby-bear" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark" } valida-bus = { path = "../bus" } valida-derive = { path = "../derive" } valida-machine = { path = "../machine" } diff --git a/alu_u32/src/add/mod.rs b/alu_u32/src/add/mod.rs index f3f1db0b..8a382fb0 100644 --- a/alu_u32/src/add/mod.rs +++ b/alu_u32/src/add/mod.rs @@ -14,7 +14,7 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; use valida_util::pad_to_power_of_two; pub mod columns; diff --git a/alu_u32/src/bitwise/mod.rs b/alu_u32/src/bitwise/mod.rs index 5d16f176..ffa4bc4c 100644 --- a/alu_u32/src/bitwise/mod.rs +++ b/alu_u32/src/bitwise/mod.rs @@ -13,7 +13,7 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; use valida_util::pad_to_power_of_two; pub mod columns; diff --git a/alu_u32/src/div/mod.rs b/alu_u32/src/div/mod.rs index 410cb0c8..60cce76b 100644 --- a/alu_u32/src/div/mod.rs +++ b/alu_u32/src/div/mod.rs @@ -15,9 +15,9 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; -use valida_util::pad_to_power_of_two; +use valida_util::pad_to_power_of_two; +use p3_uni_stark::StarkConfig; pub mod columns; pub mod stark; diff --git a/alu_u32/src/lt/mod.rs b/alu_u32/src/lt/mod.rs index 2dd34959..364ec7b5 100644 --- a/alu_u32/src/lt/mod.rs +++ b/alu_u32/src/lt/mod.rs @@ -16,9 +16,9 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; -use valida_util::pad_to_power_of_two; +use valida_util::pad_to_power_of_two; +use p3_uni_stark::StarkConfig; pub mod columns; pub mod stark; diff --git a/alu_u32/src/mul/mod.rs b/alu_u32/src/mul/mod.rs index 45d4c800..c43155ee 100644 --- a/alu_u32/src/mul/mod.rs +++ b/alu_u32/src/mul/mod.rs @@ -13,7 +13,7 @@ use core::borrow::BorrowMut; use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; pub mod columns; pub mod stark; diff --git a/alu_u32/src/shift/mod.rs b/alu_u32/src/shift/mod.rs index b9a0452a..6f5b2df3 100644 --- a/alu_u32/src/shift/mod.rs +++ b/alu_u32/src/shift/mod.rs @@ -15,7 +15,7 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; use valida_util::pad_to_power_of_two; pub mod columns; diff --git a/alu_u32/src/sub/mod.rs b/alu_u32/src/sub/mod.rs index bd92797f..d935acc2 100644 --- a/alu_u32/src/sub/mod.rs +++ b/alu_u32/src/sub/mod.rs @@ -14,7 +14,8 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; + use valida_util::pad_to_power_of_two; pub mod columns; diff --git a/basic/src/lib.rs b/basic/src/lib.rs index 1dcacee2..55128a79 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -16,7 +16,7 @@ use p3_uni_stark::{ ProverConstraintFolder, ProverData, StarkConfig, SymbolicAirBuilder, }; use p3_util::log2_ceil_usize; - +use p3_field::PrimeField32; use valida_alu_u32::{ add::{Add32Chip, Add32Instruction, MachineWithAdd32Chip}, bitwise::{ @@ -53,7 +53,7 @@ use valida_program::{MachineWithProgramChip, ProgramChip}; use valida_range::{MachineWithRangeChip, RangeCheckerChip}; #[derive(Default)] -pub struct BasicMachine> { +pub struct BasicMachine { // Core instructions load32: Load32Instruction, @@ -276,86 +276,85 @@ impl MachineWithRangeChip for BasicMachi } } -impl> Machine for BasicMachine { - type F = F; - type EF = EF; +impl Machine for BasicMachine { + fn run(&mut self, program: &ProgramROM, advice: &mut Adv) { loop { - let pc = self.cpu().pc; + let pc = self.cpu.pc; let instruction = program.get_instruction(pc); let opcode = instruction.opcode; let ops = instruction.operands; match opcode { - >::OPCODE => { + >::OPCODE => { Load32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Store32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { JalInstruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { JalvInstruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { BeqInstruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { BneInstruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Imm32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Add32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Sub32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Mul32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Mulhs32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Mulhu32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Div32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { SDiv32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Shl32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Shr32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Sra32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Lt32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { And32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Or32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { Xor32Instruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { ReadAdviceInstruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { WriteInstruction::execute_with_advice(self, ops, advice); } - >::OPCODE => { + >::OPCODE => { StopInstruction::execute_with_advice(self, ops, advice); } _ => {} @@ -363,13 +362,13 @@ impl> Machine for BasicMac self.read_word(pc as usize); - if opcode == >::OPCODE { + if opcode == >::OPCODE { break; } } - let n = self.cpu().clock.next_power_of_two() - self.cpu().clock; + let n = self.cpu.clock.next_power_of_two() - self.cpu.clock; for _ in 0..n { - self.read_word(self.cpu().pc as usize); + self.read_word(self.cpu.pc as usize); } } fn add_chip_trace( @@ -395,16 +394,16 @@ impl> Machine for BasicMac } fn prove(&self, config: &SC, challenger: &mut SC::Challenger) -> MachineProof where - SC: StarkConfig, + SC: StarkConfig, { let mut trace_commitments = Vec::new(); let mut quotient_commitments = Vec::new(); let mut log_degrees = Vec::new(); let mut log_quotient_degrees = Vec::new(); - - let air = &self.cpu; +/* + let air = &self.cpu(); assert_eq!(air.operations.len() > 0, true); - let trace = air.generate_trace(self); + let trace = air.generate_trace(air, self); self.add_chip_trace( config, challenger, @@ -415,10 +414,10 @@ impl> Machine for BasicMac air, trace, ); - +*/ if self.add_u32.operations.len() > 0 { let air = &self.add_u32; - let trace = air.generate_trace(self); + let trace = , SC>>::generate_trace(air,self); self.add_chip_trace( config, @@ -433,7 +432,8 @@ impl> Machine for BasicMac } if self.sub_u32.operations.len() > 0 { let air = &self.sub_u32; - let trace = air.generate_trace(self); + let trace = , SC>>::generate_trace(air, self); + self.add_chip_trace( config, challenger, @@ -447,7 +447,8 @@ impl> Machine for BasicMac } if self.mul_u32.operations.len() > 0 { let air = &self.mul_u32; - let trace = air.generate_trace(self); + let trace =, SC>>::generate_trace(air, self); + self.add_chip_trace( config, challenger, @@ -461,7 +462,8 @@ impl> Machine for BasicMac } if self.div_u32.operations.len() > 0 { let air = &self.div_u32; - let trace = air.generate_trace(self); + + let trace = , SC>>::generate_trace(air, self); self.add_chip_trace( config, challenger, @@ -475,7 +477,9 @@ impl> Machine for BasicMac } if self.shift_u32.operations.len() > 0 { let air = &self.shift_u32; - let trace = air.generate_trace(self); + let trace = , SC>>::generate_trace(air, self); + + self.add_chip_trace( config, challenger, @@ -489,7 +493,8 @@ impl> Machine for BasicMac } if self.lt_u32.operations.len() > 0 { let air = &self.lt_u32; - let trace = air.generate_trace(self); + let trace = , SC>>::generate_trace(air, self); + self.add_chip_trace( config, challenger, @@ -504,7 +509,8 @@ impl> Machine for BasicMac if self.bitwise_u32.operations.len() > 0 { let air = &self.bitwise_u32; - let trace = air.generate_trace(self); + let trace = , SC>>::generate_trace(air, self); + self.add_chip_trace( config, challenger, @@ -551,7 +557,7 @@ impl> Machine for BasicMac fn verify(proof: &MachineProof) -> Result<(), ()> where - SC: StarkConfig, + SC: StarkConfig, { Ok(()) } diff --git a/cpu/Cargo.toml b/cpu/Cargo.toml index 35de0dc3..b2f883b1 100644 --- a/cpu/Cargo.toml +++ b/cpu/Cargo.toml @@ -10,7 +10,7 @@ p3-baby-bear = { path = "../../Plonky3/baby-bear" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark"} valida-bus = { path = "../bus" } valida-machine = { path = "../machine" } valida-memory = { path = "../memory" } diff --git a/cpu/src/lib.rs b/cpu/src/lib.rs index 6fef97d7..f2ff0c1c 100644 --- a/cpu/src/lib.rs +++ b/cpu/src/lib.rs @@ -23,7 +23,7 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; pub mod columns; pub mod stark; diff --git a/machine/src/__internal/check_constraints.rs b/machine/src/__internal/check_constraints.rs index 424c7af5..4fcaf766 100644 --- a/machine/src/__internal/check_constraints.rs +++ b/machine/src/__internal/check_constraints.rs @@ -1,6 +1,7 @@ use crate::__internal::DebugConstraintBuilder; use crate::chip::eval_permutation_constraints; -use crate::config::StarkConfig; +use p3_uni_stark::StarkConfig; + use crate::{Chip, Machine}; use p3_air::{Air, TwoRowMatrixView}; use p3_field::{AbstractField, Field}; diff --git a/machine/src/__internal/debug_builder.rs b/machine/src/__internal/debug_builder.rs index 6cfcaa08..37be734f 100644 --- a/machine/src/__internal/debug_builder.rs +++ b/machine/src/__internal/debug_builder.rs @@ -1,8 +1,7 @@ -use crate::config::StarkConfig; use crate::{Machine, ValidaAirBuilder}; use p3_air::{AirBuilder, PairBuilder, PermutationAirBuilder, TwoRowMatrixView}; use p3_field::AbstractField; - +use p3_uni_stark::StarkConfig; /// An `AirBuilder` which asserts that each constraint is zero, allowing any failed constraints to /// be detected early. pub struct DebugConstraintBuilder<'a, M: Machine, SC: StarkConfig> { diff --git a/machine/src/__internal/folding_builder.rs b/machine/src/__internal/folding_builder.rs index 85ecfea3..0f646d91 100644 --- a/machine/src/__internal/folding_builder.rs +++ b/machine/src/__internal/folding_builder.rs @@ -1,6 +1,6 @@ use crate::{Machine, ValidaAirBuilder}; use p3_air::{AirBuilder, PairBuilder, PermutationAirBuilder, TwoRowMatrixView}; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; pub struct ConstraintFolder<'a, M: Machine, SC: StarkConfig> { pub(crate) machine: &'a M, diff --git a/machine/src/chip.rs b/machine/src/chip.rs index 7719a36b..49d16220 100644 --- a/machine/src/chip.rs +++ b/machine/src/chip.rs @@ -4,7 +4,8 @@ use alloc::vec; use alloc::vec::Vec; use valida_util::batch_multiplicative_inverse; -use crate::config::StarkConfig; +//use crate::config::StarkConfig; +use p3_uni_stark::StarkConfig; use p3_air::{Air, AirBuilder, PairBuilder, PermutationAirBuilder, VirtualPairCol}; use p3_field::{AbstractExtensionField, AbstractField, ExtensionField, Field, Powers}; use p3_matrix::{dense::RowMajorMatrix, Matrix, MatrixRowSlices}; diff --git a/machine/src/lib.rs b/machine/src/lib.rs index bdc1e6c9..4faf352a 100644 --- a/machine/src/lib.rs +++ b/machine/src/lib.rs @@ -177,7 +177,7 @@ pub trait Machine { fn prove(&self, config: &SC, challenger: &mut SC::Challenger) -> MachineProof where - SC: StarkConfig; + SC: StarkConfig; fn verify>(proof: &MachineProof) -> Result<(), ()>; } diff --git a/memory/Cargo.toml b/memory/Cargo.toml index cf010ded..cb4c1a2e 100644 --- a/memory/Cargo.toml +++ b/memory/Cargo.toml @@ -10,7 +10,7 @@ p3-baby-bear = { path = "../../Plonky3/baby-bear" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark" } valida-bus = { path = "../bus" } valida-machine = { path = "../machine" } valida-derive = { path = "../derive" } diff --git a/memory/src/lib.rs b/memory/src/lib.rs index 360c8b56..3e9f46d9 100644 --- a/memory/src/lib.rs +++ b/memory/src/lib.rs @@ -10,12 +10,12 @@ use core::mem::transmute; use valida_bus::MachineWithMemBus; use valida_machine::{BusArgument, Chip, Interaction, Machine, Word}; use valida_util::batch_multiplicative_inverse; - +use p3_uni_stark::StarkConfig; use p3_air::VirtualPairCol; use p3_field::{Field, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; + pub mod columns; pub mod stark; diff --git a/native_field/Cargo.toml b/native_field/Cargo.toml index ea2fd887..7229c013 100644 --- a/native_field/Cargo.toml +++ b/native_field/Cargo.toml @@ -11,7 +11,7 @@ p3-air = { path = "../../Plonky3/air" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark" } valida-bus = { path = "../bus" } valida-derive = { path = "../derive" } valida-machine = { path = "../machine" } diff --git a/native_field/src/lib.rs b/native_field/src/lib.rs index 382db7ea..66b67b53 100644 --- a/native_field/src/lib.rs +++ b/native_field/src/lib.rs @@ -17,7 +17,8 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field, PrimeField32}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; + pub mod columns; pub mod stark; diff --git a/output/Cargo.toml b/output/Cargo.toml index 755842be..a147be2c 100644 --- a/output/Cargo.toml +++ b/output/Cargo.toml @@ -10,7 +10,7 @@ p3-baby-bear = { path = "../../Plonky3/baby-bear" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark"} valida-bus = { path = "../bus" } valida-cpu = { path = "../cpu" } valida-machine = { path = "../machine" } diff --git a/output/src/lib.rs b/output/src/lib.rs index 31fc6179..158e24cb 100644 --- a/output/src/lib.rs +++ b/output/src/lib.rs @@ -12,7 +12,7 @@ use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::*; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; use valida_util::pad_to_power_of_two; pub mod columns; diff --git a/program/Cargo.toml b/program/Cargo.toml index 7c1f984d..82c42f03 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" p3-air = { path = "../../Plonky3/air" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } - +p3-uni-stark = {path = "../../Plonky3/uni-stark"} valida-bus = { path = "../bus" } valida-derive = { path = "../derive" } valida-machine = { path = "../machine" } diff --git a/program/src/lib.rs b/program/src/lib.rs index 151300cf..bc49796b 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -12,7 +12,7 @@ use valida_util::pad_to_power_of_two; use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field}; use p3_matrix::dense::RowMajorMatrix; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; pub mod columns; pub mod stark; diff --git a/range/Cargo.toml b/range/Cargo.toml index 9b72e6e2..81f49ece 100644 --- a/range/Cargo.toml +++ b/range/Cargo.toml @@ -10,7 +10,7 @@ p3-baby-bear = { path = "../../Plonky3/baby-bear" } p3-field = { path = "../../Plonky3/field" } p3-matrix = { path = "../../Plonky3/matrix" } p3-maybe-rayon = { path = "../../Plonky3/maybe-rayon" } - +p3-uni-stark = { path = "../../Plonky3/uni-stark" } valida-bus = { path = "../bus" } valida-machine = { path = "../machine" } valida-util = { path = "../util" } diff --git a/range/src/lib.rs b/range/src/lib.rs index aa988357..45bd3bc8 100644 --- a/range/src/lib.rs +++ b/range/src/lib.rs @@ -14,7 +14,8 @@ use valida_machine::{Chip, Machine, Word}; use p3_air::VirtualPairCol; use p3_field::{AbstractField, Field}; use p3_matrix::dense::RowMajorMatrix; -use valida_machine::config::StarkConfig; +use p3_uni_stark::StarkConfig; + pub mod columns; pub mod stark;