From 39c23d838d339630556cc8bfeb97d6598ebc12a9 Mon Sep 17 00:00:00 2001 From: rodiazet Date: Thu, 23 Jan 2025 15:16:44 +0100 Subject: [PATCH] eof: Addressing review comments --- libevmasm/Assembly.cpp | 9 ++++++++- .../array/nested_calldata_storage.sol | 4 ++-- .../array/nested_calldata_storage2.sol | 5 ++--- .../syntaxTests/array/nested_calldata_storage.sol | 2 +- .../syntaxTests/array/nested_calldata_storage2.sol | 2 +- ...nctions_with_variable_number_of_stack_slots.sol | 2 -- .../inlineAssembly/string_literal_switch_case.sol | 3 --- .../sizeLimits/eof/bytecode_too_large.sol | 14 ++++++++++++++ ...ith_unspecified_encoding_internal_functions.sol | 2 -- ...hout_call.sol => call_options_without_call.sol} | 3 --- .../eof/gas_with_call_nonpayable.sol | 14 -------------- .../eof/inline_assembly_instructions_allowed.sol | 1 - .../inline_assembly_instructions_allowed_pure.sol | 1 - .../inline_assembly_instructions_allowed_view.sol | 1 - ...nline_assembly_instructions_disallowed_pure.sol | 1 + ...mbly_instructions_disallowed_pure_byzantium.sol | 12 ------------ ...nline_assembly_instructions_disallowed_view.sol | 1 - 17 files changed, 29 insertions(+), 48 deletions(-) create mode 100644 test/libsolidity/syntaxTests/sizeLimits/eof/bytecode_too_large.sol rename test/libsolidity/syntaxTests/viewPureChecker/{eof/gas_value_without_call.sol => call_options_without_call.sol} (83%) delete mode 100644 test/libsolidity/syntaxTests/viewPureChecker/eof/gas_with_call_nonpayable.sol delete mode 100644 test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure_byzantium.sol diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 22bff5415333..5aac9ec86561 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -1660,7 +1660,14 @@ LinkerObject const& Assembly::assembleEOF() const ptrdiff_t const relativeJumpOffset = static_cast(tagPos) - (static_cast(refPos) + 2); // This cannot happen in practice because we'll run into section size limit first. - solAssert(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF, "Relative jump too far"); + if (!(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF)) + // TODO: Include source location. Note that origin locations we have in debug data are + // not usable for error reporting when compiling pure Yul because they point at the optimized source. + throw Error( + 2703_error, + Error::Type::CodeGenerationError, + "Relative jump too far" + ); solAssert(relativeJumpOffset < -2 || 0 <= relativeJumpOffset, "Relative jump offset into immediate argument."); setBigEndianUint16(ret.bytecode, refPos, static_cast(static_cast(relativeJumpOffset))); } diff --git a/test/libsolidity/semanticTests/array/nested_calldata_storage.sol b/test/libsolidity/semanticTests/array/nested_calldata_storage.sol index e7daf471aeb7..7cc9753bec8f 100644 --- a/test/libsolidity/semanticTests/array/nested_calldata_storage.sol +++ b/test/libsolidity/semanticTests/array/nested_calldata_storage.sol @@ -1,8 +1,8 @@ pragma abicoder v2; contract C { - uint[][2] public tmp_i; - function i(uint[][2] calldata s) external { tmp_i = s; } + uint[][2] public tmp_i; + function i(uint[][2] calldata s) external { tmp_i = s; } } // ==== // compileViaYul: true diff --git a/test/libsolidity/semanticTests/array/nested_calldata_storage2.sol b/test/libsolidity/semanticTests/array/nested_calldata_storage2.sol index 4431136a8f97..f8db31b54cc8 100644 --- a/test/libsolidity/semanticTests/array/nested_calldata_storage2.sol +++ b/test/libsolidity/semanticTests/array/nested_calldata_storage2.sol @@ -1,10 +1,9 @@ pragma abicoder v2; contract C { - uint[][] public tmp_i; - function i(uint[][] calldata s) external { tmp_i = s; } + uint[][] public tmp_i; + function i(uint[][] calldata s) external { tmp_i = s; } } - // ==== // compileViaYul: true // ---- diff --git a/test/libsolidity/syntaxTests/array/nested_calldata_storage.sol b/test/libsolidity/syntaxTests/array/nested_calldata_storage.sol index 581aa8482203..e9ef53842c81 100644 --- a/test/libsolidity/syntaxTests/array/nested_calldata_storage.sol +++ b/test/libsolidity/syntaxTests/array/nested_calldata_storage.sol @@ -6,6 +6,6 @@ contract C { } // ==== -// bytecodeFormat: legacy +// compileViaYul: false // ---- // UnimplementedFeatureError 1834: (35-127): Copying nested calldata dynamic arrays to storage is not implemented in the old code generator. diff --git a/test/libsolidity/syntaxTests/array/nested_calldata_storage2.sol b/test/libsolidity/syntaxTests/array/nested_calldata_storage2.sol index 98c2ccac0f1c..5db87f0d4edb 100644 --- a/test/libsolidity/syntaxTests/array/nested_calldata_storage2.sol +++ b/test/libsolidity/syntaxTests/array/nested_calldata_storage2.sol @@ -6,6 +6,6 @@ contract C { } // ==== -// bytecodeFormat: legacy +// compileViaYul: false // ---- // UnimplementedFeatureError 1834: (35-125): Copying nested calldata dynamic arrays to storage is not implemented in the old code generator. diff --git a/test/libsolidity/syntaxTests/functionTypes/external_functions_with_variable_number_of_stack_slots.sol b/test/libsolidity/syntaxTests/functionTypes/external_functions_with_variable_number_of_stack_slots.sol index e995d7889f4a..a6d8d7c1d31c 100644 --- a/test/libsolidity/syntaxTests/functionTypes/external_functions_with_variable_number_of_stack_slots.sol +++ b/test/libsolidity/syntaxTests/functionTypes/external_functions_with_variable_number_of_stack_slots.sol @@ -3,7 +3,5 @@ contract C { this.f{value: 42}.address; } } -// ==== -// bytecodeFormat: legacy // ---- // Warning 6321: (64-68): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.sol b/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.sol index 6b45d24215c8..d612d10d0abb 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.sol @@ -7,6 +7,3 @@ contract C { } } } -// ==== -// bytecodeFormat: legacy -// ---- diff --git a/test/libsolidity/syntaxTests/sizeLimits/eof/bytecode_too_large.sol b/test/libsolidity/syntaxTests/sizeLimits/eof/bytecode_too_large.sol new file mode 100644 index 000000000000..e7c369577ce8 --- /dev/null +++ b/test/libsolidity/syntaxTests/sizeLimits/eof/bytecode_too_large.sol @@ -0,0 +1,14 @@ +// TODO: Change to proper error when all optimizations implemented for EOF +pragma abicoder v2; + +contract test { + function f() public pure returns (string memory ret) { + // 27000 bytes long data + ret = "........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"; + } +} +// ==== +// EVMVersion: >=cancun +// bytecodeFormat: >=EOFv1 +// ---- +// CodeGenerationError 2703: (96-27229): Relative jump too far diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol index e4e13b7ef570..a69dcfa924b8 100644 --- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol +++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol @@ -4,8 +4,6 @@ contract C { h; } } -// ==== -// bytecodeFormat: legacy // ---- // TypeError 2056: (94-103): This type cannot be encoded. // TypeError 2056: (105-106): This type cannot be encoded. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/gas_value_without_call.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_options_without_call.sol similarity index 83% rename from test/libsolidity/syntaxTests/viewPureChecker/eof/gas_value_without_call.sol rename to test/libsolidity/syntaxTests/viewPureChecker/call_options_without_call.sol index 78b563bf157a..f2da35b2d6db 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/gas_value_without_call.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/call_options_without_call.sol @@ -10,6 +10,3 @@ contract C { this.f{value: 42}; } } -// ==== -// bytecodeFormat: >=EOFv1 -// ---- diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/gas_with_call_nonpayable.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/gas_with_call_nonpayable.sol deleted file mode 100644 index c91b19ea1a98..000000000000 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/gas_with_call_nonpayable.sol +++ /dev/null @@ -1,14 +0,0 @@ -contract C { - function f(address a) external view returns (bool success) { - (success,) = a.call(""); - } - function h() external payable {} - function i() external view { - this.h(); - } -} -// ==== -// bytecodeFormat: >=EOFv1 -// ---- -// TypeError 8961: (90-100): Function cannot be declared as view because this expression (potentially) modifies the state. -// TypeError 8961: (171-179): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed.sol index 99c45f6caa01..562079ee3587 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed.sol @@ -76,7 +76,6 @@ contract C { } } // ==== -// EVMVersion: >=paris // bytecodeFormat: >=EOFv1 // ---- // Warning 5740: (89-1400): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_pure.sol index 19b775e8ade2..f3da4722ff7d 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_pure.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_pure.sol @@ -77,7 +77,6 @@ contract C { } } // ==== -// EVMVersion: >=london // bytecodeFormat: >=EOFv1 // ---- // Warning 5740: (94-1425): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_view.sol index dce7062beb50..d1a5be03601e 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_view.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed_view.sol @@ -77,7 +77,6 @@ contract C { } } // ==== -// EVMVersion: >=paris // bytecodeFormat: >=EOFv1 // ---- // Warning 5740: (94-1411): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure.sol index c2095c750f25..e50b0360c256 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure.sol @@ -8,6 +8,7 @@ contract C { pop(caller()) pop(callvalue()) pop(extcall(0, 1, 2, 3)) + pop(extstaticcall(0, 1, 2)) pop(extdelegatecall(0, 1, 2)) log0(0, 1) log1(0, 1, 2) diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure_byzantium.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure_byzantium.sol deleted file mode 100644 index a2250d80dc93..000000000000 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_pure_byzantium.sol +++ /dev/null @@ -1,12 +0,0 @@ -contract C { - function f() public pure { - assembly { - pop(extstaticcall(0, 1, 2)) - } - } -} -// ==== -// EVMVersion: >=byzantium -// bytecodeFormat: >=EOFv1 -// ---- -// TypeError 2527: (79-101): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". diff --git a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_view.sol index cc0bd62c21e8..43bfaed1decc 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_view.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed_view.sol @@ -16,7 +16,6 @@ contract C { } } // ==== -// EVMVersion: >=london // bytecodeFormat: >=EOFv1 // ---- // TypeError 8961: (75-87): Function cannot be declared as view because this expression (potentially) modifies the state.