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

bug fix: e2e missed proof validity check #854

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion ceno_zkvm/src/bin/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ fn main() {
// do statistics
let stat_recorder = StatisticRecorder::default();
let transcript = TranscriptWithStat::new(&stat_recorder, b"riscv");
verifier.verify_proof(zkvm_proof.clone(), transcript).ok();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check was missing before fix

assert!(
verifier
.verify_proof_halt(zkvm_proof.clone(), transcript, zkvm_proof.has_halt())
.is_ok()
);
println!("e2e proof stat: {}", zkvm_proof);
println!(
"hashes count = {}",
Expand Down
20 changes: 19 additions & 1 deletion ceno_zkvm/src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use std::{
};
use sumcheck::structs::IOPProverMessage;

use crate::structs::TowerProofs;
use crate::{
instructions::{Instruction, riscv::ecall::HaltInstruction},
structs::TowerProofs,
};

pub mod constants;
pub mod prover;
Expand Down Expand Up @@ -168,6 +171,21 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProof<E, PCS> {
pub fn num_circuits(&self) -> usize {
self.opcode_proofs.len() + self.table_proofs.len()
}

pub fn has_halt(&self) -> bool {
let halt_instance_count = self
.opcode_proofs
.get(&HaltInstruction::<E>::name())
.map(|(_, p)| p.num_instances)
.unwrap_or(0);
if halt_instance_count > 0 {
assert_eq!(
halt_instance_count, 1,
"abnormal halt instance count {halt_instance_count} != 1"
);
}
halt_instance_count == 1
}
}

impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Display
Expand Down
14 changes: 4 additions & 10 deletions ceno_zkvm/src/scheme/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use transcript::{ForkableTranscript, Transcript};
use crate::{
error::ZKVMError,
expression::{Instance, StructuralWitIn},
instructions::{Instruction, riscv::ecall::HaltInstruction},
scheme::{
constants::{NUM_FANIN, NUM_FANIN_LOGUP, SEL_DEGREE},
utils::eval_by_expr_with_instance,
Expand Down Expand Up @@ -56,18 +55,13 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMVerifier<E, PCS>
&self,
vm_proof: ZKVMProof<E, PCS>,
transcript: impl ForkableTranscript<E>,
does_halt: bool,
expect_halt: bool,
) -> Result<bool, ZKVMError> {
// require ecall/halt proof to exist, depending whether we expect a halt.
let num_instances = vm_proof
.opcode_proofs
.get(&HaltInstruction::<E>::name())
.map(|(_, p)| p.num_instances)
.unwrap_or(0);
if num_instances != (does_halt as usize) {
let has_halt = vm_proof.has_halt();
if has_halt != expect_halt {
return Err(ZKVMError::VerifyError(format!(
"ecall/halt num_instances={}, expected={}",
num_instances, does_halt as usize
"ecall/halt mismatch: expected {expect_halt} != {has_halt}",
)));
}

Expand Down