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    PushExt2intt,
17    PushSmtPeek,
18    PushMapVal,
19    PushMapValN,
20    PushMtNode,
21    InsertMem,
22    InsertHdword,
23    InsertHdwordWithDomain,
24    InsertHperm,
25    PushSignature { kind: SignatureKind },
26}
27
28impl From<&SystemEventNode> for SystemEvent {
29    fn from(value: &SystemEventNode) -> Self {
30        use SystemEventNode::*;
31        match value {
32            PushU64Div => Self::U64Div,
33            PushExt2intt => Self::Ext2Intt,
34            PushSmtPeek => Self::SmtPeek,
35            PushMapVal => Self::MapValueToStack,
36            PushMapValN => Self::MapValueToStackN,
37            PushMtNode => Self::MerkleNodeToStack,
38            InsertMem => Self::MemToMap,
39            InsertHdword => Self::HdwordToMap,
40            InsertHdwordWithDomain => Self::HdwordToMapWithDomain,
41            InsertHperm => Self::HpermToMap,
42            PushSignature { kind } => match kind {
43                SignatureKind::RpoFalcon512 => Self::FalconSigToStack,
44            },
45        }
46    }
47}
48
49impl crate::prettier::PrettyPrint for SystemEventNode {
50    fn render(&self) -> crate::prettier::Document {
51        crate::prettier::display(self)
52    }
53}
54
55impl fmt::Display for SystemEventNode {
56    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57        match self {
58            Self::PushU64Div => write!(f, "push_u64div"),
59            Self::PushExt2intt => write!(f, "push_ext2intt"),
60            Self::PushSmtPeek => write!(f, "push_smtpeek"),
61            Self::PushMapVal => write!(f, "push_mapval"),
62            Self::PushMapValN => write!(f, "push_mapvaln"),
63            Self::PushMtNode => write!(f, "push_mtnode"),
64            Self::InsertMem => write!(f, "insert_mem"),
65            Self::InsertHdword => write!(f, "insert_hdword"),
66            Self::InsertHdwordWithDomain => write!(f, "insert_hdword_d"),
67            Self::InsertHperm => writeln!(f, "insert_hperm"),
68            Self::PushSignature { kind } => write!(f, "push_sig.{kind}"),
69        }
70    }
71}
72
73/// A newtype wrapper for [vm_core::SignatureKind]
74#[derive(Debug, Copy, Clone, PartialEq, Eq)]
75#[repr(u8)]
76pub enum SignatureKind {
77    RpoFalcon512 = 0,
78}
79
80impl From<SignatureKind> for vm_core::SignatureKind {
81    fn from(kind: SignatureKind) -> Self {
82        match kind {
83            SignatureKind::RpoFalcon512 => Self::RpoFalcon512,
84        }
85    }
86}
87
88impl fmt::Display for SignatureKind {
89    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90        let kind: vm_core::SignatureKind = (*self).into();
91        write!(f, "{kind}")
92    }
93}