Merge pull request #13698 from ethereum/evm-paris

Add basic support for the EVM version Paris
This commit is contained in:
Kamil Śliwak 2022-11-21 19:08:01 +01:00 committed by GitHub
commit 5211d3da0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 45 additions and 10 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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 <https://eips.ethereum.org/EIPS/eip-3198>`_ and `EIP-1559 <https://eips.ethereum.org/EIPS/eip-1559>`_) can be accessed via the global ``block.basefee`` or ``basefee()`` in inline assembly.
- ``paris``
- No changes, however the semantics of the ``difficulty`` value have changed (see `EIP-4399 <https://eips.ethereum.org/EIPS/eip-4399>`_).
.. 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.

View File

@ -933,7 +933,7 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a
+-------------------------+-----+---+-----------------------------------------------------------------+
| number() | | F | current block number |
+-------------------------+-----+---+-----------------------------------------------------------------+
| difficulty() | | F | difficulty of the current block |
| difficulty() | | F | difficulty of the current block (see note below) |
+-------------------------+-----+---+-----------------------------------------------------------------+
| gaslimit() | | F | block gas limit of the current block |
+-------------------------+-----+---+-----------------------------------------------------------------+
@ -948,6 +948,13 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a
You need to use the ``returndatasize`` opcode to check which part of this memory area contains the return data.
The remaining bytes will retain their values as of before the call.
.. note::
With the Paris network upgrade the semantics of ``difficulty`` have been changed.
It returns the value of ``prevrandao``, which is a 256-bit value, whereas the highest recorded
difficulty value within Ethash was ~54 bits.
This change is described in `EIP-4399 <https://eips.ethereum.org/EIPS/eip-4399>`_.
Please note that irrelevant to which EVM version is selected in the compiler, the semantics of
instructions depend on the final chain of deployment.
In some internal dialects, there are additional functions:

View File

@ -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<EVMVersion> 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) {}

View File

@ -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

View File

@ -586,7 +586,7 @@ General Information)").c_str(),
g_strEVMVersion.c_str(),
po::value<string>()->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(),

View File

@ -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");

View File

@ -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);

View File

@ -5,6 +5,7 @@ contract C {
}
// ====
// compileToEwasm: also
// EVMVersion: <paris
// ----
// f() -> 200000000
// f() -> 200000000

View File

@ -0,0 +1,12 @@
contract C {
function f() public returns (uint) {
return block.difficulty;
}
}
// ====
// compileToEwasm: also
// EVMVersion: >=paris
// ----
// f() -> 0xa86c2e601b6c44eb4848f7d23d9df3113fbcac42041c49cbed5000cb4f118777
// f() -> 0xa86c2e601b6c44eb4848f7d23d9df3113fbcac42041c49cbed5000cb4f118777
// f() -> 0xa86c2e601b6c44eb4848f7d23d9df3113fbcac42041c49cbed5000cb4f118777

View File

@ -48,7 +48,9 @@ static vector<EVMVersion> 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)

View File

@ -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();
}
}

View File

@ -396,6 +396,8 @@ message Program {
PETERSBURG = 5;
ISTANBUL = 6;
BERLIN = 7;
LONDON = 8;
PARIS = 9;
}
oneof program_oneof {
Block block = 1;