aleo_rust/program/helpers/offline.rs
1// Copyright (C) 2019-2023 Aleo Systems Inc.
2// This file is part of the Aleo SDK library.
3
4// The Aleo SDK library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Aleo SDK library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
16
17use super::*;
18
19/// Offline Execution of a program
20#[derive(Clone)]
21pub struct OfflineExecution<N: Network> {
22 execution: Execution<N>,
23 response: Option<Response<N>>,
24 trace: Trace<N>,
25 public_outputs: Option<Vec<Value<N>>>,
26}
27
28impl<N: Network> OfflineExecution<N> {
29 /// Create a new offline execution
30 pub(crate) fn new(
31 execution: Execution<N>,
32 response: Option<Response<N>>,
33 trace: Trace<N>,
34 public_outputs: Option<Vec<Value<N>>>,
35 ) -> Self {
36 Self { execution, response, trace, public_outputs }
37 }
38
39 /// Get the execution
40 pub fn execution(&self) -> &Execution<N> {
41 &self.execution
42 }
43
44 /// Get the execution id
45 pub fn execution_id(&self) -> Result<Field<N>> {
46 self.execution.to_execution_id()
47 }
48
49 /// Get the execution proof
50 pub fn execution_proof(&self) -> Option<&Proof<N>> {
51 self.execution.proof()
52 }
53
54 /// Get the outputs of the execution
55 pub fn outputs(&self) -> Option<Vec<Value<N>>> {
56 self.response.as_ref().map(|r| r.outputs().to_vec())
57 }
58
59 /// Get public outputs
60 pub fn public_outputs(&self) -> Option<Vec<Value<N>>> {
61 self.public_outputs.clone()
62 }
63
64 /// Get the trace of the execution
65 pub fn trace(&self) -> &Trace<N> {
66 &self.trace
67 }
68
69 /// Verify the execution proof against the given verifier inputs and program verifying key
70 #[allow(clippy::type_complexity)]
71 pub fn verify_execution_proof(
72 &self,
73 locator: &str,
74 verifier_inputs: Vec<(VerifyingKey<N>, Vec<Vec<N::Field>>)>,
75 execution: &Execution<N>,
76 ) -> Result<(), String> {
77 Trace::verify_execution_proof(locator, verifier_inputs, execution).map_err(|e| e.to_string())
78 }
79}