Skip to content

Commit

Permalink
bug fix: e2e halt check
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Mar 6, 2025
1 parent e8197db commit 3e3ebfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
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();
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

0 comments on commit 3e3ebfa

Please sign in to comment.