Skip to main content

tasm_lib/traits/
rust_shadow.rs

1use std::collections::HashMap;
2use strum::Display;
3use triton_vm::prelude::*;
4
5use crate::prelude::*;
6
7pub trait RustShadow {
8    fn inner(&self) -> &dyn BasicSnippet;
9
10    fn rust_shadow_wrapper(
11        &self,
12        stdin: &[BFieldElement],
13        nondeterminism: &NonDeterminism,
14        stack: &mut Vec<BFieldElement>,
15        memory: &mut HashMap<BFieldElement, BFieldElement>,
16        sponge: &mut Option<Tip5>,
17    ) -> Result<Vec<BFieldElement>, RustShadowError>;
18
19    fn test(&self);
20
21    fn bench(&self);
22}
23
24/// Errors that can occur during the execution of the [Rust shadow](RustShadow)
25/// implementation of a snippet.
26#[derive(Debug, Display, Copy, Clone, Eq, PartialEq)]
27pub enum RustShadowError {
28    ArithmeticOverflow,
29    DecodingError,
30    InvalidProof,
31    SpongeUninitialized,
32    StackUnderflow,
33    U64ToU32Error,
34    U64ToUsizeError,
35    UsizeToU32Error,
36    VmError,
37
38    /// Mimics a Triton VM [AssertionError](isa::instruction::AssertionError).
39    ///
40    /// The payload can be used to check error ID equivalence.
41    AssertionError(i128),
42
43    /// Like [AssertionError](Self::AssertionError), but for vector assertions.
44    VectorAssertionError(i128),
45
46    /// An unspecified issue.
47    Other,
48}
49
50impl std::error::Error for RustShadowError {}