-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVM: implement SELFDESTRUCT opcode. (#593)
This required a small refactor to allow us to mutably borrow the Runtime.
- Loading branch information
Showing
10 changed files
with
130 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6080604052348015600f57600080fd5b5060988061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806335f4699414602d575b600080fd5b60336035565b005b73ff000000000000000000000000000000000003e973ffffffffffffffffffffffffffffffffffffffff16fffea26469706673582212205539162e3dd1c84b3cf9043b55e3890bbe09c5726899ad6003650e8f1ac698b564736f6c63430008070033 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use fil_actor_evm as evm; | ||
use fil_actors_runtime::test_utils::*; | ||
use fvm_ipld_encoding::RawBytes; | ||
use fvm_shared::address::Address; | ||
|
||
#[test] | ||
fn test_selfdestruct() { | ||
let mut rt = MockRuntime::default(); | ||
|
||
let contract = Address::new_id(100); | ||
let beneficiary = Address::new_id(1001); | ||
|
||
let params = evm::ConstructorParams { | ||
bytecode: hex::decode(include_str!("selfdestruct.hex")).unwrap().into(), | ||
input_data: RawBytes::default(), | ||
}; | ||
|
||
// invoke constructor | ||
rt.actor_code_cids.insert(contract, *EVM_ACTOR_CODE_ID); | ||
rt.expect_validate_caller_any(); | ||
rt.set_origin(contract); | ||
|
||
let result = rt | ||
.call::<evm::EvmContractActor>( | ||
evm::Method::Constructor as u64, | ||
&RawBytes::serialize(params).unwrap(), | ||
) | ||
.unwrap(); | ||
expect_empty(result); | ||
rt.verify(); | ||
|
||
let solidity_params = hex::decode("35f46994").unwrap(); | ||
let params = evm::InvokeParams { input_data: RawBytes::from(solidity_params) }; | ||
rt.expect_validate_caller_any(); | ||
rt.expect_delete_actor(beneficiary); | ||
|
||
rt.call::<evm::EvmContractActor>( | ||
evm::Method::InvokeContract as u64, | ||
&RawBytes::serialize(params).unwrap(), | ||
) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
contract Selfdestruct { | ||
function die() public { | ||
selfdestruct(payable(address(0xFF000000000000000000000000000000000003E9))); | ||
} | ||
} |