returnSize assigned according to truth value of returnInfo.dynamicReturnSize

This commit is contained in:
nishant-sachdeva
2022-03-03 18:55:10 +05:30
parent ebefb5d980
commit beabc51c20
40 changed files with 261 additions and 116 deletions
@@ -17,7 +17,7 @@ contract D {
// compileViaYul: also
// ----
// constructor(): 2 ->
// gas irOptimized: 200295
// gas irOptimized: 203967
// gas legacy: 245842
// gas legacyOptimized: 195676
// f() -> 2
@@ -18,7 +18,7 @@ contract D {
// compileViaYul: also
// ----
// constructor(): 2 ->
// gas irOptimized: 200458
// gas irOptimized: 204130
// gas legacy: 246202
// gas legacyOptimized: 195914
// f() -> 2
@@ -25,7 +25,7 @@ contract C {
// compileViaYul: also
// ----
// constructor(), 1 ether ->
// gas irOptimized: 308423
// gas irOptimized: 315341
// gas legacy: 465314
// gas legacyOptimized: 304481
// f(uint256): 0 -> FAILURE
@@ -27,7 +27,7 @@ contract C {
// revertStrings: debug
// ----
// constructor(), 1 ether ->
// gas irOptimized: 445767
// gas irOptimized: 452673
// gas legacy: 834272
// gas legacyOptimized: 510004
// f(uint256): 0 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code"
@@ -18,7 +18,7 @@ contract C {
// compileViaYul: also
// ----
// constructor(), 20 wei
// gas irOptimized: 213663
// gas irOptimized: 219285
// gas legacy: 294569
// gas legacyOptimized: 174699
// f(uint256): 20 -> 1370859564726510389319704988634906228201275401179
@@ -26,7 +26,7 @@ contract C {
// f(uint256): 20 -> FAILURE
// x() -> 1
// stack(uint256): 1023 -> FAILURE
// gas irOptimized: 304303
// gas irOptimized: 314884
// gas legacy: 483942
// gas legacyOptimized: 298807
// x() -> 1
@@ -41,7 +41,7 @@ contract test {
// compileViaYul: also
// ----
// constructor(), 20 wei ->
// gas irOptimized: 274154
// gas irOptimized: 283040
// gas legacy: 402654
// gas legacyOptimized: 274470
// sendAmount(uint256): 5 -> 5
@@ -40,7 +40,7 @@ contract test {
// compileViaYul: also
// ----
// constructor(), 20 wei ->
// gas irOptimized: 274154
// gas irOptimized: 283040
// gas legacy: 402654
// gas legacyOptimized: 274470
// sendAmount(uint256): 5 -> 5
@@ -0,0 +1,31 @@
interface ShortReturn {
function f() external pure returns (bytes32);
}
contract LongReturn {
function f() external pure returns (uint[20] memory) {}
}
contract Test {
function test() public returns (uint) {
LongReturn longReturn = new LongReturn();
uint freeMemoryBefore;
assembly {
freeMemoryBefore := mload(0x40)
}
ShortReturn(address(longReturn)).f();
uint freeMemoryAfter;
assembly {
freeMemoryAfter := mload(0x40)
}
return freeMemoryAfter - freeMemoryBefore;
}
}
// ====
// compileViaYul: true
// ----
// test() -> 0x20
// gas legacy: 131966
@@ -0,0 +1,32 @@
interface LongReturn {
function f() external pure returns (uint[20] memory);
}
contract ShortReturn {
function f() external pure returns (bytes32) {}
}
contract Test {
function test() public returns (uint) {
ShortReturn shortReturn = new ShortReturn();
uint freeMemoryBefore;
assembly {
freeMemoryBefore := mload(0x40)
}
LongReturn(address(shortReturn)).f();
uint freeMemoryAfter;
assembly {
freeMemoryAfter := mload(0x40)
}
return freeMemoryAfter - freeMemoryBefore;
}
}
// ====
// EVMVersion: <=homestead
// compileViaYul: true
// ----
// test() -> 0x0500
// gas legacy: 131966
@@ -0,0 +1,34 @@
interface LongReturn {
function f() external pure returns (uint[20] memory);
}
contract ShortReturn {
function f() external pure returns (bytes32) {}
}
contract Test {
function test() public returns (uint) {
ShortReturn shortReturn = new ShortReturn();
uint freeMemoryBefore;
assembly {
freeMemoryBefore := mload(0x40)
}
// This reverts. The external call succeeds but ABI decoding fails due to the returned
// `bytes32` being much shorter than the expected `uint[20]`.
LongReturn(address(shortReturn)).f();
uint freeMemoryAfter;
assembly {
freeMemoryAfter := mload(0x40)
}
return freeMemoryAfter - freeMemoryBefore;
}
}
// ====
// EVMVersion: >homestead
// compileViaYul: true
// ----
// test() -> FAILURE
// gas legacy: 131966