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 initial code for recursion limit #4729

Merged
merged 24 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
04ed29c
Asc message execution - requery message bytecode after each message e…
Leo-Besancon Jun 18, 2024
52814d4
fix call stack inconsistency (#4709)
Leo-Besancon Jun 21, 2024
b64e360
Improve async message checks (#4706)
Leo-Besancon Jun 25, 2024
86e1d02
Fix ledger change to take into account cancelled message balance chan…
Leo-Besancon Jul 2, 2024
880eec7
Fix async msg same slot (#4718)
Leo-Besancon Jul 2, 2024
e25f021
Add initial code for recursion limit
Leo-Besancon Jul 16, 2024
9c13a14
Latest runtime
Leo-Besancon Jul 16, 2024
c0f3a0a
Run CI on PRs based on mainnet_2_3
Leo-Besancon Jul 16, 2024
57bf59d
fmt
Leo-Besancon Jul 16, 2024
ad071b5
Fix config and add UTs
Leo-Besancon Jul 16, 2024
fb20aec
Update scenarios_mandatories.rs
Leo-Besancon Jul 16, 2024
7c7c32f
Review comments (CI for all branches starting with "mainnet_" + comment)
Leo-Besancon Jul 17, 2024
2cc4a17
Update ci.yml
Leo-Besancon Jul 17, 2024
766f044
Remove manual increment / decrement in interface implementation
Leo-Besancon Aug 5, 2024
aa77944
Merge branch 'mainnet_2_3' into add_recursion_counter
Leo-Besancon Oct 15, 2024
3f37c1d
fmt + update sc_runtime + fix warning
Leo-Besancon Oct 15, 2024
e12ee3c
Merge branch 'mainnet_2_3' into add_recursion_counter
Leo-Besancon Oct 15, 2024
8504ced
Update test
Leo-Besancon Oct 15, 2024
e36e31d
Update constants.rs
Leo-Besancon Oct 15, 2024
869c46a
Updated execution config for tests
Leo-Besancon Oct 16, 2024
0069fd5
Updated usize -> u16 for recursion counter and limits
Leo-Besancon Oct 16, 2024
8c5ff99
Update test comments
Leo-Besancon Oct 16, 2024
d351f76
Add comments regarding the needs of this limits
Leo-Besancon Oct 16, 2024
b3cf306
Update sc-runtime branch
Leo-Besancon Oct 16, 2024
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
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ massa_wallet = { path = "./massa-wallet" }

# Massa projects dependencies
massa-proto-rs = { git = "https://github.com/massalabs/massa-proto-rs", branch = "mainnet_2_3" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "branch" = "next_breaking_update" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "branch" = "add_recursion_counter" }
peernet = { git = "https://github.com/massalabs/PeerNet", "rev" = "04b05ddd320fbe76cc858115af7b5fc28bdb8310" }
# Dev only - use local dependencies
# massa-proto-rs = { path = "../massa-proto-rs" }
Expand Down
2 changes: 2 additions & 0 deletions massa-execution-exports/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub struct ExecutionConfig {
pub max_execution_traces_slot_limit: usize,
/// Where to dump blocks
pub block_dump_folder_path: PathBuf,
/// Max recursive calls depth in SC
pub max_recursive_calls_depth: usize,
Leo-Besancon marked this conversation as resolved.
Show resolved Hide resolved
Leo-Besancon marked this conversation as resolved.
Show resolved Hide resolved
/// Runtime condom middleware limits
pub condom_limits: CondomLimits,
}
1 change: 1 addition & 0 deletions massa-execution-exports/src/test_exports/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl Default for ExecutionConfig {
broadcast_slot_execution_traces_channel_capacity: 5000,
max_execution_traces_slot_limit: 320,
block_dump_folder_path,
max_recursive_calls_depth: 50,
Leo-Besancon marked this conversation as resolved.
Show resolved Hide resolved
condom_limits: CondomLimits {
max_exports: Some(100),
max_functions: Some(100),
Expand Down
9 changes: 9 additions & 0 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub struct ExecutionContextSnapshot {
/// The gas remaining before the last subexecution.
/// so *excluding* the gas used by the last sc call.
pub gas_remaining_before_subexecution: Option<u64>,

/// recursion counter, incremented for each new nested call
pub recursion_counter: usize,
}

/// An execution context that needs to be initialized before executing bytecode,
Expand Down Expand Up @@ -179,6 +182,9 @@ pub struct ExecutionContext {
/// The gas remaining before the last subexecution.
/// so *excluding* the gas used by the last sc call.
pub gas_remaining_before_subexecution: Option<u64>,

/// recursion counter, incremented for each new nested call
pub recursion_counter: usize,
}

impl ExecutionContext {
Expand Down Expand Up @@ -244,6 +250,7 @@ impl ExecutionContext {
address_factory: AddressFactory { mip_store },
execution_trail_hash,
gas_remaining_before_subexecution: None,
recursion_counter: 0,
}
}

Expand All @@ -265,6 +272,7 @@ impl ExecutionContext {
event_count: self.events.0.len(),
unsafe_rng: self.unsafe_rng.clone(),
gas_remaining_before_subexecution: self.gas_remaining_before_subexecution,
recursion_counter: self.recursion_counter,
}
}

Expand Down Expand Up @@ -293,6 +301,7 @@ impl ExecutionContext {
self.stack = snapshot.stack;
self.unsafe_rng = snapshot.unsafe_rng;
self.gas_remaining_before_subexecution = snapshot.gas_remaining_before_subexecution;
self.recursion_counter = snapshot.recursion_counter;

// For events, set snapshot delta to error events.
for event in self.events.0.range_mut(snapshot.event_count..) {
Expand Down
23 changes: 23 additions & 0 deletions massa-execution-worker/src/interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,29 @@ impl Interface for InterfaceImpl {
Ok(())
}

fn increment_recursion_counter(&self) -> Result<()> {
let mut context = context_guard!(self);

context.recursion_counter += 1;

if context.recursion_counter > self.config.max_recursive_calls_depth {
bail!("recursion depth limit reached");
}

Ok(())
}

fn decrement_recursion_counter(&self) -> Result<()> {
let mut context = context_guard!(self);

match context.recursion_counter.checked_sub(1) {
Some(value) => context.recursion_counter = value,
None => bail!("recursion counter underflow"),
}

Ok(())
}

/// Initialize the call when bytecode calls a function from another bytecode
/// This function transfers the coins passed as parameter,
/// prepares the current execution context by pushing a new element on the top of the call stack,
Expand Down
Loading
Loading