From 0072b112b8421ce742e5c2ef038699bb42946afb Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:56:19 -0800 Subject: [PATCH 1/7] Add TRANSACTION_SPEND_LIMIT --- console/network/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/console/network/src/lib.rs b/console/network/src/lib.rs index 6598e42849..c03001fc6a 100644 --- a/console/network/src/lib.rs +++ b/console/network/src/lib.rs @@ -104,6 +104,8 @@ pub trait Network: const MAX_DEPLOYMENT_LIMIT: u64 = 1 << 20; // 1,048,576 constraints /// The maximum number of microcredits that can be spent as a fee. const MAX_FEE: u64 = 1_000_000_000_000_000; + /// The maximum number of microcredits that can be spent on a finalize block. + const TRANSACTION_SPEND_LIMIT: u64 = 1_000_000_000_000_000; /// The anchor height, defined as the expected number of blocks to reach the coinbase target. const ANCHOR_HEIGHT: u32 = Self::ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32; From f3c0ca5f43d961eaff596b80be129af56fffac70 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:56:54 -0800 Subject: [PATCH 2/7] Move cost to process crate --- synthesizer/{src/vm/helpers => process/src}/cost.rs | 13 ++++--------- synthesizer/process/src/lib.rs | 3 +++ synthesizer/src/vm/deploy.rs | 2 +- synthesizer/src/vm/execute.rs | 2 +- synthesizer/src/vm/helpers/mod.rs | 3 --- synthesizer/src/vm/verify.rs | 4 ++-- 6 files changed, 11 insertions(+), 16 deletions(-) rename synthesizer/{src/vm/helpers => process/src}/cost.rs (98%) diff --git a/synthesizer/src/vm/helpers/cost.rs b/synthesizer/process/src/cost.rs similarity index 98% rename from synthesizer/src/vm/helpers/cost.rs rename to synthesizer/process/src/cost.rs index bcee10e70d..9382297443 100644 --- a/synthesizer/src/vm/helpers/cost.rs +++ b/synthesizer/process/src/cost.rs @@ -12,10 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{ - prelude::{Stack, StackProgramTypes}, - VM, -}; +use crate::{Process, Stack, StackProgramTypes}; + use console::{ prelude::*, program::{FinalizeType, Identifier, LiteralType, PlaintextType}, @@ -59,10 +57,7 @@ pub fn deployment_cost(deployment: &Deployment) -> Result<(u64, ( } /// Returns the *minimum* cost in microcredits to publish the given execution (total cost, (storage cost, finalize cost)). -pub fn execution_cost>( - vm: &VM, - execution: &Execution, -) -> Result<(u64, (u64, u64))> { +pub fn execution_cost(process: &Process, execution: &Execution) -> Result<(u64, (u64, u64))> { // Compute the storage cost in microcredits. let storage_cost = execution.size_in_bytes()?; @@ -73,7 +68,7 @@ pub fn execution_cost>( // Retrieve the program ID and function name. let (program_id, function_name) = (transition.program_id(), transition.function_name()); // Retrieve the finalize cost. - let cost = cost_in_microcredits(vm.process().read().get_stack(program_id)?, function_name)?; + let cost = cost_in_microcredits(process.get_stack(program_id)?, function_name)?; // Accumulate the finalize cost. if cost > 0 { finalize_cost = finalize_cost diff --git a/synthesizer/process/src/lib.rs b/synthesizer/process/src/lib.rs index 53953ecad6..4beb82b95e 100644 --- a/synthesizer/process/src/lib.rs +++ b/synthesizer/process/src/lib.rs @@ -18,6 +18,9 @@ // TODO (howardwu): Update the return type on `execute` after stabilizing the interface. #![allow(clippy::type_complexity)] +mod cost; +pub use cost::*; + mod stack; pub use stack::*; diff --git a/synthesizer/src/vm/deploy.rs b/synthesizer/src/vm/deploy.rs index f9e260793c..9350fe5007 100644 --- a/synthesizer/src/vm/deploy.rs +++ b/synthesizer/src/vm/deploy.rs @@ -40,7 +40,7 @@ impl> VM { let owner = ProgramOwner::new(private_key, deployment_id, rng)?; // Compute the minimum deployment cost. - let (minimum_deployment_cost, _) = deployment_cost(&deployment)?; + let (minimum_deployment_cost, _) = process::deployment_cost(&deployment)?; // Authorize the fee. let fee_authorization = match fee_record { Some(record) => self.authorize_fee_private( diff --git a/synthesizer/src/vm/execute.rs b/synthesizer/src/vm/execute.rs index b27626504d..be37619227 100644 --- a/synthesizer/src/vm/execute.rs +++ b/synthesizer/src/vm/execute.rs @@ -45,7 +45,7 @@ impl> VM { let fee = match is_fee_required || is_priority_fee_declared { true => { // Compute the minimum execution cost. - let (minimum_execution_cost, (_, _)) = execution_cost(self, &execution)?; + let (minimum_execution_cost, (_, _)) = process::execution_cost(&self.process().read(), &execution)?; // Compute the execution ID. let execution_id = execution.to_execution_id()?; // Authorize the fee. diff --git a/synthesizer/src/vm/helpers/mod.rs b/synthesizer/src/vm/helpers/mod.rs index 2ef9403bee..1fd8ec7321 100644 --- a/synthesizer/src/vm/helpers/mod.rs +++ b/synthesizer/src/vm/helpers/mod.rs @@ -15,9 +15,6 @@ pub(crate) mod committee; pub use committee::*; -mod cost; -pub use cost::*; - mod macros; mod rewards; diff --git a/synthesizer/src/vm/verify.rs b/synthesizer/src/vm/verify.rs index 2a97b6e8d5..b5284f09f5 100644 --- a/synthesizer/src/vm/verify.rs +++ b/synthesizer/src/vm/verify.rs @@ -161,7 +161,7 @@ impl> VM { bail!("Failed to compute the Merkle root for deployment transaction '{id}'") }; // Compute the minimum deployment cost. - let (cost, _) = deployment_cost(deployment)?; + let (cost, _) = process::deployment_cost(deployment)?; // Ensure the fee is sufficient to cover the cost. if *fee.base_amount()? < cost { bail!("Transaction '{id}' has an insufficient base fee (deployment) - requires {cost} microcredits") @@ -183,7 +183,7 @@ impl> VM { // If the fee is required, then check that the base fee amount is satisfied. if is_fee_required { // Compute the execution cost. - let (cost, _) = execution_cost(self, execution)?; + let (cost, _) = process::execution_cost(&self.process().read(), execution)?; // Ensure the fee is sufficient to cover the cost. if *fee.base_amount()? < cost { bail!( From a76ad7915c51269266599fe18fecd78ba2946704 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:59:48 -0800 Subject: [PATCH 3/7] Add check for TRANSACTION_SPEND_LIMIT --- synthesizer/process/src/verify_deployment.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/synthesizer/process/src/verify_deployment.rs b/synthesizer/process/src/verify_deployment.rs index f499fdebcc..843bc5340b 100644 --- a/synthesizer/process/src/verify_deployment.rs +++ b/synthesizer/process/src/verify_deployment.rs @@ -33,6 +33,16 @@ impl Process { let stack = Stack::new(self, deployment.program())?; lap!(timer, "Compute the stack"); + // Ensure that each finalize block does not exceed the `TRANSACTION_SPEND_LIMIT`. + for (function_name, _) in deployment.program().functions() { + let finalize_cost = cost_in_microcredits(&stack, function_name)?; + ensure!( + finalize_cost <= N::TRANSACTION_SPEND_LIMIT, + "Finalize block '{function_name}' has a cost '{finalize_cost}' which exceeds the transaction spend limit '{}'", + N::TRANSACTION_SPEND_LIMIT + ); + } + // Ensure the verifying keys are well-formed and the certificates are valid. let verification = stack.verify_deployment::(deployment, rng); lap!(timer, "Verify the deployment"); From 963d1fe944c46bbb5018d55fd83128c0183f923c Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:49:44 -0800 Subject: [PATCH 4/7] Add test --- console/network/src/lib.rs | 2 +- synthesizer/process/src/cost.rs | 1 - synthesizer/src/vm/mod.rs | 84 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/console/network/src/lib.rs b/console/network/src/lib.rs index c03001fc6a..45b109c29c 100644 --- a/console/network/src/lib.rs +++ b/console/network/src/lib.rs @@ -105,7 +105,7 @@ pub trait Network: /// The maximum number of microcredits that can be spent as a fee. const MAX_FEE: u64 = 1_000_000_000_000_000; /// The maximum number of microcredits that can be spent on a finalize block. - const TRANSACTION_SPEND_LIMIT: u64 = 1_000_000_000_000_000; + const TRANSACTION_SPEND_LIMIT: u64 = 100_000_000; /// The anchor height, defined as the expected number of blocks to reach the coinbase target. const ANCHOR_HEIGHT: u32 = Self::ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32; diff --git a/synthesizer/process/src/cost.rs b/synthesizer/process/src/cost.rs index 9382297443..d30bc504f5 100644 --- a/synthesizer/process/src/cost.rs +++ b/synthesizer/process/src/cost.rs @@ -19,7 +19,6 @@ use console::{ program::{FinalizeType, Identifier, LiteralType, PlaintextType}, }; use ledger_block::{Deployment, Execution}; -use ledger_store::ConsensusStorage; use synthesizer_program::{CastType, Command, Finalize, Instruction, Operand, StackProgram}; /// Returns the *minimum* cost in microcredits to publish the given deployment (total cost, (storage cost, synthesis cost, namespace cost)). diff --git a/synthesizer/src/vm/mod.rs b/synthesizer/src/vm/mod.rs index 8db16cb60a..a009c8d969 100644 --- a/synthesizer/src/vm/mod.rs +++ b/synthesizer/src/vm/mod.rs @@ -397,6 +397,7 @@ pub(crate) mod test_helpers { use indexmap::IndexMap; use once_cell::sync::OnceCell; use std::borrow::Borrow; + use synthesizer_process::{cost_in_microcredits, Stack}; use synthesizer_snark::VerifyingKey; pub(crate) type CurrentNetwork = MainnetV0; @@ -1395,4 +1396,87 @@ finalize do: // Verify. vm.check_transaction(&transaction, None, rng).unwrap(); } + + #[test] + fn test_deployment_exceeding_max_transaction_spend() { + let rng = &mut TestRng::default(); + + // Initialize a private key. + let private_key = sample_genesis_private_key(rng); + + // Initialize the genesis block. + let genesis = sample_genesis_block(rng); + + // Initialize the VM. + let vm = sample_vm(); + // Update the VM. + vm.add_next_block(&genesis).unwrap(); + + // Construct two programs, one that is allowed and one that exceeds the maximum transaction spend. + let mut allowed_program = None; + let mut exceeding_program = None; + + for i in 0..::MAX_COMMANDS.ilog2() { + // Construct the finalize body. + let finalize_body = + (0..2.pow(i)).map(|i| format!("hash.bhp256 0field into r{i} as field;")).collect::>().join("\n"); + + // Construct the program. + let program = Program::from_str(&format!( + r"program test_max_spend_limit_{i}.aleo; + function foo: + async foo into r0; + output r0 as test_max_spend_limit_{i}.aleo/foo.future; + + finalize foo:{finalize_body}", + )) + .unwrap(); + + // Initialize a stack for the program. + let stack = Stack::::new(&vm.process().read(), &program).unwrap(); + + // Check the finalize cost. + let finalize_cost = cost_in_microcredits(&stack, &Identifier::from_str("foo").unwrap()).unwrap(); + + // If the finalize cost exceeds the maximum transaction spend, assign the program to the exceeding program and break. + // Otherwise, assign the program to the allowed program and continue. + if finalize_cost > ::TRANSACTION_SPEND_LIMIT { + exceeding_program = Some(program); + break; + } else { + allowed_program = Some(program); + } + } + + // Ensure that the allowed and exceeding programs are not None. + assert!(allowed_program.is_some()); + assert!(exceeding_program.is_some()); + + let allowed_program = allowed_program.unwrap(); + let exceeding_program = exceeding_program.unwrap(); + + // Deploy the allowed program. + let deployment = vm.deploy(&private_key, &allowed_program, None, 0, None, rng).unwrap(); + + // Verify the deployment transaction. + assert!(vm.check_transaction(&deployment, None, rng).is_ok()); + + // Construct the next block. + let block = sample_next_block(&vm, &private_key, &[deployment], rng).unwrap(); + + // Check that the block has one accepted transaction. + assert_eq!(block.transactions().num_accepted(), 1); + + // Add the deployment to a block and update the VM. + vm.add_next_block(&block).unwrap(); + + // Check that the program exists in the VM. + assert!(vm.contains_program(allowed_program.id())); + + // Deploy the exceeding program. + let deployment = vm.deploy(&private_key, &exceeding_program, None, 0, None, rng).unwrap(); + + // Verify the deployment transaction. + assert!(vm.check_transaction(&deployment, None, rng).is_err()); + } } From 5edfadada91f1df992442135b3fb9d1a1b2d7084 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:46:43 -0800 Subject: [PATCH 5/7] Move test --- ledger/src/tests.rs | 101 ++++++++++++++++++++++++++++++++++++-- synthesizer/src/vm/mod.rs | 81 ------------------------------ 2 files changed, 98 insertions(+), 84 deletions(-) diff --git a/ledger/src/tests.rs b/ledger/src/tests.rs index 26744f15c4..061f8efa82 100644 --- a/ledger/src/tests.rs +++ b/ledger/src/tests.rs @@ -28,7 +28,8 @@ use indexmap::IndexMap; use ledger_block::{ConfirmedTransaction, Rejected, Transaction}; use ledger_committee::{Committee, MIN_VALIDATOR_STAKE}; use ledger_store::{helpers::memory::ConsensusMemory, ConsensusStore}; -use synthesizer::{program::Program, vm::VM}; +use synthesizer::{program::Program, Stack, vm::VM}; +use synthesizer::prelude::cost_in_microcredits; #[test] fn test_load() { @@ -1421,7 +1422,7 @@ fn test_max_committee_limit_with_bonds() { Value::::from_str(&first_address.to_string()).unwrap(), Value::::from_str(&format!("{MIN_VALIDATOR_STAKE}u64")).unwrap(), ] - .iter(), + .iter(), None, 0, None, @@ -1464,7 +1465,7 @@ fn test_max_committee_limit_with_bonds() { Value::::from_str(&second_address.to_string()).unwrap(), Value::::from_str(&format!("{MIN_VALIDATOR_STAKE}u64")).unwrap(), ] - .iter(), + .iter(), None, 0, None, @@ -1497,3 +1498,97 @@ fn test_max_committee_limit_with_bonds() { let committee = ledger.latest_committee().unwrap(); assert!(!committee.is_committee_member(second_address)); } + +#[test] +fn test_deployment_exceeding_max_transaction_spend() { + let rng = &mut TestRng::default(); + + // Initialize the test environment. + let crate::test_helpers::TestEnv { ledger, private_key, .. } = crate::test_helpers::sample_test_env(rng); + + // Construct two programs, one that is allowed and one that exceeds the maximum transaction spend. + let mut allowed_program = None; + let mut exceeding_program = None; + + for i in 0..::MAX_COMMANDS.ilog2() { + // Construct the finalize body. + let finalize_body = + (0..2.pow(i)).map(|i| format!("hash.bhp256 0field into r{i} as field;")).collect::>().join("\n"); + + // Construct the program. + let program = Program::from_str(&format!( + r"program test_max_spend_limit_{i}.aleo; + function foo: + async foo into r0; + output r0 as test_max_spend_limit_{i}.aleo/foo.future; + + finalize foo:{finalize_body}", + )) + .unwrap(); + + // Initialize a stack for the program. + let stack = Stack::::new(&ledger.vm().process().read(), &program).unwrap(); + + // Check the finalize cost. + let finalize_cost = cost_in_microcredits(&stack, &Identifier::from_str("foo").unwrap()).unwrap(); + + // If the finalize cost exceeds the maximum transaction spend, assign the program to the exceeding program and break. + // Otherwise, assign the program to the allowed program and continue. + if finalize_cost > ::TRANSACTION_SPEND_LIMIT { + exceeding_program = Some(program); + break; + } else { + allowed_program = Some(program); + } + } + + // Ensure that the allowed and exceeding programs are not None. + assert!(allowed_program.is_some()); + assert!(exceeding_program.is_some()); + + let allowed_program = allowed_program.unwrap(); + let exceeding_program = exceeding_program.unwrap(); + + // Deploy the allowed program. + let deployment = ledger.vm().deploy(&private_key, &allowed_program, None, 0, None, rng).unwrap(); + + // Verify the deployment transaction. + assert!(ledger.vm().check_transaction(&deployment, None, rng).is_ok()); + + // Construct the next block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment], rng) + .unwrap(); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Check that the program exists in the VM. + assert!(ledger.vm().contains_program(allowed_program.id())); + + // Deploy the exceeding program. + let deployment = ledger.vm().deploy(&private_key, &exceeding_program, None, 0, None, rng).unwrap(); + + // Verify the deployment transaction. + assert!(ledger.vm().check_transaction(&deployment, None, rng).is_err()); + + // Construct the next block. + let block = ledger + .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment], rng) + .unwrap(); + + // Check that the number of aborted transactions is 1. + assert_eq!(block.aborted_transaction_ids().len(), 1); + + // Check that the next block is valid. + ledger.check_next_block(&block, rng).unwrap(); + + // Add the block to the ledger. + ledger.advance_to_next_block(&block).unwrap(); + + // Check that the program does not exist in the VM. + assert!(!ledger.vm().contains_program(exceeding_program.id())); +} diff --git a/synthesizer/src/vm/mod.rs b/synthesizer/src/vm/mod.rs index a009c8d969..39085f9845 100644 --- a/synthesizer/src/vm/mod.rs +++ b/synthesizer/src/vm/mod.rs @@ -1397,86 +1397,5 @@ finalize do: vm.check_transaction(&transaction, None, rng).unwrap(); } - #[test] - fn test_deployment_exceeding_max_transaction_spend() { - let rng = &mut TestRng::default(); - - // Initialize a private key. - let private_key = sample_genesis_private_key(rng); - - // Initialize the genesis block. - let genesis = sample_genesis_block(rng); - - // Initialize the VM. - let vm = sample_vm(); - // Update the VM. - vm.add_next_block(&genesis).unwrap(); - - // Construct two programs, one that is allowed and one that exceeds the maximum transaction spend. - let mut allowed_program = None; - let mut exceeding_program = None; - - for i in 0..::MAX_COMMANDS.ilog2() { - // Construct the finalize body. - let finalize_body = - (0..2.pow(i)).map(|i| format!("hash.bhp256 0field into r{i} as field;")).collect::>().join("\n"); - - // Construct the program. - let program = Program::from_str(&format!( - r"program test_max_spend_limit_{i}.aleo; - function foo: - async foo into r0; - output r0 as test_max_spend_limit_{i}.aleo/foo.future; - - finalize foo:{finalize_body}", - )) - .unwrap(); - // Initialize a stack for the program. - let stack = Stack::::new(&vm.process().read(), &program).unwrap(); - - // Check the finalize cost. - let finalize_cost = cost_in_microcredits(&stack, &Identifier::from_str("foo").unwrap()).unwrap(); - - // If the finalize cost exceeds the maximum transaction spend, assign the program to the exceeding program and break. - // Otherwise, assign the program to the allowed program and continue. - if finalize_cost > ::TRANSACTION_SPEND_LIMIT { - exceeding_program = Some(program); - break; - } else { - allowed_program = Some(program); - } - } - - // Ensure that the allowed and exceeding programs are not None. - assert!(allowed_program.is_some()); - assert!(exceeding_program.is_some()); - - let allowed_program = allowed_program.unwrap(); - let exceeding_program = exceeding_program.unwrap(); - - // Deploy the allowed program. - let deployment = vm.deploy(&private_key, &allowed_program, None, 0, None, rng).unwrap(); - - // Verify the deployment transaction. - assert!(vm.check_transaction(&deployment, None, rng).is_ok()); - - // Construct the next block. - let block = sample_next_block(&vm, &private_key, &[deployment], rng).unwrap(); - - // Check that the block has one accepted transaction. - assert_eq!(block.transactions().num_accepted(), 1); - - // Add the deployment to a block and update the VM. - vm.add_next_block(&block).unwrap(); - - // Check that the program exists in the VM. - assert!(vm.contains_program(allowed_program.id())); - - // Deploy the exceeding program. - let deployment = vm.deploy(&private_key, &exceeding_program, None, 0, None, rng).unwrap(); - - // Verify the deployment transaction. - assert!(vm.check_transaction(&deployment, None, rng).is_err()); - } } From 7be7995b2f27103f80bd6eb0bed163c78a16299e Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:51:23 -0800 Subject: [PATCH 6/7] Cleanup --- ledger/src/tests.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/ledger/src/tests.rs b/ledger/src/tests.rs index 061f8efa82..f75153a01c 100644 --- a/ledger/src/tests.rs +++ b/ledger/src/tests.rs @@ -1574,21 +1574,4 @@ fn test_deployment_exceeding_max_transaction_spend() { // Verify the deployment transaction. assert!(ledger.vm().check_transaction(&deployment, None, rng).is_err()); - - // Construct the next block. - let block = ledger - .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment], rng) - .unwrap(); - - // Check that the number of aborted transactions is 1. - assert_eq!(block.aborted_transaction_ids().len(), 1); - - // Check that the next block is valid. - ledger.check_next_block(&block, rng).unwrap(); - - // Add the block to the ledger. - ledger.advance_to_next_block(&block).unwrap(); - - // Check that the program does not exist in the VM. - assert!(!ledger.vm().contains_program(exceeding_program.id())); } From 1c9e77a2c55ee5de18f151b5de078cc1394808f3 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:16:13 -0800 Subject: [PATCH 7/7] Addres feedback; clippy; fmt --- ledger/src/tests.rs | 14 ++++++-------- synthesizer/src/vm/deploy.rs | 2 +- synthesizer/src/vm/execute.rs | 2 +- synthesizer/src/vm/mod.rs | 5 +---- synthesizer/src/vm/verify.rs | 4 ++-- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/ledger/src/tests.rs b/ledger/src/tests.rs index f75153a01c..8446e47e48 100644 --- a/ledger/src/tests.rs +++ b/ledger/src/tests.rs @@ -28,8 +28,7 @@ use indexmap::IndexMap; use ledger_block::{ConfirmedTransaction, Rejected, Transaction}; use ledger_committee::{Committee, MIN_VALIDATOR_STAKE}; use ledger_store::{helpers::memory::ConsensusMemory, ConsensusStore}; -use synthesizer::{program::Program, Stack, vm::VM}; -use synthesizer::prelude::cost_in_microcredits; +use synthesizer::{prelude::cost_in_microcredits, program::Program, vm::VM, Stack}; #[test] fn test_load() { @@ -1422,7 +1421,7 @@ fn test_max_committee_limit_with_bonds() { Value::::from_str(&first_address.to_string()).unwrap(), Value::::from_str(&format!("{MIN_VALIDATOR_STAKE}u64")).unwrap(), ] - .iter(), + .iter(), None, 0, None, @@ -1465,7 +1464,7 @@ fn test_max_committee_limit_with_bonds() { Value::::from_str(&second_address.to_string()).unwrap(), Value::::from_str(&format!("{MIN_VALIDATOR_STAKE}u64")).unwrap(), ] - .iter(), + .iter(), None, 0, None, @@ -1524,7 +1523,7 @@ fn test_deployment_exceeding_max_transaction_spend() { finalize foo:{finalize_body}", )) - .unwrap(); + .unwrap(); // Initialize a stack for the program. let stack = Stack::::new(&ledger.vm().process().read(), &program).unwrap(); @@ -1556,9 +1555,8 @@ fn test_deployment_exceeding_max_transaction_spend() { assert!(ledger.vm().check_transaction(&deployment, None, rng).is_ok()); // Construct the next block. - let block = ledger - .prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment], rng) - .unwrap(); + let block = + ledger.prepare_advance_to_next_beacon_block(&private_key, vec![], vec![], vec![deployment], rng).unwrap(); // Check that the next block is valid. ledger.check_next_block(&block, rng).unwrap(); diff --git a/synthesizer/src/vm/deploy.rs b/synthesizer/src/vm/deploy.rs index 9350fe5007..f9e260793c 100644 --- a/synthesizer/src/vm/deploy.rs +++ b/synthesizer/src/vm/deploy.rs @@ -40,7 +40,7 @@ impl> VM { let owner = ProgramOwner::new(private_key, deployment_id, rng)?; // Compute the minimum deployment cost. - let (minimum_deployment_cost, _) = process::deployment_cost(&deployment)?; + let (minimum_deployment_cost, _) = deployment_cost(&deployment)?; // Authorize the fee. let fee_authorization = match fee_record { Some(record) => self.authorize_fee_private( diff --git a/synthesizer/src/vm/execute.rs b/synthesizer/src/vm/execute.rs index be37619227..2acd01d06f 100644 --- a/synthesizer/src/vm/execute.rs +++ b/synthesizer/src/vm/execute.rs @@ -45,7 +45,7 @@ impl> VM { let fee = match is_fee_required || is_priority_fee_declared { true => { // Compute the minimum execution cost. - let (minimum_execution_cost, (_, _)) = process::execution_cost(&self.process().read(), &execution)?; + let (minimum_execution_cost, (_, _)) = execution_cost(&self.process().read(), &execution)?; // Compute the execution ID. let execution_id = execution.to_execution_id()?; // Authorize the fee. diff --git a/synthesizer/src/vm/mod.rs b/synthesizer/src/vm/mod.rs index 39085f9845..68ee600d11 100644 --- a/synthesizer/src/vm/mod.rs +++ b/synthesizer/src/vm/mod.rs @@ -55,7 +55,7 @@ use ledger_store::{ TransactionStore, TransitionStore, }; -use synthesizer_process::{Authorization, Process, Trace}; +use synthesizer_process::{deployment_cost, execution_cost, Authorization, Process, Trace}; use synthesizer_program::{FinalizeGlobalState, FinalizeOperation, FinalizeStoreTrait, Program}; use aleo_std::prelude::{finish, lap, timer}; @@ -397,7 +397,6 @@ pub(crate) mod test_helpers { use indexmap::IndexMap; use once_cell::sync::OnceCell; use std::borrow::Borrow; - use synthesizer_process::{cost_in_microcredits, Stack}; use synthesizer_snark::VerifyingKey; pub(crate) type CurrentNetwork = MainnetV0; @@ -1396,6 +1395,4 @@ finalize do: // Verify. vm.check_transaction(&transaction, None, rng).unwrap(); } - - } diff --git a/synthesizer/src/vm/verify.rs b/synthesizer/src/vm/verify.rs index b5284f09f5..285565325f 100644 --- a/synthesizer/src/vm/verify.rs +++ b/synthesizer/src/vm/verify.rs @@ -161,7 +161,7 @@ impl> VM { bail!("Failed to compute the Merkle root for deployment transaction '{id}'") }; // Compute the minimum deployment cost. - let (cost, _) = process::deployment_cost(deployment)?; + let (cost, _) = deployment_cost(deployment)?; // Ensure the fee is sufficient to cover the cost. if *fee.base_amount()? < cost { bail!("Transaction '{id}' has an insufficient base fee (deployment) - requires {cost} microcredits") @@ -183,7 +183,7 @@ impl> VM { // If the fee is required, then check that the base fee amount is satisfied. if is_fee_required { // Compute the execution cost. - let (cost, _) = process::execution_cost(&self.process().read(), execution)?; + let (cost, _) = execution_cost(&self.process().read(), execution)?; // Ensure the fee is sufficient to cover the cost. if *fee.base_amount()? < cost { bail!(