Merge pull request #13265 from ethereum/no-append-metadata

Add `--no-append-metadata` in CLI and `metadata.append` in JSON
This commit is contained in:
Kamil Śliwak
2022-10-04 17:32:22 +02:00
committed by GitHub
25 changed files with 164 additions and 7 deletions
+4
View File
@@ -308,6 +308,7 @@ void CompilerStack::reset(bool _keepSettings)
m_revertStrings = RevertStrings::Default;
m_optimiserSettings = OptimiserSettings::minimal();
m_metadataLiteralSources = false;
m_metadataFormat = defaultMetadataFormat();
m_metadataHash = MetadataHash::IPFS;
m_stopAfter = State::CompilationSuccessful;
}
@@ -1548,6 +1549,9 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con
if (m_revertStrings != RevertStrings::Default)
meta["settings"]["debug"]["revertStrings"] = revertStringsToString(m_revertStrings);
if (m_metadataFormat == MetadataFormat::NoMetadata)
meta["settings"]["metadata"]["appendCBOR"] = false;
if (m_metadataLiteralSources)
meta["settings"]["metadata"]["useLiteralContent"] = true;
+6 -3
View File
@@ -345,10 +345,13 @@ public:
Json::Value gasEstimates(std::string const& _contractName) const;
/// Changes the format of the metadata appended at the end of the bytecode.
/// This is mostly a workaround to avoid bytecode and gas differences between compiler builds
/// caused by differences in metadata. Should only be used for testing.
void setMetadataFormat(MetadataFormat _metadataFormat) { m_metadataFormat = _metadataFormat; }
static MetadataFormat defaultMetadataFormat()
{
return VersionIsRelease ? MetadataFormat::WithReleaseVersionTag : MetadataFormat::WithPrereleaseVersionTag;
}
private:
/// The state per source unit. Filled gradually during parsing.
struct Source
@@ -515,7 +518,7 @@ private:
/// Whether or not there has been an error during processing.
/// If this is true, the stack will refuse to generate code.
bool m_hasError = false;
MetadataFormat m_metadataFormat = VersionIsRelease ? MetadataFormat::WithReleaseVersionTag : MetadataFormat::WithPrereleaseVersionTag;
MetadataFormat m_metadataFormat = defaultMetadataFormat();
};
}
+10 -1
View File
@@ -509,6 +509,8 @@ std::optional<Json::Value> checkMetadataKeys(Json::Value const& _input)
{
if (_input.isObject())
{
if (_input.isMember("appendCBOR") && !_input["appendCBOR"].isBool())
return formatFatalError(Error::Type::JSONError, "\"settings.metadata.appendCBOR\" must be Boolean");
if (_input.isMember("useLiteralContent") && !_input["useLiteralContent"].isBool())
return formatFatalError(Error::Type::JSONError, "\"settings.metadata.useLiteralContent\" must be Boolean");
@@ -516,7 +518,7 @@ std::optional<Json::Value> checkMetadataKeys(Json::Value const& _input)
if (_input.isMember("bytecodeHash") && !hashes.count(_input["bytecodeHash"].asString()))
return formatFatalError(Error::Type::JSONError, "\"settings.metadata.bytecodeHash\" must be \"ipfs\", \"bzzr1\" or \"none\"");
}
static set<string> keys{"useLiteralContent", "bytecodeHash"};
static set<string> keys{"appendCBOR", "useLiteralContent", "bytecodeHash"};
return checkKeys(_input, keys, "settings.metadata");
}
@@ -911,6 +913,12 @@ std::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompiler:
if (auto result = checkMetadataKeys(metadataSettings))
return *result;
solAssert(CompilerStack::defaultMetadataFormat() != CompilerStack::MetadataFormat::NoMetadata, "");
ret.metadataFormat =
metadataSettings.get("appendCBOR", Json::Value(true)).asBool() ?
CompilerStack::defaultMetadataFormat() :
CompilerStack::MetadataFormat::NoMetadata;
ret.metadataLiteralSources = metadataSettings.get("useLiteralContent", Json::Value(false)).asBool();
if (metadataSettings.isMember("bytecodeHash"))
{
@@ -1086,6 +1094,7 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
compilerStack.selectDebugInfo(_inputsAndSettings.debugInfoSelection.value());
compilerStack.setLibraries(_inputsAndSettings.libraries);
compilerStack.useMetadataLiteralSources(_inputsAndSettings.metadataLiteralSources);
compilerStack.setMetadataFormat(_inputsAndSettings.metadataFormat);
compilerStack.setMetadataHash(_inputsAndSettings.metadataHash);
compilerStack.setRequestedContractNames(requestedContractNames(_inputsAndSettings.outputSelection));
compilerStack.setModelCheckerSettings(_inputsAndSettings.modelCheckerSettings);
+1
View File
@@ -83,6 +83,7 @@ private:
std::optional<langutil::DebugInfoSelection> debugInfoSelection;
std::map<std::string, util::h160> libraries;
bool metadataLiteralSources = false;
CompilerStack::MetadataFormat metadataFormat = CompilerStack::defaultMetadataFormat();
CompilerStack::MetadataHash metadataHash = CompilerStack::MetadataHash::IPFS;
Json::Value outputSelection;
ModelCheckerSettings modelCheckerSettings = ModelCheckerSettings{};