From b97bb086de91e1f834e6e92cfdc8a985a6f761de Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 29 Nov 2015 00:09:15 +0100 Subject: [PATCH] Introduce selfdestruct alias for suicide. --- libsolidity/analysis/GlobalContext.cpp | 4 +++- libsolidity/ast/Types.h | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- test/contracts/Wallet.cpp | 4 ++-- test/libsolidity/SolidityEndToEndTest.cpp | 16 ++++++++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index d519934d2..a7ffcfad7 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -39,7 +39,9 @@ m_magicVariables(vector>{make_shared< make_shared("tx", make_shared(MagicType::Kind::Transaction)), make_shared("now", make_shared(256)), make_shared("suicide", - make_shared(strings{"address"}, strings{}, FunctionType::Location::Suicide)), + make_shared(strings{"address"}, strings{}, FunctionType::Location::Selfdestruct)), + make_shared("selfdestruct", + make_shared(strings{"address"}, strings{}, FunctionType::Location::Selfdestruct)), make_shared("addmod", make_shared(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Location::AddMod)), make_shared("mulmod", diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index f841a1beb..ea9bd1980 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -739,7 +739,7 @@ public: Creation, ///< external call using CREATE Send, ///< CALL, but without data and gas SHA3, ///< SHA3 - Suicide, ///< SUICIDE + Selfdestruct, ///< SELFDESTRUCT ECRecover, ///< CALL to special contract for ecrecover SHA256, ///< CALL to special contract for sha256 RIPEMD160, ///< CALL to special contract for ripemd160 diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 6c288ae7e..d4140ae86 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -535,7 +535,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) {} ); break; - case Location::Suicide: + case Location::Selfdestruct: arguments.front()->accept(*this); utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), true); m_context << eth::Instruction::SUICIDE; diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index 4a4848f1a..476e817be 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -361,9 +361,9 @@ contract Wallet is multisig, multiowned, daylimit { multiowned(_owners, _required) daylimit(_daylimit) { } - // kills the contract sending everything to `_to`. + // destroys the contract sending everything to `_to`. function kill(address _to) onlymanyowners(sha3(msg.data)) external { - suicide(_to); + selfdestruct(_to); } // gets called when no other function matches diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 0b3561457..a01b89493 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1483,6 +1483,22 @@ BOOST_AUTO_TEST_CASE(suicide) BOOST_CHECK_EQUAL(m_state.balance(address), amount); } +BOOST_AUTO_TEST_CASE(selfdestruct) +{ + char const* sourceCode = "contract test {\n" + " function a(address receiver) returns (uint ret) {\n" + " selfdestruct(receiver);\n" + " return 10;\n" + " }\n" + "}\n"; + u256 amount(130); + compileAndRun(sourceCode, amount); + u160 address(23); + BOOST_CHECK(callContractFunction("a(address)", address) == bytes()); + BOOST_CHECK(!m_state.addressHasCode(m_contractAddress)); + BOOST_CHECK_EQUAL(m_state.balance(address), amount); +} + BOOST_AUTO_TEST_CASE(sha3) { char const* sourceCode = "contract test {\n"