Skip to content

Commit 7056e9b

Browse files
committed
Move function to helpers
1 parent a2ff425 commit 7056e9b

File tree

4 files changed

+45
-35
lines changed

4 files changed

+45
-35
lines changed

synthesizer/src/vm/helpers/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub use history::*;
2323

2424
mod macros;
2525

26+
mod program;
27+
pub use program::*;
28+
2629
mod rewards;
2730
pub use rewards::*;
2831

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2019-2025 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+
16+
use console::{network::Network, program::ValueType};
17+
use snarkvm_synthesizer_program::Program;
18+
19+
use anyhow::{Result, bail, ensure};
20+
21+
/// Verifies that the existing output register indices are not changed in a new version of the program.
22+
// Note. This function is public so that depednent crates can cleanly surface this error to users.
23+
pub fn check_output_register_indices_unchanged<N: Network>(
24+
old_program: &Program<N>,
25+
new_program: &Program<N>,
26+
) -> Result<()> {
27+
for (id, function) in old_program.functions() {
28+
// Get the corresponding function in the new program.
29+
let Ok(new_function) = new_program.get_function(id) else { bail!("Missing function '{id}'") };
30+
// Ensure the record output registers match.
31+
let existing_output_registers =
32+
function.outputs().iter().filter(|output| matches!(output.value_type(), ValueType::Record(_)));
33+
let new_output_registers =
34+
new_function.outputs().iter().filter(|output| matches!(output.value_type(), ValueType::Record(_)));
35+
ensure!(
36+
existing_output_registers.eq(new_output_registers),
37+
"Function '{id}' has mismatched record output registers"
38+
);
39+
}
40+
Ok(())
41+
}

synthesizer/src/vm/mod.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,7 @@ use crate::{Restrictions, cast_mut_ref, cast_ref, convert, process};
2929
use console::{
3030
account::{Address, PrivateKey},
3131
network::prelude::*,
32-
program::{
33-
Argument,
34-
Identifier,
35-
Literal,
36-
Locator,
37-
Plaintext,
38-
ProgramID,
39-
ProgramOwner,
40-
Record,
41-
Response,
42-
Value,
43-
ValueType,
44-
},
32+
program::{Argument, Identifier, Literal, Locator, Plaintext, ProgramID, ProgramOwner, Record, Response, Value},
4533
types::{Field, Group, U16, U64},
4634
};
4735
use snarkvm_algorithms::snark::varuna::VarunaVersion;

synthesizer/src/vm/verify.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -681,28 +681,6 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
681681
}
682682
}
683683

684-
/// Verifies that the existing output register indices are not changed in a new version of the program.
685-
// Note. This function is public so that depednent crates can cleanly surface this error to users.
686-
pub fn check_output_register_indices_unchanged<N: Network>(
687-
old_program: &Program<N>,
688-
new_program: &Program<N>,
689-
) -> Result<()> {
690-
for (id, function) in old_program.functions() {
691-
// Get the corresponding function in the new program.
692-
let Ok(new_function) = new_program.get_function(id) else { bail!("Missing function '{id}'") };
693-
// Ensure the record output registers match.
694-
let existing_output_registers =
695-
function.outputs().iter().filter(|output| matches!(output.value_type(), ValueType::Record(_)));
696-
let new_output_registers =
697-
new_function.outputs().iter().filter(|output| matches!(output.value_type(), ValueType::Record(_)));
698-
ensure!(
699-
existing_output_registers.eq(new_output_registers),
700-
"Function '{id}' has mismatched record output registers"
701-
);
702-
}
703-
Ok(())
704-
}
705-
706684
#[cfg(test)]
707685
mod tests {
708686
use super::*;

0 commit comments

Comments
 (0)