Merge pull request #11331 from ethereum/respectMemoryModelForwardingRevert

Respect memory model forwarding revert
This commit is contained in:
chriseth 2021-04-29 16:31:10 +02:00 committed by GitHub
commit 1814cad4f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 18 deletions

View File

@ -3792,11 +3792,13 @@ string YulUtilFunctions::forwardingRevertFunction()
if (forward)
return Whiskers(R"(
function <functionName>() {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
let pos := <allocateUnbounded>()
returndatacopy(pos, 0, returndatasize())
revert(pos, returndatasize())
}
)")
("functionName", functionName)
("allocateUnbounded", allocateUnboundedFunction())
.render();
else
return Whiskers(R"(

View File

@ -66,8 +66,9 @@ object "D_16" {
datacopy(128, dataoffset("C_3"), _2)
if iszero(create(_1, 128, _2))
{
returndatacopy(_1, _1, returndatasize())
revert(_1, returndatasize())
let pos := mload(64)
returndatacopy(pos, _1, returndatasize())
revert(pos, returndatasize())
}
return(mload(64), _1)
}

View File

@ -136,8 +136,9 @@ object \"D_16\" {
}
function revert_forward_1() {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
let pos := allocate_unbounded()
returndatacopy(pos, 0, returndatasize())
revert(pos, returndatasize())
}
function shift_right_224_unsigned(value) -> newValue {

View File

@ -35,9 +35,9 @@ object "C_3" {
======= viair_subobjects/input.sol:D =======
Binary:
608060405234156100105760006000fd5b60b680610020600039806000f350fe60806040526004361015156087576000803560e01c6326121ff0141560855734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061008e60803980608083f01515607e573d82833e3d82fd5b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd
608060405234156100105760006000fd5b60ba80610020600039806000f350fe6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd
Binary of the runtime part:
60806040526004361015156087576000803560e01c6326121ff0141560855734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061008e60803980608083f01515607e573d82833e3d82fd5b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd
6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd
Optimized IR:
/*******************************************************
* WARNING *
@ -78,8 +78,9 @@ object "D_16" {
datacopy(128, dataoffset("C_3"), _2)
if iszero(create(_1, 128, _2))
{
returndatacopy(_1, _1, returndatasize())
revert(_1, returndatasize())
let pos := mload(64)
returndatacopy(pos, _1, returndatasize())
revert(pos, returndatasize())
}
return(mload(64), _1)
}

View File

@ -45,6 +45,6 @@ contract C {
// compileViaYul: also
// ----
// test() -> 5, 6, 7
// gas irOptimized: 345542
// gas irOptimized: 345942
// gas legacy: 500424
// gas legacyOptimized: 309013

View File

@ -18,15 +18,15 @@ contract C {
// compileViaYul: also
// ----
// constructor(), 20 wei
// gas irOptimized: 265125
// gas irOptimized: 255579
// gas legacy: 285485
// gas legacyOptimized: 177957
// gas legacyOptimized: 177933
// f(uint256): 20 -> 1370859564726510389319704988634906228201275401179
// x() -> 1
// f(uint256): 20 -> FAILURE
// x() -> 1
// stack(uint256): 1023 -> FAILURE
// gas irOptimized: 853785
// gas irOptimized: 856335
// gas legacy: 981671
// gas legacyOptimized: 824895
// x() -> 1

View File

@ -28,6 +28,6 @@ contract C {
// compileViaYul: also
// ----
// t() -> 9
// gas irOptimized: 103946
// gas irOptimized: 103941
// gas legacy: 161097
// gas legacyOptimized: 112116

View File

@ -22,6 +22,6 @@ contract A {
// ----
// different_salt() -> true
// same_salt() -> true
// gas irOptimized: 98438968
// gas irOptimized: 98438966
// gas legacy: 98439116
// gas legacyOptimized: 98438970

View File

@ -38,10 +38,10 @@ contract D {
// f() -> 0x1 # This should work, next should throw #
// gas legacy: 102944
// fview() -> FAILURE
// gas irOptimized: 98438658
// gas irOptimized: 98438664
// gas legacy: 98438822
// gas legacyOptimized: 98438615
// fpure() -> FAILURE
// gas irOptimized: 98438658
// gas irOptimized: 98438664
// gas legacy: 98438822
// gas legacyOptimized: 98438616