Skip to content

Commit

Permalink
eof: Update semanticTests tests for EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Jan 31, 2025
1 parent 21fdda6 commit 152f4af
Show file tree
Hide file tree
Showing 51 changed files with 309 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contract B4 { constructor() {} }
contract C {
function createWithValue(bytes memory c, uint256 value) public payable returns (bool) {
uint256 y = 0;
// TODO: This test is hard to recreate for EOF as for now eofcreate is disallowed in inline assembly.
assembly { y := create(value, add(c, 0x20), mload(c)) }
return y != 0;
}
Expand All @@ -29,6 +30,7 @@ contract C {
}
// ====
// EVMVersion: >homestead
// bytecodeFormat: legacy
// ----
// f(uint256), 2000 ether: 0 -> true
// f(uint256), 2000 ether: 100 -> false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
function longdata(S memory) pure returns (bytes memory) {
return
"xasopca.pngaibngidak.jbtnudak.cAP.BRRSMCPJAGPD KIAJDOMHUKR,SCPID"
Expand Down Expand Up @@ -36,5 +37,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
library L {
function longdata() pure internal returns (bytes memory) {
return
Expand Down Expand Up @@ -30,5 +31,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
==== Source: mod.sol ====
function longdata() pure returns (bytes memory) {
return
Expand Down Expand Up @@ -32,5 +33,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
abstract contract S {
function longdata() internal pure returns (bytes memory) {
return
Expand Down Expand Up @@ -31,5 +32,7 @@ contract C is S {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
contract A {
function longdata() pure external returns (bytes memory) {
return
Expand Down Expand Up @@ -37,5 +38,7 @@ contract C {
x < 2 * type(A).creationCode.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
abstract contract S {
function longdata() internal pure returns (bytes memory) {
return
Expand Down Expand Up @@ -31,5 +32,7 @@ contract C is S {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
abstract contract S {
function longdata() internal virtual pure returns (bytes memory);
}
Expand Down Expand Up @@ -35,5 +36,7 @@ contract C is X {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: Implement this test for EOF. Now it's not possible because deployed contract address depends on contract bytecode.
// This means that the address changes when optimisations are applied.
contract D {
event Deposit(address indexed _from, bytes32 indexed _id, uint _value);
function deposit(bytes32 _id) public payable {
Expand All @@ -13,6 +15,8 @@ contract C {
d.deposit(_id);
}
}
// ====
// bytecodeFormat: legacy
// ----
// constructor() ->
// gas irOptimized: 113970
Expand Down
1 change: 1 addition & 0 deletions test/libsolidity/semanticTests/experimental/stub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ contract C {
// EVMVersion: >=constantinople
// ====
// compileViaYul: true
// bytecodeFormat: legacy
// ----
// (): 0 -> 0
// (): 1 -> 544
1 change: 1 addition & 0 deletions test/libsolidity/semanticTests/experimental/type_class.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ contract C {
// ====
// EVMVersion: >=constantinople
// compileViaYul: true
// bytecodeFormat: legacy
// ----
// () -> 1, 0
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ contract D {
return test();
}
}
// ====
// bytecodeFormat: legacy
// ----
// f() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ contract C {
function bal() external returns (uint) { return address(this).balance; }
receive() external payable {}
}
// ====
// bytecodeFormat: legacy
// ----
// (), 1 ether
// call() -> 1, 2, 2, 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ contract C {
return 7;
}
}
// ====
// bytecodeFormat: legacy
// ----
// f() -> FAILURE
// g() -> FAILURE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
contract C {
function f(uint x) external payable returns (uint) { return 1; }
function f(uint x, uint y) external payable returns (uint) { return 2; }
function call() public payable returns (uint x, uint y) {
x = this.f{value: 10}(2);
y = this.f{value: 10}(2, 3);
}
function bal() external returns (uint) { return address(this).balance; }
receive() external payable {}
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// (), 1 ether
// call() -> 1, 2
// bal() -> 1000000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
abstract contract D {
function g() public virtual;
}


contract C {
D d = D(address(0x1212));

function f() public returns (uint256) {
// This call throws on legacy bytecode because of calling nonexisting contract. Legacy checks that there is
// a non-empty code under under an address. EOF doesn't do it because non-observability assumption
d.g();
return 7;
}

function h() public returns (uint256) {
address(d).call(""); // this does not throw (low-level)
return 7;
}
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// f() -> 7
// h() -> 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This tests skipping the extcodesize check.

contract T {
constructor() { this.f(); }
function f() external {}
}
contract U {
constructor() { this.f(); }
function f() external returns (uint) {}
}

contract C {
function f(uint c) external returns (uint) {
if (c == 0) new T();
else if (c == 1) new U();
return 1 + c;
}
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// f(uint256): 0 -> 1
// f(uint256): 1 -> FAILURE
// f(uint256): 2 -> 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This tests skipping the extcodesize check.

interface I {
function a() external pure;
function b() external;
function c() external payable;
function x() external returns (uint);
function y() external returns (string memory);
}
contract C {
I i = I(address(0xcafecafe));
constructor() payable {}
function f(uint c) external returns (uint) {
if (c == 0) i.a();
else if (c == 1) i.b();
else if (c == 2) i.c();
else if (c == 3) i.c{value: 1}();
else if (c == 4) i.x();
else if (c == 5) i.y();
return 1 + c;
}
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// constructor(), 1 ether ->
// gas irOptimized: 88853
// gas irOptimized code: 164400
// gas legacy: 102721
// gas legacy code: 334400
// gas legacyOptimized: 91499
// gas legacyOptimized code: 196400
// f(uint256): 0 -> 1
// f(uint256): 1 -> 2
// f(uint256): 2 -> 3
// f(uint256): 3 -> 4
// f(uint256): 4 -> FAILURE
// f(uint256): 5 -> FAILURE
// f(uint256): 6 -> 7
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract C {
}
// ====
// EVMVersion: >=byzantium
// bytecodeFormat: legacy
// ----
// f(uint256): 0 -> FAILURE
// f(uint256): 1 -> FAILURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ contract C {
return 1 + c;
}
}
// ====
// bytecodeFormat: legacy
// ----
// constructor(), 1 ether ->
// gas irOptimized: 88853
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract C {
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// bytecodeFormat: legacy
// ----
// constructor(), 1 ether ->
// gas irOptimized: 98698
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ contract test {
myBal = address(this).balance;
}
}
// ====
// bytecodeFormat: legacy
// ----
// constructor(), 20 wei ->
// gas irOptimized: 120218
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ contract C {
return true;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test_function() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ contract D {
}
// ====
// EVMVersion: >=cancun
// bytecodeFormat: legacy
// ----
// constructor() ->
// gas irOptimized: 127596
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ contract C {
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// bytecodeFormat: legacy
// ----
// g() -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code"
19 changes: 19 additions & 0 deletions test/libsolidity/semanticTests/reverts/eof/revert_return_area.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
contract C {
fallback() external {
revert("abc");
}

function f() public returns (uint s, uint r) {
address x = address(this);
assembly {
mstore(0, 7)
s := extcall(x, 0, 0, 0)
returndatacopy(0, 0, 32)
r := mload(0)
}
}
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// f() -> 0x01, 0x08c379a000000000000000000000000000000000000000000000000000000000
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ contract C {
}
// ====
// EVMVersion: >=byzantium
// bytecodeFormat: legacy
// ----
// f() -> 0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
contract B
{
uint x;
function getBalance() public view returns (uint) {
return address(this).balance * 1000 + x;
}
constructor(uint _x) payable {
x = _x;
}
}

contract A {
function f() public payable returns (uint, uint, uint) {
B x = new B{salt: "abc1", value: 3}(7);
B y = new B{value: 3, salt: "abc2"}(8);
B z = new B{salt: "abc3", value: 3}(9);
return (x.getBalance(), y.getBalance(), z.getBalance());
}
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// f(), 10 ether -> 3007, 3008, 3009
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract C {
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// bytecodeFormat: legacy
// ----
// createDSalted(bytes32,uint256): 42, 64 ->
// gas legacy: 78573
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract A {
}
// ====
// EVMVersion: >=constantinople
// bytecodeFormat: legacy
// ----
// f(), 10 ether -> 3007, 3008, 3009
// gas irOptimized: 187022
Expand Down
Loading

0 comments on commit 152f4af

Please sign in to comment.