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

Fix stack inconsistency #4708

Closed
wants to merge 8 commits into from
Closed
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
15 changes: 12 additions & 3 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ impl ExecutionState {
context.stack = vec![
ExecutionStackElement {
address: message.sender,
coins: message.coins,
coins: Default::default(),
owned_addresses: vec![message.sender],
operation_datastore: None,
},
Expand Down Expand Up @@ -1175,10 +1175,19 @@ impl ExecutionState {

// load and execute the compiled module
// IMPORTANT: do not keep a lock here as `run_function` uses the `get_module` interface
let module = self
let Ok(module) = self
.module_cache
.write()
.load_module(&bytecode, message.max_gas)?;
.load_module(&bytecode, message.max_gas)
else {
let err =
ExecutionError::RuntimeError("could not load module for async execution".into());
let mut context = context_guard!(self);
context.reset_to_snapshot(context_snapshot, err.clone());
context.cancel_async_message(&message);
return Err(err);
};

let response = massa_sc_runtime::run_function(
&*self.execution_interface,
module,
Expand Down
14 changes: 14 additions & 0 deletions massa-execution-worker/src/interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,11 @@ impl Interface for InterfaceImpl {
if validity_end.1 >= self.config.thread_count {
bail!("validity end thread exceeds the configuration thread count")
}

if max_gas < self.config.gas_costs.max_instance_cost {
bail!("max gas is lower than the minimum instance cost")
}

let target_addr = Address::from_str(target_address)?;

// check that the target address is an SC address
Expand All @@ -1200,6 +1205,15 @@ impl Interface for InterfaceImpl {

let mut execution_context = context_guard!(self);
let emission_slot = execution_context.slot;

if Slot::new(validity_end.0, validity_end.1) < Slot::new(validity_start.0, validity_start.1)
{
bail!("validity end is earlier than the validity start")
}
if Slot::new(validity_end.0, validity_end.1) < emission_slot {
bail!("validity end is earlier than the current slot")
}

let emission_index = execution_context.created_message_index;
let sender = execution_context.get_current_address()?;
let coins = Amount::from_raw(raw_coins);
Expand Down
Loading