diff --git a/crates/pyrometer/tests/test_data/intrinsics.sol b/crates/pyrometer/tests/test_data/intrinsics.sol index 42c1b72d..d391a045 100644 --- a/crates/pyrometer/tests/test_data/intrinsics.sol +++ b/crates/pyrometer/tests/test_data/intrinsics.sol @@ -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() diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs b/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs index 73732437..0d8f7763 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs @@ -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 diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs b/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs index 503e3cd5..b2403ace 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs @@ -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}; @@ -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, diff --git a/crates/solc-expressions/src/yul/yul_funcs.rs b/crates/solc-expressions/src/yul/yul_funcs.rs index 217008df..a4124f5d 100644 --- a/crates/solc-expressions/src/yul/yul_funcs.rs +++ b/crates/solc-expressions/src/yul/yul_funcs.rs @@ -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" => {