Skip to main content

tasm_lib/traits/
rust_shadow.rs

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