Merge pull request #10047 from ethereum/removeMemoryGuards

Disable StackLimitEvader again until we have stronger correctness guarantees.
This commit is contained in:
chriseth 2020-10-15 18:56:33 +02:00 committed by GitHub
commit c9ed1b9ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 53 additions and 163 deletions

View File

@ -668,6 +668,9 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
string IRGenerator::memoryInit(bool _useMemoryGuard)
{
// TODO: Remove once we have made sure it is safe, i.e. after "Yul memory objects lite".
// Also restore the tests removed in the commit that adds this comment.
_useMemoryGuard = false;
// This function should be called at the beginning of the EVM call frame
// and thus can assume all memory to be zero, including the contents of
// the "zero memory area" (the position CompilerUtils::zeroPointer points to).

View File

@ -9,7 +9,7 @@ IR:
object "C_80" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_80()
@ -25,7 +25,7 @@ object "C_80" {
}
object "C_80_deployed" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -9,7 +9,7 @@ Optimized IR:
object "C_6" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("C_6_deployed")
codecopy(0, dataoffset("C_6_deployed"), _1)
@ -19,7 +19,7 @@ object "C_6" {
object "C_6_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
revert(0, 0)
}
}
@ -37,7 +37,7 @@ Optimized IR:
object "D_9" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("D_9_deployed")
codecopy(0, dataoffset("D_9_deployed"), _1)
@ -47,7 +47,7 @@ object "D_9" {
object "D_9_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
revert(0, 0)
}
}

View File

@ -9,7 +9,7 @@ Optimized IR:
object "C_2" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("C_2_deployed")
codecopy(0, dataoffset("C_2_deployed"), _1)
@ -19,7 +19,7 @@ object "C_2" {
object "C_2_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
revert(0, 0)
}
}
@ -37,7 +37,7 @@ Optimized IR:
object "D_13" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("D_13_deployed")
codecopy(0, dataoffset("D_13_deployed"), _1)
@ -47,21 +47,20 @@ object "D_13" {
object "D_13_deployed" {
code {
{
let _1 := memoryguard(0x80)
mstore(64, _1)
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let _2 := 0
if eq(0x26121ff0, shr(224, calldataload(_2)))
let _1 := 0
if eq(0x26121ff0, shr(224, calldataload(_1)))
{
if callvalue() { revert(_2, _2) }
if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) }
let _3 := datasize("C_2")
let _4 := add(_1, _3)
if or(gt(_4, 0xffffffffffffffff), lt(_4, _1)) { invalid() }
datacopy(_1, dataoffset("C_2"), _3)
pop(create(_2, _1, sub(_4, _1)))
return(allocateMemory(_2), _2)
if callvalue() { revert(_1, _1) }
if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) }
let _2 := datasize("C_2")
let _3 := add(128, _2)
if or(gt(_3, 0xffffffffffffffff), lt(_3, 128)) { invalid() }
datacopy(128, dataoffset("C_2"), _2)
pop(create(_1, 128, _2))
return(allocateMemory(_1), _1)
}
}
revert(0, 0)
@ -77,7 +76,7 @@ object "D_13" {
object "C_2" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("C_2_deployed")
codecopy(0, dataoffset("C_2_deployed"), _1)
@ -87,7 +86,7 @@ object "D_13" {
object "C_2_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
revert(0, 0)
}
}

View File

@ -19,18 +19,16 @@ object "D_11" {
object "D_11_deployed" {
code {
{
let _1 := memoryguard(0x80)
mstore(64, _1)
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let _2 := 0
if eq(0x26121ff0, shr(224, calldataload(_2)))
let _1 := 0
if eq(0x26121ff0, shr(224, calldataload(_1)))
{
if callvalue() { revert(_2, _2) }
if slt(add(calldatasize(), not(3)), _2) { revert(_2, _2) }
if gt(_1, 0xffffffffffffffff) { invalid() }
mstore(64, _1)
return(_1, _2)
if callvalue() { revert(_1, _1) }
if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) }
mstore(64, 128)
return(128, _1)
}
}
revert(0, 0)

View File

@ -9,7 +9,7 @@ Optimized IR:
object "D_7" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("D_7_deployed")
codecopy(0, dataoffset("D_7_deployed"), _1)

View File

@ -9,7 +9,7 @@ Optimized IR:
object "C_56" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("C_56_deployed")
codecopy(0, dataoffset("C_56_deployed"), _1)
@ -19,7 +19,7 @@ object "C_56" {
object "C_56_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let _1 := 0

View File

@ -9,7 +9,7 @@ Optimized IR:
object "Arraysum_33" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("Arraysum_33_deployed")
codecopy(0, dataoffset("Arraysum_33_deployed"), _1)
@ -19,7 +19,7 @@ object "Arraysum_33" {
object "Arraysum_33_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let _1 := 0

View File

@ -7,7 +7,7 @@
object \"C_6\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_6()
codecopy(0, dataoffset(\"C_6_deployed\"), datasize(\"C_6_deployed\"))
@ -17,7 +17,7 @@ object \"C_6\" {
}
object \"C_6_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_224_unsigned(calldataload(0))

View File

@ -8,7 +8,7 @@
object \"C_6\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_6()
@ -24,7 +24,7 @@ object \"C_6\" {
}
object \"C_6_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -9,7 +9,7 @@ Optimized IR:
object "C_6" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if callvalue() { revert(0, 0) }
codecopy(0, dataoffset("C_6_deployed"), datasize("C_6_deployed"))
return(0, datasize("C_6_deployed"))
@ -18,7 +18,7 @@ object "C_6" {
object "C_6_deployed" {
code {
{
mstore(64, memoryguard(0x80))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{
let selector := shift_right_224_unsigned(calldataload(0))

View File

@ -8,7 +8,7 @@
object \"C_10\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_10()
@ -24,7 +24,7 @@ object \"C_10\" {
}
object \"C_10_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -8,7 +8,7 @@
object \"C_10\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_10()
@ -24,7 +24,7 @@ object \"C_10\" {
}
object \"C_10_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -8,7 +8,7 @@
object \"C_10\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_10()
@ -24,7 +24,7 @@ object \"C_10\" {
}
object \"C_10_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -8,7 +8,7 @@
object \"C_10\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_10()
@ -24,7 +24,7 @@ object \"C_10\" {
}
object \"C_10_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -8,7 +8,7 @@
object \"C_10\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if callvalue() { revert(0, 0) }
constructor_C_10()
@ -24,7 +24,7 @@ object \"C_10\" {
}
object \"C_10_deployed\" {
code {
mstore(64, memoryguard(128))
mstore(64, 128)
if iszero(lt(calldatasize(), 4))
{

View File

@ -1,53 +0,0 @@
contract C {
uint256[1024] s;
function f() public returns (uint256 x) {
x = 42;
uint256 x0 = s[0];
uint256 x1 = s[1];
uint256 x2 = s[2];
uint256 x3 = s[3];
uint256 x4 = s[4];
uint256 x5 = s[5];
uint256 x6 = s[6];
uint256 x7 = s[7];
uint256 x8 = s[8];
uint256 x9 = s[9];
uint256 x10 = s[10];
uint256 x11 = s[11];
uint256 x12 = s[12];
uint256 x13 = s[13];
uint256 x14 = s[14];
uint256 x15 = s[15];
uint256 x16 = s[16];
uint256 x17 = s[17];
uint256 x18 = s[18];
s[1000] = x0 + 2;
s[118] = x18;
s[117] = x17;
s[116] = x16;
s[115] = x15;
s[114] = x14;
s[113] = x13;
s[112] = x12;
s[111] = x11;
s[110] = x10;
s[109] = x9;
s[108] = x8;
s[107] = x7;
s[106] = x6;
s[105] = x5;
s[104] = x4;
s[103] = x3;
s[102] = x2;
s[101] = x1;
s[100] = x0;
}
function test() public view returns(uint256) {
return s[1000];
}
}
// ====
// compileViaYul: true
// ----
// f() -> 0x2a
// test() -> 2

View File

@ -1,57 +0,0 @@
contract C {
uint256[1024] s;
function g() public returns (uint256) {
// try to prevent inlining
return f() + f() + f() + f() + f();
}
function f() public returns (uint256 x) {
x = 42;
uint256 x0 = s[0];
uint256 x1 = s[1];
uint256 x2 = s[2];
uint256 x3 = s[3];
uint256 x4 = s[4];
uint256 x5 = s[5];
uint256 x6 = s[6];
uint256 x7 = s[7];
uint256 x8 = s[8];
uint256 x9 = s[9];
uint256 x10 = s[10];
uint256 x11 = s[11];
uint256 x12 = s[12];
uint256 x13 = s[13];
uint256 x14 = s[14];
uint256 x15 = s[15];
uint256 x16 = s[16];
uint256 x17 = s[17];
uint256 x18 = s[18];
s[1000] = x0 + 2;
s[118] = x18;
s[117] = x17;
s[116] = x16;
s[115] = x15;
s[114] = x14;
s[113] = x13;
s[112] = x12;
s[111] = x11;
s[110] = x10;
s[109] = x9;
s[108] = x8;
s[107] = x7;
s[106] = x6;
s[105] = x5;
s[104] = x4;
s[103] = x3;
s[102] = x2;
s[101] = x1;
s[100] = x0;
}
function test() public view returns(uint256) {
return s[1000];
}
}
// ====
// compileViaYul: true
// ----
// f() -> 0x2a
// test() -> 2