Skip to main content

miden_precompiles_verifier/
lib.rs

1#![no_std]
2
3extern crate alloc;
4#[cfg(any(test, feature = "std"))]
5extern crate std;
6
7pub use miden_core::{
8    deferred::DeferredRoot,
9    proof::{HashFunction, StarkProof},
10};
11pub use miden_precompiles_air::security::{
12    AirShape, InstanceShape, LookupShape, ProofSecurityParameters, ProtocolParams, SecurityReport,
13    SecurityTerm,
14};
15
16#[cfg(any(test, feature = "std"))]
17pub(crate) mod ace;
18#[cfg(any(test, feature = "std"))]
19pub(crate) mod ace_registry;
20#[cfg(feature = "registry-tools")]
21pub mod ace_registry_regen;
22#[cfg(feature = "std")]
23pub mod masm_verifier;
24mod verify;
25
26pub use verify::{VerifyError, verify_deferred};
27
28#[cfg(test)]
29mod tests {
30    use alloc::vec;
31
32    use miden_core::{Felt, Word, deferred::TRUE_DIGEST, proof::MAX_STARK_PROOF_BYTES};
33
34    use super::*;
35
36    fn pinned_keccak_root() -> Word {
37        Word::new(
38            [
39                8727402973153492738,
40                13033997996299931781,
41                5394599319400709983,
42                17469579631022355290,
43            ]
44            .map(Felt::new_unchecked),
45        )
46    }
47
48    #[test]
49    fn rejects_pinned_old_poseidon2_proof() {
50        const PROOF_BYTES: &[u8] = include_bytes!("../tests/fixtures/pvm_poseidon2_v0_31.bin");
51        let proof = StarkProof::new(PROOF_BYTES.to_vec(), HashFunction::Poseidon2);
52
53        assert!(verify_deferred(&proof, pinned_keccak_root()).is_err());
54        assert!(verify_deferred(&proof, TRUE_DIGEST).is_err());
55    }
56
57    #[test]
58    fn verifies_pinned_current_poseidon2_proof() {
59        // This proof uses the b"abc" Keccak witness from the precompile prover tests.
60        const PROOF_BYTES: &[u8] = include_bytes!("../tests/fixtures/pvm_poseidon2_v0_35.bin");
61        let proof = StarkProof::new(PROOF_BYTES.to_vec(), HashFunction::Poseidon2);
62
63        verify_deferred(&proof, pinned_keccak_root()).expect("current Poseidon2 proof must verify");
64        assert!(verify_deferred(&proof, TRUE_DIGEST).is_err());
65    }
66
67    #[test]
68    fn verify_deferred_enforces_fixed_stark_proof_size_ceiling() {
69        let proof = StarkProof::new(vec![0; MAX_STARK_PROOF_BYTES + 1], HashFunction::Blake3_256);
70
71        assert!(matches!(
72            verify_deferred(&proof, TRUE_DIGEST),
73            Err(VerifyError::ProofTooLarge { size: _, max: MAX_STARK_PROOF_BYTES })
74        ));
75    }
76}