Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update core verifier with public values constraints #493

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions core/src/stark/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,31 +242,50 @@ impl<SC: StarkGenericConfig, A: MachineAir<Val<SC>>> MachineStark<SC, A> {
{
// Observe the preprocessed commitment.
challenger.observe(vk.commit.clone());
// TODO: Observe the challenges in a tree-like structure for easily verifiable reconstruction
// in a map-reduce recursion setting.
tracing::debug_span!("observe challenges for all shards").in_scope(|| {
proof.shard_proofs.iter().for_each(|proof| {
challenger.observe(proof.commitment.main_commit.clone());
let public_values =
PublicValues::<Word<Val<SC>>, Val<SC>>::new(proof.public_values);
challenger.observe_slice(&public_values.to_vec());
});

// Observe the challenges.
proof.shard_proofs.iter().for_each(|proof| {
challenger.observe(proof.commitment.main_commit.clone());
let public_values = PublicValues::<Word<Val<SC>>, Val<SC>>::new(proof.public_values);
challenger.observe_slice(&public_values.to_vec());
});

// Verify the segment proofs.
tracing::info!("verifying shard proofs");
for (i, proof) in proof.shard_proofs.iter().enumerate() {
tracing::debug_span!("verifying shard", segment = i).in_scope(|| {
let chips = self
.shard_chips_ordered(&proof.chip_ordering)
.collect::<Vec<_>>();
Verifier::verify_shard(&self.config, vk, &chips, &mut challenger.clone(), proof)
.map_err(ProgramVerificationError::InvalidSegmentProof)
})?;
// Verify the shards.
for proof in proof.shard_proofs.iter() {
let chips = self
.shard_chips_ordered(&proof.chip_ordering)
.collect::<Vec<_>>();
Verifier::verify_shard(&self.config, vk, &chips, &mut challenger.clone(), proof)
.map_err(ProgramVerificationError::InvalidSegmentProof)?;
}

// Verify the public values for each shard.
for i in 0..proof.shard_proofs.len() {
let curr = &proof.shard_proofs[i];

// Assert that the shard number is correct.
assert_eq!(curr.public_values.shard, (i + 1) as u32);
}
tracing::info!("verifying individual shards succeeded");

tracing::info!("verifying cumulative sum is 0");
// Verify the public values between shards.
for i in 1..proof.shard_proofs.len() {
let curr = &proof.shard_proofs[i];
let prev = &proof.shard_proofs[i - 1];

// Assert that the program counter is carried over correctly.
assert_eq!(prev.public_values.next_pc, curr.public_values.start_pc);

// Assert that the public values digest is the same.
assert_eq!(
prev.public_values.committed_value_digest,
curr.public_values.committed_value_digest
);
}

// Verify the public values of the last shard.
let last = &proof.shard_proofs[proof.shard_proofs.len() - 1];
assert_eq!(last.public_values.exit_code, 0);

// Verify the cumulative sum is 0.
let mut sum = SC::Challenge::zero();
for proof in proof.shard_proofs.iter() {
Expand Down
2 changes: 0 additions & 2 deletions core/src/stark/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ impl<SC: StarkGenericConfig, A: MachineAir<Val<SC>>> Verifier<SC, A> {
)
.map_err(|_| VerificationError::InvalidopeningArgument)?;

// Verify the constrtaint evaluations.

for (chip, trace_domain, qc_domains, values) in izip!(
chips.iter(),
trace_domains,
Expand Down
2 changes: 2 additions & 0 deletions eval/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(generic_const_exprs)]

use clap::{command, Parser};
use csv::WriterBuilder;
use serde::Serialize;
Expand Down
14 changes: 2 additions & 12 deletions examples/fibonacci/program/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Loading
Loading