mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Add --no-append-metadata in CLI and metadata.append in JSON
				
					
				
			Skips appending metadata to the binary
This commit is contained in:
		
							parent
							
								
									8b7010872c
								
							
						
					
					
						commit
						f96e802e74
					
				| @ -308,6 +308,7 @@ void CompilerStack::reset(bool _keepSettings) | |||||||
| 		m_revertStrings = RevertStrings::Default; | 		m_revertStrings = RevertStrings::Default; | ||||||
| 		m_optimiserSettings = OptimiserSettings::minimal(); | 		m_optimiserSettings = OptimiserSettings::minimal(); | ||||||
| 		m_metadataLiteralSources = false; | 		m_metadataLiteralSources = false; | ||||||
|  | 		m_metadataFormat = defaultMetadataFormat(); | ||||||
| 		m_metadataHash = MetadataHash::IPFS; | 		m_metadataHash = MetadataHash::IPFS; | ||||||
| 		m_stopAfter = State::CompilationSuccessful; | 		m_stopAfter = State::CompilationSuccessful; | ||||||
| 	} | 	} | ||||||
| @ -1548,6 +1549,9 @@ string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) con | |||||||
| 	if (m_revertStrings != RevertStrings::Default) | 	if (m_revertStrings != RevertStrings::Default) | ||||||
| 		meta["settings"]["debug"]["revertStrings"] = revertStringsToString(m_revertStrings); | 		meta["settings"]["debug"]["revertStrings"] = revertStringsToString(m_revertStrings); | ||||||
| 
 | 
 | ||||||
|  | 	if (m_metadataFormat == MetadataFormat::NoMetadata) | ||||||
|  | 		meta["settings"]["metadata"]["appendCBOR"] = false; | ||||||
|  | 
 | ||||||
| 	if (m_metadataLiteralSources) | 	if (m_metadataLiteralSources) | ||||||
| 		meta["settings"]["metadata"]["useLiteralContent"] = true; | 		meta["settings"]["metadata"]["useLiteralContent"] = true; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -349,6 +349,11 @@ public: | |||||||
| 	/// caused by differences in metadata. Should only be used for testing.
 | 	/// caused by differences in metadata. Should only be used for testing.
 | ||||||
| 	void setMetadataFormat(MetadataFormat _metadataFormat) { m_metadataFormat = _metadataFormat; } | 	void setMetadataFormat(MetadataFormat _metadataFormat) { m_metadataFormat = _metadataFormat; } | ||||||
| 
 | 
 | ||||||
|  | 	static MetadataFormat defaultMetadataFormat() | ||||||
|  | 	{ | ||||||
|  | 		return VersionIsRelease ? MetadataFormat::WithReleaseVersionTag : MetadataFormat::WithPrereleaseVersionTag; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
| 	/// The state per source unit. Filled gradually during parsing.
 | 	/// The state per source unit. Filled gradually during parsing.
 | ||||||
| 	struct Source | 	struct Source | ||||||
| @ -515,7 +520,7 @@ private: | |||||||
| 	/// Whether or not there has been an error during processing.
 | 	/// Whether or not there has been an error during processing.
 | ||||||
| 	/// If this is true, the stack will refuse to generate code.
 | 	/// If this is true, the stack will refuse to generate code.
 | ||||||
| 	bool m_hasError = false; | 	bool m_hasError = false; | ||||||
| 	MetadataFormat m_metadataFormat = VersionIsRelease ? MetadataFormat::WithReleaseVersionTag : MetadataFormat::WithPrereleaseVersionTag; | 	MetadataFormat m_metadataFormat = defaultMetadataFormat(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -509,6 +509,8 @@ std::optional<Json::Value> checkMetadataKeys(Json::Value const& _input) | |||||||
| { | { | ||||||
| 	if (_input.isObject()) | 	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()) | 		if (_input.isMember("useLiteralContent") && !_input["useLiteralContent"].isBool()) | ||||||
| 			return formatFatalError(Error::Type::JSONError, "\"settings.metadata.useLiteralContent\" must be Boolean"); | 			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())) | 		if (_input.isMember("bytecodeHash") && !hashes.count(_input["bytecodeHash"].asString())) | ||||||
| 			return formatFatalError(Error::Type::JSONError, "\"settings.metadata.bytecodeHash\" must be \"ipfs\", \"bzzr1\" or \"none\""); | 			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"); | 	return checkKeys(_input, keys, "settings.metadata"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -911,6 +913,12 @@ std::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompiler: | |||||||
| 	if (auto result = checkMetadataKeys(metadataSettings)) | 	if (auto result = checkMetadataKeys(metadataSettings)) | ||||||
| 		return *result; | 		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(); | 	ret.metadataLiteralSources = metadataSettings.get("useLiteralContent", Json::Value(false)).asBool(); | ||||||
| 	if (metadataSettings.isMember("bytecodeHash")) | 	if (metadataSettings.isMember("bytecodeHash")) | ||||||
| 	{ | 	{ | ||||||
| @ -1086,6 +1094,7 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting | |||||||
| 		compilerStack.selectDebugInfo(_inputsAndSettings.debugInfoSelection.value()); | 		compilerStack.selectDebugInfo(_inputsAndSettings.debugInfoSelection.value()); | ||||||
| 	compilerStack.setLibraries(_inputsAndSettings.libraries); | 	compilerStack.setLibraries(_inputsAndSettings.libraries); | ||||||
| 	compilerStack.useMetadataLiteralSources(_inputsAndSettings.metadataLiteralSources); | 	compilerStack.useMetadataLiteralSources(_inputsAndSettings.metadataLiteralSources); | ||||||
|  | 	compilerStack.setMetadataFormat(_inputsAndSettings.metadataFormat); | ||||||
| 	compilerStack.setMetadataHash(_inputsAndSettings.metadataHash); | 	compilerStack.setMetadataHash(_inputsAndSettings.metadataHash); | ||||||
| 	compilerStack.setRequestedContractNames(requestedContractNames(_inputsAndSettings.outputSelection)); | 	compilerStack.setRequestedContractNames(requestedContractNames(_inputsAndSettings.outputSelection)); | ||||||
| 	compilerStack.setModelCheckerSettings(_inputsAndSettings.modelCheckerSettings); | 	compilerStack.setModelCheckerSettings(_inputsAndSettings.modelCheckerSettings); | ||||||
|  | |||||||
| @ -83,6 +83,7 @@ private: | |||||||
| 		std::optional<langutil::DebugInfoSelection> debugInfoSelection; | 		std::optional<langutil::DebugInfoSelection> debugInfoSelection; | ||||||
| 		std::map<std::string, util::h160> libraries; | 		std::map<std::string, util::h160> libraries; | ||||||
| 		bool metadataLiteralSources = false; | 		bool metadataLiteralSources = false; | ||||||
|  | 		CompilerStack::MetadataFormat metadataFormat = CompilerStack::defaultMetadataFormat(); | ||||||
| 		CompilerStack::MetadataHash metadataHash = CompilerStack::MetadataHash::IPFS; | 		CompilerStack::MetadataHash metadataHash = CompilerStack::MetadataHash::IPFS; | ||||||
| 		Json::Value outputSelection; | 		Json::Value outputSelection; | ||||||
| 		ModelCheckerSettings modelCheckerSettings = ModelCheckerSettings{}; | 		ModelCheckerSettings modelCheckerSettings = ModelCheckerSettings{}; | ||||||
|  | |||||||
| @ -689,6 +689,7 @@ void CommandLineInterface::compile() | |||||||
| 	{ | 	{ | ||||||
| 		if (m_options.metadata.literalSources) | 		if (m_options.metadata.literalSources) | ||||||
| 			m_compiler->useMetadataLiteralSources(true); | 			m_compiler->useMetadataLiteralSources(true); | ||||||
|  | 		m_compiler->setMetadataFormat(m_options.metadata.format); | ||||||
| 		m_compiler->setMetadataHash(m_options.metadata.hash); | 		m_compiler->setMetadataHash(m_options.metadata.hash); | ||||||
| 		if (m_options.modelChecker.initialize) | 		if (m_options.modelChecker.initialize) | ||||||
| 			m_compiler->setModelCheckerSettings(m_options.modelChecker.settings); | 			m_compiler->setModelCheckerSettings(m_options.modelChecker.settings); | ||||||
|  | |||||||
| @ -62,6 +62,7 @@ static string const g_strLibraries = "libraries"; | |||||||
| static string const g_strLink = "link"; | static string const g_strLink = "link"; | ||||||
| static string const g_strLSP = "lsp"; | static string const g_strLSP = "lsp"; | ||||||
| static string const g_strMachine = "machine"; | static string const g_strMachine = "machine"; | ||||||
|  | static string const g_strNoCBORMetadata = "no-cbor-metadata"; | ||||||
| static string const g_strMetadataHash = "metadata-hash"; | static string const g_strMetadataHash = "metadata-hash"; | ||||||
| static string const g_strMetadataLiteral = "metadata-literal"; | static string const g_strMetadataLiteral = "metadata-literal"; | ||||||
| static string const g_strModelCheckerContracts = "model-checker-contracts"; | static string const g_strModelCheckerContracts = "model-checker-contracts"; | ||||||
| @ -240,6 +241,7 @@ bool CommandLineOptions::operator==(CommandLineOptions const& _other) const noex | |||||||
| 		compiler.outputs == _other.compiler.outputs && | 		compiler.outputs == _other.compiler.outputs && | ||||||
| 		compiler.estimateGas == _other.compiler.estimateGas && | 		compiler.estimateGas == _other.compiler.estimateGas && | ||||||
| 		compiler.combinedJsonRequests == _other.compiler.combinedJsonRequests && | 		compiler.combinedJsonRequests == _other.compiler.combinedJsonRequests && | ||||||
|  | 		metadata.format == _other.metadata.format && | ||||||
| 		metadata.hash == _other.metadata.hash && | 		metadata.hash == _other.metadata.hash && | ||||||
| 		metadata.literalSources == _other.metadata.literalSources && | 		metadata.literalSources == _other.metadata.literalSources && | ||||||
| 		optimizer.enabled == _other.optimizer.enabled && | 		optimizer.enabled == _other.optimizer.enabled && | ||||||
| @ -748,6 +750,10 @@ General Information)").c_str(), | |||||||
| 
 | 
 | ||||||
| 	po::options_description metadataOptions("Metadata Options"); | 	po::options_description metadataOptions("Metadata Options"); | ||||||
| 	metadataOptions.add_options() | 	metadataOptions.add_options() | ||||||
|  | 		( | ||||||
|  | 			g_strNoCBORMetadata.c_str(), | ||||||
|  | 			"Do not append CBOR metadata to the end of the bytecode." | ||||||
|  | 		) | ||||||
| 		( | 		( | ||||||
| 			g_strMetadataHash.c_str(), | 			g_strMetadataHash.c_str(), | ||||||
| 			po::value<string>()->value_name(util::joinHumanReadable(g_metadataHashArgs, ",")), | 			po::value<string>()->value_name(util::joinHumanReadable(g_metadataHashArgs, ",")), | ||||||
| @ -922,6 +928,7 @@ void CommandLineParser::processArgs() | |||||||
| 		{g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | 		{g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
| 		{g_strViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | 		{g_strViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
| 		{g_strMetadataLiteral, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | 		{g_strMetadataLiteral, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
|  | 		{g_strNoCBORMetadata, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
| 		{g_strMetadataHash, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | 		{g_strMetadataHash, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
| 		{g_strModelCheckerShowUnproved, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | 		{g_strModelCheckerShowUnproved, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
| 		{g_strModelCheckerDivModNoSlacks, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | 		{g_strModelCheckerDivModNoSlacks, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, | ||||||
| @ -1221,6 +1228,21 @@ void CommandLineParser::processArgs() | |||||||
| 			solThrow(CommandLineValidationError, "Invalid option for --" + g_strMetadataHash + ": " + hashStr); | 			solThrow(CommandLineValidationError, "Invalid option for --" + g_strMetadataHash + ": " + hashStr); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if (m_args.count(g_strNoCBORMetadata)) | ||||||
|  | 	{ | ||||||
|  | 		if ( | ||||||
|  | 			m_args.count(g_strMetadataHash) && | ||||||
|  | 			m_options.metadata.hash != CompilerStack::MetadataHash::None | ||||||
|  | 		) | ||||||
|  | 			solThrow( | ||||||
|  | 				CommandLineValidationError, | ||||||
|  | 				"Cannot specify a metadata hashing method when --" + | ||||||
|  | 				g_strNoCBORMetadata + " is set." | ||||||
|  | 			); | ||||||
|  | 
 | ||||||
|  | 		m_options.metadata.format = CompilerStack::MetadataFormat::NoMetadata; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if (m_args.count(g_strModelCheckerContracts)) | 	if (m_args.count(g_strModelCheckerContracts)) | ||||||
| 	{ | 	{ | ||||||
| 		string contractsStr = m_args[g_strModelCheckerContracts].as<string>(); | 		string contractsStr = m_args[g_strModelCheckerContracts].as<string>(); | ||||||
|  | |||||||
| @ -215,6 +215,7 @@ struct CommandLineOptions | |||||||
| 
 | 
 | ||||||
| 	struct | 	struct | ||||||
| 	{ | 	{ | ||||||
|  | 		CompilerStack::MetadataFormat format = CompilerStack::defaultMetadataFormat(); | ||||||
| 		CompilerStack::MetadataHash hash = CompilerStack::MetadataHash::IPFS; | 		CompilerStack::MetadataHash hash = CompilerStack::MetadataHash::IPFS; | ||||||
| 		bool literalSources = false; | 		bool literalSources = false; | ||||||
| 	} metadata; | 	} metadata; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user