Overview
TheVM type is the highest-level interface in the synthesizer, managing program execution, deployment, verification, and blockchain state. It integrates the process, storage, and consensus logic.
Type Definition
Initialization
VM::from
Initializes a VM from consensus storage.ConsensusStore<N, C>
required
Consensus storage backend containing blocks, transactions, and finalize state
Result<VM<N, C>>
Returns a new VM instance with all deployed programs loaded from storage
Example
Loading Process
During initialization, the VM:- Loads the
credits.aleoprogram and initializes its mappings - Retrieves all deployment transactions from storage
- Loads deployments in order of block height to respect dependencies
- Creates the universal SRS and puzzle
- Spawns a background thread for sequential operations
Program Deployment
VM::deploy
Creates a deployment transaction for a new program.&PrivateKey<N>
required
Private key of the program owner
&Program<N>
required
The program to deploy
Option<Record<N, Plaintext<N>>>
Record to pay private fee. If
None, uses public fee from on-chain balanceu64
Additional fee on top of the base deployment cost (in microcredits)
Option<&dyn QueryTrait<N>>
Query interface for blockchain state. Defaults to VM’s block store
&mut R
Cryptographically secure random number generator
Result<Transaction<N>, VmDeployError>
Returns a deployment transaction ready to broadcast
Example
Deployment Cost Calculation
The deployment cost is computed based on:- Program size (bytes)
- Number of functions
- Complexity of each function
- Storage cost for program state
Program Execution
VM::execute
Executes a program function and returns a transaction.&PrivateKey<N>
required
Private key to authorize the execution
impl TryInto<ProgramID<N>>
required
Program identifier (e.g., “token.aleo”)
impl TryInto<Identifier<N>>
required
Function name to execute (e.g., “transfer_private”)
impl ExactSizeIterator<Item = impl TryInto<Value<N>>>
required
Function input values (records, plaintext values, etc.)
Option<Record<N, Plaintext<N>>>
Record for private fee. If
None, uses public feeu64
Additional fee on top of execution cost (in microcredits)
Option<&dyn QueryTrait<N>>
Query interface for blockchain state
&mut R
Cryptographically secure random number generator
Result<Transaction<N>, VmExecError>
Returns an execution transaction with proof
Example
VM::execute_with_response
Executes a function and returns both the transaction and the response.execute, but returns a tuple:
Result<(Transaction<N>, Response<N>), VmExecError>
Returns both the transaction and the function’s response containing output values
Authorization
Authorization is the first step of execution, creating a signed request without generating proofs.VM::authorize
Authorizes a function call without executing it.&PrivateKey<N>
required
Private key to sign the authorization
impl TryInto<ProgramID<N>>
required
Program to execute
impl TryInto<Identifier<N>>
required
Function to authorize
impl IntoIterator
required
Function inputs
&mut R
required
Random number generator
Result<Authorization<N>, VmAuthError>
Returns an authorization that can be executed later
VM::execute_authorization
Executes a pre-authorized call.- Offline signing
- Multi-party computation
- Deferred execution
Fee Management
VM::authorize_fee_private
Authorizes a private fee using a credits record.Record<N, Plaintext<N>>
required
Credits record to spend for the fee
u64
required
Minimum fee required for the operation
u64
Additional fee for priority execution
Field<N>
required
The deployment or execution ID this fee is for
VM::authorize_fee_public
Authorizes a public fee using on-chain balance.Block Management
VM::add_next_block
Adds a new block to the VM and updates state.&Block<N>
required
The block to add (must be the next sequential block)
Result<()>
Returns
Ok(()) if the block was successfully added and finalizedProcess
- Constructs finalize state from block metadata
- Inserts block into storage (atomic operation)
- Finalizes all transactions in the block
- Updates verifying keys if consensus version changes
- Rolls back on finalization failure
VM::finalize
Finalizes transactions and updates on-chain state.FinalizeGlobalState
required
Global finalize state (block height, timestamp, etc.)
&[Ratify<N>]
required
Block ratifications (genesis committee, block rewards, etc.)
&Solutions<N>
required
Proof-of-work solutions
impl Iterator<Item = &Transaction<N>>
required
Transactions to finalize
Result<Vec<FinalizeOperation<N>>>
Returns the list of state operations performed
State Access
VM::finalize_store
Returns the finalize storage for reading/writing mappings.VM::block_store
Returns the block storage.VM::transaction_store
Returns the transaction storage.VM::transition_store
Returns the transition storage.Genesis Blocks
VM::genesis_beacon
Creates a genesis block for a new beacon chain.VM::genesis_quorum
Creates a genesis block with custom committee and balances.Committee<N>
required
Initial committee of validators
IndexMap<Address<N>, u64>
required
Initial public credit balances
IndexMap<Address<N>, (Address<N>, Address<N>, u64)>
required
Initial bonded balances for staking
Program Management
VM::contains_program
Checks if a program exists in the VM.VM::process
Returns the underlying process.Performance Features
Sequential Operations
The VM uses a background thread for operations that must be sequential:- Block additions
- State finalization
- Storage writes
Transaction Caching
The VM caches partially-verified transactions to avoid redundant verification:Thread Safety
The VM isClone and uses Arc<RwLock<_>> for shared state, making it safe to use across threads: