Skip to content
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
10 changes: 5 additions & 5 deletions crates/starknet_proof_verifier/src/proof_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ProgramOutput {
/// The bootloader output for a single task is:
/// `[num_tasks, output_size, program_hash, ...task_output...]`
///
/// We replace `num_tasks` with `[PROOF_VERSION_V0, program_variant]` and skip `output_size`,
/// We replace `num_tasks` with `[PROOF_VERSION_V1, program_variant]` and skip `output_size`,
/// which is a bootloader-internal field not part of the proof facts.
pub fn try_into_proof_facts(
&self,
Expand All @@ -87,7 +87,7 @@ impl ProgramOutput {
return Err(ProgramOutputError::TooShort(self.0.len()));
}
// Add the proof version and variant markers in place of num_tasks.
let mut facts = vec![ProofVersion::V0.as_felt()];
let mut facts = vec![ProofVersion::V1.as_felt()];
Comment thread
cursor[bot] marked this conversation as resolved.
facts.push(program_variant);
// Skip num_tasks (index 0) and output_size (index 1); add the task output
// (program_hash followed by the virtual OS output).
Expand All @@ -104,17 +104,17 @@ impl From<Vec<Felt>> for ProgramOutput {

/// Reconstructs the output preimage from proof facts for circuit verification.
///
/// Proof facts layout: `[PROOF_VERSION_V0, variant, program_hash, ...task_output]`
/// Proof facts layout: `[PROOF_VERSION_V*, variant, program_hash, ...task_output]`
/// Output preimage layout: `[num_tasks=1, output_size, program_hash, ...task_output]`
/// where `output_size = task_content.len() + 1` (includes itself).
pub fn reconstruct_output_preimage(
proof_facts: &ProofFacts,
) -> Result<Vec<Felt>, VerifyProofError> {
// Proof facts must contain at least [PROOF_VERSION_V0, variant, program_hash].
// Proof facts must contain at least [PROOF_VERSION_V*, variant, program_hash].
if proof_facts.0.len() < 3 {
return Err(VerifyProofError::ProofFactsTooShort { length: proof_facts.0.len() });
}
// Skip PROOF_VERSION_V0 (index 0) and variant (index 1).
// Skip PROOF_VERSION_V* (index 0) and variant (index 1).
let task_content = &proof_facts.0[2..];
let output_size = Felt::from(
u64::try_from(task_content.len() + 1).expect("task content length exceeds u64::MAX"),
Expand Down
6 changes: 3 additions & 3 deletions crates/starknet_proof_verifier/src/proof_verifier_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rstest::rstest;
use starknet_api::test_utils::{path_in_resources, read_json_file};
use starknet_api::transaction::fields::{Proof, ProofFacts, PROOF_VERSION_V0};
use starknet_api::transaction::fields::{Proof, ProofFacts, ProofVersion};
use starknet_types_core::felt::Felt;

use crate::{reconstruct_output_preimage, verify_proof, ProgramOutput};
Expand All @@ -21,8 +21,8 @@ fn roundtrip_program_output_to_proof_facts_and_back() {
let program_variant = Felt::from(0x42_u64);
let proof_facts = program_output.try_into_proof_facts(program_variant).unwrap();

// Verify the proof facts structure: [PROOF_VERSION_V0, variant, program_hash, ...task_output].
assert_eq!(proof_facts.0[0], PROOF_VERSION_V0);
// Verify the proof facts structure: [PROOF_VERSION_V1, variant, program_hash, ...task_output].
assert_eq!(proof_facts.0[0], ProofVersion::V1.as_felt());
assert_eq!(proof_facts.0[1], program_variant);
assert_eq!(proof_facts.0[2], program_hash);
assert_eq!(&proof_facts.0[3..], &task_output);
Expand Down
Loading