Merge pull request #4280 from ethereum/disallow-sha3-suicide

[BREAKING] Disallow sha3 suicide
This commit is contained in:
Alex Beregszaszi 2018-06-12 18:46:05 +01:00 committed by GitHub
commit 71dc401170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 64 additions and 158 deletions

View File

@ -1,38 +1,32 @@
### 0.5.0 (unreleased)
Language Features:
* General: Support ``pop()`` for storage arrays.
Breaking Changes:
* Disallow conversions between bytesX and uintY of different size.
* Code Generator: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code!
* Commandline interface: Require ``-`` if standard input is used as source.
* General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code.
* General: Disallow ``sha3`` and ``suicide`` aliases.
* General: Introduce ``emit`` as a keyword instead of parsing it as identifier.
* General: New keywords: ``calldata``
* General: Add new reserved keywords: ``alias``, ``apply``, ``auto``, ``copyof``, ``define``, ``immutable``,
* General: New reserved keywords: ``alias``, ``apply``, ``auto``, ``copyof``, ``define``, ``immutable``,
``implements``, ``macro``, ``mutable``, ``override``, ``partial``, ``promise``, ``reference``, ``sealed``,
``sizeof``, ``supports``, ``typedef`` and ``unchecked``.
* General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code.
* General: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code!
* Introduce ``emit`` as a keyword instead of parsing it as identifier.
* Type Checker: Disallow arithmetic operations for Boolean variables.
* Disallow trailing dots that are not followed by a number.
* Remove assembly instructions ``sha3`` and ``suicide``
* General: Remove assembly instruction aliases ``sha3`` and ``suicide``
* Parser: Disallow trailing dots that are not followed by a number.
* Type Checker: Disallow arithmetic operations for boolean variables.
* Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size.
* Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible.
Language Features:
* General: Allow appending ``calldata`` keyword to types, to explicitly specify data location for arguments of external functions.
* General: Support ``pop()`` for storage arrays.
Bugfixes:
Features:
Compiler Features:
* Type Checker: Show named argument in case of error.
Bugfixes:
### 0.4.24 (2018-05-16)
Language Features:
* Code Generator: Use native shift instructions on target Constantinople.
* General: Allow multiple variables to be declared as part of a tuple assignment, e.g. ``(uint a, uint b) = ...``.

View File

@ -1708,18 +1708,10 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression()))
{
string msg;
if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3)
msg = "\"sha3\" has been deprecated in favour of \"keccak256\"";
m_errorReporter.typeError(_functionCall.location(), "\"sha3\" has been deprecated in favour of \"keccak256\"");
else if (functionName->name() == "suicide" && functionType->kind() == FunctionType::Kind::Selfdestruct)
msg = "\"suicide\" has been deprecated in favour of \"selfdestruct\"";
if (!msg.empty())
{
if (v050)
m_errorReporter.typeError(_functionCall.location(), msg);
else
m_errorReporter.warning(_functionCall.location(), msg);
}
m_errorReporter.typeError(_functionCall.location(), "\"suicide\" has been deprecated in favour of \"selfdestruct\"");
}
if (!m_insideEmitStatement && functionType->kind() == FunctionType::Kind::Event)
{

View File

@ -54,11 +54,11 @@ contract moduleHandler is multiOwner, announcementTypes {
require( owners[msg.sender] );
require( modules.length == 0 );
foundationAddress = foundation;
addModule( modules_s(Token, sha3('Token'), false, false), ! forReplace);
addModule( modules_s(Premium, sha3('Premium'), false, false), ! forReplace);
addModule( modules_s(Publisher, sha3('Publisher'), false, true), ! forReplace);
addModule( modules_s(Schelling, sha3('Schelling'), false, true), ! forReplace);
addModule( modules_s(Provider, sha3('Provider'), true, true), ! forReplace);
addModule( modules_s(Token, keccak256('Token'), false, false), ! forReplace);
addModule( modules_s(Premium, keccak256('Premium'), false, false), ! forReplace);
addModule( modules_s(Publisher, keccak256('Publisher'), false, true), ! forReplace);
addModule( modules_s(Schelling, keccak256('Schelling'), false, true), ! forReplace);
addModule( modules_s(Provider, keccak256('Provider'), true, true), ! forReplace);
}
function addModule(modules_s input, bool call) internal {
/*
@ -117,7 +117,7 @@ contract moduleHandler is multiOwner, announcementTypes {
@id Index of module.
@found Was there any result or not.
*/
bytes32 _name = sha3(name);
bytes32 _name = keccak256(name);
for ( uint256 a=0 ; a<modules.length ; a++ ) {
if ( modules[a].name == _name ) {
return (true, true, a);
@ -151,9 +151,9 @@ contract moduleHandler is multiOwner, announcementTypes {
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success );
if ( ! ( _found && modules[_id].name == sha3('Publisher') )) {
if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("replaceModule", sha3(name, addr, callCallback))) ) {
if ( ! insertAndCheckDo(calcDoHash("replaceModule", keccak256(name, addr, callCallback))) ) {
return true;
}
}
@ -169,7 +169,7 @@ contract moduleHandler is multiOwner, announcementTypes {
function callReplaceCallback(string moduleName, address newModule) external returns (bool success) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("callReplaceCallback", sha3(moduleName, newModule))) ) {
if ( ! insertAndCheckDo(calcDoHash("callReplaceCallback", keccak256(moduleName, newModule))) ) {
return true;
}
var (_success, _found, _id) = getModuleIDByName(moduleName);
@ -190,13 +190,13 @@ contract moduleHandler is multiOwner, announcementTypes {
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success );
if ( ! ( _found && modules[_id].name == sha3('Publisher') )) {
if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("newModule", sha3(name, addr, schellingEvent, transferEvent))) ) {
if ( ! insertAndCheckDo(calcDoHash("newModule", keccak256(name, addr, schellingEvent, transferEvent))) ) {
return true;
}
}
addModule( modules_s(addr, sha3(name), schellingEvent, transferEvent), true);
addModule( modules_s(addr, keccak256(name), schellingEvent, transferEvent), true);
return true;
}
function dropModule(string name, bool callCallback) external returns (bool success) {
@ -209,9 +209,9 @@ contract moduleHandler is multiOwner, announcementTypes {
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success );
if ( ! ( _found && modules[_id].name == sha3('Publisher') )) {
if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("replaceModule", sha3(name, callCallback))) ) {
if ( ! insertAndCheckDo(calcDoHash("replaceModule", keccak256(name, callCallback))) ) {
return true;
}
}
@ -226,7 +226,7 @@ contract moduleHandler is multiOwner, announcementTypes {
function callDisableCallback(string moduleName) external returns (bool success) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("callDisableCallback", sha3(moduleName))) ) {
if ( ! insertAndCheckDo(calcDoHash("callDisableCallback", keccak256(moduleName))) ) {
return true;
}
var (_success, _found, _id) = getModuleIDByName(moduleName);
@ -248,7 +248,7 @@ contract moduleHandler is multiOwner, announcementTypes {
@bool Was the function successfull?
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success && _found && modules[_id].name == sha3('Token') );
require( _success && _found && modules[_id].name == keccak256('Token') );
for ( uint256 a=0 ; a<modules.length ; a++ ) {
if ( modules[a].transferEvent && abstractModule(modules[a].addr).isActive() ) {
require( abstractModule(modules[a].addr).transferEvent(from, to, value) );
@ -267,7 +267,7 @@ contract moduleHandler is multiOwner, announcementTypes {
@bool Was the function successfull?
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success && _found && modules[_id].name == sha3('Schelling') );
require( _success && _found && modules[_id].name == keccak256('Schelling') );
for ( uint256 a=0 ; a<modules.length ; a++ ) {
if ( modules[a].schellingEvent && abstractModule(modules[a].addr).isActive() ) {
require( abstractModule(modules[a].addr).newSchellingRoundEvent(roundID, reward) );
@ -287,9 +287,9 @@ contract moduleHandler is multiOwner, announcementTypes {
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success );
if ( ! ( _found && modules[_id].name == sha3('Publisher') )) {
if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("replaceModuleHandler", sha3(newHandler))) ) {
if ( ! insertAndCheckDo(calcDoHash("replaceModuleHandler", keccak256(newHandler))) ) {
return true;
}
}
@ -353,7 +353,7 @@ contract moduleHandler is multiOwner, announcementTypes {
@success Was the function successfull?
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success && _found && modules[_id].name == sha3('Provider') );
require( _success && _found && modules[_id].name == keccak256('Provider') );
(_success, _found, _id) = getModuleIDByName('Token');
require( _success && _found );
require( token(modules[_id].addr).mint(to, value) );
@ -385,7 +385,7 @@ contract moduleHandler is multiOwner, announcementTypes {
@success Was the function successfull?
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success && _found && modules[_id].name == sha3('Provider') );
require( _success && _found && modules[_id].name == keccak256('Provider') );
(_success, _found, _id) = getModuleIDByName('Token');
require( _success && _found );
require( token(modules[_id].addr).processTransactionFee(from, value) );
@ -400,7 +400,7 @@ contract moduleHandler is multiOwner, announcementTypes {
@success Was the function successfull?
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success && _found && modules[_id].name == sha3('Schelling') );
require( _success && _found && modules[_id].name == keccak256('Schelling') );
(_success, _found, _id) = getModuleIDByName('Token');
require( _success && _found );
require( token(modules[_id].addr).burn(from, value) );
@ -417,9 +417,9 @@ contract moduleHandler is multiOwner, announcementTypes {
*/
var (_success, _found, _id) = getModuleIDByAddress(msg.sender);
require( _success );
if ( ! ( _found && modules[_id].name == sha3('Publisher') )) {
if ( ! ( _found && modules[_id].name == keccak256('Publisher') )) {
require( block.number < debugModeUntil );
if ( ! insertAndCheckDo(calcDoHash("configureModule", sha3(moduleName, aType, value))) ) {
if ( ! insertAndCheckDo(calcDoHash("configureModule", keccak256(moduleName, aType, value))) ) {
return true;
}
}
@ -437,7 +437,7 @@ contract moduleHandler is multiOwner, announcementTypes {
*/
require( owners[msg.sender] );
if ( forever ) {
if ( ! insertAndCheckDo(calcDoHash("freezing", sha3(forever))) ) {
if ( ! insertAndCheckDo(calcDoHash("freezing", keccak256(forever))) ) {
return;
}
}

View File

@ -21,12 +21,12 @@ contract multiOwner is safeMath {
Externals
*/
function insertOwner(address addr) external {
if ( insertAndCheckDo(calcDoHash("insertOwner", sha3(addr))) ) {
if ( insertAndCheckDo(calcDoHash("insertOwner", keccak256(addr))) ) {
_addOwner(addr);
}
}
function dropOwner(address addr) external {
if ( insertAndCheckDo(calcDoHash("dropOwner", sha3(addr))) ) {
if ( insertAndCheckDo(calcDoHash("dropOwner", keccak256(addr))) ) {
_delOwner(addr);
}
}
@ -42,7 +42,7 @@ contract multiOwner is safeMath {
return ownerCount * 75 / 100;
}
function calcDoHash(string job, bytes32 data) public constant returns (bytes32 hash) {
return sha3(job, data);
return keccak256(job, data);
}
function validDoHash(bytes32 doHash) public constant returns (bool valid) {
return doDB[doHash].length > 0;

View File

@ -335,7 +335,7 @@ contract schelling is module, announcementTypes, schellingVars {
require( voter.status == voterStatus.afterPrepareVote );
require( voter.roundID < currentRound );
if ( sha3(vote) == voter.hash ) {
if ( keccak256(vote) == voter.hash ) {
delete voter.hash;
if (round.blockHeight+roundBlockDelay/2 >= block.number) {
if ( bytes(vote)[0] == aboveChar ) {

View File

@ -196,7 +196,7 @@ contract MilestoneTracker {
}
/// @notice `onlyDonor` Approves the proposed milestone list
/// @param _hashProposals The sha3() of the proposed milestone list's
/// @param _hashProposals The keccak256() of the proposed milestone list's
/// bytecode; this confirms that the `donor` knows the set of milestones
/// they are approving
function acceptProposedMilestones(bytes32 _hashProposals
@ -205,7 +205,7 @@ contract MilestoneTracker {
uint i;
if (!changingMilestones) throw;
if (sha3(proposedMilestones) != _hashProposals) throw;
if (keccak256(proposedMilestones) != _hashProposals) throw;
// Cancel all the unfinished milestones
for (i=0; i<milestones.length; i++) {

View File

@ -1971,25 +1971,6 @@ BOOST_AUTO_TEST_CASE(log_in_constructor)
BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(u256(2)));
}
BOOST_AUTO_TEST_CASE(suicide)
{
char const* sourceCode = R"(
contract test {
function test() payable {}
function a(address receiver) returns (uint ret) {
suicide(receiver);
return 10;
}
}
)";
u256 amount(130);
compileAndRun(sourceCode, amount);
u160 address(23);
ABI_CHECK(callContractFunction("a(address)", address), bytes());
BOOST_CHECK(!addressHasCode(m_contractAddress));
BOOST_CHECK_EQUAL(balanceAt(address), amount);
}
BOOST_AUTO_TEST_CASE(selfdestruct)
{
char const* sourceCode = R"(
@ -2028,23 +2009,6 @@ BOOST_AUTO_TEST_CASE(keccak256)
testContractAgainstCpp("a(bytes32)", f, u256(-1));
}
BOOST_AUTO_TEST_CASE(sha3)
{
char const* sourceCode = R"(
contract test {
// to confuse the optimiser
function b(bytes32 input) returns (bytes32) {
return sha3(input);
}
function a(bytes32 input) returns (bool) {
return keccak256(input) == b(input);
}
}
)";
compileAndRun(sourceCode);
BOOST_REQUIRE(callContractFunction("a(bytes32)", u256(42)) == encodeArgs(true));
}
BOOST_AUTO_TEST_CASE(sha256)
{
char const* sourceCode = R"(
@ -3760,27 +3724,6 @@ BOOST_AUTO_TEST_CASE(iterated_keccak256_with_bytes)
));
}
BOOST_AUTO_TEST_CASE(sha3_multiple_arguments)
{
char const* sourceCode = R"(
contract c {
function foo(uint a, uint b, uint c) returns (bytes32 d)
{
d = sha3(a, b, c);
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13), encodeArgs(
dev::keccak256(
toBigEndian(u256(10)) +
toBigEndian(u256(12)) +
toBigEndian(u256(13))
)
));
}
BOOST_AUTO_TEST_CASE(generic_call)
{
char const* sourceCode = R"**(
@ -11642,13 +11585,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value)
return value;
}
function get_delegated() external returns (bool) {
return this.delegatecall(bytes4(sha3("get()")));
return this.delegatecall(bytes4(keccak256("get()")));
}
function assert0() external view {
assert(value == 0);
}
function assert0_delegated() external returns (bool) {
return this.delegatecall(bytes4(sha3("assert0()")));
return this.delegatecall(bytes4(keccak256("assert0()")));
}
}
)DELIMITER";

View File

@ -8,5 +8,5 @@ contract test {
}
}
// ----
// Warning: (58-64): "sha3" has been deprecated in favour of "keccak256"
// Warning: (99-109): "suicide" has been deprecated in favour of "selfdestruct"
// TypeError: (58-64): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (99-109): "suicide" has been deprecated in favour of "selfdestruct"

View File

@ -1,15 +0,0 @@
pragma experimental "v0.5.0";
contract test {
function f() pure public {
bytes32 x = sha3(uint8(1));
x;
}
function g() public {
suicide(1);
}
}
// ----
// TypeError: (88-102): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (88-102): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// TypeError: (88-102): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// TypeError: (137-147): "suicide" has been deprecated in favour of "selfdestruct"

View File

@ -2,9 +2,6 @@ contract C {
function f() pure public returns (bytes32) {
return keccak256(1);
}
function g() pure public returns (bytes32) {
return sha3(1);
}
function h() pure public returns (bytes32) {
return sha256(1);
}
@ -20,14 +17,10 @@ contract C {
// Warning: (87-88): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (77-89): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (77-89): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (161-168): "sha3" has been deprecated in favour of "keccak256"
// Warning: (166-167): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (161-168): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (161-168): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (247-248): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (240-249): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (240-249): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (331-332): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (321-333): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (321-333): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (420-421): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (168-169): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (161-170): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (161-170): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (252-253): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
// Warning: (242-254): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (242-254): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (341-342): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.

View File

@ -2,9 +2,6 @@ contract C {
function f() pure public returns (bytes32) {
return keccak256(uint8(1));
}
function g() pure public returns (bytes32) {
return sha3(uint8(1));
}
function h() pure public returns (bytes32) {
return sha256(uint8(1));
}
@ -21,10 +18,7 @@ contract C {
// ----
// Warning: (77-96): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (77-96): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// Warning: (168-182): "sha3" has been deprecated in favour of "keccak256"
// Warning: (168-182): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (168-182): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// Warning: (254-270): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (254-270): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// Warning: (342-361): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (342-361): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// Warning: (168-184): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (168-184): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// Warning: (256-275): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
// Warning: (256-275): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.

View File

@ -53,6 +53,11 @@ DIR=$(mktemp -d)
rm -f soljson.js
cp "$SOLJSON" soljson.js
# ensure to use always 0.5.0 sources
# FIXME: should be removed once the version bump in this repo is done
rm -rf test/DAO040
cp -R test/DAO test/DAO040
# Update version (needed for some tests)
echo "Updating package.json to version $VERSION"
npm version --no-git-tag-version $VERSION