Refactor overwriteRelease flag.

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
Djordje Mijovic 2021-02-11 09:45:28 +01:00
parent 003701f6bc
commit 68a4efb2e7
2 changed files with 21 additions and 4 deletions

View File

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

View File

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