From 7a34d34045ffd972c25a27a07b322135d97cc7b5 Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Wed, 17 May 2023 16:21:37 +0200 Subject: [PATCH] Restrict experimental solidity to constantinople and above --- libsolidity/parsing/Parser.cpp | 2 ++ scripts/test_antlr_grammar.sh | 2 +- .../libsolidity/ASTJSON/pragma_experimental_solidity.json | 2 +- test/libsolidity/ASTJSON/pragma_experimental_solidity.sol | 3 ++- .../ASTJSON/pragma_experimental_solidity_parseOnly.json | 2 +- .../syntaxTests/pragma/experimental_solidity.sol | 2 ++ .../experimental_solidity_multisource_not_all_enable.sol | 2 ++ .../pragma/experimental_solidity_out_of_order_1.sol | 2 ++ .../pragma/experimental_solidity_out_of_order_2.sol | 2 ++ .../pragma/experimental_solidity_wrong_evm_version.sol | 8 ++++++++ 10 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/libsolidity/syntaxTests/pragma/experimental_solidity_wrong_evm_version.sol diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 39b2df131..34fc9644e 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -248,6 +248,8 @@ ASTPointer Parser::parsePragmaDirective(bool const _finishedPar if (literals.size() >= 2 && literals[0] == "experimental" && literals[1] == "solidity") { + if (m_evmVersion < EVMVersion::constantinople()) + fatalParserError(7637_error, "Experimental solidity requires Constantinople EVM version at the minimum."); if (_finishedParsingTopLevelPragmas) fatalParserError(8185_error, "Experimental pragma \"solidity\" can only be set at the beginning of the source unit."); m_experimentalSolidityEnabledInCurrentSourceUnit = true; diff --git a/scripts/test_antlr_grammar.sh b/scripts/test_antlr_grammar.sh index 6ab28fc5f..e84f9b064 100755 --- a/scripts/test_antlr_grammar.sh +++ b/scripts/test_antlr_grammar.sh @@ -110,7 +110,7 @@ do SOL_FILES+=("$line") done < <( grep --include "*.sol" -riL -E \ - "^\/\/ (Syntax|Type|Declaration)Error|^\/\/ ParserError (1684|2837|3716|3997|5333|6275|6281|6933|7319|8185)|^==== Source:" \ + "^\/\/ (Syntax|Type|Declaration)Error|^\/\/ ParserError (1684|2837|3716|3997|5333|6275|6281|6933|7319|8185|7637)|^==== Source:" \ "${ROOT_DIR}/test/libsolidity/syntaxTests" \ "${ROOT_DIR}/test/libsolidity/semanticTests" | # Skipping the unicode tests as I couldn't adapt the lexical grammar to recursively counting RLO/LRO/PDF's. diff --git a/test/libsolidity/ASTJSON/pragma_experimental_solidity.json b/test/libsolidity/ASTJSON/pragma_experimental_solidity.json index d2f7e56ad..66ece94e0 100644 --- a/test/libsolidity/ASTJSON/pragma_experimental_solidity.json +++ b/test/libsolidity/ASTJSON/pragma_experimental_solidity.json @@ -17,5 +17,5 @@ "src": "0:29:1" } ], - "src": "0:30:1" + "src": "0:70:1" } diff --git a/test/libsolidity/ASTJSON/pragma_experimental_solidity.sol b/test/libsolidity/ASTJSON/pragma_experimental_solidity.sol index e0c1c81aa..b902bb061 100644 --- a/test/libsolidity/ASTJSON/pragma_experimental_solidity.sol +++ b/test/libsolidity/ASTJSON/pragma_experimental_solidity.sol @@ -1,3 +1,4 @@ pragma experimental solidity; - +// ==== +// EVMVersion: >=constantinople // ---- diff --git a/test/libsolidity/ASTJSON/pragma_experimental_solidity_parseOnly.json b/test/libsolidity/ASTJSON/pragma_experimental_solidity_parseOnly.json index a1a3410ff..b1ac937a2 100644 --- a/test/libsolidity/ASTJSON/pragma_experimental_solidity_parseOnly.json +++ b/test/libsolidity/ASTJSON/pragma_experimental_solidity_parseOnly.json @@ -16,5 +16,5 @@ "src": "0:29:1" } ], - "src": "0:30:1" + "src": "0:70:1" } diff --git a/test/libsolidity/syntaxTests/pragma/experimental_solidity.sol b/test/libsolidity/syntaxTests/pragma/experimental_solidity.sol index 9bb74a7ec..b6f871d87 100644 --- a/test/libsolidity/syntaxTests/pragma/experimental_solidity.sol +++ b/test/libsolidity/syntaxTests/pragma/experimental_solidity.sol @@ -1,3 +1,5 @@ pragma experimental solidity; +// ==== +// EVMVersion: >=constantinople // ---- // Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments. diff --git a/test/libsolidity/syntaxTests/pragma/experimental_solidity_multisource_not_all_enable.sol b/test/libsolidity/syntaxTests/pragma/experimental_solidity_multisource_not_all_enable.sol index 747b8e166..fe4125e84 100644 --- a/test/libsolidity/syntaxTests/pragma/experimental_solidity_multisource_not_all_enable.sol +++ b/test/libsolidity/syntaxTests/pragma/experimental_solidity_multisource_not_all_enable.sol @@ -18,6 +18,8 @@ import "A.sol"; contract D { A a; } +// ==== +// EVMVersion: >=constantinople // ---- // ParserError 2141: (B.sol:0-29): File declares "pragma experimental solidity". If you want to enable the experimental mode, all source units must include the pragma. // ParserError 2141: (C.sol:0-29): File declares "pragma experimental solidity". If you want to enable the experimental mode, all source units must include the pragma. diff --git a/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_1.sol b/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_1.sol index 5fde260f6..d6741b0d3 100644 --- a/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_1.sol +++ b/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_1.sol @@ -1,5 +1,7 @@ contract A {} pragma experimental solidity; +// ==== +// EVMVersion: >=constantinople // ---- // ParserError 8185: (45-45): Experimental pragma "solidity" can only be set at the beginning of the source unit. diff --git a/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_2.sol b/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_2.sol index 3748a5c76..940bd3fbb 100644 --- a/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_2.sol +++ b/test/libsolidity/syntaxTests/pragma/experimental_solidity_out_of_order_2.sol @@ -9,5 +9,7 @@ struct A { uint256 x; } +// ==== +// EVMVersion: >=constantinople // ---- // ParserError 8185: (83-89): Experimental pragma "solidity" can only be set at the beginning of the source unit. diff --git a/test/libsolidity/syntaxTests/pragma/experimental_solidity_wrong_evm_version.sol b/test/libsolidity/syntaxTests/pragma/experimental_solidity_wrong_evm_version.sol new file mode 100644 index 000000000..3e070535b --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/experimental_solidity_wrong_evm_version.sol @@ -0,0 +1,8 @@ +pragma experimental solidity; + +contract C {} + +// ==== +// EVMVersion: