Skip to content

Commit

Permalink
Merge pull request #256 from chriseth/selfdestruct
Browse files Browse the repository at this point in the history
Introduce selfdestruct alias for suicide.
  • Loading branch information
chriseth committed Nov 30, 2015
2 parents a3801be + b97bb08 commit a8736b7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libsolidity/analysis/GlobalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::Transaction)),
make_shared<MagicVariableDeclaration>("now", make_shared<IntegerType>(256)),
make_shared<MagicVariableDeclaration>("suicide",
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Suicide)),
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Selfdestruct)),
make_shared<MagicVariableDeclaration>("selfdestruct",
make_shared<FunctionType>(strings{"address"}, strings{}, FunctionType::Location::Selfdestruct)),
make_shared<MagicVariableDeclaration>("addmod",
make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Location::AddMod)),
make_shared<MagicVariableDeclaration>("mulmod",
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class FunctionType: public Type
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
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/contracts/Wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a8736b7

Please sign in to comment.