Skip to content

Commit

Permalink
Support petersburg in evmVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 28, 2019
1 parent ab33ff1 commit 735a319
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Language Features:


Compiler Features:
* Support ``petersburg`` as ``evmVersion``.
* Inline Assembly: Consider ``extcodehash`` as part of Constantinople.
* SMTChecker: Do not report underflow/overflow if they always revert. This removes false positives when using ``SafeMath``.
* Static Analyzer: Warn about expressions with custom types when they have no effect.
Expand Down
3 changes: 2 additions & 1 deletion docs/using-the-compiler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ at each version. Backward compatibility is not guaranteed between each version.
- ``constantinople`` (still in progress)
- opcodes ``shl``, ``shr`` and ``sar`` are available in assembly.
- shifting operators use shifting opcodes and thus need less gas.
- ``petersburg`` (still in progress)

.. _compiler-api:

Expand Down Expand Up @@ -193,7 +194,7 @@ Input Description
// Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage.
"runs": 200
},
"evmVersion": "byzantium", // Version of the EVM to compile for. Affects type checking and code generation. Can be homestead, tangerineWhistle, spuriousDragon, byzantium or constantinople
"evmVersion": "byzantium", // Version of the EVM to compile for. Affects type checking and code generation. Can be homestead, tangerineWhistle, spuriousDragon, byzantium, constantinople or petersburg
// Metadata settings (optional)
"metadata": {
// Use only literal content and not URLs (false by default)
Expand Down
8 changes: 5 additions & 3 deletions liblangutil/EVMVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace langutil

/**
* A version specifier of the EVM we want to compile to.
* Defaults to the latest version.
* Defaults to the latest version deployed on Ethereum mainnet.
*/
class EVMVersion:
boost::less_than_comparable<EVMVersion>,
Expand All @@ -44,10 +44,11 @@ class EVMVersion:
static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; }
static EVMVersion byzantium() { return {Version::Byzantium}; }
static EVMVersion constantinople() { return {Version::Constantinople}; }
static EVMVersion petersburg() { return {Version::Petersburg}; }

static boost::optional<EVMVersion> fromString(std::string const& _version)
{
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople()})
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg()})
if (_version == v.name())
return v;
return {};
Expand All @@ -65,6 +66,7 @@ class EVMVersion:
case Version::SpuriousDragon: return "spuriousDragon";
case Version::Byzantium: return "byzantium";
case Version::Constantinople: return "constantinople";
case Version::Petersburg: return "petersburg";
}
return "INVALID";
}
Expand All @@ -81,7 +83,7 @@ class EVMVersion:
bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); }

private:
enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople };
enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople, Petersburg };

EVMVersion(Version _version): m_version(_version) {}

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/analysis/ReferencesResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
analysisInfo,
errorsIgnored,
errorTypeForLoose,
yul::EVMDialect::looseAssemblyForEVM(EVMVersion::constantinople()),
yul::EVMDialect::looseAssemblyForEVM(EVMVersion::petersburg()),
resolver
).analyze(_inlineAssembly.operations());
return false;
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
}

// Using latest EVM Version for now, it will be run again later.
yul::Parser asmParser(m_errorReporter, yul::EVMDialect::looseAssemblyForEVM(EVMVersion::constantinople()));
yul::Parser asmParser(m_errorReporter, yul::EVMDialect::looseAssemblyForEVM(EVMVersion::petersburg()));
shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true);
if (block == nullptr)
BOOST_THROW_EXCEPTION(FatalError());
Expand Down
2 changes: 2 additions & 0 deletions test/RPCSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ void RPCSession::test_setChainParams(vector<string> const& _accounts)
}
if (test::Options::get().evmVersion() >= langutil::EVMVersion::constantinople())
forks += "\"constantinopleForkBlock\": \"0x00\",\n";
if (test::Options::get().evmVersion() >= langutil::EVMVersion::petersburg())
forks += "\"constantinopleFixForkBlock\": \"0x00\",\n";
static string const c_configString = R"(
{
"sealEngine": "NoProof",
Expand Down
2 changes: 2 additions & 0 deletions test/libsolidity/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ BOOST_AUTO_TEST_CASE(evm_version)
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != string::npos);
result = compile(inputForVersion("\"evmVersion\": \"constantinople\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"constantinople\"") != string::npos);
result = compile(inputForVersion("\"evmVersion\": \"petersburg\","));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"petersburg\"") != string::npos);
// test default
result = compile(inputForVersion(""));
BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != string::npos);
Expand Down
2 changes: 1 addition & 1 deletion test/tools/yulopti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class YulOpti
private:
ErrorList m_errors;
shared_ptr<yul::Block> m_ast;
shared_ptr<Dialect> m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion::constantinople())};
shared_ptr<Dialect> m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion::petersburg())};
shared_ptr<AsmAnalysisInfo> m_analysisInfo;
shared_ptr<NameDispenser> m_nameDispenser;
};
Expand Down

0 comments on commit 735a319

Please sign in to comment.