diff --git a/Changelog.md b/Changelog.md index 5407d51ab..277af2377 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.8.6 (unreleased) Language Features: + * Yul: Special meaning of ``".metadata"`` data object in Yul object. Compiler Features: diff --git a/docs/yul.rst b/docs/yul.rst index fc2dec45d..55e8b824f 100644 --- a/docs/yul.rst +++ b/docs/yul.rst @@ -1076,6 +1076,23 @@ regular strings in native encoding. For code, Above, ``Block`` refers to ``Block`` in the Yul code grammar explained in the previous chapter. +.. note:: + + Data objects or sub-objects whose names contain a ``.`` can be defined + but it is not possible to access them through ``datasize``, + ``dataoffset`` or ``datacopy`` because ``.`` is used as a separator + to access objects inside another object. + +.. note:: + + The data object called ``".metadata"`` has a special meaning: + It cannot be accessed from code and is always appended to the very end of the + bytecode, regardless of its position in the object. + + Other data objects with special significance might be added in the + future, but their names will always start with a ``.``. + + An example Yul Object is shown below: .. code-block:: yul diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index cce06ccb7..b6003c3f8 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -92,7 +92,7 @@ public: void pushSubroutineOffset(size_t _subRoutine) { append(AssemblyItem(PushSub, _subRoutine)); } /// Appends @a _data literally to the very end of the bytecode. - void appendAuxiliaryDataToEnd(bytes const& _data) { m_auxiliaryData += _data; } + void appendToAuxiliaryData(bytes const& _data) { m_auxiliaryData += _data; } /// Returns the assembly items. AssemblyItems const& items() const { return m_items; } diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index 0b6385943..e3308b2de 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -38,7 +38,7 @@ void Compiler::compileContract( { ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimiserSettings); runtimeCompiler.compileContract(_contract, _otherCompilers); - m_runtimeContext.appendAuxiliaryData(_metadata); + m_runtimeContext.appendToAuxiliaryData(_metadata); // This might modify m_runtimeContext because it can access runtime functions at // creation time. diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index a40afb498..b36397864 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -279,7 +279,7 @@ public: void optimizeYul(yul::Object& _object, yul::EVMDialect const& _dialect, OptimiserSettings const& _optimiserSetting, std::set const& _externalIdentifiers = {}); /// Appends arbitrary data to the end of the bytecode. - void appendAuxiliaryData(bytes const& _data) { m_asm->appendAuxiliaryDataToEnd(_data); } + void appendToAuxiliaryData(bytes const& _data) { m_asm->appendToAuxiliaryData(_data); } /// Run optimisation step. void optimise(OptimiserSettings const& _settings) { m_asm->optimise(translateOptimiserSettings(_settings)); } diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index 776c2afe1..0dee6a496 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -90,10 +90,11 @@ set collectReachableCallables( pair IRGenerator::run( ContractDefinition const& _contract, + bytes const& _cborMetadata, map const& _otherYulSources ) { - string const ir = yul::reindent(generate(_contract, _otherYulSources)); + string const ir = yul::reindent(generate(_contract, _cborMetadata, _otherYulSources)); yul::AssemblyStack asmStack(m_evmVersion, yul::AssemblyStack::Language::StrictAssembly, m_optimiserSettings); if (!asmStack.parseAndAnalyze("", ir)) @@ -118,6 +119,7 @@ pair IRGenerator::run( string IRGenerator::generate( ContractDefinition const& _contract, + bytes const& _cborMetadata, map const& _otherYulSources ) { @@ -152,6 +154,7 @@ string IRGenerator::generate( } + data "" hex"" } } @@ -207,6 +210,9 @@ string IRGenerator::generate( generateInternalDispatchFunctions(); t("deployedFunctions", m_context.functionCollector().requestedFunctions()); t("deployedSubObjects", subObjectSources(m_context.subObjectsCreated())); + t("metadataName", yul::Object::metadataName()); + t("cborMetadata", toHex(_cborMetadata)); + // This has to be called only after all other code generation for the deployed object is complete. bool deployedInvolvesAssembly = m_context.inlineAssemblySeen(); diff --git a/libsolidity/codegen/ir/IRGenerator.h b/libsolidity/codegen/ir/IRGenerator.h index 7a1b72c0b..fb7dde788 100644 --- a/libsolidity/codegen/ir/IRGenerator.h +++ b/libsolidity/codegen/ir/IRGenerator.h @@ -54,12 +54,14 @@ public: /// (or just pretty-printed, depending on the optimizer settings). std::pair run( ContractDefinition const& _contract, + bytes const& _cborMetadata, std::map const& _otherYulSources ); private: std::string generate( ContractDefinition const& _contract, + bytes const& _cborMetadata, std::map const& _otherYulSources ); std::string generate(Block const& _block); diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 5fee63f45..ab7e6e501 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1351,7 +1351,11 @@ void CompilerStack::generateIR(ContractDefinition const& _contract) otherYulSources.emplace(pair.second.contract, pair.second.yulIR); IRGenerator generator(m_evmVersion, m_revertStrings, m_optimiserSettings); - tie(compiledContract.yulIR, compiledContract.yulIROptimized) = generator.run(_contract, otherYulSources); + tie(compiledContract.yulIR, compiledContract.yulIROptimized) = generator.run( + _contract, + createCBORMetadata(compiledContract), + otherYulSources + ); } void CompilerStack::generateEVMFromIR(ContractDefinition const& _contract) @@ -1375,8 +1379,6 @@ void CompilerStack::generateEVMFromIR(ContractDefinition const& _contract) //cout << yul::AsmPrinter{}(*stack.parserResult()->code) << endl; - // TODO: support passing metadata - string deployedName = IRNames::deployedObject(_contract); solAssert(!deployedName.empty(), ""); tie(compiledContract.evmAssembly, compiledContract.evmRuntimeAssembly) = stack.assembleEVMWithDeployed(deployedName); diff --git a/libyul/Object.cpp b/libyul/Object.cpp index 72206c4b6..3dadf9cb5 100644 --- a/libyul/Object.cpp +++ b/libyul/Object.cpp @@ -65,10 +65,15 @@ string Object::toString(Dialect const* _dialect) const set Object::qualifiedDataNames() const { - set qualifiedNames = name.empty() ? set{} : set{name}; + set qualifiedNames = + name.empty() || contains(name.str(), '.') ? + set{} : + set{name}; for (shared_ptr const& subObjectNode: subObjects) { yulAssert(qualifiedNames.count(subObjectNode->name) == 0, ""); + if (contains(subObjectNode->name.str(), '.')) + continue; qualifiedNames.insert(subObjectNode->name); if (auto const* subObject = dynamic_cast(subObjectNode.get())) for (YulString const& subSubObj: subObject->qualifiedDataNames()) diff --git a/libyul/Object.h b/libyul/Object.h index aa4bde629..81406a1df 100644 --- a/libyul/Object.h +++ b/libyul/Object.h @@ -71,6 +71,7 @@ public: /// @returns the set of names of data objects accessible from within the code of /// this object, including the name of object itself + /// Handles all names containing dots as reserved identifiers, not accessible as data. std::set qualifiedDataNames() const; /// @returns vector of subIDs if possible to reach subobject with @a _qualifiedName, throws otherwise @@ -92,6 +93,9 @@ public: std::vector> subObjects; std::map subIndexByName; std::shared_ptr analysisInfo; + + /// @returns the name of the special metadata data object. + static std::string metadataName() { return ".metadata"; } }; } diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h index ef5c73c67..9e1a28dab 100644 --- a/libyul/backends/evm/AbstractAssembly.h +++ b/libyul/backends/evm/AbstractAssembly.h @@ -110,6 +110,9 @@ public: /// Appends an assignment to an immutable variable. virtual void appendImmutableAssignment(std::string const& _identifier) = 0; + /// Appends data to the very end of the bytecode. Repeated calls concatenate. + virtual void appendToAuxiliaryData(bytes const& _data) = 0; + /// Mark this assembly as invalid. Any attempt to request bytecode from it should throw. virtual void markAsInvalid() = 0; }; diff --git a/libyul/backends/evm/EVMObjectCompiler.cpp b/libyul/backends/evm/EVMObjectCompiler.cpp index 2b9808387..f65f7f1e3 100644 --- a/libyul/backends/evm/EVMObjectCompiler.cpp +++ b/libyul/backends/evm/EVMObjectCompiler.cpp @@ -53,7 +53,11 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize) else { Data const& data = dynamic_cast(*subNode); - context.subIDs[data.name] = m_assembly.appendData(data.data); + // Special handling of metadata. + if (data.name.str() == Object::metadataName()) + m_assembly.appendToAuxiliaryData(data.data); + else + context.subIDs[data.name] = m_assembly.appendData(data.data); } yulAssert(_object.analysisInfo, "No analysis info."); diff --git a/libyul/backends/evm/EthAssemblyAdapter.cpp b/libyul/backends/evm/EthAssemblyAdapter.cpp index 85af84fc3..1c41534b2 100644 --- a/libyul/backends/evm/EthAssemblyAdapter.cpp +++ b/libyul/backends/evm/EthAssemblyAdapter.cpp @@ -161,6 +161,11 @@ AbstractAssembly::SubID EthAssemblyAdapter::appendData(bytes const& _data) return subID; } +void EthAssemblyAdapter::appendToAuxiliaryData(bytes const& _data) +{ + m_assembly.appendToAuxiliaryData(_data); +} + void EthAssemblyAdapter::appendImmutable(std::string const& _identifier) { m_assembly.appendImmutable(_identifier); diff --git a/libyul/backends/evm/EthAssemblyAdapter.h b/libyul/backends/evm/EthAssemblyAdapter.h index e40719020..e47b79956 100644 --- a/libyul/backends/evm/EthAssemblyAdapter.h +++ b/libyul/backends/evm/EthAssemblyAdapter.h @@ -58,6 +58,8 @@ public: void appendDataSize(std::vector const& _subPath) override; SubID appendData(bytes const& _data) override; + void appendToAuxiliaryData(bytes const& _data) override; + void appendImmutable(std::string const& _identifier) override; void appendImmutableAssignment(std::string const& _identifier) override; diff --git a/libyul/backends/evm/NoOutputAssembly.h b/libyul/backends/evm/NoOutputAssembly.h index ebd83fe57..b41d7f4a6 100644 --- a/libyul/backends/evm/NoOutputAssembly.h +++ b/libyul/backends/evm/NoOutputAssembly.h @@ -70,6 +70,8 @@ public: void appendDataSize(std::vector const& _subPath) override; SubID appendData(bytes const& _data) override; + void appendToAuxiliaryData(bytes const&) override {} + void appendImmutable(std::string const& _identifier) override; void appendImmutableAssignment(std::string const& _identifier) override; diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 6076923ab..4d99961ca 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -153,6 +153,10 @@ function test_solc_behaviour() sed -i.bak -E -e 's/(\"object\":\"[^"]+\$__)[0-9a-f]+(\")/\1\2/g' "$stdout_path" # shellcheck disable=SC2016 sed -i.bak -E -e 's/([0-9a-f]{34}\$__)[0-9a-f]+(__\$[0-9a-f]{17})/\1\2/g' "$stdout_path" + # Remove metadata in assembly output (see below about the magic numbers) + sed -i.bak -E -e 's/"[0-9a-f]+64697066735822[0-9a-f]+64736f6c63[0-9a-f]+/"/g' "$stdout_path" + # Remove hash of text representation in ewasm + sed -i.bak -E -e 's/The Keccak-256 hash of the text representation of .*: [0-9a-f]+/The Keccak-256 hash of the text representation of /g' "$stdout_path" # Replace escaped newlines by actual newlines for readability # shellcheck disable=SC1003 diff --git a/test/cmdlineTests/constant_optimizer_yul/output b/test/cmdlineTests/constant_optimizer_yul/output index 181a8105b..05ff4bea3 100644 --- a/test/cmdlineTests/constant_optimizer_yul/output +++ b/test/cmdlineTests/constant_optimizer_yul/output @@ -26,5 +26,6 @@ object "C_12" { stop() } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/exp_base_literal/output b/test/cmdlineTests/exp_base_literal/output index 14b1a616a..17f3670ef 100644 --- a/test/cmdlineTests/exp_base_literal/output +++ b/test/cmdlineTests/exp_base_literal/output @@ -331,6 +331,7 @@ object "C_81" { } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output index 829981fcf..496e9de16 100644 --- a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output +++ b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output @@ -23,6 +23,7 @@ object "C_7" { revert(0, 0) } } + data ".metadata" hex"" } } @@ -51,5 +52,6 @@ object "D_10" { revert(0, 0) } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/ir_compiler_subobjects/output b/test/cmdlineTests/ir_compiler_subobjects/output index 96ebe2727..2cbfee997 100644 --- a/test/cmdlineTests/ir_compiler_subobjects/output +++ b/test/cmdlineTests/ir_compiler_subobjects/output @@ -23,6 +23,7 @@ object "C_3" { revert(0, 0) } } + data ".metadata" hex"" } } @@ -93,7 +94,9 @@ object "D_16" { revert(0, 0) } } + data ".metadata" hex"" } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output index 72ed66a1d..254b355e3 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output @@ -33,5 +33,6 @@ object "D_12" { revert(0, 0) } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output index a04c2f13b..7ce79e765 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output @@ -33,5 +33,6 @@ object "D_8" { revert(0, 0) } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/keccak_optimization_deploy_code/output b/test/cmdlineTests/keccak_optimization_deploy_code/output index 48721502a..99eac4c53 100644 --- a/test/cmdlineTests/keccak_optimization_deploy_code/output +++ b/test/cmdlineTests/keccak_optimization_deploy_code/output @@ -28,5 +28,6 @@ object "C_12" { stop() } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/keccak_optimization_low_runs/output b/test/cmdlineTests/keccak_optimization_low_runs/output index c2e9b023a..5644a1388 100644 --- a/test/cmdlineTests/keccak_optimization_low_runs/output +++ b/test/cmdlineTests/keccak_optimization_low_runs/output @@ -26,5 +26,6 @@ object "C_7" { stop() } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/name_simplifier/args b/test/cmdlineTests/name_simplifier/args index 8539e69f5..2ce860510 100644 --- a/test/cmdlineTests/name_simplifier/args +++ b/test/cmdlineTests/name_simplifier/args @@ -1 +1 @@ ---optimize --ir-optimized --metadata-hash none +--optimize --ir-optimized diff --git a/test/cmdlineTests/name_simplifier/output b/test/cmdlineTests/name_simplifier/output index 96f2ec391..255f781b0 100644 --- a/test/cmdlineTests/name_simplifier/output +++ b/test/cmdlineTests/name_simplifier/output @@ -122,5 +122,6 @@ object "C_59" { revert(0, 0x24) } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/optimize_full_storage_write/args b/test/cmdlineTests/optimize_full_storage_write/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimize_full_storage_write/args +++ b/test/cmdlineTests/optimize_full_storage_write/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_BlockDeDuplicator/args b/test/cmdlineTests/optimizer_BlockDeDuplicator/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_BlockDeDuplicator/args +++ b/test/cmdlineTests/optimizer_BlockDeDuplicator/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_array_sload/args b/test/cmdlineTests/optimizer_array_sload/args index 8539e69f5..2ce860510 100644 --- a/test/cmdlineTests/optimizer_array_sload/args +++ b/test/cmdlineTests/optimizer_array_sload/args @@ -1 +1 @@ ---optimize --ir-optimized --metadata-hash none +--optimize --ir-optimized diff --git a/test/cmdlineTests/optimizer_array_sload/output b/test/cmdlineTests/optimizer_array_sload/output index f5a3cf77d..5cfd79d9e 100644 --- a/test/cmdlineTests/optimizer_array_sload/output +++ b/test/cmdlineTests/optimizer_array_sload/output @@ -60,5 +60,6 @@ object "Arraysum_34" { revert(0, 0x24) } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/optimizer_inliner_add/args b/test/cmdlineTests/optimizer_inliner_add/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_inliner_add/args +++ b/test/cmdlineTests/optimizer_inliner_add/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_inliner_call_from_constructor/args b/test/cmdlineTests/optimizer_inliner_call_from_constructor/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_inliner_call_from_constructor/args +++ b/test/cmdlineTests/optimizer_inliner_call_from_constructor/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_inliner_dynamic_reference/args b/test/cmdlineTests/optimizer_inliner_dynamic_reference/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_inliner_dynamic_reference/args +++ b/test/cmdlineTests/optimizer_inliner_dynamic_reference/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_inliner_dynamic_reference_constructor/args b/test/cmdlineTests/optimizer_inliner_dynamic_reference_constructor/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_inliner_dynamic_reference_constructor/args +++ b/test/cmdlineTests/optimizer_inliner_dynamic_reference_constructor/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_inliner_inc/args b/test/cmdlineTests/optimizer_inliner_inc/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_inliner_inc/args +++ b/test/cmdlineTests/optimizer_inliner_inc/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_inliner_multireturn/args b/test/cmdlineTests/optimizer_inliner_multireturn/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_inliner_multireturn/args +++ b/test/cmdlineTests/optimizer_inliner_multireturn/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/optimizer_user_yul/args b/test/cmdlineTests/optimizer_user_yul/args index 8942fcc35..a73dc7c21 100644 --- a/test/cmdlineTests/optimizer_user_yul/args +++ b/test/cmdlineTests/optimizer_user_yul/args @@ -1 +1 @@ ---optimize --asm --metadata-hash none +--optimize --asm diff --git a/test/cmdlineTests/revert_strings/output b/test/cmdlineTests/revert_strings/output index 8fd41fba4..8a80f1d56 100644 --- a/test/cmdlineTests/revert_strings/output +++ b/test/cmdlineTests/revert_strings/output @@ -357,6 +357,7 @@ object "C_15" { } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/standard_ewasm_requested/output.json b/test/cmdlineTests/standard_ewasm_requested/output.json index d3eef7f27..c70693bc6 100644 --- a/test/cmdlineTests/standard_ewasm_requested/output.json +++ b/test/cmdlineTests/standard_ewasm_requested/output.json @@ -1,7 +1,7 @@ -{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d010000000125086000006000017e6000017f60017e017f60017f0060017f017f60027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000708657468657265756d06726576657274000608657468657265756d0c67657443616c6c56616c7565000408657468657265756d0666696e6973680006030a090002030202020505010503010001060100071102066d656d6f72790200046d61696e000400b6030c435f335f6465706c6f7965640061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b0ae303099a0102027f047e024010072100200041c0006a210120012000490440000b4200a7100bad422086210220024200422088a7100bad84210320012003370000200141086a2003370000200141106a2003370000200141186a100c37000041001002410829000021044200420084200441002900008484504504401008100510010b42a9032105100942b901100620051006100010092005100610030b0b2f02017f017e02404200210120012001200184200184520440000b20012001422088520440000b2001a721000b20000b2901017f024042004200420084420084520440000b42002000422088520440000b2000a721010b20010b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b1e01027f024010052101200141c0006a210020002001490440000b0b20000b3c01027f024042004200420084420084520440000b4200428001422088520440000b428001a72101200141c0006a210020002001490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100a411074210220022000411076100a7221010b20010b2401027e0240428001a7100bad42208621012001428001422088a7100bad8421000b20000b","wast":"(module +{"contracts":{"A":{"C":{"ewasm":{"wasm":"","wast":"(module ;; custom section for sub-module - ;; The Keccak-256 hash of the text representation of \"C_3_deployed\": d5523336521d49fa8bd64dba28ece7291aa7d45c646a23eabd038bbeecc2d803 - ;; (@custom \"C_3_deployed\" \"0061736d010000000112046000006000017f60017f017f60027f7f0002130108657468657265756d06726576657274000303060500010102020503010001060100071102066d656d6f72790200046d61696e00010ad20205a10104027f017e017f047e024010022100200041c0006a210120012000490440000b420021022002a7210320031005ad42208621042002422088210520042005a71005ad84210620012006370000200141086a2006370000200141106a2006370000428001a71005ad4220862107200141186a2007428001422088a71005ad8437000020022002200284200284520440000b20022005520440000b1003200310000b0b2b01017f024042004200420084420084520440000b420042c000422088520440000b42c000a721000b20000b4203017f017e017f02404200210120012001200184200184520440000b20012001422088520440000b2001a72102200241c0006a210020002002490440000b0b20000b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100441107421022002200041107610047221010b20010b\") + ;; The Keccak-256 hash of the text representation of + ;; (@custom \"C_3_deployed\" \"\") (import \"ethereum\" \"codeCopy\" (func $eth.codeCopy (param i32 i32 i32))) (import \"ethereum\" \"revert\" (func $eth.revert (param i32 i32))) (import \"ethereum\" \"getCallValue\" (func $eth.getCallValue (param i32))) diff --git a/test/cmdlineTests/standard_irOptimized_requested/output.json b/test/cmdlineTests/standard_irOptimized_requested/output.json index 85364f6d5..438793053 100644 --- a/test/cmdlineTests/standard_irOptimized_requested/output.json +++ b/test/cmdlineTests/standard_irOptimized_requested/output.json @@ -67,6 +67,7 @@ object \"C_7\" { function shift_right_224_unsigned(value) -> newValue { newValue := shr(224, value) } } + data \".metadata\" hex\"\" } } "}}},"sources":{"A":{"id":0}}} diff --git a/test/cmdlineTests/standard_ir_requested/output.json b/test/cmdlineTests/standard_ir_requested/output.json index edee7445e..bc5afb411 100644 --- a/test/cmdlineTests/standard_ir_requested/output.json +++ b/test/cmdlineTests/standard_ir_requested/output.json @@ -96,6 +96,7 @@ object \"C_7\" { } + data \".metadata\" hex\"\" } } diff --git a/test/cmdlineTests/standard_viair_requested/output.json b/test/cmdlineTests/standard_viair_requested/output.json index b09f39fa7..ca317a29b 100644 --- a/test/cmdlineTests/standard_viair_requested/output.json +++ b/test/cmdlineTests/standard_viair_requested/output.json @@ -62,6 +62,7 @@ object \"C_3\" { } + data \".metadata\" hex\"\" } } @@ -250,10 +251,12 @@ object \"D_16\" { } + data \".metadata\" hex\"\" } } + data \".metadata\" hex\"\" } } diff --git a/test/cmdlineTests/viair_abicoder_v1/output b/test/cmdlineTests/viair_abicoder_v1/output index 5c227b33f..c001c8bfe 100644 --- a/test/cmdlineTests/viair_abicoder_v1/output +++ b/test/cmdlineTests/viair_abicoder_v1/output @@ -117,6 +117,7 @@ object "test_11" { } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/viair_subobjects/output b/test/cmdlineTests/viair_subobjects/output index 3847e7df6..e025a6a83 100644 --- a/test/cmdlineTests/viair_subobjects/output +++ b/test/cmdlineTests/viair_subobjects/output @@ -1,9 +1,9 @@ ======= viair_subobjects/input.sol:C ======= Binary: -60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd + Binary of the runtime part: -608060405260006000fd + Optimized IR: /******************************************************* * WARNING * @@ -29,15 +29,16 @@ object "C_3" { revert(0, 0) } } + data ".metadata" hex"" } } ======= viair_subobjects/input.sol:D ======= Binary: -608060405234156100105760006000fd5b60ba80610020608039806080f350fe6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd + Binary of the runtime part: -6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd + Optimized IR: /******************************************************* * WARNING * @@ -105,7 +106,9 @@ object "D_16" { revert(0, 0) } } + data ".metadata" hex"" } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/yul_optimizer_steps/output b/test/cmdlineTests/yul_optimizer_steps/output index dee816447..10981782f 100644 --- a/test/cmdlineTests/yul_optimizer_steps/output +++ b/test/cmdlineTests/yul_optimizer_steps/output @@ -40,5 +40,6 @@ object "C_7" { function shift_right_unsigned(value) -> newValue { newValue := shr(224, value) } } + data ".metadata" hex"" } } diff --git a/test/cmdlineTests/yul_string_format_ascii/output.json b/test/cmdlineTests/yul_string_format_ascii/output.json index 379c14171..8e7ef86b0 100644 --- a/test/cmdlineTests/yul_string_format_ascii/output.json +++ b/test/cmdlineTests/yul_string_format_ascii/output.json @@ -195,6 +195,7 @@ object \"C_11\" { } + data \".metadata\" hex\"\" } } diff --git a/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json b/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json index 98e28617f..c6de505db 100644 --- a/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json @@ -119,6 +119,7 @@ object \"C_11\" { } + data \".metadata\" hex\"\" } } diff --git a/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json b/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json index 7226bfa95..c4b747f3d 100644 --- a/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json @@ -131,6 +131,7 @@ object \"C_11\" { } + data \".metadata\" hex\"\" } } diff --git a/test/cmdlineTests/yul_string_format_ascii_long/output.json b/test/cmdlineTests/yul_string_format_ascii_long/output.json index 6ad20e86b..fe60dc52f 100644 --- a/test/cmdlineTests/yul_string_format_ascii_long/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_long/output.json @@ -199,6 +199,7 @@ object \"C_11\" { } + data \".metadata\" hex\"\" } } diff --git a/test/cmdlineTests/yul_string_format_hex/output.json b/test/cmdlineTests/yul_string_format_hex/output.json index dc8a2a67c..0e2851bad 100644 --- a/test/cmdlineTests/yul_string_format_hex/output.json +++ b/test/cmdlineTests/yul_string_format_hex/output.json @@ -131,6 +131,7 @@ object \"C_11\" { } + data \".metadata\" hex\"\" } } diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index a79e773b9..5e260b14d 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -97,8 +97,8 @@ BOOST_AUTO_TEST_CASE(all_assembly_items) _assembly.appendImmutableAssignment("someImmutable"); // Operation _assembly.append(Instruction::STOP); - _assembly.appendAuxiliaryDataToEnd(bytes{0x42, 0x66}); - _assembly.appendAuxiliaryDataToEnd(bytes{0xee, 0xaa}); + _assembly.appendToAuxiliaryData(bytes{0x42, 0x66}); + _assembly.appendToAuxiliaryData(bytes{0xee, 0xaa}); checkCompilation(_assembly); diff --git a/test/libyul/objectCompiler/metadata.yul b/test/libyul/objectCompiler/metadata.yul new file mode 100644 index 000000000..8f3b087a3 --- /dev/null +++ b/test/libyul/objectCompiler/metadata.yul @@ -0,0 +1,39 @@ +object "A" { + code { + pop(datasize("x")) + pop(datasize("C")) + } + + object "B" { + code { pop(dataoffset("other")) } + data ".metadata" "M1" + data "other" "Hello, World2!" + } + + data "C" "ABC" + data ".metadata" "M2" + data "x" "Hello, World2!" +} +// ---- +// Assembly: +// /* "source":26:44 */ +// pop(0x0e) +// /* "source":49:67 */ +// pop(0x03) +// stop +// data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 48656c6c6f2c20576f726c643221 +// data_e1629b9dda060bb30c7908346f6af189c16773fa148d3366701fbaa35d54f3c8 414243 +// +// sub_0: assembly { +// /* "source":99:123 */ +// pop(data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336) +// stop +// data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 48656c6c6f2c20576f726c643221 +// +// auxdata: 0x4d31 +// } +// +// auxdata: 0x4d32 +// Bytecode: 600e50600350fe4d32 +// Opcodes: PUSH1 0xE POP PUSH1 0x3 POP INVALID 0x4D ORIGIN +// SourceMappings: 26:18:0:-:0;;49; diff --git a/test/libyul/yulSyntaxTests/metadata_access.yul b/test/libyul/yulSyntaxTests/metadata_access.yul new file mode 100644 index 000000000..63aeb4760 --- /dev/null +++ b/test/libyul/yulSyntaxTests/metadata_access.yul @@ -0,0 +1,32 @@ +object "A" { + code { + pop(dataoffset(".other")) + pop(datasize(".other")) + pop(datasize("B..other")) + // "B.other" does not exist. + pop(datasize("B.other")) + // ".metadata" is not accessible by definition + pop(dataoffset(".metadata")) + pop(datasize(".metadata")) + pop(dataoffset("B..metadata")) + pop(datasize("B..metadata")) + } + + object "B" { + code {} + data ".metadata" "Hello, World!" + data ".other" "Hello, World2!" + } + + data ".metadata" "Hello, World!" + data ".other" "Hello, World2!" +} +// ---- +// TypeError 3517: (41-49): Unknown data object ".other". +// TypeError 3517: (69-77): Unknown data object ".other". +// TypeError 3517: (97-107): Unknown data object "B..other". +// TypeError 3517: (160-169): Unknown data object "B.other". +// TypeError 3517: (242-253): Unknown data object ".metadata". +// TypeError 3517: (273-284): Unknown data object ".metadata". +// TypeError 3517: (306-319): Unknown data object "B..metadata". +// TypeError 3517: (339-352): Unknown data object "B..metadata". diff --git a/test/libyul/yulSyntaxTests/metadata_access_2.yul b/test/libyul/yulSyntaxTests/metadata_access_2.yul new file mode 100644 index 000000000..a4b013e85 --- /dev/null +++ b/test/libyul/yulSyntaxTests/metadata_access_2.yul @@ -0,0 +1,13 @@ +object "A" { + code { + sstore(dataoffset("0"), dataoffset("1")) + sstore(0, datasize(".mightbereservedinthefuture")) + } + + data "0" "UVW" + data ".metadata" "ABC" + data "1" "XYZ" + data ".mightbereservedinthefuture" "TRS" +} +// ---- +// TypeError 3517: (90-119): Unknown data object ".mightbereservedinthefuture". diff --git a/test/libyul/yulSyntaxTests/metadata_access_subobject.yul b/test/libyul/yulSyntaxTests/metadata_access_subobject.yul new file mode 100644 index 000000000..216b56ac6 --- /dev/null +++ b/test/libyul/yulSyntaxTests/metadata_access_subobject.yul @@ -0,0 +1,12 @@ +object "A" { + code { + sstore(dataoffset(".metadata.x"), 0) + } + + object ".metadata" { + code {} + data "x" "ABC" + } +} +// ---- +// TypeError 3517: (41-54): Unknown data object ".metadata.x".