Skip to content

Commit

Permalink
issue/155: wip: generate public inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
morganthomas committed Apr 21, 2024
1 parent 90f1f55 commit 75a2471
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
28 changes: 25 additions & 3 deletions basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -260,6 +260,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
let alpha: SC::Challenge = challenger.sample_ext_element();

let mut quotients: Vec<RowMajorMatrix<SC::Val>> = vec![];
let mut public_inputs: Vec<Vec<(ColumnIndex, ColumnVector<SC::Val>)>> = vec![];

let mut i: usize = 0;

Expand All @@ -284,6 +285,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.program();
Expand All @@ -307,6 +309,9 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(Chip::generate_public_inputs(
chip as &dyn Chip<Self, SC>,
));
i += 1;

let chip = self.mem();
Expand All @@ -330,6 +335,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.add_u32();
Expand All @@ -353,6 +359,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.sub_u32();
Expand All @@ -376,6 +383,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.mul_u32();
Expand All @@ -399,6 +407,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.div_u32();
Expand All @@ -422,6 +431,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.shift_u32();
Expand All @@ -445,6 +455,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.lt_u32();
Expand All @@ -468,6 +479,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.com_u32();
Expand All @@ -491,6 +503,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.bitwise_u32();
Expand All @@ -514,6 +527,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.output();
Expand All @@ -537,6 +551,9 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(Chip::generate_public_inputs(
chip as &dyn Chip<Self, SC>,
));
i += 1;

let chip = self.range();
Expand All @@ -560,6 +577,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(vec![]);
i += 1;

let chip = self.static_data();
Expand All @@ -583,6 +601,9 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
&perm_challenges,
alpha,
));
public_inputs.push(Chip::generate_public_inputs(
chip as &dyn Chip<Self, SC>,
));
i += 1;

assert_eq!(quotients.len(), NUM_CHIPS);
Expand Down Expand Up @@ -633,7 +654,8 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
.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![]];

Expand All @@ -657,7 +679,7 @@ impl<F: PrimeField32 + TwoAdicField> Machine<F> for BasicMachine<F> {
.unwrap()
.clone();
ChipProof {
public_inputs: vec![],
public_inputs,
log_degree: *log_degree,
opened_values,
cumulative_sum,
Expand Down
2 changes: 1 addition & 1 deletion basic_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
11 changes: 8 additions & 3 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, SC>,
));
}
})
.collect::<TokenStream2>();
Expand All @@ -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;
Expand Down Expand Up @@ -360,6 +363,7 @@ fn prove_method(chips: &[&Field]) -> TokenStream2 {
let alpha: SC::Challenge = challenger.sample_ext_element();

let mut quotients: Vec<RowMajorMatrix<SC::Val>> = vec![];
let mut public_inputs: Vec<Vec<(ColumnIndex, ColumnVector<SC::Val>)>> = vec![];
#compute_quotients
assert_eq!(quotients.len(), #num_chips);
assert_eq!(log_quotient_degrees.len(), #num_chips);
Expand Down Expand Up @@ -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![]];
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion machine/src/chip.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +21,10 @@ pub trait Chip<M: Machine<SC::Val>, SC: StarkConfig>:
/// Generate the main trace for the chip given the provided machine.
fn generate_trace(&self, machine: &M) -> RowMajorMatrix<SC::Val>;

fn generate_public_inputs(&self) -> Vec<(ColumnIndex, ColumnVector<SC::Val>)> {
vec![]
}

fn local_sends(&self) -> Vec<Interaction<SC::Val>> {
vec![]
}
Expand Down

0 comments on commit 75a2471

Please sign in to comment.