From 9f4deb1b2ba22121081e67246f2b83a342d12844 Mon Sep 17 00:00:00 2001 From: brock elmore Date: Fri, 2 Aug 2024 11:46:50 -0700 Subject: [PATCH 1/2] selfdestruct --- crates/pyrometer/tests/test_data/intrinsics.sol | 4 ++++ .../src/func_call/intrinsic_call/intrinsic_caller.rs | 2 +- .../src/func_call/intrinsic_call/solidity.rs | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/pyrometer/tests/test_data/intrinsics.sol b/crates/pyrometer/tests/test_data/intrinsics.sol index 42c1b72d..043435ab 100644 --- a/crates/pyrometer/tests/test_data/intrinsics.sol +++ b/crates/pyrometer/tests/test_data/intrinsics.sol @@ -23,6 +23,10 @@ contract Intrinsics { require(d[3] == hex"bb"); } + function selfdestructed() public { + selfdestruct(payable(address(this))); + } + 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, From f0662f576590864e8aea174b6ad9ca7abf2642c3 Mon Sep 17 00:00:00 2001 From: brock elmore Date: Fri, 2 Aug 2024 11:49:21 -0700 Subject: [PATCH 2/2] yul selfdestruct --- crates/pyrometer/tests/test_data/intrinsics.sol | 6 ++++++ crates/solc-expressions/src/yul/yul_funcs.rs | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/pyrometer/tests/test_data/intrinsics.sol b/crates/pyrometer/tests/test_data/intrinsics.sol index 043435ab..d391a045 100644 --- a/crates/pyrometer/tests/test_data/intrinsics.sol +++ b/crates/pyrometer/tests/test_data/intrinsics.sol @@ -27,6 +27,12 @@ contract Intrinsics { 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/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" => {