Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block data usage detection flags #1

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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", tag = "2.1.0" }

[features]
signature_with_id = [ "tvm_block/signature_with_id", "tvm_vm/signature_with_id" ]
Expand Down
10 changes: 9 additions & 1 deletion src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

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;
use std::sync::Mutex;

use tvm_block::AccStatusChange;
use tvm_block::Account;
Expand Down Expand Up @@ -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<Mutex<bool>>,
pub block_collation_was_finished: Arc<Mutex<bool>>,
}

pub struct ActionPhaseResult {
Expand Down Expand Up @@ -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)),
}
}
}
Expand Down Expand Up @@ -483,6 +487,10 @@ pub trait TransactionExecutor {
.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() {
Expand Down
21 changes: 21 additions & 0 deletions src/vmsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// See the License for the specific TON DEV software governing permissions and
// limitations under the License.

use std::sync::Arc;
use std::sync::Mutex;

use tvm_block::GlobalCapabilities;
use tvm_types::Cell;
use tvm_types::HashmapE;
Expand Down Expand Up @@ -40,9 +43,21 @@ pub struct VMSetup {
gas: Option<Gas>,
libraries: Vec<HashmapE>,
ctx: VMSetupContext,
vm_execution_is_block_related: Arc<Mutex<bool>>,
block_collation_was_finished: Arc<Mutex<bool>>,
}

impl VMSetup {
pub fn set_block_related_flags(
mut self,
vm_execution_is_block_related: Arc<Mutex<bool>>,
block_collation_was_finished: Arc<Mutex<bool>>,
) -> 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 {
Expand All @@ -54,6 +69,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)),
}
}

Expand Down Expand Up @@ -147,6 +164,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
}
}