Merge pull request #13733 from ethereum/eofSetting

Add experimental EOF options for CLI and Standard JSON.
This commit is contained in:
Daniel
2022-11-23 20:37:24 +01:00
committed by GitHub
38 changed files with 198 additions and 22 deletions
+24 -2
View File
@@ -225,6 +225,15 @@ void CompilerStack::setEVMVersion(langutil::EVMVersion _version)
m_evmVersion = _version;
}
void CompilerStack::setEOFVersion(std::optional<uint8_t> _version)
{
if (m_stackState >= CompilationSuccessful)
solThrow(CompilerError, "Must set EOF version before compiling.");
if (_version && _version != 1)
solThrow(CompilerError, "Invalid EOF version.");
m_eofVersion = _version;
}
void CompilerStack::setModelCheckerSettings(ModelCheckerSettings _settings)
{
if (m_stackState >= ParsedAndImported)
@@ -1308,6 +1317,7 @@ void CompilerStack::compileContract(
)
{
solAssert(!m_viaIR, "");
solUnimplementedAssert(!m_eofVersion.has_value(), "Experimental EOF support is only available for via-IR compilation.");
solAssert(m_stackState >= AnalysisPerformed, "");
if (m_hasError)
solThrow(CompilerError, "Called compile with errors.");
@@ -1373,7 +1383,15 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
for (auto const& pair: m_contracts)
otherYulSources.emplace(pair.second.contract, pair.second.yulIR);
IRGenerator generator(m_evmVersion, m_revertStrings, m_optimiserSettings, sourceIndices(), m_debugInfoSelection, this);
IRGenerator generator(
m_evmVersion,
m_eofVersion,
m_revertStrings,
m_optimiserSettings,
sourceIndices(),
m_debugInfoSelection,
this
);
tie(compiledContract.yulIR, compiledContract.yulIROptimized) = generator.run(
_contract,
createCBORMetadata(compiledContract, /* _forIR */ true),
@@ -1398,6 +1416,7 @@ void CompilerStack::generateEVMFromIR(ContractDefinition const& _contract)
// Re-parse the Yul IR in EVM dialect
yul::YulStack stack(
m_evmVersion,
m_eofVersion,
yul::YulStack::Language::StrictAssembly,
m_optimiserSettings,
m_debugInfoSelection
@@ -1430,6 +1449,7 @@ void CompilerStack::generateEwasm(ContractDefinition const& _contract)
// Re-parse the Yul IR in EVM dialect
yul::YulStack stack(
m_evmVersion,
m_eofVersion,
yul::YulStack::Language::StrictAssembly,
m_optimiserSettings,
m_debugInfoSelection
@@ -1580,6 +1600,8 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con
if (_forIR)
meta["settings"]["viaIR"] = _forIR;
meta["settings"]["evmVersion"] = m_evmVersion.name();
if (m_eofVersion.has_value())
meta["settings"]["eofVersion"] = *m_eofVersion;
meta["settings"]["compilationTarget"][_contract.contract->sourceUnitName()] =
*_contract.contract->annotation().canonicalName;
@@ -1704,7 +1726,7 @@ bytes CompilerStack::createCBORMetadata(Contract const& _contract, bool _forIR)
else
solAssert(m_metadataHash == MetadataHash::None, "Invalid metadata hash");
if (experimentalMode)
if (experimentalMode || m_eofVersion.has_value())
encoder.pushBool("experimental", true);
if (m_metadataFormat == MetadataFormat::WithReleaseVersionTag)
encoder.pushBytes("solc", VersionCompactBytes);
+5
View File
@@ -181,6 +181,10 @@ public:
/// Must be set before parsing.
void setEVMVersion(langutil::EVMVersion _version = langutil::EVMVersion{});
/// Set the EOF version used before running compile.
/// If set to std::nullopt (the default), legacy non-EOF bytecode is generated.
void setEOFVersion(std::optional<uint8_t> version);
/// Set model checker settings.
void setModelCheckerSettings(ModelCheckerSettings _settings);
@@ -498,6 +502,7 @@ private:
State m_stopAfter = State::CompilationSuccessful;
bool m_viaIR = false;
langutil::EVMVersion m_evmVersion;
std::optional<uint8_t> m_eofVersion;
ModelCheckerSettings m_modelCheckerSettings;
std::map<std::string, std::set<std::string>> m_requestedContractNames;
bool m_generateEvmBytecode = true;
@@ -800,6 +800,16 @@ std::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompiler:
ret.evmVersion = *version;
}
if (settings.isMember("eofVersion"))
{
if (!settings["eofVersion"].isUInt())
return formatFatalError(Error::Type::JSONError, "eofVersion must be an unsigned integer.");
auto eofVersion = settings["evmVersion"].asUInt();
if (eofVersion != 1)
return formatFatalError(Error::Type::JSONError, "Invalid EOF version requested.");
ret.eofVersion = 1;
}
if (settings.isMember("debug"))
{
if (auto result = checkKeys(settings["debug"], {"revertStrings", "debugInfo"}, "settings.debug"))
@@ -1413,6 +1423,7 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
YulStack stack(
_inputsAndSettings.evmVersion,
_inputsAndSettings.eofVersion,
YulStack::Language::StrictAssembly,
_inputsAndSettings.optimiserSettings,
_inputsAndSettings.debugInfoSelection.has_value() ?
+1
View File
@@ -77,6 +77,7 @@ private:
std::map<std::string, std::string> sources;
std::map<util::h256, std::string> smtLib2Responses;
langutil::EVMVersion evmVersion;
std::optional<uint8_t> eofVersion;
std::vector<ImportRemapper::Remapping> remappings;
RevertStrings revertStrings = RevertStrings::Default;
OptimiserSettings optimiserSettings = OptimiserSettings::minimal();