diff --git a/Cargo.toml b/Cargo.toml index a59104a408..d182f817b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,8 +55,8 @@ kadcast = "=0.7.0" phoenix-circuits = { version = "=0.4.0", default-features = false } phoenix-core = { version = "=0.32.0", default-features = false } # we leave piecrust open until a stable release is out -piecrust = "=0.27.0-rc.0" -piecrust-uplink = "0.17.2-rc.0" +piecrust = "=0.27.0" +piecrust-uplink = "0.17.3" poseidon-merkle = "=0.7.0" # External dependencies diff --git a/node/src/mempool.rs b/node/src/mempool.rs index 43e9282c56..2d0470399e 100644 --- a/node/src/mempool.rs +++ b/node/src/mempool.rs @@ -222,8 +222,11 @@ impl MempoolSrv { } let gas_per_deploy_byte = vm.gas_per_deploy_byte(); - let min_gas_limit = - vm::bytecode_charge(&deploy.bytecode, gas_per_deploy_byte); + let min_gas_limit = vm::bytecode_charge( + &deploy.bytecode, + gas_per_deploy_byte, + vm.min_deploy_points(), + ); if tx.inner.gas_limit() < min_gas_limit { return Err(TxAcceptanceError::GasLimitTooLow(min_gas_limit)); } diff --git a/node/src/vm.rs b/node/src/vm.rs index 9e5885cd7d..dec91117e9 100644 --- a/node/src/vm.rs +++ b/node/src/vm.rs @@ -13,6 +13,7 @@ use dusk_core::transfer::data::ContractBytecode; use dusk_core::transfer::moonlight::AccountData; use node_data::events::contract::ContractEvent; use node_data::ledger::{Block, SpentTransaction, Transaction}; +use std::cmp::max; #[derive(Default)] pub struct Config {} @@ -88,6 +89,7 @@ pub trait VMExecution: Send + Sync + 'static { fn gas_per_deploy_byte(&self) -> u64; fn min_deployment_gas_price(&self) -> u64; fn min_gas_limit(&self) -> u64; + fn min_deploy_points(&self) -> u64; } #[allow(clippy::large_enum_variant)] @@ -105,6 +107,10 @@ pub enum PreverificationResult { pub fn bytecode_charge( bytecode: &ContractBytecode, gas_per_deploy_byte: u64, + min_deploy_points: u64, ) -> u64 { - bytecode.bytes.len() as u64 * gas_per_deploy_byte + max( + bytecode.bytes.len() as u64 * gas_per_deploy_byte, + min_deploy_points, + ) } diff --git a/rusk/default.config.toml b/rusk/default.config.toml index 71d023a9b0..830c4d38b3 100644 --- a/rusk/default.config.toml +++ b/rusk/default.config.toml @@ -26,6 +26,7 @@ #gas_per_deploy_byte = 100 #min_deployment_gas_price = 2000 #min_gas_limit = 75000 +#min_deploy_points = 5000000 [databroker] max_inv_entries = 100 diff --git a/rusk/src/bin/config/chain.rs b/rusk/src/bin/config/chain.rs index d429897a81..1e69ac6175 100644 --- a/rusk/src/bin/config/chain.rs +++ b/rusk/src/bin/config/chain.rs @@ -32,6 +32,7 @@ pub(crate) struct ChainConfig { // forking the chain. gas_per_deploy_byte: Option, min_deployment_gas_price: Option, + min_deploy_points: Option, min_gas_limit: Option, block_gas_limit: Option, @@ -93,6 +94,10 @@ impl ChainConfig { self.min_deployment_gas_price } + pub(crate) fn min_deploy_points(&self) -> Option { + self.min_deploy_points + } + pub(crate) fn min_gas_limit(&self) -> Option { self.min_gas_limit } diff --git a/rusk/src/bin/main.rs b/rusk/src/bin/main.rs index 666879a197..bc4780ae0e 100644 --- a/rusk/src/bin/main.rs +++ b/rusk/src/bin/main.rs @@ -85,6 +85,7 @@ async fn main() -> Result<(), Box> { .with_min_deployment_gas_price( config.chain.min_deployment_gas_price(), ) + .with_min_deploy_points(config.chain.min_deploy_points()) .with_min_gas_limit(config.chain.min_gas_limit()) .with_block_gas_limit(config.chain.block_gas_limit()); }; diff --git a/rusk/src/lib/builder/node.rs b/rusk/src/lib/builder/node.rs index f67ffa1efa..ac38f733d9 100644 --- a/rusk/src/lib/builder/node.rs +++ b/rusk/src/lib/builder/node.rs @@ -44,6 +44,7 @@ pub struct RuskNodeBuilder { gas_per_deploy_byte: Option, min_deployment_gas_price: Option, min_gas_limit: Option, + min_deploy_points: Option, block_gas_limit: u64, feeder_call_gas: u64, state_dir: PathBuf, @@ -56,6 +57,7 @@ pub struct RuskNodeBuilder { const DEFAULT_GAS_PER_DEPLOY_BYTE: u64 = 100; const DEFAULT_MIN_DEPLOYMENT_GAS_PRICE: u64 = 2000; const DEFAULT_MIN_GAS_LIMIT: u64 = 75000; +const DEFAULT_MIN_DEPLOY_POINTS: u64 = 5_000_000; impl RuskNodeBuilder { pub fn with_consensus_keys(mut self, consensus_keys_path: String) -> Self { @@ -142,6 +144,14 @@ impl RuskNodeBuilder { self } + pub fn with_min_deploy_points( + mut self, + min_deploy_points: Option, + ) -> Self { + self.min_deploy_points = min_deploy_points; + self + } + pub fn with_block_gas_limit(mut self, block_gas_limit: u64) -> Self { self.block_gas_limit = block_gas_limit; self @@ -187,6 +197,8 @@ impl RuskNodeBuilder { .min_deployment_gas_price .unwrap_or(DEFAULT_MIN_DEPLOYMENT_GAS_PRICE); let min_gas_limit = self.min_gas_limit.unwrap_or(DEFAULT_MIN_GAS_LIMIT); + let min_deploy_points = + self.min_deploy_points.unwrap_or(DEFAULT_MIN_DEPLOY_POINTS); let rusk = Rusk::new( self.state_dir, @@ -195,6 +207,7 @@ impl RuskNodeBuilder { gas_per_deploy_byte, min_deployment_gas_price, min_gas_limit, + min_deploy_points, self.block_gas_limit, self.feeder_call_gas, rues_sender.clone(), diff --git a/rusk/src/lib/node.rs b/rusk/src/lib/node.rs index bf665a8b5d..593f8f5cb8 100644 --- a/rusk/src/lib/node.rs +++ b/rusk/src/lib/node.rs @@ -44,6 +44,7 @@ pub struct Rusk { pub(crate) gas_per_deploy_byte: u64, pub(crate) min_deployment_gas_price: u64, pub(crate) min_gas_limit: u64, + pub(crate) min_deploy_points: u64, pub(crate) feeder_gas_limit: u64, pub(crate) block_gas_limit: u64, pub(crate) event_sender: broadcast::Sender, diff --git a/rusk/src/lib/node/rusk.rs b/rusk/src/lib/node/rusk.rs index a33a42ba3f..1dddf0d6c8 100644 --- a/rusk/src/lib/node/rusk.rs +++ b/rusk/src/lib/node/rusk.rs @@ -61,6 +61,7 @@ impl Rusk { gas_per_deploy_byte: u64, min_deployment_gas_price: u64, min_gas_limit: u64, + min_deploy_points: u64, block_gas_limit: u64, feeder_gas_limit: u64, event_sender: broadcast::Sender, @@ -101,6 +102,7 @@ impl Rusk { gas_per_deploy_byte, min_deployment_gas_price, min_gas_limit, + min_deploy_points, feeder_gas_limit, event_sender, #[cfg(feature = "archive")] @@ -171,6 +173,7 @@ impl Rusk { &mut session, &unspent_tx.inner, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, ) { Ok(receipt) => { @@ -191,6 +194,7 @@ impl Rusk { &mut session, &spent_tx.inner.inner, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, ); } @@ -283,6 +287,7 @@ impl Rusk { slashing, voters, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, ) .map(|(a, b, _, _)| (a, b)) @@ -322,6 +327,7 @@ impl Rusk { slashing, voters, self.gas_per_deploy_byte, + self.min_deploy_points, self.min_deployment_gas_price, )?; @@ -580,6 +586,7 @@ fn accept( slashing: Vec, voters: &[Voter], gas_per_deploy_byte: u64, + min_deploy_points: u64, min_deployment_gas_price: u64, ) -> Result<( Vec, @@ -604,6 +611,7 @@ fn accept( &mut session, tx, gas_per_deploy_byte, + min_deploy_points, min_deployment_gas_price, )?; @@ -683,9 +691,14 @@ fn contract_deploy( deploy: &ContractDeploy, gas_limit: u64, gas_per_deploy_byte: u64, + min_deploy_points: u64, receipt: &mut CallReceipt, ContractError>>, ) { - let deploy_charge = bytecode_charge(&deploy.bytecode, gas_per_deploy_byte); + let deploy_charge = bytecode_charge( + &deploy.bytecode, + gas_per_deploy_byte, + min_deploy_points, + ); let min_gas_limit = receipt.gas_spent + deploy_charge; let hash = blake3::hash(deploy.bytecode.bytes.as_slice()); if gas_limit < min_gas_limit { @@ -755,13 +768,17 @@ fn execute( session: &mut Session, tx: &ProtocolTransaction, gas_per_deploy_byte: u64, + min_deploy_points: u64, min_deployment_gas_price: u64, ) -> Result, ContractError>>, PiecrustError> { // Transaction will be discarded if it is a deployment transaction // with gas limit smaller than deploy charge. if let Some(deploy) = tx.deploy() { - let deploy_charge = - bytecode_charge(&deploy.bytecode, gas_per_deploy_byte); + let deploy_charge = bytecode_charge( + &deploy.bytecode, + gas_per_deploy_byte, + min_deploy_points, + ); if tx.gas_price() < min_deployment_gas_price { return Err(PiecrustError::Panic( "gas price too low to deploy".into(), @@ -793,6 +810,7 @@ fn execute( deploy, gas_left, gas_per_deploy_byte, + min_deploy_points, &mut receipt, ); } diff --git a/rusk/src/lib/node/vm.rs b/rusk/src/lib/node/vm.rs index e33a062393..ff0c31e217 100644 --- a/rusk/src/lib/node/vm.rs +++ b/rusk/src/lib/node/vm.rs @@ -279,6 +279,10 @@ impl VMExecution for Rusk { fn min_gas_limit(&self) -> u64 { self.min_gas_limit } + + fn min_deploy_points(&self) -> u64 { + self.min_deploy_points + } } fn has_unique_elements(iter: T) -> bool diff --git a/rusk/tests/common/state.rs b/rusk/tests/common/state.rs index 114461d0f7..d4b536994f 100644 --- a/rusk/tests/common/state.rs +++ b/rusk/tests/common/state.rs @@ -33,6 +33,7 @@ const CHAIN_ID: u8 = 0xFA; pub const DEFAULT_GAS_PER_DEPLOY_BYTE: u64 = 100; pub const DEFAULT_MIN_DEPLOYMENT_GAS_PRICE: u64 = 2000; pub const DEFAULT_MIN_GAS_LIMIT: u64 = 75000; +pub const DEFAULT_MIN_DEPLOY_POINTS: u64 = 5000000; // Creates a Rusk initial state in the given directory pub fn new_state>( @@ -64,6 +65,7 @@ pub fn new_state_with_chainid>( DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_DEPLOYMENT_GAS_PRICE, DEFAULT_MIN_GAS_LIMIT, + DEFAULT_MIN_DEPLOY_POINTS, block_gas_limit, u64::MAX, sender, diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index 70d5a2fae9..657ab3bb06 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -25,6 +25,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::DEFAULT_MIN_DEPLOYMENT_GAS_PRICE; +use crate::common::state::DEFAULT_MIN_DEPLOY_POINTS; use crate::common::state::{generator_procedure, ExecuteResult}; use crate::common::state::{ DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_GAS_LIMIT, @@ -106,6 +107,7 @@ fn initial_state>(dir: P, deploy_bob: bool) -> Result { DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_DEPLOYMENT_GAS_PRICE, DEFAULT_MIN_GAS_LIMIT, + DEFAULT_MIN_DEPLOY_POINTS, BLOCK_GAS_LIMIT, u64::MAX, sender, diff --git a/rusk/tests/services/owner_calls.rs b/rusk/tests/services/owner_calls.rs index 12abe72f13..802454f7d5 100644 --- a/rusk/tests/services/owner_calls.rs +++ b/rusk/tests/services/owner_calls.rs @@ -32,6 +32,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::DEFAULT_MIN_DEPLOYMENT_GAS_PRICE; +use crate::common::state::DEFAULT_MIN_DEPLOY_POINTS; use crate::common::state::{ DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_GAS_LIMIT, }; @@ -85,6 +86,7 @@ fn initial_state>( DEFAULT_GAS_PER_DEPLOY_BYTE, DEFAULT_MIN_DEPLOYMENT_GAS_PRICE, DEFAULT_MIN_GAS_LIMIT, + DEFAULT_MIN_DEPLOY_POINTS, BLOCK_GAS_LIMIT, u64::MAX, sender,