Skip to main content

Overview

The VM 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:
  1. Loads the credits.aleo program and initializes its mappings
  2. Retrieves all deployment transactions from storage
  3. Loads deployments in order of block height to respect dependencies
  4. Creates the universal SRS and puzzle
  5. 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 balance
u64
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
Source: synthesizer/src/vm/deploy.rs:62

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 fee
u64
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

Source: synthesizer/src/vm/execute.rs:29-49

VM::execute_with_response

Executes a function and returns both the transaction and the response.
Parameters are identical to execute, but returns a tuple:
Result<(Transaction<N>, Response<N>), VmExecError>
Returns both the transaction and the function’s response containing output values
Source: synthesizer/src/vm/execute.rs:57-66

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
Source: synthesizer/src/vm/authorize.rs:23-30

VM::execute_authorization

Executes a pre-authorized call.
This allows separating authorization from execution, useful for:
  • Offline signing
  • Multi-party computation
  • Deferred execution
Source: synthesizer/src/vm/execute.rs:120-130

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
Source: synthesizer/src/vm/authorize.rs:58-66

VM::authorize_fee_public

Authorizes a public fee using on-chain balance.
Source: synthesizer/src/vm/authorize.rs:92-99

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 finalized

Process

  1. Constructs finalize state from block metadata
  2. Inserts block into storage (atomic operation)
  3. Finalizes all transactions in the block
  4. Updates verifying keys if consensus version changes
  5. Rolls back on finalization failure
Source: synthesizer/src/vm/mod.rs:472-479

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.
Source: synthesizer/src/vm/mod.rs:285-308

Genesis Blocks

VM::genesis_beacon

Creates a genesis block for a new beacon chain.
Creates a genesis block with 4 validators (default). Source: synthesizer/src/vm/mod.rs:328-330

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
Source: synthesizer/src/vm/mod.rs:383-390

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
This allows the main thread to continue processing while state updates occur atomically.

Transaction Caching

The VM caches partially-verified transactions to avoid redundant verification:
Cache key includes transaction ID and program checksums, invalidating when programs upgrade. Source: synthesizer/src/vm/mod.rs:121-132

Thread Safety

The VM is Clone and uses Arc<RwLock<_>> for shared state, making it safe to use across threads:
This allows concurrent read access while ensuring exclusive write access for state modifications.