Skip to content

Commit 15246df

Browse files
starknet_api: add PROOF_VERSION_V1 and accept either marker in ProofFactsVariant
1 parent 69ce1ec commit 15246df

1 file changed

Lines changed: 46 additions & 4 deletions

File tree

crates/starknet_api/src/transaction/fields.rs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ pub const VIRTUAL_SNOS: Felt = Felt::from_hex_unchecked("0x5649525455414c5f534e4
633633
// Represent the `PROOF_VERSION_V0` marker as a Felt ('PROOF0').
634634
pub const PROOF_VERSION_V0: Felt = Felt::from_hex_unchecked("0x50524f4f4630");
635635

636+
// Represent the `PROOF_VERSION_V1` marker as a Felt ('PROOF1').
637+
pub const PROOF_VERSION_V1: Felt = Felt::from_hex_unchecked("0x50524f4f4631");
638+
636639
/// The version of the virtual OS output (short string 'VIRTUAL_SNOS0').
637640
/// This must match the Cairo constant `VIRTUAL_OS_OUTPUT_VERSION` in `virtual_os_output.cairo`.
638641
pub const VIRTUAL_OS_OUTPUT_VERSION: Felt =
@@ -681,11 +684,12 @@ impl TryFrom<&ProofFacts> for ProofFactsVariant {
681684
)));
682685
};
683686

684-
// Validate that the first element is PROOF_VERSION_V0.
685-
if *proof_version != PROOF_VERSION_V0 {
687+
// Validate that the first element is a supported PROOF_VERSION marker.
688+
if *proof_version != PROOF_VERSION_V0 && *proof_version != PROOF_VERSION_V1 {
686689
return Err(StarknetApiError::InvalidProofFacts(format!(
687-
"Expected first field to be {} (PROOF_VERSION_V0), but got {}",
688-
PROOF_VERSION_V0, proof_version
690+
"Expected first field to be {} (PROOF_VERSION_V0) or {} (PROOF_VERSION_V1), but \
691+
got {}",
692+
PROOF_VERSION_V0, PROOF_VERSION_V1, proof_version
689693
)));
690694
}
691695

@@ -815,3 +819,41 @@ impl Proof {
815819
self.0.is_empty()
816820
}
817821
}
822+
823+
#[cfg(test)]
824+
mod tests {
825+
use rstest::rstest;
826+
827+
use super::*;
828+
829+
fn snos_proof_facts(proof_version: Felt) -> ProofFacts {
830+
ProofFacts(Arc::new(vec![
831+
proof_version,
832+
VIRTUAL_SNOS,
833+
Felt::from(0xABCD_u64),
834+
VIRTUAL_OS_OUTPUT_VERSION,
835+
Felt::from(0_u64),
836+
Felt::from(0xBEEF_u64),
837+
Felt::from(0xC0FFEE_u64),
838+
]))
839+
}
840+
841+
#[rstest]
842+
#[case::v0(PROOF_VERSION_V0)]
843+
#[case::v1(PROOF_VERSION_V1)]
844+
fn proof_facts_variant_accepts_supported_versions(#[case] version: Felt) {
845+
let variant = ProofFactsVariant::try_from(&snos_proof_facts(version))
846+
.expect("supported version should parse");
847+
match variant {
848+
ProofFactsVariant::Snos(snos) => assert_eq!(snos.proof_version, version),
849+
ProofFactsVariant::Empty => panic!("expected Snos variant"),
850+
}
851+
}
852+
853+
#[test]
854+
fn proof_facts_variant_rejects_unknown_version() {
855+
let result =
856+
ProofFactsVariant::try_from(&snos_proof_facts(Felt::from_hex_unchecked("0xDEAD")));
857+
assert!(matches!(result, Err(StarknetApiError::InvalidProofFacts(_))));
858+
}
859+
}

0 commit comments

Comments
 (0)