diff --git a/basic/src/lib.rs b/basic/src/lib.rs index 9343cde..899e128 100644 --- a/basic/src/lib.rs +++ b/basic/src/lib.rs @@ -47,7 +47,7 @@ use valida_machine::__internal::{ }; use valida_machine::{ generate_permutation_trace, verify_constraints, AdviceProvider, BusArgument, Chip, ChipProof, - Commitments, Instruction, Machine, MachineProof, OpenedValues, ProgramROM, StoppingFlag, + Commitments, Instruction, Machine, MachineProof, OpenedValues, ProgramROM, StoppingFlag, ColumnVector, ColumnIndex, ValidaAirBuilder, }; use valida_memory::{MachineWithMemoryChip, MemoryChip}; @@ -260,6 +260,7 @@ impl Machine for BasicMachine { let alpha: SC::Challenge = challenger.sample_ext_element(); let mut quotients: Vec> = vec![]; + let mut public_inputs: Vec)>> = vec![]; let mut i: usize = 0; @@ -284,6 +285,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.program(); @@ -307,6 +309,9 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(Chip::generate_public_inputs( + chip as &dyn Chip, + )); i += 1; let chip = self.mem(); @@ -330,6 +335,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.add_u32(); @@ -353,6 +359,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.sub_u32(); @@ -376,6 +383,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.mul_u32(); @@ -399,6 +407,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.div_u32(); @@ -422,6 +431,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.shift_u32(); @@ -445,6 +455,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.lt_u32(); @@ -468,6 +479,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.com_u32(); @@ -491,6 +503,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.bitwise_u32(); @@ -514,6 +527,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.output(); @@ -537,6 +551,9 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(Chip::generate_public_inputs( + chip as &dyn Chip, + )); i += 1; let chip = self.range(); @@ -560,6 +577,7 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(vec![]); i += 1; let chip = self.static_data(); @@ -583,6 +601,9 @@ impl Machine for BasicMachine { &perm_challenges, alpha, )); + public_inputs.push(Chip::generate_public_inputs( + chip as &dyn Chip, + )); i += 1; assert_eq!(quotients.len(), NUM_CHIPS); @@ -633,7 +654,8 @@ impl Machine for BasicMachine { .zip(perm_openings) .zip(quotient_openings) .zip(perm_traces) - .map(|((((log_degree, main), perm), quotient), perm_trace)| { + .zip(public_inputs) + .map(|(((((log_degree, main), perm), quotient), perm_trace), public_inputs)| { // TODO: add preprocessed openings let [preprocessed_local, preprocessed_next] = [vec![], vec![]]; @@ -657,7 +679,7 @@ impl Machine for BasicMachine { .unwrap() .clone(); ChipProof { - public_inputs: vec![], + public_inputs, log_degree: *log_degree, opened_values, cumulative_sum, diff --git a/basic_macro/src/lib.rs b/basic_macro/src/lib.rs index 8d2b44e..51c85f1 100644 --- a/basic_macro/src/lib.rs +++ b/basic_macro/src/lib.rs @@ -40,7 +40,7 @@ use valida_cpu::{CpuChip, MachineWithCpuChip}; use valida_derive::Machine; use valida_machine::{ AdviceProvider, BusArgument, Chip, ChipProof, Instruction, Machine, MachineProof, ProgramROM, - StoppingFlag, ValidaAirBuilder, + StoppingFlag, ValidaAirBuilder, ColumnVector, ColumnIndex, }; use valida_memory::{MachineWithMemoryChip, MemoryChip}; use valida_output::{MachineWithOutputChip, OutputChip, WriteInstruction}; diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 9d7b25d..646883e 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -268,6 +268,9 @@ fn prove_method(chips: &[&Field]) -> TokenStream2 { &perm_challenges, alpha, )); + public_inputs.push(Chip::generate_public_inputs( + self.#chip_name() as &dyn Chip, + )); } }) .collect::(); @@ -283,7 +286,7 @@ fn prove_method(chips: &[&Field]) -> TokenStream2 { use ::valida_machine::__internal::p3_commit::{Pcs, UnivariatePcs, UnivariatePcsWithLde}; use ::valida_machine::__internal::p3_matrix::{Matrix, MatrixRowSlices, dense::RowMajorMatrix}; use ::valida_machine::__internal::p3_util::log2_strict_usize; - use ::valida_machine::{generate_permutation_trace, MachineProof, ChipProof, Commitments}; + use ::valida_machine::{generate_permutation_trace, Chip, MachineProof, ChipProof, Commitments}; use ::valida_machine::OpenedValues; use alloc::vec; use alloc::vec::Vec; @@ -360,6 +363,7 @@ fn prove_method(chips: &[&Field]) -> TokenStream2 { let alpha: SC::Challenge = challenger.sample_ext_element(); let mut quotients: Vec> = vec![]; + let mut public_inputs: Vec)>> = vec![]; #compute_quotients assert_eq!(quotients.len(), #num_chips); assert_eq!(log_quotient_degrees.len(), #num_chips); @@ -409,7 +413,8 @@ fn prove_method(chips: &[&Field]) -> TokenStream2 { .zip(perm_openings) .zip(quotient_openings) .zip(perm_traces) - .map(|((((log_degree, main), perm), quotient), perm_trace)| { + .zip(public_inputs) + .map(|(((((log_degree, main), perm), quotient), perm_trace), public_inputs)| { // TODO: add preprocessed openings let [preprocessed_local, preprocessed_next] = [vec![], vec![]]; @@ -430,7 +435,7 @@ fn prove_method(chips: &[&Field]) -> TokenStream2 { let cumulative_sum = perm_trace.row_slice(perm_trace.height() - 1).last().unwrap().clone(); ChipProof { - public_inputs: vec![], + public_inputs, log_degree: *log_degree, opened_values, cumulative_sum, diff --git a/machine/src/chip.rs b/machine/src/chip.rs index afd6e09..691d0fa 100644 --- a/machine/src/chip.rs +++ b/machine/src/chip.rs @@ -1,5 +1,5 @@ use crate::folding_builder::VerifierConstraintFolder; -use crate::Machine; +use crate::{Machine, ColumnVector, ColumnIndex}; use crate::__internal::{DebugConstraintBuilder, ProverConstraintFolder}; use alloc::vec; use alloc::vec::Vec; @@ -21,6 +21,10 @@ pub trait Chip, SC: StarkConfig>: /// Generate the main trace for the chip given the provided machine. fn generate_trace(&self, machine: &M) -> RowMajorMatrix; + fn generate_public_inputs(&self) -> Vec<(ColumnIndex, ColumnVector)> { + vec![] + } + fn local_sends(&self) -> Vec> { vec![] }