Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: yul selfdestruct #97

Open
wants to merge 2 commits into
base: brock/no_recurse
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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