diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index d518c50d3..1995c7750 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1580,6 +1580,9 @@ private: bytes CompilerStack::createCBORMetadata(Contract const& _contract) const { + if (m_metadataFormat == MetadataFormat::NoMetadata) + return bytes{}; + bool const experimentalMode = !onlySafeExperimentalFeaturesActivated( _contract.contract->sourceUnit().annotation().experimentalFeatures ); @@ -1597,10 +1600,16 @@ bytes CompilerStack::createCBORMetadata(Contract const& _contract) const if (experimentalMode || m_viaIR) encoder.pushBool("experimental", true); - if (m_release) + if (m_metadataFormat == MetadataFormat::WithReleaseVersionTag) encoder.pushBytes("solc", VersionCompactBytes); else + { + solAssert( + m_metadataFormat == MetadataFormat::WithPrereleaseVersionTag, + "Invalid metadata format." + ); encoder.pushString("solc", VersionStringStrict); + } return encoder.serialise(); } diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 5049561c4..db087a663 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -98,6 +98,12 @@ public: CompilationSuccessful }; + enum class MetadataFormat { + WithReleaseVersionTag, + WithPrereleaseVersionTag, + NoMetadata + }; + enum class MetadataHash { IPFS, Bzzr1, @@ -336,8 +342,10 @@ public: /// @returns a JSON representing the estimated gas usage for contract creation, internal and external functions Json::Value gasEstimates(std::string const& _contractName) const; - /// Overwrites the release/prerelease flag. Should only be used for testing. - void overwriteReleaseFlag(bool release) { m_release = release; } + /// 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; } private: /// The state per source unit. Filled gradually during parsing. struct Source @@ -496,7 +504,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; - bool m_release = VersionIsRelease; + MetadataFormat m_metadataFormat = VersionIsRelease ? MetadataFormat::WithReleaseVersionTag : MetadataFormat::WithPrereleaseVersionTag; }; }