From 5789eaa78d0e00f6289101e02f7de5e9decdc7e5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 14 Nov 2016 11:46:43 +0100 Subject: Metadata stamp. --- libsolidity/codegen/Compiler.cpp | 10 ++++------ libsolidity/codegen/Compiler.h | 3 ++- libsolidity/codegen/CompilerContext.cpp | 7 +++++++ libsolidity/codegen/CompilerContext.h | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index 22d25698..168e9462 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -30,7 +30,8 @@ using namespace dev::solidity; void Compiler::compileContract( ContractDefinition const& _contract, - std::map const& _contracts + std::map const& _contracts, + h256 const& _metadataHash ) { ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize); @@ -43,11 +44,8 @@ void Compiler::compileContract( m_context.optimise(m_optimize, m_optimizeRuns); - if (_contract.isLibrary()) - { - solAssert(m_runtimeSub != size_t(-1), ""); - m_context.injectVersionStampIntoSub(m_runtimeSub); - } + solAssert(m_runtimeSub != size_t(-1), ""); + m_context.injectMetadataHashIntoSub(m_runtimeSub, _metadataHash); } void Compiler::compileClone( diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index c8bf7861..58ef1963 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -42,7 +42,8 @@ public: void compileContract( ContractDefinition const& _contract, - std::map const& _contracts + std::map const& _contracts, + h256 const& _metadataHash ); /// Compiles a contract that uses DELEGATECALL to call into a pre-deployed version of the given /// contract at runtime, but contains the full creation-time code. diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index b99b0548..9b921e9d 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -227,6 +227,13 @@ void CompilerContext::injectVersionStampIntoSub(size_t _subIndex) sub.injectStart(fromBigEndian(binaryVersion())); } +void CompilerContext::injectMetadataHashIntoSub(size_t _subIndex, h256 const& _metadataHash) +{ + eth::Assembly& sub = m_asm->sub(_subIndex); + sub.injectStart(Instruction::POP); + sub.injectStart(u256(_metadataHash)); +} + FunctionDefinition const& CompilerContext::resolveVirtualFunction( FunctionDefinition const& _function, vector::const_iterator _searchStart diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 3c6d9d73..c8a35f93 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -155,6 +155,9 @@ public: /// Prepends "PUSH POP" void injectVersionStampIntoSub(size_t _subIndex); + /// Prepends "PUSH POP" + void injectMetadataHashIntoSub(size_t _subIndex, h256 const& _metadataHash); + void optimise(bool _fullOptimsation, unsigned _runs = 200) { m_asm->optimise(_fullOptimsation, true, _runs); } /// @returns the runtime context if in creation mode and runtime context is set, nullptr otherwise. -- cgit From 91ecc4533dffbe67fa27adfaff27780ddf69c21a Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 24 Nov 2016 10:32:52 +0100 Subject: Add swarm hash to the end of the bytecode. --- libsolidity/codegen/Compiler.cpp | 4 +--- libsolidity/codegen/CompilerContext.cpp | 7 ------- libsolidity/codegen/CompilerContext.h | 4 ++-- 3 files changed, 3 insertions(+), 12 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index 168e9462..b7e0cc64 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -36,6 +36,7 @@ void Compiler::compileContract( { ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize); runtimeCompiler.compileContract(_contract, _contracts); + m_runtimeContext.appendAuxiliaryData(_metadataHash.asBytes()); // This might modify m_runtimeContext because it can access runtime functions at // creation time. @@ -43,9 +44,6 @@ void Compiler::compileContract( m_runtimeSub = creationCompiler.compileConstructor(_contract, _contracts); m_context.optimise(m_optimize, m_optimizeRuns); - - solAssert(m_runtimeSub != size_t(-1), ""); - m_context.injectMetadataHashIntoSub(m_runtimeSub, _metadataHash); } void Compiler::compileClone( diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 9b921e9d..b99b0548 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -227,13 +227,6 @@ void CompilerContext::injectVersionStampIntoSub(size_t _subIndex) sub.injectStart(fromBigEndian(binaryVersion())); } -void CompilerContext::injectMetadataHashIntoSub(size_t _subIndex, h256 const& _metadataHash) -{ - eth::Assembly& sub = m_asm->sub(_subIndex); - sub.injectStart(Instruction::POP); - sub.injectStart(u256(_metadataHash)); -} - FunctionDefinition const& CompilerContext::resolveVirtualFunction( FunctionDefinition const& _function, vector::const_iterator _searchStart diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index c8a35f93..8fdb3e03 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -155,8 +155,8 @@ public: /// Prepends "PUSH POP" void injectVersionStampIntoSub(size_t _subIndex); - /// Prepends "PUSH POP" - void injectMetadataHashIntoSub(size_t _subIndex, h256 const& _metadataHash); + /// Appends arbitrary data to the end of the bytecode. + void appendAuxiliaryData(bytes const& _data) { m_asm->appendAuxiliaryDataToEnd(_data); } void optimise(bool _fullOptimsation, unsigned _runs = 200) { m_asm->optimise(_fullOptimsation, true, _runs); } -- cgit From 1e35526eb6a7c5af074170f6291491d3cb0bd6ba Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 24 Nov 2016 12:32:42 +0100 Subject: Fix tests. --- libsolidity/codegen/CompilerContext.cpp | 7 ------- libsolidity/codegen/CompilerContext.h | 3 --- 2 files changed, 10 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index b99b0548..2de5a3ec 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -220,13 +220,6 @@ void CompilerContext::appendInlineAssembly( solAssert(assembly::InlineAssemblyStack().parseAndAssemble(*assembly, *m_asm, identifierAccess), ""); } -void CompilerContext::injectVersionStampIntoSub(size_t _subIndex) -{ - eth::Assembly& sub = m_asm->sub(_subIndex); - sub.injectStart(Instruction::POP); - sub.injectStart(fromBigEndian(binaryVersion())); -} - FunctionDefinition const& CompilerContext::resolveVirtualFunction( FunctionDefinition const& _function, vector::const_iterator _searchStart diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 8fdb3e03..80671528 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -152,9 +152,6 @@ public: std::map const& _replacements = std::map{} ); - /// Prepends "PUSH POP" - void injectVersionStampIntoSub(size_t _subIndex); - /// Appends arbitrary data to the end of the bytecode. void appendAuxiliaryData(bytes const& _data) { m_asm->appendAuxiliaryDataToEnd(_data); } -- cgit From 6a7ff039df15be59fbb71dc3dfaad09fb0b8961f Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 29 Nov 2016 17:47:47 +0100 Subject: Use CBOR encoding. --- libsolidity/codegen/Compiler.cpp | 4 ++-- libsolidity/codegen/Compiler.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index b7e0cc64..44264a07 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -31,12 +31,12 @@ using namespace dev::solidity; void Compiler::compileContract( ContractDefinition const& _contract, std::map const& _contracts, - h256 const& _metadataHash + bytes const& _metadata ) { ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimize); runtimeCompiler.compileContract(_contract, _contracts); - m_runtimeContext.appendAuxiliaryData(_metadataHash.asBytes()); + m_runtimeContext.appendAuxiliaryData(_metadata); // This might modify m_runtimeContext because it can access runtime functions at // creation time. diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index 58ef1963..eef078c1 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -43,7 +43,7 @@ public: void compileContract( ContractDefinition const& _contract, std::map const& _contracts, - h256 const& _metadataHash + bytes const& _metadata ); /// Compiles a contract that uses DELEGATECALL to call into a pre-deployed version of the given /// contract at runtime, but contains the full creation-time code. -- cgit