Skip to content
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

eof: Semantic tests update #15665

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, bool hash3NonZero) {
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));
hash3NonZero = bytes32(0) != keccak256(abi.encodePacked(this.f));
}
}
// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
Comment on lines +14 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EVMVersion: >=prague is redundant when the test is already restricted to EOF. You have that in multiple tests.

// ----
// f() -> 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, true
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ contract C {
hash3 = keccak256(abi.encodePacked(this.f));
}
}
// ====
// bytecodeFormat: legacy
// ----
// f() -> 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0x0e9229fb1d2cd02cee4b6c9f25497777014a8766e3479666d1c619066d2887ec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is currently hard to recreate on EOF because we're planning to disallow eofcreate() (and without assembly this will be just a compilation error), but we should have it eventually. Please add a TODO.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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
@@ -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;
}
}
// ====
// bytecodeFormat: >=EOFv1
// 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
Comment on lines +23 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove gas expectations when you're creating EOF versions of tests. We're not calculating them for EOF and I think they're not even checked for correctness here (because legacy is skipped) so they're misleading.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ contract C {
return true;
}
}
// ====
// bytecodeFormat: legacy
// ----
// f(), 2000 ether -> true
// gas irOptimized: 117623
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// 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;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests from semanticTests/deployedCodeExclusion/ should have a TODO to eventually be recreated on EOF. They're testing subassembly deduplication, which is still relevant, just not implemented yet. Also, we likely won't be able to test it like this because we lose access to code introspection, but it could be checked by looking at produced bytecode in a commandline test. Or even better, by using the new artifact introduced by #15710 to directly check which assemblies were included.

Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ contract C {
x < 2 * type(A).creationCode.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// 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;
}
}
// ====
// bytecodeFormat: legacy
// ----
// 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;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
interface Parent {
function parentFun() external returns (uint256);
}

interface SubA is Parent {
function subAFun() external returns (uint256);
}

interface SubB is Parent {
function subBFun() external returns (uint256);
}

contract Impl is SubA, SubB {
function parentFun() override external returns (uint256) { return 1; }
function subAFun() override external returns (uint256) { return 2; }
function subBFun() override external returns (uint256) { return 3; }
}

contract C {
function convertParent() public returns (uint256) {
Parent p = new Impl();
return p.parentFun();
}

function convertSubA() public returns (uint256, uint256) {
bytes32 s = 0x0000000000000000000000000000000000000000000000000000000000000001;
SubA sa = new Impl{salt: s}();
return (sa.parentFun(), sa.subAFun());
}

function convertSubB() public returns (uint256, uint256) {
bytes32 s = 0x0000000000000000000000000000000000000000000000000000000000000002;
SubB sb = new Impl{salt: s}();
return (sb.parentFun(), sb.subBFun());
}
}
// ====
// bytecodeFormat: legacy
// ----
// convertParent() -> 1
// gas irOptimized: 85524
// convertSubA() -> 1, 2
// gas irOptimized: 86155
// gas legacy: 99047
// convertSubB() -> 1, 3
// gas irOptimized: 86098
// gas legacy: 98981
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(0x6AfCA7D4Df015A0Ba25dA0d02D175603a5fB40E6)));
}
function f(function() external pure x) external view {
require(false, E5(x));
}
}

// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// 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"0000000000000000000000006afca7d4df015a0ba25da0d02d175603a5fb40e6"
// f(function): left(0x6afca7d4df015a0ba25da0d02d175603a5fb40e60dbe671f0000000000000000) -> FAILURE, hex"0c3f12eb", hex"6afca7d4df015a0ba25da0d02d175603a5fb40e60dbe671f0000000000000000"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error CustomError(function(uint256) external pure returns (uint256));

contract C
{
function f(function(uint256) external pure returns (uint256) x) external view
{
// more than one stack slot
require(false, CustomError(x));
}
}

// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// f(function): left(0xa4dc3b5fce39438ce512c732ccb22e3212856bb6f37cdc8e0000000000000000) -> FAILURE, hex"271b1dfa", hex"a4dc3b5fce39438ce512c732ccb22e3212856bb6f37cdc8e0000000000000000"
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract C {

// ====
// compileViaYul: true
// bytecodeFormat: legacy
// ----
// a() -> FAILURE, hex"92bbf6e8"
// b() -> FAILURE, hex"47e26897", hex"0000000000000000000000000000000000000000000000000000000000000001"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ contract C
}
}

// ====
// bytecodeFormat: legacy
// ----
// f() -> FAILURE, hex"271b1dfa", hex"c06afe3a8444fc0004668591e8306bfb9968e79ef37cdc8e0000000000000000"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract C {
event Test(function() external indexed);
function f(function() external x) public {
emit Test(x);
}
}
// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// f(function): left(0x8f8cc95dcbe7358c1cf1409d3a7ad079e89576bb26121ff00000000000000000) ->
// ~ emit Test(function): #0x8f8cc95dcbe7358c1cf1409d3a7ad079e89576bb26121ff00000000000000000
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(function() external x) public {
emit TestA(x);
}
function f2(function(uint256) external x) public {
emit TestB(x);
}
}
// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// f1(function): left(0x347eaa94e3f63220b1f27af5888d33325ddbd4dec27fc3050000000000000000) ->
// ~ emit TestA(function): #0x347eaa94e3f63220b1f27af5888d33325ddbd4dec27fc3050000000000000000
// f2(function): left(0x347eaa94e3f63220b1f27af5888d33325ddbd4debf3724af0000000000000000) ->
// ~ emit TestB(function): #0x347eaa94e3f63220b1f27af5888d33325ddbd4debf3724af0000000000000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should have an EOF version.

Copy link
Member

@cameel cameel Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for:

  • functionCall/calling_nonexisting_contract_throws.sol
  • functionCall/external_call_at_construction_time.sol
  • functionCall/external_call_to_nonexisting.sol

Empty contracts do not revert on EOF, but that needs to be tested too. Does not need to be an exactly copy of these tests, could also be a new one that combines all the relevant points from those.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also:

  • salted_create/prediction_example.sol: calculation on EOF is different, but should still be covered.
  • various/create_calldata.sol: on EOF the calldata accessible via msg.data does contain constructor arguments and this should be tested.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract C {
d.deposit(_id);
}
}
// ====
// bytecodeFormat: legacy
// ----
// constructor() ->
// gas irOptimized: 113970
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ contract C {
emit Test(this.f);
}
}
// ====
// bytecodeFormat: legacy
// ----
// 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);
}
}
// ====
// bytecodeFormat: legacy
// ----
// f1() ->
// ~ emit TestA(function): #0xc06afe3a8444fc0004668591e8306bfb9968e79ec27fc3050000000000000000
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 @@ -174,6 +174,8 @@ contract DepositContract is IDepositContract, ERC165 {
ret[7] = bytesValue[0];
}
}
// ====
// bytecodeFormat: legacy
// ----
// constructor()
// gas irOptimized: 809570
Expand Down
Loading
Loading