-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust semantic tests to work on both EOF and legacy #15768
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
contract C { | ||
event Test(function() external indexed); | ||
function f() public { | ||
emit Test(this.f); | ||
emit Test(C(address(0x1234)).f); | ||
} | ||
} | ||
// ---- | ||
// f() -> | ||
// ~ emit Test(function): #0xc06afe3a8444fc0004668591e8306bfb9968e79e26121ff00000000000000000 | ||
// ~ emit Test(function): #0x123426121ff00000000000000000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pragma abicoder v2; | ||
|
||
library Pairing { | ||
struct G1Point { | ||
uint X; | ||
|
@@ -35,34 +37,26 @@ library Pairing { | |
|
||
/// @return r the sum of two points of G1 | ||
function add(G1Point memory p1, G1Point memory p2) internal returns (G1Point memory r) { | ||
uint[4] memory input; | ||
uint[6] memory input; | ||
input[0] = p1.X; | ||
input[1] = p1.Y; | ||
input[2] = p2.X; | ||
input[3] = p2.Y; | ||
bool success; | ||
assembly { | ||
success := call(sub(gas(), 2000), 6, 0, input, 0xc0, r, 0x60) | ||
// Use "invalid" to make gas estimation work | ||
switch success case 0 { invalid() } | ||
} | ||
(bool success, bytes memory encodedResult) = address(6).call(abi.encode(input)); | ||
Comment on lines
-38
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something I don't really understand. According to https://www.evm.codes/precompiled Similarly, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, the reason I'm removing the assembly blocks in this file is of course that This contract seems to be using assembly only to work around some problem related to gas estimation (and maybe also to make the call cheaper), which is not an issue in our tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the record, @ekpyron got to the bottom of it:
#15788 fixes this. |
||
require(success); | ||
r = abi.decode(encodedResult, (G1Point)); | ||
} | ||
|
||
/// @return r the product of a point on G1 and a scalar, i.e. | ||
/// p == p.mul(1) and p.add(p) == p.mul(2) for all points p. | ||
function mul(G1Point memory p, uint s) internal returns (G1Point memory r) { | ||
uint[3] memory input; | ||
uint[4] memory input; | ||
input[0] = p.X; | ||
input[1] = p.Y; | ||
input[2] = s; | ||
bool success; | ||
assembly { | ||
success := call(sub(gas(), 2000), 7, 0, input, 0x80, r, 0x60) | ||
// Use "invalid" to make gas estimation work | ||
switch success case 0 { invalid() } | ||
} | ||
(bool success, bytes memory encodedResult) = address(7).call(abi.encode(input)); | ||
require(success); | ||
r = abi.decode(encodedResult, (G1Point)); | ||
} | ||
|
||
/// @return the result of computing the pairing check | ||
|
@@ -83,15 +77,19 @@ library Pairing { | |
input[i * 6 + 4] = p2[i].Y[0]; | ||
input[i * 6 + 5] = p2[i].Y[1]; | ||
} | ||
uint[1] memory out; | ||
bool success; | ||
assembly { | ||
success := call(sub(gas(), 2000), 8, 0, add(input, 0x20), mul(inputSize, 0x20), out, 0x20) | ||
// Use "invalid" to make gas estimation work | ||
switch success case 0 { invalid() } | ||
|
||
bytes memory encodedInput = new bytes(inputSize * 32); | ||
for (uint i = 0; i < inputSize; i++) | ||
{ | ||
uint offset = (i + 1) * 32; | ||
uint item = input[i]; | ||
assembly ("memory-safe") { | ||
mstore(add(encodedInput, offset), item) | ||
} | ||
} | ||
(bool success, bytes memory encodedResult) = address(8).call(encodedInput); | ||
require(success); | ||
return out[0] != 0; | ||
return abi.decode(encodedResult, (bool)); | ||
} | ||
function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal returns (bool) { | ||
G1Point[] memory p1 = new G1Point[](2); | ||
|
@@ -294,11 +292,11 @@ contract Test { | |
// f() -> true | ||
// g() -> true | ||
// pair() -> true | ||
// gas irOptimized: 270409 | ||
// gas legacy: 275219 | ||
// gas legacyOptimized: 266862 | ||
// gas irOptimized: 275319 | ||
// gas legacy: 293854 | ||
// gas legacyOptimized: 276409 | ||
// verifyTx() -> true | ||
// ~ emit Verified(string): 0x20, 0x16, "Successfully verified." | ||
// gas irOptimized: 785720 | ||
// gas legacy: 801903 | ||
// gas legacyOptimized: 770941 | ||
// gas irOptimized: 821446 | ||
// gas legacy: 914211 | ||
// gas legacyOptimized: 820319 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,6 @@ contract helper { | |
return flag; | ||
} | ||
} | ||
|
||
|
||
contract test { | ||
helper h; | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
contract C { | ||
function f() public view returns (address a1, address a2) { | ||
a1 = this.f.address; | ||
this.f.address; | ||
[this.f.address][0]; | ||
a2 = [this.f.address][0]; | ||
a1 = C(address(0x1234)).f.address; | ||
C(address(0x1234)).f.address; | ||
[C(address(0x1234)).f.address][0]; | ||
a2 = [C(address(0x1234)).f.address][0]; | ||
} | ||
} | ||
// ---- | ||
// f() -> 0xc06afe3a8444fc0004668591e8306bfb9968e79e, 0xc06afe3a8444fc0004668591e8306bfb9968e79e | ||
// f() -> 0x1234, 0x1234 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cases like this fail on EOF, because the default salt is
0
and therefore unsaltednew
always generates the same address. And deploying to the same address causes a revert unless the initcode is identical.