Skip to content

Commit

Permalink
Improve async message checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Besancon committed Jun 13, 2024
1 parent 0490df8 commit d29eb55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 11 additions & 2 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
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
15 changes: 15 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,16 @@ 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")
}

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")
}

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

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

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

if emission_slot > Slot::new(validity_start.0, validity_start.1) {
bail!("validity start 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

0 comments on commit d29eb55

Please sign in to comment.