Skip to content
Merged
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
4 changes: 2 additions & 2 deletions crates/starknet_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::transaction::fields::{
ProofFacts,
ResourceBounds,
ValidResourceBounds,
PROOF_VERSION,
PROOF_VERSION_V0,
VIRTUAL_OS_OUTPUT_VERSION,
VIRTUAL_SNOS,
};
Expand Down Expand Up @@ -413,7 +413,7 @@ impl ProofFacts {
// These fields are not verified by the OS (they are application-related).
let l2_to_l1_messages_segment_size = Felt::ZERO;
proof_facts![
PROOF_VERSION,
PROOF_VERSION_V0,
VIRTUAL_SNOS,
program_hash,
VIRTUAL_OS_OUTPUT_VERSION,
Expand Down
12 changes: 6 additions & 6 deletions crates/starknet_api/src/transaction/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ impl AccountDeploymentData {
// Represent the string `VIRTUAL_SNOS` as a Felt.
pub const VIRTUAL_SNOS: Felt = Felt::from_hex_unchecked("0x5649525455414c5f534e4f53");

// Represent the `PROOF_VERSION` marker as a Felt ('PROOF0').
pub const PROOF_VERSION: Felt = Felt::from_hex_unchecked("0x50524f4f4630");
// Represent the `PROOF_VERSION_V0` marker as a Felt ('PROOF0').
pub const PROOF_VERSION_V0: Felt = Felt::from_hex_unchecked("0x50524f4f4630");

/// The version of the virtual OS output (short string 'VIRTUAL_SNOS0').
/// This must match the Cairo constant `VIRTUAL_OS_OUTPUT_VERSION` in `virtual_os_output.cairo`.
Expand Down Expand Up @@ -681,11 +681,11 @@ impl TryFrom<&ProofFacts> for ProofFactsVariant {
)));
};

// Validate that the first element is PROOF_VERSION.
if *proof_version != PROOF_VERSION {
// Validate that the first element is PROOF_VERSION_V0.
if *proof_version != PROOF_VERSION_V0 {
return Err(StarknetApiError::InvalidProofFacts(format!(
"Expected first field to be {} (PROOF_VERSION), but got {}",
PROOF_VERSION, proof_version
"Expected first field to be {} (PROOF_VERSION_V0), but got {}",
PROOF_VERSION_V0, proof_version
)));
}

Expand Down
10 changes: 7 additions & 3 deletions crates/starknet_os/src/constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use starknet_api::core::{
L2_ADDRESS_UPPER_BOUND,
STARKNET_OS_CONFIG_HASH_VERSION,
};
use starknet_api::transaction::fields::{PROOF_VERSION, VIRTUAL_OS_OUTPUT_VERSION, VIRTUAL_SNOS};
use starknet_api::transaction::fields::{
PROOF_VERSION_V0,
VIRTUAL_OS_OUTPUT_VERSION,
VIRTUAL_SNOS,
};
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
use starknet_committer::hash_function::hash::CONTRACT_CLASS_LEAF_V0;

Expand Down Expand Up @@ -78,10 +82,10 @@ fn test_virtual_snos() {
assert_eq!(Const::VirtualSnos.fetch_from_os_program().unwrap(), VIRTUAL_SNOS);
}

/// Asserts that the Rust PROOF_VERSION constant matches the Cairo constant.
/// Asserts that the Rust PROOF_VERSION_V0 constant matches the Cairo constant.
#[test]
fn test_proof_version() {
assert_eq!(Const::ProofVersion.fetch_from_os_program().unwrap(), PROOF_VERSION);
assert_eq!(Const::ProofVersion.fetch_from_os_program().unwrap(), PROOF_VERSION_V0);
}

/// Asserts that the Rust STARKNET_OS_CONFIG_HASH_VERSION constant matches the Cairo constant.
Expand Down
16 changes: 8 additions & 8 deletions crates/starknet_proof_verifier/src/proof_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use apollo_sizeof::SizeOf;
use privacy_circuit_verify::{verify_recursive_circuit, PrivacyProofOutput};
use serde::{Deserialize, Serialize};
use starknet_api::transaction::fields::{Proof, ProofFacts, PROOF_VERSION};
use starknet_api::transaction::fields::{Proof, ProofFacts, PROOF_VERSION_V0};
use starknet_types_core::felt::Felt;
use thiserror::Error;

Expand Down Expand Up @@ -68,7 +68,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, program_variant]` and skip `output_size`,
/// We replace `num_tasks` with `[PROOF_VERSION_V0, 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 @@ -83,7 +83,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![PROOF_VERSION];
let mut facts = vec![PROOF_VERSION_V0];
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 @@ -100,17 +100,17 @@ impl From<Vec<Felt>> for ProgramOutput {

/// Reconstructs the output preimage from proof facts for circuit verification.
///
/// Proof facts layout: `[PROOF_VERSION, variant, program_hash, ...task_output]`
/// Proof facts layout: `[PROOF_VERSION_V0, 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, variant, program_hash].
// Proof facts must contain at least [PROOF_VERSION_V0, variant, program_hash].
if proof_facts.0.len() < 3 {
return Err(VerifyProofError::ProofFactsTooShort { length: proof_facts.0.len() });
}
// Skip PROOF_VERSION (index 0) and variant (index 1).
// Skip PROOF_VERSION_V0 (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 All @@ -125,8 +125,8 @@ pub fn verify_proof(proof_facts: ProofFacts, proof: Proof) -> Result<(), VerifyP
return Err(VerifyProofError::EmptyProof);
}

// Validate that the first element of proof facts is PROOF_VERSION.
let expected_proof_version = PROOF_VERSION;
// Validate that the first element of proof facts is PROOF_VERSION_V0.
let expected_proof_version = PROOF_VERSION_V0;
let actual_first = proof_facts.0.first().copied().unwrap_or_default();
if actual_first != expected_proof_version {
return Err(VerifyProofError::InvalidProofVersion {
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};
use starknet_api::transaction::fields::{Proof, ProofFacts, PROOF_VERSION_V0};
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, variant, program_hash, ...task_output].
assert_eq!(proof_facts.0[0], PROOF_VERSION);
// Verify the proof facts structure: [PROOF_VERSION_V0, variant, program_hash, ...task_output].
assert_eq!(proof_facts.0[0], PROOF_VERSION_V0);
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