tasm_lib/verifier/vm_proof_iter/
shared.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::data_type::DataType;
use crate::data_type::StructType;

pub fn vm_proof_iter_type() -> StructType {
    let name = "VmProofIter".to_string();
    let current_item_pointer = ("current_item_pointer".to_string(), DataType::Bfe);
    let current_item_count = ("current_item_count".to_string(), DataType::U32);
    let total_item_count = ("total_item_count".to_string(), DataType::U32);
    let proof_start_pointer = ("proof_start_pointer".to_string(), DataType::Bfe);
    let proof_length = ("proof_length".to_string(), DataType::U32);

    let fields = vec![
        current_item_count,
        total_item_count,
        proof_start_pointer,
        proof_length,
        current_item_pointer,
    ];

    StructType { name, fields }
}

#[cfg(test)]
pub(super) mod vm_proof_iter_struct {
    use triton_vm::prelude::bfe;
    use triton_vm::prelude::BFieldCodec;
    use triton_vm::prelude::BFieldElement;
    use triton_vm::proof::Proof;
    use triton_vm::proof_stream::ProofStream;

    use crate::prelude::TasmObject;

    /// Represent Triton VM's knowledge about a proof.
    #[derive(Debug, Clone, Copy, Eq, PartialEq, BFieldCodec, TasmObject)]
    pub(crate) struct VmProofIter {
        pub(crate) current_item_count: u32,
        pub(crate) total_item_count: u32,
        pub(crate) proof_start_pointer: BFieldElement,
        pub(crate) proof_length: u32,
        pub(crate) current_item_pointer: BFieldElement,
    }

    impl VmProofIter {
        pub(crate) fn new(proof_pointer: BFieldElement, proof: &Proof) -> Self {
            let proof_length = proof.0.len() + 1;
            let proof_stream: ProofStream = proof.try_into().unwrap();
            VmProofIter {
                current_item_count: 0,
                total_item_count: proof_stream.items.len().try_into().unwrap(),
                proof_start_pointer: proof_pointer,
                proof_length: proof_length.try_into().unwrap(),

                // uses highly specific knowledge of `BFieldCodec`
                current_item_pointer: proof_pointer + bfe!(4),
            }
        }
    }
}