Skip to content

Commit 777385f

Browse files
authored
Merge pull request #13028 from ethereum/disallow-returndatasize-returndatacopy
Disallow RETURNDATASIZE and RETURNDATACOPY in inline assembly blocks in pure functions
2 parents 00fb31c + 7f4f655 commit 777385f

10 files changed

+44
-34
lines changed

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Breaking changes:
88
* Commandline Interface: Remapping targets are not automatically added to allowed paths.
99
* Commandline Interface: Assembler mode no longer enables all outputs by default.
1010
* General: The identifier ``basefee`` is a reserved identifier in Yul for all EVM versions.
11+
* View Pure Checker: Mark ``returndatasize`` and ``returndatacopy`` as view to disallow them in inline assembly blocks in pure functions.
1112

1213

1314
### 0.8.15 (unreleased)

libevmasm/SemanticInformation.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction)
481481
case Instruction::EXTCODESIZE:
482482
case Instruction::EXTCODECOPY:
483483
case Instruction::EXTCODEHASH:
484+
case Instruction::RETURNDATASIZE:
485+
case Instruction::RETURNDATACOPY:
484486
case Instruction::BLOCKHASH:
485487
case Instruction::COINBASE:
486488
case Instruction::TIMESTAMP:

test/externalTests/ens.sh

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ function ens_test
7575
# In some cases Hardhat does not detect revert reasons properly via IR.
7676
# TODO: Remove this when https://github.com/NomicFoundation/hardhat/issues/2115 gets fixed.
7777
sed -i "s|it\(('Does not allow wrapping a name you do not own',\)|it.skip\1|g" test/wrapper/NameWrapper.js
78+
# Related to disallow returndatasize and returndatacopy in inline assembly blocks in pure functions https://github.com/ethereum/solidity/pull/13028
79+
# TODO: Remove this after release 0.9 and ENS updated to support it.
80+
sed -i 's/pure/view/' contracts/utils/LowLevelCallUtils.sol
7881

7982
find . -name "*.sol" -exec sed -i -e 's/^\(\s*\)\(assembly\)/\1\/\/\/ @solidity memory-safe-assembly\n\1\2/' '{}' \;
8083

test/libsolidity/syntaxTests/inlineAssembly/evm_byzantium.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
contract C {
2-
function f() pure external {
2+
function f() view external {
33
assembly {
44
let s := returndatasize()
55
returndatacopy(0, 0, s)

test/libsolidity/syntaxTests/inlineAssembly/evm_byzantium_on_homestead.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
contract C {
2-
function f() pure external {
2+
function f() view external {
33
assembly {
44
let s := returndatasize()
55
returndatacopy(0, 0, s)

test/libsolidity/syntaxTests/inlineAssembly/returndatasize_as_variable_call_post_byzantium.sol.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
contract C {
2-
function f() public pure {
2+
function f() public view {
33
uint returndatasize;
44
returndatasize;
55
assembly {

test/libsolidity/syntaxTests/inlineAssembly/returndatasize_as_variable_post_byzantium.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
contract C {
2-
function f() public pure {
2+
function f() public view {
33
uint returndatasize;
44
returndatasize;
55
assembly {

test/libsolidity/syntaxTests/inlineAssembly/returndatasize_as_variable_pre_byzantium.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
contract C { function f() public pure { uint returndatasize; returndatasize; assembly { pop(returndatasize()) }}}
1+
contract C { function f() public view { uint returndatasize; returndatasize; assembly { pop(returndatasize()) }}}
22
// ====
33
// EVMVersion: =homestead
44
// ----

test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed_pure.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ contract C {
4747
//codecopy(0, 1, 2)
4848
//pop(extcodesize(0))
4949
//extcodecopy(0, 1, 2, 3)
50-
pop(returndatasize())
51-
returndatacopy(0, 1, 2)
50+
//pop(returndatasize())
51+
//returndatacopy(0, 1, 2)
5252
//pop(extcodehash(0))
5353
//pop(create(0, 1, 2))
5454
//pop(create2(0, 1, 2, 3))
@@ -85,6 +85,6 @@ contract C {
8585
// ====
8686
// EVMVersion: >=london
8787
// ----
88-
// Warning 5740: (94-1759): Unreachable code.
89-
// Warning 5740: (1772-1784): Unreachable code.
90-
// Warning 5740: (1827-1836): Unreachable code.
88+
// Warning 5740: (94-1763): Unreachable code.
89+
// Warning 5740: (1776-1788): Unreachable code.
90+
// Warning 5740: (1831-1840): Unreachable code.

test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure.sol

+28-24
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ contract C {
1111
pop(callvalue())
1212
pop(extcodesize(0))
1313
extcodecopy(0, 1, 2, 3)
14+
pop(returndatasize())
15+
returndatacopy(0, 1, 2)
1416
pop(extcodehash(0))
1517
pop(create(0, 1, 2))
1618
pop(create2(0, 1, 2, 3))
@@ -44,7 +46,7 @@ contract C {
4446
// ====
4547
// EVMVersion: >=london
4648
// ----
47-
// Warning 5740: (672-1083): Unreachable code.
49+
// Warning 5740: (742-1153): Unreachable code.
4850
// TypeError 2527: (79-87): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
4951
// TypeError 8961: (101-113): Function cannot be declared as pure because this expression (potentially) modifies the state.
5052
// TypeError 2527: (130-135): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
@@ -55,26 +57,28 @@ contract C {
5557
// TypeError 2527: (265-276): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
5658
// TypeError 2527: (294-308): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
5759
// TypeError 2527: (322-345): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
58-
// TypeError 2527: (362-376): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
59-
// TypeError 8961: (394-409): Function cannot be declared as pure because this expression (potentially) modifies the state.
60-
// TypeError 8961: (427-446): Function cannot be declared as pure because this expression (potentially) modifies the state.
61-
// TypeError 8961: (464-489): Function cannot be declared as pure because this expression (potentially) modifies the state.
62-
// TypeError 8961: (507-536): Function cannot be declared as pure because this expression (potentially) modifies the state.
63-
// TypeError 8961: (554-584): Function cannot be declared as pure because this expression (potentially) modifies the state.
64-
// TypeError 2527: (602-630): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
65-
// TypeError 8961: (644-659): Function cannot be declared as pure because this expression (potentially) modifies the state.
66-
// TypeError 8961: (672-682): Function cannot be declared as pure because this expression (potentially) modifies the state.
67-
// TypeError 8961: (695-708): Function cannot be declared as pure because this expression (potentially) modifies the state.
68-
// TypeError 8961: (721-737): Function cannot be declared as pure because this expression (potentially) modifies the state.
69-
// TypeError 8961: (750-769): Function cannot be declared as pure because this expression (potentially) modifies the state.
70-
// TypeError 8961: (782-804): Function cannot be declared as pure because this expression (potentially) modifies the state.
71-
// TypeError 2527: (821-830): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
72-
// TypeError 2527: (848-857): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
73-
// TypeError 2527: (875-883): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
74-
// TypeError 2527: (901-911): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
75-
// TypeError 2527: (929-941): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
76-
// TypeError 2527: (959-969): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
77-
// TypeError 2527: (987-998): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
78-
// TypeError 2527: (1016-1024): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
79-
// TypeError 2527: (1042-1054): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
80-
// TypeError 2527: (1072-1082): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
60+
// TypeError 2527: (362-378): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
61+
// TypeError 2527: (392-415): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
62+
// TypeError 2527: (432-446): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
63+
// TypeError 8961: (464-479): Function cannot be declared as pure because this expression (potentially) modifies the state.
64+
// TypeError 8961: (497-516): Function cannot be declared as pure because this expression (potentially) modifies the state.
65+
// TypeError 8961: (534-559): Function cannot be declared as pure because this expression (potentially) modifies the state.
66+
// TypeError 8961: (577-606): Function cannot be declared as pure because this expression (potentially) modifies the state.
67+
// TypeError 8961: (624-654): Function cannot be declared as pure because this expression (potentially) modifies the state.
68+
// TypeError 2527: (672-700): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
69+
// TypeError 8961: (714-729): Function cannot be declared as pure because this expression (potentially) modifies the state.
70+
// TypeError 8961: (742-752): Function cannot be declared as pure because this expression (potentially) modifies the state.
71+
// TypeError 8961: (765-778): Function cannot be declared as pure because this expression (potentially) modifies the state.
72+
// TypeError 8961: (791-807): Function cannot be declared as pure because this expression (potentially) modifies the state.
73+
// TypeError 8961: (820-839): Function cannot be declared as pure because this expression (potentially) modifies the state.
74+
// TypeError 8961: (852-874): Function cannot be declared as pure because this expression (potentially) modifies the state.
75+
// TypeError 2527: (891-900): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
76+
// TypeError 2527: (918-927): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
77+
// TypeError 2527: (945-953): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
78+
// TypeError 2527: (971-981): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
79+
// TypeError 2527: (999-1011): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
80+
// TypeError 2527: (1029-1039): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
81+
// TypeError 2527: (1057-1068): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
82+
// TypeError 2527: (1086-1094): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
83+
// TypeError 2527: (1112-1124): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
84+
// TypeError 2527: (1142-1152): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".

0 commit comments

Comments
 (0)