miden_base_sys/bindings/mod.rs
1//! Bindings for Miden protocol
2//!
3//! # Word Field Ordering
4//!
5//! The Miden protocol MASM procedures expect and/or return Word on the stack with the least
6//! significant felt on top of the stack.
7//!
8//! - In Rust: Word fields are stored as [e0, e1, e2, e3]
9//! - In MASM procedures: These are pushed/popped from the stack in reverse order [e3, e2, e1, e0]
10
11pub mod active_account;
12pub mod active_note;
13pub mod faucet;
14pub mod input_note;
15pub mod native_account;
16pub mod note;
17pub mod output_note;
18pub mod storage;
19pub mod tx;
20mod types;
21
22pub use miden_field_repr::{FromFeltRepr, ToFeltRepr};
23pub use types::*;
24
25/// Maximum number of attachments per note, defined by the protocol MASM source at
26/// `asm/kernels/transaction-core/src/output_note.masm`.
27const MAX_ATTACHMENTS_PER_NOTE: usize = 4;
28
29/// Maximum words per attachment, defined by the protocol MASM source at
30/// `asm/protocol_utils/src/note.masm`.
31const MAX_ATTACHMENT_WORDS: usize = 256;
32
33/// Asserts that a note attachment count is within the protocol limit.
34fn assert_attachment_count(num_attachments: usize) {
35 assert!(
36 num_attachments <= MAX_ATTACHMENTS_PER_NOTE,
37 "note cannot contain more than {MAX_ATTACHMENTS_PER_NOTE} attachments"
38 );
39}
40
41/// Asserts that an attachment word count is within the protocol limit.
42fn assert_attachment_word_count(num_words: usize) {
43 assert!(
44 num_words <= MAX_ATTACHMENT_WORDS,
45 "note attachment cannot contain more than {MAX_ATTACHMENT_WORDS} words"
46 );
47}