From 02a080625ae1ea20614772cd107577289fe483e3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Feb 2024 12:37:24 +0300 Subject: [PATCH 1/4] Add block data usage detection flags --- Cargo.toml | 2 +- src/transaction_executor.rs | 23 ++++++++++++++--------- src/vmsetup.rs | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dc4ee35..db4d918 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ log = "0.4" thiserror = "1.0.56" tvm_block = { git = "https://github.com/tvmlabs/tvm-block", tag = "2.0.0" } tvm_types = { git = "https://github.com/tvmlabs/tvm-types", tag = "3.0.1" } -tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", tag="2.0.0" } +tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", branch = "feature-block_usage_detection" } [features] signature_with_id = [ "tvm_block/signature_with_id", "tvm_vm/signature_with_id" ] diff --git a/src/transaction_executor.rs b/src/transaction_executor.rs index 615a6d6..a60e386 100644 --- a/src/transaction_executor.rs +++ b/src/transaction_executor.rs @@ -15,7 +15,7 @@ use std::collections::LinkedList; use std::convert::TryInto; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use tvm_block::AccStatusChange; use tvm_block::Account; @@ -123,6 +123,8 @@ pub struct ExecuteParams { pub block_version: u32, #[cfg(feature = "signature_with_id")] pub signature_id: i32, + pub vm_execution_is_block_related: Arc>, + pub block_collation_was_finished: Arc>, } pub struct ActionPhaseResult { @@ -161,6 +163,8 @@ impl Default for ExecuteParams { block_version: 0, #[cfg(feature = "signature_with_id")] signature_id: 0, + vm_execution_is_block_related: Arc::new(Mutex::new(false)), + block_collation_was_finished: Arc::new(Mutex::new(false)), } } } @@ -477,14 +481,15 @@ pub trait TransactionExecutor { signature_id: params.signature_id, }, ) - .set_smart_contract_info(smc_info)? - .set_stack(stack) - .set_data(data)? - .set_libraries(libs) - .set_gas(gas) - .set_debug(params.debug) - .create(); - + .set_smart_contract_info(smc_info)? + .set_stack(stack) + .set_data(data)? + .set_libraries(libs) + .set_gas(gas) + .set_debug(params.debug) + .set_block_related_flags(params.vm_execution_is_block_related.clone(), params.block_collation_was_finished.clone()) + .create(); + if let Some(modifiers) = params.behavior_modifiers.clone() { vm.modify_behavior(modifiers); } diff --git a/src/vmsetup.rs b/src/vmsetup.rs index e894cc0..1345867 100644 --- a/src/vmsetup.rs +++ b/src/vmsetup.rs @@ -9,6 +9,7 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. +use std::sync::{Arc, Mutex}; use tvm_block::GlobalCapabilities; use tvm_types::Cell; use tvm_types::HashmapE; @@ -40,9 +41,22 @@ pub struct VMSetup { gas: Option, libraries: Vec, ctx: VMSetupContext, + vm_execution_is_block_related: Arc>, + block_collation_was_finished: Arc>, } impl VMSetup { + + pub fn set_block_related_flags( + mut self, + vm_execution_is_block_related: Arc>, + block_collation_was_finished: Arc>, + ) -> VMSetup { + self.vm_execution_is_block_related = vm_execution_is_block_related; + self.block_collation_was_finished = block_collation_was_finished; + self + } + /// Creates new instance of VMSetup with contract code. /// Initializes some registers of TVM with predefined values. pub fn with_context(code: SliceData, ctx: VMSetupContext) -> Self { @@ -54,6 +68,8 @@ impl VMSetup { gas: Some(Gas::empty()), libraries: vec![], ctx, + vm_execution_is_block_related: Arc::new(Mutex::new(false)), + block_collation_was_finished: Arc::new(Mutex::new(false)), } } @@ -147,6 +163,10 @@ impl VMSetup { vm.set_block_version(self.ctx.block_version); #[cfg(feature = "signature_with_id")] vm.set_signature_id(self.ctx.signature_id); + vm.set_block_related_flags( + self.vm_execution_is_block_related, + self.block_collation_was_finished, + ); vm } } From aae9d6df638e1f542966d328d618f75ebf31eee6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Feb 2024 16:12:34 +0300 Subject: [PATCH 2/4] Increase version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db4d918..34a7680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ edition = "2021" name = "tvm_executor" rust-version = "1.75.0" -version = "2.0.0" +version = "2.1.0" [dependencies] anyhow = "1.0.79" @@ -11,7 +11,7 @@ log = "0.4" thiserror = "1.0.56" tvm_block = { git = "https://github.com/tvmlabs/tvm-block", tag = "2.0.0" } tvm_types = { git = "https://github.com/tvmlabs/tvm-types", tag = "3.0.1" } -tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", branch = "feature-block_usage_detection" } +tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", tag = "2.1.0" } [features] signature_with_id = [ "tvm_block/signature_with_id", "tvm_vm/signature_with_id" ] From 393ead849ba94a100a2591c817c9e8b17bf20d71 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Feb 2024 16:39:38 +0300 Subject: [PATCH 3/4] fmt --- src/transaction_executor.rs | 24 ++++++++++++++---------- src/vmsetup.rs | 5 +++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/transaction_executor.rs b/src/transaction_executor.rs index a60e386..3c67cd6 100644 --- a/src/transaction_executor.rs +++ b/src/transaction_executor.rs @@ -15,7 +15,8 @@ use std::collections::LinkedList; use std::convert::TryInto; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; +use std::sync::Mutex; use tvm_block::AccStatusChange; use tvm_block::Account; @@ -481,15 +482,18 @@ pub trait TransactionExecutor { signature_id: params.signature_id, }, ) - .set_smart_contract_info(smc_info)? - .set_stack(stack) - .set_data(data)? - .set_libraries(libs) - .set_gas(gas) - .set_debug(params.debug) - .set_block_related_flags(params.vm_execution_is_block_related.clone(), params.block_collation_was_finished.clone()) - .create(); - + .set_smart_contract_info(smc_info)? + .set_stack(stack) + .set_data(data)? + .set_libraries(libs) + .set_gas(gas) + .set_debug(params.debug) + .set_block_related_flags( + params.vm_execution_is_block_related.clone(), + params.block_collation_was_finished.clone(), + ) + .create(); + if let Some(modifiers) = params.behavior_modifiers.clone() { vm.modify_behavior(modifiers); } diff --git a/src/vmsetup.rs b/src/vmsetup.rs index 1345867..92b1b6c 100644 --- a/src/vmsetup.rs +++ b/src/vmsetup.rs @@ -9,7 +9,9 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use std::sync::{Arc, Mutex}; +use std::sync::Arc; +use std::sync::Mutex; + use tvm_block::GlobalCapabilities; use tvm_types::Cell; use tvm_types::HashmapE; @@ -46,7 +48,6 @@ pub struct VMSetup { } impl VMSetup { - pub fn set_block_related_flags( mut self, vm_execution_is_block_related: Arc>, From 0038ee163cd7c4ab748409517df037f6cb0e9a81 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Feb 2024 16:41:28 +0300 Subject: [PATCH 4/4] Fix clippy --- src/transaction_executor.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/transaction_executor.rs b/src/transaction_executor.rs index 3c67cd6..a575f5e 100644 --- a/src/transaction_executor.rs +++ b/src/transaction_executor.rs @@ -12,7 +12,6 @@ use std::cmp::min; use std::collections::LinkedList; -use std::convert::TryInto; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; use std::sync::Arc;