tasm_lib/verifier/claim/
shared.rs

1use crate::data_type::DataType;
2use crate::data_type::StructType;
3
4// TODO: This *must* match the type of `Claim` used in Triton VM. It would be preferable if
5// it could be derived/generated from that type at the source.
6// The tests below *should* verify that this type is consistent with the one used in TVM.
7pub(crate) fn claim_type() -> StructType {
8    StructType {
9        name: "Claim".to_owned(),
10        fields: vec![
11            ("program_digest".to_owned(), DataType::Digest),
12            ("version".to_owned(), DataType::U32),
13            ("input".to_owned(), DataType::List(Box::new(DataType::Bfe))),
14            ("output".to_owned(), DataType::List(Box::new(DataType::Bfe))),
15        ],
16    }
17}
18
19#[cfg(test)]
20use triton_vm::prelude::*;
21
22/// Insert a claim into static memory, assuming static memory is empty prior to this insertion.
23/// Returns the pointer to the inserted claim, and the size of the encoded claim.
24#[cfg(test)]
25pub(crate) fn insert_claim_into_static_memory(
26    memory: &mut std::collections::HashMap<BFieldElement, BFieldElement>,
27    claim: &Claim,
28) -> (BFieldElement, u32) {
29    // Statically allocated memory starts at -2 and grows downward. So a value of size 1
30    // will be assigned to address `-2` if no other static memory allocations have occurred
31    // before it.
32
33    let size_of_encoded_claim: u32 = claim.encode().len().try_into().unwrap();
34    let size_as_i32: i32 = size_of_encoded_claim.try_into().unwrap();
35    let claim_pointer = bfe!(-size_as_i32 - 1);
36
37    crate::memory::encode_to_memory(memory, claim_pointer, claim);
38
39    (claim_pointer, size_of_encoded_claim)
40}