Skip to content

Commit

Permalink
fix: handle errors and non-existent addresses in selfdestruct
Browse files Browse the repository at this point in the history
In the EVM:

1. Self destruct continues even if it sends funds into oblivion.
2. Self destruct will auto-create a beneficiary.

This lets us punt filecoin-project/ref-fvm#736
to M2.2.
  • Loading branch information
Stebalien committed Dec 2, 2022
1 parent ddd6e5f commit d6fcade
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions actors/evm/src/interpreter/instructions/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ pub fn selfdestruct(
if system.readonly {
return Err(StatusCode::StaticModeViolation);
}
let beneficiary: Address = EthAddress::from(beneficiary).try_into()?;
system.rt.delete_actor(&beneficiary)?;
// Try to give funds to the beneficiary. We don't use the `delete_actor` syscall to do this
// because that won't auto-create the beneficiary (and will fail if, for some reason, we can't
// send them the funds).
//
// If we fail, we'll just burn the funds. Yes, this is what the EVM does.
if let Ok(addr) = EthAddress::from(beneficiary).try_into() {
let balance = system.rt.current_balance();
let _ = system.rt.send(&addr, METHOD_SEND, RawBytes::default(), balance);
}
// Now try to delete ourselves. If this fails, we abort execution.
system.rt.delete_actor(&BURNT_FUNDS_ACTOR_ADDR)?;
Ok(Output::default())
}

0 comments on commit d6fcade

Please sign in to comment.