Skip to content

Commit

Permalink
fix(levm): copy return data if callframe reverts in generic_create (#…
Browse files Browse the repository at this point in the history
…1544)

**Motivation**

If the callframe that performs contract creation ends with an opcode
revert, we should copy the output to the sub_return_data of the current
callframe.

**Description**

- Add a check if the result is revert because of VMError::RevertOpcode,
we copy the output of the txreport to the current callframe
sub_return_data
  • Loading branch information
LeanSerra authored Dec 20, 2024
1 parent 45eeb94 commit cb4a64e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/vm/levm/src/opcode_handlers/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,18 @@ impl VM {
.stack
.push(address_to_word(new_address))?;
}
TxResult::Revert(_) => {
TxResult::Revert(err) => {
// Return value to sender
self.increase_account_balance(deployer_address, value_in_wei_to_send)?;

// Deployment failed so account shouldn't exist
cache::remove_account(&mut self.cache, &new_address);
self.accrued_substate.created_accounts.remove(&new_address);

// If revert we have to copy the return_data
if err == VMError::RevertOpcode {
current_call_frame.sub_return_data = tx_report.output;
}
current_call_frame.stack.push(CREATE_DEPLOYMENT_FAIL)?;
}
}
Expand Down

0 comments on commit cb4a64e

Please sign in to comment.