From eb8af2caec99ffe65276b5f03976cd68800c0786 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 9 Nov 2022 12:12:18 +0100 Subject: [PATCH] Add basic support for the EVM version Paris This mostly means testing with evmone, but instruction renaming of difficulty->prevrandao is omitted. --- .circleci/soltest_all.sh | 2 +- Changelog.md | 1 + docs/using-the-compiler.rst | 5 +++-- liblangutil/EVMVersion.h | 6 ++++-- scripts/tests.sh | 2 +- solc/CommandLineParser.cpp | 2 +- test/EVMHost.cpp | 3 ++- test/libsolidity/StandardCompiler.cpp | 2 ++ .../semanticTests/state/block_difficulty.sol | 1 + .../state/block_difficulty_post_paris.sol | 12 ++++++++++++ test/tools/fuzzer_common.cpp | 4 +++- test/tools/ossfuzz/protoToYul.cpp | 4 ++++ test/tools/ossfuzz/yulProto.proto | 2 ++ 13 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 test/libsolidity/semanticTests/state/block_difficulty_post_paris.sol diff --git a/.circleci/soltest_all.sh b/.circleci/soltest_all.sh index 3e29d1d2e..23663ce46 100755 --- a/.circleci/soltest_all.sh +++ b/.circleci/soltest_all.sh @@ -31,7 +31,7 @@ REPODIR="$(realpath "$(dirname "$0")"/..)" # shellcheck source=scripts/common.sh source "${REPODIR}/scripts/common.sh" -EVM_VALUES=(homestead byzantium constantinople petersburg istanbul berlin london) +EVM_VALUES=(homestead byzantium constantinople petersburg istanbul berlin london paris) DEFAULT_EVM=london [[ " ${EVM_VALUES[*]} " =~ $DEFAULT_EVM ]] OPTIMIZE_VALUES=(0 1) diff --git a/Changelog.md b/Changelog.md index 849a7625b..6296cd3fb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ Language Features: Compiler Features: * Commandline Interface: Return exit code ``2`` on uncaught exceptions. * Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode. + * EVM: Basic support for the EVM version "Paris". * Natspec: Add event Natspec inheritance for devdoc. * Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode. * Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string. diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index b9ecc60ab..89cce88a6 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -172,7 +172,8 @@ at each version. Backward compatibility is not guaranteed between each version. the optimizer. - ``london`` (**default**) - The block's base fee (`EIP-3198 `_ and `EIP-1559 `_) can be accessed via the global ``block.basefee`` or ``basefee()`` in inline assembly. - +- ``paris`` + - No changes. .. index:: ! standard JSON, ! --standard-json .. _compiler-api: @@ -305,7 +306,7 @@ Input Description }, // Version of the EVM to compile for. // Affects type checking and code generation. Can be homestead, - // tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul or berlin + // tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, london or paris "evmVersion": "byzantium", // Optional: Change compilation pipeline to go through the Yul intermediate representation. // This is false by default. diff --git a/liblangutil/EVMVersion.h b/liblangutil/EVMVersion.h index 268df7d9d..d36633845 100644 --- a/liblangutil/EVMVersion.h +++ b/liblangutil/EVMVersion.h @@ -56,10 +56,11 @@ public: static EVMVersion istanbul() { return {Version::Istanbul}; } static EVMVersion berlin() { return {Version::Berlin}; } static EVMVersion london() { return {Version::London}; } + static EVMVersion paris() { return {Version::Paris}; } static std::optional fromString(std::string const& _version) { - for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin(), london()}) + for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin(), london(), paris()}) if (_version == v.name()) return v; return std::nullopt; @@ -81,6 +82,7 @@ public: case Version::Istanbul: return "istanbul"; case Version::Berlin: return "berlin"; case Version::London: return "london"; + case Version::Paris: return "paris"; } return "INVALID"; } @@ -102,7 +104,7 @@ public: bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); } private: - enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople, Petersburg, Istanbul, Berlin, London }; + enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople, Petersburg, Istanbul, Berlin, London, Paris }; EVMVersion(Version _version): m_version(_version) {} diff --git a/scripts/tests.sh b/scripts/tests.sh index 80559f5e2..f8230c54a 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -105,7 +105,7 @@ EVM_VERSIONS="homestead byzantium" if [ -z "$CI" ] then - EVM_VERSIONS+=" constantinople petersburg istanbul berlin london" + EVM_VERSIONS+=" constantinople petersburg istanbul berlin london paris" fi # And then run the Solidity unit-tests in the matrix combination of optimizer / no optimizer diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index a2e4a0d66..2a1ce0228 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -586,7 +586,7 @@ General Information)").c_str(), g_strEVMVersion.c_str(), po::value()->value_name("version")->default_value(EVMVersion{}.name()), "Select desired EVM version. Either homestead, tangerineWhistle, spuriousDragon, " - "byzantium, constantinople, petersburg, istanbul, berlin or london." + "byzantium, constantinople, petersburg, istanbul, berlin, london or paris." ) ( g_strExperimentalViaIR.c_str(), diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index 21c7a58ed..222b4e443 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -122,7 +122,8 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm): m_evmRevision = EVMC_BERLIN; else if (_evmVersion == langutil::EVMVersion::london()) m_evmRevision = EVMC_LONDON; - // TODO: support EVMVersion::paris() + else if (_evmVersion == langutil::EVMVersion::paris()) + m_evmRevision = EVMC_PARIS; else assertThrow(false, Exception, "Unsupported EVM version"); diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 54c12d30c..61b28b11e 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -1082,6 +1082,8 @@ BOOST_AUTO_TEST_CASE(evm_version) BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"berlin\"") != string::npos); result = compile(inputForVersion("\"evmVersion\": \"london\",")); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"london\"") != string::npos); + result = compile(inputForVersion("\"evmVersion\": \"paris\",")); + BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"paris\"") != string::npos); // test default result = compile(inputForVersion("")); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"london\"") != string::npos); diff --git a/test/libsolidity/semanticTests/state/block_difficulty.sol b/test/libsolidity/semanticTests/state/block_difficulty.sol index ae2a5b43a..4f6a6b08f 100644 --- a/test/libsolidity/semanticTests/state/block_difficulty.sol +++ b/test/libsolidity/semanticTests/state/block_difficulty.sol @@ -5,6 +5,7 @@ contract C { } // ==== // compileToEwasm: also +// EVMVersion: 200000000 // f() -> 200000000 diff --git a/test/libsolidity/semanticTests/state/block_difficulty_post_paris.sol b/test/libsolidity/semanticTests/state/block_difficulty_post_paris.sol new file mode 100644 index 000000000..9fb467e6f --- /dev/null +++ b/test/libsolidity/semanticTests/state/block_difficulty_post_paris.sol @@ -0,0 +1,12 @@ +contract C { + function f() public returns (uint) { + return block.difficulty; + } +} +// ==== +// compileToEwasm: also +// EVMVersion: >=paris +// ---- +// f() -> 0xa86c2e601b6c44eb4848f7d23d9df3113fbcac42041c49cbed5000cb4f118777 +// f() -> 0xa86c2e601b6c44eb4848f7d23d9df3113fbcac42041c49cbed5000cb4f118777 +// f() -> 0xa86c2e601b6c44eb4848f7d23d9df3113fbcac42041c49cbed5000cb4f118777 diff --git a/test/tools/fuzzer_common.cpp b/test/tools/fuzzer_common.cpp index 094a84554..25ad6986c 100644 --- a/test/tools/fuzzer_common.cpp +++ b/test/tools/fuzzer_common.cpp @@ -48,7 +48,9 @@ static vector s_evmVersions = { EVMVersion::constantinople(), EVMVersion::petersburg(), EVMVersion::istanbul(), - EVMVersion::berlin() + EVMVersion::berlin(), + EVMVersion::london(), + EVMVersion::paris() }; void FuzzerUtil::testCompilerJsonInterface(string const& _input, bool _optimize, bool _quiet) diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index f6759dddb..cd2898e12 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -112,6 +112,10 @@ EVMVersion ProtoConverter::evmVersionMapping(Program_Version const& _ver) return EVMVersion::istanbul(); case Program::BERLIN: return EVMVersion::berlin(); + case Program::LONDON: + return EVMVersion::london(); + case Program::PARIS: + return EVMVersion::paris(); } } diff --git a/test/tools/ossfuzz/yulProto.proto b/test/tools/ossfuzz/yulProto.proto index 60f0ea1f6..76d85068d 100644 --- a/test/tools/ossfuzz/yulProto.proto +++ b/test/tools/ossfuzz/yulProto.proto @@ -396,6 +396,8 @@ message Program { PETERSBURG = 5; ISTANBUL = 6; BERLIN = 7; + LONDON = 8; + PARIS = 9; } oneof program_oneof { Block block = 1;