pub trait ScriptArgs: Sized + Sealed {
const FIXED_LEN: Option<usize>;
// Required methods
fn decode(arg: Word) -> ScriptArgsResult<Self>;
fn encode(&self) -> EncodedScriptArgs;
}Expand description
Transaction-script arguments transported through the TX_SCRIPT_ARGS word.
Every type that implements both FromFeltRepr and ToFeltRepr is a ScriptArgs
automatically. The felt-repr encoding selects one of two transport modes at compile time:
- Word mode (
FIXED_LENof at most 4 felts): the encoding is packed directly into the args word; the unused felts are zero, anddecoderejects anything else. - Commitment mode (longer or variable-length encodings): the args word is the Poseidon2
hash of the zero-padded encoding.
decodefetches the preimage from the advice provider and the hash is verified in-VM, so the host cannot substitute values.
The mode is a compile-time property of the argument type, so within one type definition the encoder and decoder always agree on the transport mode. The word carries no field layout — host-side mirrors of a guest type must reproduce its felt-repr wire sequence (see the migration guide for how to pin that).
The trait is sealed: the blanket FromFeltRepr + ToFeltRepr implementation is the only one,
which is what makes the documented transport guarantees hold for every implementor.
Required Associated Constants§
Required Methods§
Sourcefn decode(arg: Word) -> ScriptArgsResult<Self>
fn decode(arg: Word) -> ScriptArgsResult<Self>
Decodes the arguments from the TX_SCRIPT_ARGS word.
Returns an error when the encoding is malformed: a felt-repr decode failure, non-zero
padding, or a non-canonical commitment preimage. The #[tx_script]-generated entrypoint
wrapper panics on the error, failing the transaction. Commitment-mode decoding requires
the Miden VM; word-mode decoding is pure.
Sourcefn encode(&self) -> EncodedScriptArgs
fn encode(&self) -> EncodedScriptArgs
Encodes the arguments for transaction construction on the host.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".