mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3900 from meowingtwurtle/removeAssemblyAliases
[BREAKING] Remove suicide and sha3 assembly instructions
This commit is contained in:
commit
0a074d8494
@ -10,6 +10,7 @@ Breaking Changes:
|
|||||||
* 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: ``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.
|
||||||
* Type Checker: Disallow arithmetic operations for Boolean variables.
|
* Type Checker: Disallow arithmetic operations for Boolean variables.
|
||||||
* Disallow trailing dots that are not followed by a number.
|
* Disallow trailing dots that are not followed by a number.
|
||||||
|
* Remove assembly instructions ``sha3`` and ``suicide``
|
||||||
|
|
||||||
Language Features:
|
Language Features:
|
||||||
* General: Allow appending ``calldata`` keyword to types, to explicitly specify data location for arguments of external functions.
|
* General: Allow appending ``calldata`` keyword to types, to explicitly specify data location for arguments of external functions.
|
||||||
|
@ -220,8 +220,6 @@ In the grammar, opcodes are represented as pre-defined identifiers.
|
|||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| keccak256(p, n) | | F | keccak(mem[p...(p+n))) |
|
| keccak256(p, n) | | F | keccak(mem[p...(p+n))) |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| sha3(p, n) | | F | keccak(mem[p...(p+n))) |
|
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
|
||||||
| jump(label) | `-` | F | jump to label / code position |
|
| jump(label) | `-` | F | jump to label / code position |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| jumpi(label, cond) | `-` | F | jump to label if cond is nonzero |
|
| jumpi(label, cond) | `-` | F | jump to label if cond is nonzero |
|
||||||
|
@ -318,11 +318,6 @@ std::map<string, dev::solidity::Instruction> const& Parser::instructions()
|
|||||||
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
|
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
|
||||||
s_instructions[name] = instruction.second;
|
s_instructions[name] = instruction.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add alias for suicide
|
|
||||||
s_instructions["suicide"] = solidity::Instruction::SELFDESTRUCT;
|
|
||||||
// add alis for sha3
|
|
||||||
s_instructions["sha3"] = solidity::Instruction::KECCAK256;
|
|
||||||
}
|
}
|
||||||
return s_instructions;
|
return s_instructions;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ library strings {
|
|||||||
*/
|
*/
|
||||||
function keccak(slice self) internal returns (bytes32 ret) {
|
function keccak(slice self) internal returns (bytes32 ret) {
|
||||||
assembly {
|
assembly {
|
||||||
ret := sha3(mload(add(self, 32)), mload(self))
|
ret := keccak256(mload(add(self, 32)), mload(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ library strings {
|
|||||||
let len := mload(needle)
|
let len := mload(needle)
|
||||||
let selfptr := mload(add(self, 0x20))
|
let selfptr := mload(add(self, 0x20))
|
||||||
let needleptr := mload(add(needle, 0x20))
|
let needleptr := mload(add(needle, 0x20))
|
||||||
equal := eq(sha3(selfptr, len), sha3(needleptr, len))
|
equal := eq(keccak256(selfptr, len), keccak256(needleptr, len))
|
||||||
}
|
}
|
||||||
return equal;
|
return equal;
|
||||||
}
|
}
|
||||||
@ -386,7 +386,7 @@ library strings {
|
|||||||
let len := mload(needle)
|
let len := mload(needle)
|
||||||
let selfptr := mload(add(self, 0x20))
|
let selfptr := mload(add(self, 0x20))
|
||||||
let needleptr := mload(add(needle, 0x20))
|
let needleptr := mload(add(needle, 0x20))
|
||||||
equal := eq(sha3(selfptr, len), sha3(needleptr, len))
|
equal := eq(keccak256(selfptr, len), keccak256(needleptr, len))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ library strings {
|
|||||||
assembly {
|
assembly {
|
||||||
let len := mload(needle)
|
let len := mload(needle)
|
||||||
let needleptr := mload(add(needle, 0x20))
|
let needleptr := mload(add(needle, 0x20))
|
||||||
equal := eq(sha3(selfptr, len), sha3(needleptr, len))
|
equal := eq(keccak256(selfptr, len), keccak256(needleptr, len))
|
||||||
}
|
}
|
||||||
|
|
||||||
return equal;
|
return equal;
|
||||||
@ -443,7 +443,7 @@ library strings {
|
|||||||
assembly {
|
assembly {
|
||||||
let len := mload(needle)
|
let len := mload(needle)
|
||||||
let needleptr := mload(add(needle, 0x20))
|
let needleptr := mload(add(needle, 0x20))
|
||||||
equal := eq(sha3(selfptr, len), sha3(needleptr, len))
|
equal := eq(keccak256(selfptr, len), keccak256(needleptr, len))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,11 +479,11 @@ library strings {
|
|||||||
} else {
|
} else {
|
||||||
// For long needles, use hashing
|
// For long needles, use hashing
|
||||||
bytes32 hash;
|
bytes32 hash;
|
||||||
assembly { hash := sha3(needleptr, needlelen) }
|
assembly { hash := keccak256(needleptr, needlelen) }
|
||||||
ptr = selfptr;
|
ptr = selfptr;
|
||||||
for (idx = 0; idx <= selflen - needlelen; idx++) {
|
for (idx = 0; idx <= selflen - needlelen; idx++) {
|
||||||
bytes32 testHash;
|
bytes32 testHash;
|
||||||
assembly { testHash := sha3(ptr, needlelen) }
|
assembly { testHash := keccak256(ptr, needlelen) }
|
||||||
if (hash == testHash)
|
if (hash == testHash)
|
||||||
return ptr;
|
return ptr;
|
||||||
ptr += 1;
|
ptr += 1;
|
||||||
@ -519,11 +519,11 @@ library strings {
|
|||||||
} else {
|
} else {
|
||||||
// For long needles, use hashing
|
// For long needles, use hashing
|
||||||
bytes32 hash;
|
bytes32 hash;
|
||||||
assembly { hash := sha3(needleptr, needlelen) }
|
assembly { hash := keccak256(needleptr, needlelen) }
|
||||||
ptr = selfptr + (selflen - needlelen);
|
ptr = selfptr + (selflen - needlelen);
|
||||||
while (ptr >= selfptr) {
|
while (ptr >= selfptr) {
|
||||||
bytes32 testHash;
|
bytes32 testHash;
|
||||||
assembly { testHash := sha3(ptr, needlelen) }
|
assembly { testHash := keccak256(ptr, needlelen) }
|
||||||
if (hash == testHash)
|
if (hash == testHash)
|
||||||
return ptr + needlelen;
|
return ptr + needlelen;
|
||||||
ptr -= 1;
|
ptr -= 1;
|
||||||
|
@ -178,9 +178,9 @@ BOOST_AUTO_TEST_CASE(simple_instructions)
|
|||||||
BOOST_CHECK(successParse("{ dup1 dup1 mul dup1 sub pop }"));
|
BOOST_CHECK(successParse("{ dup1 dup1 mul dup1 sub pop }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(suicide_selfdestruct)
|
BOOST_AUTO_TEST_CASE(selfdestruct)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(successParse("{ 0x01 suicide 0x02 selfdestruct }"));
|
BOOST_CHECK(successParse("{ 0x02 selfdestruct }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(keywords)
|
BOOST_AUTO_TEST_CASE(keywords)
|
||||||
@ -740,8 +740,6 @@ BOOST_AUTO_TEST_CASE(keccak256)
|
|||||||
{
|
{
|
||||||
BOOST_CHECK(successAssemble("{ 0 0 keccak256 pop }"));
|
BOOST_CHECK(successAssemble("{ 0 0 keccak256 pop }"));
|
||||||
BOOST_CHECK(successAssemble("{ pop(keccak256(0, 0)) }"));
|
BOOST_CHECK(successAssemble("{ pop(keccak256(0, 0)) }"));
|
||||||
BOOST_CHECK(successAssemble("{ 0 0 sha3 pop }"));
|
|
||||||
BOOST_CHECK(successAssemble("{ pop(sha3(0, 0)) }"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(returndatasize)
|
BOOST_AUTO_TEST_CASE(returndatasize)
|
||||||
|
@ -11431,26 +11431,11 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly)
|
|||||||
=: ret
|
=: ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function h() pure returns (bytes32 ret) {
|
|
||||||
assembly {
|
|
||||||
ret := sha3(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function i() pure returns (bytes32 ret) {
|
|
||||||
assembly {
|
|
||||||
0
|
|
||||||
0
|
|
||||||
sha3
|
|
||||||
=: ret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||||
ABI_CHECK(callContractFunction("g()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
ABI_CHECK(callContractFunction("g()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||||
ABI_CHECK(callContractFunction("h()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
|
||||||
ABI_CHECK(callContractFunction("i()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_modifiers)
|
BOOST_AUTO_TEST_CASE(multi_modifiers)
|
||||||
|
Loading…
Reference in New Issue
Block a user