miden_assembly/ast/instruction/
advice.rs

1use core::fmt;
2
3use vm_core::sys_events::SystemEvent;
4
5// SYSTEM EVENT NODE
6// ================================================================================================
7
8/// Instructions which inject data into the advice provider.
9///
10/// These instructions can be used to perform two broad sets of operations:
11/// - Push new data onto the advice stack.
12/// - Insert new data into the advice map.
13#[derive(Clone, PartialEq, Eq, Debug)]
14pub enum SystemEventNode {
15    PushU64Div,
16    PushFalconDiv,
17    PushExt2intt,
18    PushSmtPeek,
19    PushMapVal,
20    PushMapValN,
21    PushMtNode,
22    InsertMem,
23    InsertHdword,
24    InsertHdwordWithDomain,
25    InsertHperm,
26}
27
28impl From<&SystemEventNode> for SystemEvent {
29    fn from(value: &SystemEventNode) -> Self {
30        use SystemEventNode::*;
31        match value {
32            PushU64Div => Self::U64Div,
33            PushFalconDiv => Self::FalconDiv,
34            PushExt2intt => Self::Ext2Intt,
35            PushSmtPeek => Self::SmtPeek,
36            PushMapVal => Self::MapValueToStack,
37            PushMapValN => Self::MapValueToStackN,
38            PushMtNode => Self::MerkleNodeToStack,
39            InsertMem => Self::MemToMap,
40            InsertHdword => Self::HdwordToMap,
41            InsertHdwordWithDomain => Self::HdwordToMapWithDomain,
42            InsertHperm => Self::HpermToMap,
43        }
44    }
45}
46
47impl crate::prettier::PrettyPrint for SystemEventNode {
48    fn render(&self) -> crate::prettier::Document {
49        crate::prettier::display(self)
50    }
51}
52
53impl fmt::Display for SystemEventNode {
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        match self {
56            Self::PushU64Div => write!(f, "push_u64div"),
57            Self::PushFalconDiv => write!(f, "push_falcon_div"),
58            Self::PushExt2intt => write!(f, "push_ext2intt"),
59            Self::PushSmtPeek => write!(f, "push_smtpeek"),
60            Self::PushMapVal => write!(f, "push_mapval"),
61            Self::PushMapValN => write!(f, "push_mapvaln"),
62            Self::PushMtNode => write!(f, "push_mtnode"),
63            Self::InsertMem => write!(f, "insert_mem"),
64            Self::InsertHdword => write!(f, "insert_hdword"),
65            Self::InsertHdwordWithDomain => write!(f, "insert_hdword_d"),
66            Self::InsertHperm => writeln!(f, "insert_hperm"),
67        }
68    }
69}
70
71/// A newtype wrapper for [vm_core::SignatureKind]
72#[derive(Debug, Copy, Clone, PartialEq, Eq)]
73#[repr(u8)]
74pub enum SignatureKind {
75    RpoFalcon512 = 0,
76}
77
78impl From<SignatureKind> for vm_core::SignatureKind {
79    fn from(kind: SignatureKind) -> Self {
80        match kind {
81            SignatureKind::RpoFalcon512 => Self::RpoFalcon512,
82        }
83    }
84}
85
86impl fmt::Display for SignatureKind {
87    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88        let kind: vm_core::SignatureKind = (*self).into();
89        write!(f, "{kind}")
90    }
91}