Skip to main content

Overview

The Process and Stack types form the core of program execution in snarkVM. The Process manages multiple program stacks, while each Stack contains the execution context for a single program.

Process

Type Definition

Source: synthesizer/process/src/lib.rs:87-95

Initialization

Process::load

Initializes a process with the credits.aleo program.
Result<Process<N>>
Returns a process with credits.aleo loaded and verifying keys initialized

Example

Source: synthesizer/process/src/lib.rs:227-263

Process::setup

Initializes a process and synthesizes proving keys.
circuit::Aleo<Network = N>
required
Circuit implementation type (e.g., AleoV0)
&mut R
required
Random number generator for key synthesis
Result<Process<N>>
Returns a process with full proving and verifying keys
This is used for testing and development. Production systems use load() and load pre-computed keys. Source: synthesizer/process/src/lib.rs:100-129

Stack Management

Process::add_stack

Adds a program stack to the process.
Stack<N>
required
The stack to add
Option<Arc<Stack<N>>>
Returns the previous stack if one existed for this program
Source: synthesizer/process/src/lib.rs:135-142

Process::stage_stack

Stages a stack for transactional updates.
Staged stacks can be committed with commit_stacks() or reverted with revert_stacks(). Source: synthesizer/process/src/lib.rs:149-161

Process::commit_stacks

Commits all staged stacks.
Source: synthesizer/process/src/lib.rs:166-169

Process::revert_stacks

Reverts all staged stacks to their previous state.
Source: synthesizer/process/src/lib.rs:174-185

Program Execution

Process::execute

Executes an authorization and returns the response and trace.
circuit::Aleo<Network = N>
required
Circuit implementation type
Authorization<N>
required
The authorized function call
&mut R
required
Random number generator
Result<(Response<N>, Trace<N>), ProcessExecError>
Returns the function response and execution trace

Example

Source: synthesizer/process/src/execute.rs:22-61

Program Authorization

Process::authorize

Creates an authorization for a function call.
Source: synthesizer/process/src/authorize.rs

Program Deployment

Process::deploy

Creates a deployment for a program.
&Program<N>
required
The program to deploy
Result<Deployment<N>>
Returns a deployment with synthesized verifying keys
Source: synthesizer/process/src/deploy.rs

Deployment Loading

Process::load_deployment

Loads a deployment into the process.
&Deployment<N>
required
The deployment to load
This method:
  1. Extracts the program from the deployment
  2. Creates a new stack for the program
  3. Loads verifying keys from the deployment
  4. Adds the stack to the process

Program Queries

Process::contains_program

Checks if a program exists.

Process::get_program

Retrieves a program by ID.

Process::get_stack

Retrieves a stack by program ID.

Stack

Type Definition

Source: synthesizer/process/src/stack/mod.rs:210-236

Initialization

Stack::new

Creates a new stack for a program.
&Process<N>
required
The parent process
&Program<N>
required
The program to create a stack for
Result<Stack<N>>
Returns a stack with initialized register types and state
This method:
  1. Validates the program is well-formed
  2. Checks for program conflicts or valid upgrades
  3. Initializes register types for closures and functions
  4. Initializes finalize types
  5. Validates all dependencies exist
Source: synthesizer/process/src/stack/mod.rs:240-265

Register Type Management

Stack::get_register_types

Returns register types for a closure or function.
&Identifier<N>
required
The closure or function name
Source: synthesizer/process/src/stack/mod.rs:364-370

Stack::get_finalize_types

Returns register types for finalize logic.
Source: synthesizer/process/src/stack/mod.rs:374-380

Proving/Verifying Keys

Stack::insert_proving_key

Inserts a proving key for a function.

Stack::insert_verifying_key

Inserts a verifying key for a function.

Stack::proving_key

Retrieves the proving key for a function.

Stack::verifying_key

Retrieves the verifying key for a function.

Circuit Synthesis

Stack::synthesize_key

Synthesizes proving and verifying keys for a function.
circuit::Aleo<Network = N>
required
Circuit implementation
&Identifier<N>
required
Function to synthesize keys for
&mut R
required
Random number generator
This is expensive and should only be done during setup or deployment.

Function Execution

Stack::execute_function

Executes a function and returns the response.
CallStack<N>
required
The call stack containing authorization and trace
Option<ProgramID<N>>
The calling program (for nested calls)
Option<Field<N>>
Transaction view key for record encryption
Source: synthesizer/process/src/stack/execute.rs

Evaluation (No Proof)

Stack::evaluate_function

Evaluates a function without generating proofs.
Useful for:
  • Testing
  • Query operations (read-only)
  • Local computation
Source: synthesizer/process/src/stack/evaluate.rs

CallStack

The CallStack tracks execution state.
Source: synthesizer/process/src/stack/mod.rs:102-116

CallStack Methods

CallStack::push

Pushes a request onto the call stack.

CallStack::pop

Pops a request from the call stack.

CallStack::peek

Peeks at the next request without popping.
Source: synthesizer/process/src/stack/mod.rs:160-207

Trace

The Trace records execution history.

Trace Methods

Trace::prove_execution

Generates a proof from the trace.

Trace::prove_fee

Generates a fee proof from the trace.

Authorization

The Authorization type encapsulates authorized function calls.

Authorization Methods

Authorization::push

Adds a request to the authorization.

Authorization::next

Returns the next request.

Authorization::peek_next

Peeks at the next request.

Cost Calculation

execution_cost

Calculates the execution cost.
Result<(u64, (u64, u64))>
Returns (minimum_cost, (storage_cost, namespace_cost))
Source: synthesizer/process/src/cost.rs

deployment_cost

Calculates the deployment cost.
Source: synthesizer/process/src/cost.rs