Overview
TheProcess 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
Initialization
Process::load
Initializes a process with the credits.aleo program.Result<Process<N>>
Returns a process with
credits.aleo loaded and verifying keys initializedExample
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
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
Process::stage_stack
Stages a stack for transactional updates.commit_stacks() or reverted with revert_stacks().
Source: synthesizer/process/src/lib.rs:149-161
Process::commit_stacks
Commits all staged stacks.Process::revert_stacks
Reverts all staged stacks to their previous state.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
Program Authorization
Process::authorize
Creates an authorization for a function call.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
Deployment Loading
Process::load_deployment
Loads a deployment into the process.&Deployment<N>
required
The deployment to load
- Extracts the program from the deployment
- Creates a new stack for the program
- Loads verifying keys from the deployment
- 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
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
- Validates the program is well-formed
- Checks for program conflicts or valid upgrades
- Initializes register types for closures and functions
- Initializes finalize types
- Validates all dependencies exist
Register Type Management
Stack::get_register_types
Returns register types for a closure or function.&Identifier<N>
required
The closure or function name
Stack::get_finalize_types
Returns register types for finalize logic.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
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
Evaluation (No Proof)
Stack::evaluate_function
Evaluates a function without generating proofs.- Testing
- Query operations (read-only)
- Local computation
CallStack
TheCallStack tracks execution state.
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.Trace
TheTrace 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
TheAuthorization 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))