snarkvm_synthesizer_process/evaluate.rs
1// Copyright (c) 2019-2026 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17use snarkvm_synthesizer_error::*;
18
19impl<N: Network> Process<N> {
20 /// Evaluates a program function on the given request.
21 #[inline]
22 pub fn evaluate<A: circuit::Aleo<Network = N>>(
23 &self,
24 authorization: Authorization<N>,
25 ) -> Result<Response<N>, ProcessEvalError> {
26 let timer = timer!("Process::evaluate");
27
28 // Retrieve the top-level request (without popping it).
29 let request = authorization.peek_next()?;
30
31 dev_println!("{}", format!(" • Evaluating '{}/{}'...", request.program_id(), request.function_name()));
32
33 // Retrieve the stack.
34 let stack = self.get_stack(request.program_id())?;
35 // Initialize an RNG.
36 let rng = &mut rand::thread_rng();
37 // Evaluate the function.
38 let response = stack.evaluate_function::<A, _>(CallStack::evaluate(authorization)?, None, None, rng)?;
39 lap!(timer, "Evaluate the function");
40
41 finish!(timer);
42
43 Ok(response)
44 }
45}