Enforce stack padding conventions for Miden Assembly (.masm) procedures based on invocation type (call vs exec). Use when editing, reviewing, or creating .masm procedures, especially those with Invocation annotations.
Padding requirements differ based on procedure invocation type:
| Invocation | Padding Required | Input/Output Elements |
|---|---|---|
call | Explicit padding in comments | Exactly 16 |
exec | No explicit padding | No requirement |
Procedures invoked with call must have explicit padding in:
#!) for Inputs/Outputs#) showing stack stateUse pad(N) notation where N + other elements = 16:
#! Inputs: [ASSET, pad(12)]
#! Outputs: [pad(16)]
#!
#! Invocation: call
pub proc receive_asset
Track padding through the procedure:
exec.native_account::set_item
# => [OLD_VALUE, pad(12)]
dropw
# => [pad(16)] auto-padded to 16 elements
If the stack falls below 16 elements for a call procedure, Miden auto-pads to 16. This is acceptable and should be documented in the output as the padded result.
Procedures invoked with exec should NOT have explicit padding:
#! Inputs: [PUB_KEY]
#! Outputs: []
#!
#! Invocation: exec
pub proc authenticate_transaction
exec procedures share the caller's stack directly. Explicit padding would be misleading because:
If an exec procedure's stack falls below the specified stack elements, it will consume stack items from its caller, potentially leading to unexpected behavior. This is a bug and should be fixed by ensuring the procedure maintains sufficient stack depth and avoiding dropping more stack elements than available.
# => [num_approvers, threshold]
dropw # dropw drops 4 elements, which will result in "negative" stack consumption (consuming 2 elements from the caller's stack)
Inside a procedure, the stack may temporarily exceed 16 elements:
# => [num_approvers, threshold, MULTISIG_CONFIG, pad(12)]
# ^--- 18 elements total, must be reduced before return
These extra elements must be explicitly dropped before the procedure returns (directly or via called procedures).
For call procedures:
pad(N)pad(N)# => format with pad(N) notationFor exec procedures:
pad(N) in Inputs/Outputs doc comments