/ synthesizer / process / src / verify_deployment.rs
verify_deployment.rs
 1  // Copyright (c) 2025 ADnet Contributors
 2  // This file is part of the AlphaVM 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  
16  use super::*;
17  
18  impl<N: Network> Process<N> {
19      /// Verifies the given deployment is ordered.
20      #[inline]
21      pub fn verify_deployment<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>(
22          &self,
23          consensus_version: ConsensusVersion,
24          deployment: &Deployment<N>,
25          rng: &mut R,
26      ) -> Result<()> {
27          let timer = timer!("Process::verify_deployment");
28  
29          // Retrieve the program ID.
30          let program_id = deployment.program().id();
31          // If the edition is zero, then verify that the program does not exist.
32          // Otherwise, verify that the program exists.
33          match deployment.edition().is_zero() {
34              true => ensure!(
35                  !self.contains_program(program_id),
36                  "Program '{program_id}' already exists, but the deployment edition is zero"
37              ),
38              false => ensure!(
39                  self.contains_program(program_id),
40                  "Program '{program_id}' does not exist, but the deployment edition is non-zero"
41              ),
42          }
43  
44          // Ensure the program is well-formed, by computing the stack.
45          // Note: The program owner is intentionally not set, since `program_owner` is an operand
46          //   that is only available in a finalize scope.
47          let stack = Stack::new(self, deployment.program())?;
48          lap!(timer, "Compute the stack");
49  
50          // Ensure the verifying keys are well-formed and the certificates are valid.
51          let verification = stack.verify_deployment::<A, R>(consensus_version, deployment, rng);
52          lap!(timer, "Verify the deployment");
53  
54          finish!(timer);
55          verification
56      }
57  }
58  
59  #[cfg(test)]
60  mod tests {
61      use super::*;
62  
63      type CurrentAleo = circuit::network::AleoV0;
64  
65      /// Use `cargo test profiler --features timer` to run this test.
66      #[ignore]
67      #[test]
68      fn test_profiler() -> Result<()> {
69          let rng = &mut TestRng::default();
70  
71          // Initialize the process.
72          let process = Process::load()?;
73  
74          // Fetch the large program to deploy.
75          let large_program = Program::from_str(include_str!("./resources/large_functions.alpha"))?;
76  
77          // Create a deployment for the program.
78          let deployment = process.deploy::<CurrentAleo, _>(&large_program, rng)?;
79  
80          // Verify the deployment.
81          assert!(process.verify_deployment::<CurrentAleo, _>(ConsensusVersion::V8, &deployment, rng).is_ok());
82  
83          bail!("\n\nRemember to #[ignore] this test!\n\n")
84      }
85  }