Skip to content

Commit

Permalink
tests: Update semantic tests for EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Aug 8, 2024
1 parent a902291 commit bbfb85d
Show file tree
Hide file tree
Showing 98 changed files with 12,041 additions and 29 deletions.
2 changes: 1 addition & 1 deletion test/libsolidity/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(metadata_eof_experimental)
CompilerStack compilerStack;
compilerStack.setMetadataFormat(metadataFormat);
compilerStack.setSources({{"", sourceCode}});
compilerStack.setEVMVersion({});
compilerStack.setEVMVersion(langutil::EVMVersion::prague());
compilerStack.setViaIR(true);
compilerStack.setEOFVersion(1);
compilerStack.setOptimiserSettings(true);
Expand Down
5,191 changes: 5,191 additions & 0 deletions test/libsolidity/semanticTests/UniswapV3Flattened.sol

Large diffs are not rendered by default.

5,191 changes: 5,191 additions & 0 deletions test/libsolidity/semanticTests/UniswapV3Flattened_eof.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ contract C {
hash3 = keccak256(abi.encodePacked(this.f));
}
}
// ====
// compileToEOF: false
// ----
// f() -> 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0x0e9229fb1d2cd02cee4b6c9f25497777014a8766e3479666d1c619066d2887ec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract C {
uint120[3] x;
function f() public returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) {
uint120[] memory y = new uint120[](3);
x[0] = y[0] = uint120(type(uint).max - 1);
x[1] = y[1] = uint120(type(uint).max - 2);
x[2] = y[2] = uint120(type(uint).max - 3);
hash1 = keccak256(abi.encodePacked(x));
hash2 = keccak256(abi.encodePacked(y));
hash3 = keccak256(abi.encodePacked(this.f));
}
}
// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// f() -> 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xb8fcf925e706038045e8e57a2620706dfa046b8977add2f3c9b2641f2ea6c8b7
35 changes: 18 additions & 17 deletions test/libsolidity/semanticTests/constructor/callvalue_check.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@ contract B3 {}
contract B4 { constructor() {} }

contract C {
function createWithValue(bytes memory c, uint256 value) public payable returns (bool) {
uint256 y = 0;
assembly { y := create(value, add(c, 0x20), mload(c)) }
return y != 0;
}
function f(uint256 value) public payable returns (bool) {
return createWithValue(type(B1).creationCode, value);
}
function g(uint256 value) public payable returns (bool) {
return createWithValue(type(B2).creationCode, value);
}
function h(uint256 value) public payable returns (bool) {
return createWithValue(type(B3).creationCode, value);
}
function i(uint256 value) public payable returns (bool) {
return createWithValue(type(B4).creationCode, value);
}
function createWithValue(bytes memory c, uint256 value) public payable returns (bool) {
uint256 y = 0;
assembly { y := create(value, add(c, 0x20), mload(c)) }
return y != 0;
}
function f(uint256 value) public payable returns (bool) {
return createWithValue(type(B1).creationCode, value);
}
function g(uint256 value) public payable returns (bool) {
return createWithValue(type(B2).creationCode, value);
}
function h(uint256 value) public payable returns (bool) {
return createWithValue(type(B3).creationCode, value);
}
function i(uint256 value) public payable returns (bool) {
return createWithValue(type(B4).creationCode, value);
}
}
// ====
// EVMVersion: >homestead
// compileToEOF: false
// ----
// f(uint256), 2000 ether: 0 -> true
// f(uint256), 2000 ether: 100 -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ contract C {
return true;
}
}
// ====
// compileToEOF: false
// ----
// f(), 2000 ether -> true
// gas irOptimized: 117623
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
contract A1 {}
contract B1 is A1 { constructor() payable {} }

contract A2 { constructor() {} }
contract B2 is A2 { constructor() payable {} }

contract B3 { constructor() payable {} }

contract C {
function f() public payable returns (bool) {
// Make sure none of these revert.
new B1{value: 10, salt: hex"00"}();
new B2{value: 10, salt: hex"01"}();
new B3{value: 10, salt: hex"02"}();
return true;
}
}
// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// f(), 2000 ether -> true
// gas irOptimized: 117623
// gas irOptimized code: 1800
// gas legacy: 117821
// gas legacy code: 4800
// gas legacyOptimized: 117690
// gas legacyOptimized code: 4800
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ contract C {
return x < data.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ contract C {
return x < data.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ contract C {
return x < data.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ contract C is S {
return x < data.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ contract C {
x < 2 * type(A).creationCode.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ contract C is S {
return x < data.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ contract C is X {
return x < data.length;
}
}
// ====
// compileToEOF: false
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract C {

// ====
// compileViaYul: true
// compileToEOF: false
// ----
// a() -> FAILURE, hex"92bbf6e8"
// b() -> FAILURE, hex"47e26897", hex"0000000000000000000000000000000000000000000000000000000000000001"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pragma abicoder v2;

struct S {
uint256 a;
bool b;
string s;
}

error E();
error E1(uint256);
error E2(string);
error E3(S);
error E4(address);
error E5(function() external pure);

contract C {
function a() external pure {
require(false, E());
}
function b() external pure {
require(false, E1(1));
}
function c() external pure {
require(false, E2("string literal"));
}
function d() external pure {
require(false, E3(S(1, true, "string literal")));
}
function e() external view {
require(false, E4(address(this)));
}
function f() external view {
require(false, E5(this.a));
}
}

// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// a() -> FAILURE, hex"92bbf6e8"
// b() -> FAILURE, hex"47e26897", hex"0000000000000000000000000000000000000000000000000000000000000001"
// c() -> FAILURE, hex"8f372c34", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"000000000000000000000000000000000000000000000000000000000000000e", hex"737472696e67206c69746572616c000000000000000000000000000000000000"
// d() -> FAILURE, hex"5717173e", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"000000000000000000000000000000000000000000000000000000000000000e", hex"737472696e67206c69746572616c000000000000000000000000000000000000"
// e() -> FAILURE, hex"7efef9ea", hex"0000000000000000000000008e3f661b8facaa0fa7aa0113847501029db6517e"
// f() -> FAILURE, hex"0c3f12eb", hex"8e3f661b8facaa0fa7aa0113847501029db6517e0dbe671f0000000000000000"
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ contract C
}
}

// ====
// compileToEOF: false
// ----
// f() -> FAILURE, hex"271b1dfa", hex"c06afe3a8444fc0004668591e8306bfb9968e79ef37cdc8e0000000000000000"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error CustomError(function(uint256) external pure returns (uint256));

contract C
{
function e(uint256 x) external pure returns (uint256)
{
return x;
}

function f() external view
{
// more than one stack slot
require(false, CustomError(this.e));
}
}

// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// f() -> FAILURE, hex"271b1dfa", hex"dfc163ea0fefc2097b7425134f69fcafa3742b0af37cdc8e0000000000000000"
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract C {
d.deposit(_id);
}
}
// ====
// compileToEOF: false
// ----
// constructor() ->
// gas irOptimized: 113970
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
contract D {
event Deposit(address indexed _from, bytes32 indexed _id, uint _value);
function deposit(bytes32 _id) public payable {
emit Deposit(msg.sender, _id, msg.value);
}
}
contract C {
D d;
constructor() {
d = new D();
}
function deposit(bytes32 _id) public payable {
d.deposit(_id);
}
}
// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// constructor() ->
// gas irOptimized: 113970
// gas irOptimized code: 51400
// gas legacy: 119776
// gas legacy code: 125000
// gas legacyOptimized: 114187
// gas legacyOptimized code: 57400
// deposit(bytes32), 18 wei: 0x1234 ->
// ~ emit Deposit(address,bytes32,uint256) from 0x32b73100436177e8f2d2aa1214bb4c1230143ec2: #0x3cb69f8aa1103d7ce41821a1b2e1c85c2b63dfa4, #0x1234, 0x00
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ contract C {
emit Test(this.f);
}
}
// ====
// compileToEOF: false
// ----
// f() ->
// ~ emit Test(function): #0xc06afe3a8444fc0004668591e8306bfb9968e79e26121ff00000000000000000
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ contract C {
emit TestB(this.f2);
}
}
// ====
// compileToEOF: false
// ----
// f1() ->
// ~ emit TestA(function): #0xc06afe3a8444fc0004668591e8306bfb9968e79ec27fc3050000000000000000
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
contract C {
event TestA(function() external indexed);
event TestB(function(uint256) external indexed);
function f1() public {
emit TestA(this.f1);
}
function f2(uint256 a) public {
emit TestB(this.f2);
}
}
// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// f1() ->
// ~ emit TestA(function): #0xa80a5d214a51e09e24fa3e854004da1ac3f5beffc27fc3050000000000000000
// f2(uint256): 1 ->
// ~ emit TestB(function): #0xa80a5d214a51e09e24fa3e854004da1ac3f5beffbf3724af0000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract C {
event Test(function() external indexed);
function f() public {
emit Test(this.f);
}
}
// ====
// compileToEOF: true
// EVMVersion: >=prague
// ----
// f() ->
// ~ emit Test(function): #0x1141c91a4a817b60b5339bc09ac809cedc7649ab26121ff00000000000000000
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ library strings {
// Mask out irrelevant bytes and check again
uint256 mask = type(uint256).max; // 0xffff...
if(shortest < 32) {
mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
}
uint256 diff;
// This depends on potential underflow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ contract DepositContract is IDepositContract, ERC165 {
ret[7] = bytesValue[0];
}
}
// ====
// compileToEOF: false
// ----
// constructor()
// gas irOptimized: 809570
Expand Down
Loading

0 comments on commit bbfb85d

Please sign in to comment.