aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsolidity/analysis/GlobalContext.cpp4
-rw-r--r--libsolidity/ast/Types.h2
-rw-r--r--libsolidity/codegen/Compiler.cpp18
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp2
-rw-r--r--test/contracts/Wallet.cpp4
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp33
6 files changed, 53 insertions, 10 deletions
diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp
index d519934d..a7ffcfad 100644
--- a/libsolidity/analysis/GlobalContext.cpp
+++ b/libsolidity/analysis/GlobalContext.cpp
@@ -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",
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 9224f292..3ebcb2b2 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -736,7 +736,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/Compiler.cpp b/libsolidity/codegen/Compiler.cpp
index f1d95980..18803b71 100644
--- a/libsolidity/codegen/Compiler.cpp
+++ b/libsolidity/codegen/Compiler.cpp
@@ -305,11 +305,19 @@ void Compiler::appendCalldataUnpacker(TypePointers const& _typeParameters, bool
// @todo If base type is an array or struct, it is still calldata-style encoded, so
// we would have to convert it like below.
solAssert(arrayType.location() == DataLocation::Memory, "");
- // compute data pointer
- m_context << eth::Instruction::DUP1 << eth::Instruction::MLOAD;
- m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
- m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
- m_context << u256(0x20) << eth::Instruction::ADD;
+ if (arrayType.isDynamicallySized())
+ {
+ // compute data pointer
+ m_context << eth::Instruction::DUP1 << eth::Instruction::MLOAD;
+ m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
+ m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
+ m_context << u256(0x20) << eth::Instruction::ADD;
+ }
+ else
+ {
+ m_context << eth::Instruction::DUP1;
+ m_context << u256(arrayType.calldataEncodedSize(true)) << eth::Instruction::ADD;
+ }
}
else
{
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 474247e1..fa077036 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 4a4848f1..476e817b 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 0b356145..78ceacfa 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"
@@ -4671,6 +4687,23 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors)
);
}
+BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors)
+{
+ char const* sourceCode = R"(
+ contract Creator {
+ uint public r;
+ address public ch;
+ function Creator(address[3] s, uint x) {
+ r = x;
+ ch = s[2];
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Creator", encodeArgs(u256(1), u256(2), u256(3), u256(4)));
+ BOOST_REQUIRE(callContractFunction("r()") == encodeArgs(u256(4)));
+ BOOST_REQUIRE(callContractFunction("ch()") == encodeArgs(u256(3)));
+}
+
BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage)
{
char const* sourceCode = R"(