Skip to content

Commit

Permalink
feat: support selfdestruct (#94)
Browse files Browse the repository at this point in the history
* selfdestruct

* yul selfdestruct
  • Loading branch information
brockelmore authored Aug 2, 2024
1 parent 53b2b17 commit 85f5284
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions crates/pyrometer/tests/test_data/intrinsics.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ contract Intrinsics {
require(d[3] == hex"bb");
}

function selfdestructed() public {
selfdestruct(payable(address(this)));
}

function yulSelfdestructed() public {
assembly {
selfdestruct(1)
}
}

function yulIntrinsics() public view {
assembly {
let a := timestamp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub trait IntrinsicFuncCaller:
// precompiles
"sha256" | "ripemd160" | "ecrecover" => self.precompile_call(ctx, name, inputs, loc),
// solidity
"keccak256" | "addmod" | "mulmod" | "require" | "assert" => {
"keccak256" | "addmod" | "mulmod" | "require" | "assert" | "selfdestruct" => {
self.solidity_call(arena, ctx, name, inputs, loc)
}
// typing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::func_call::helper::CallerHelper;

use graph::{
elem::Elem,
nodes::{Builtin, Concrete, ConcreteNode, ContextNode, ContextVar, ContextVarNode, ExprRet},
nodes::{
Builtin, Concrete, ConcreteNode, ContextNode, ContextVar, ContextVarNode, ExprRet,
KilledKind,
},
AnalyzerBackend,
};
use shared::{ExprErr, IntoExprErr, RangeArena};
Expand Down Expand Up @@ -92,6 +95,10 @@ pub trait SolidityCaller:
.into_expr_err(loc)?;
Ok(())
}
"selfdestruct" => {
// TODO: affect address.balance
ctx.kill(self,loc, KilledKind::Ended).into_expr_err(loc)
}
"require" | "assert" => {
Err(ExprErr::ParseError(
loc,
Expand Down
3 changes: 2 additions & 1 deletion crates/solc-expressions/src/yul/yul_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub trait YulFuncCaller:
.into_expr_err(loc)?;
Ok(())
}
"stop" | "revert" | "selfdestruct" | "invalid" => {
"selfdestruct" => ctx.kill(self, loc, KilledKind::Ended).into_expr_err(loc),
"stop" | "revert" | "invalid" => {
ctx.kill(self, loc, KilledKind::Revert).into_expr_err(loc)
}
"return" => {
Expand Down

0 comments on commit 85f5284

Please sign in to comment.