diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 07:27:26 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-01-09 07:27:26 +0800 |
commit | 9cf1c066fce4909e2ce2adebc713beef941508c6 (patch) | |
tree | 76388826ae2af11d4023bf82672668d69e720db5 /Compiler.cpp | |
parent | a7b661d3be53b4c6a05401782ab8f90202a4f776 (diff) | |
download | dexon-solidity-9cf1c066fce4909e2ce2adebc713beef941508c6.tar.gz dexon-solidity-9cf1c066fce4909e2ce2adebc713beef941508c6.tar.zst dexon-solidity-9cf1c066fce4909e2ce2adebc713beef941508c6.zip |
Adjustments to Solidity compiler code for Function Hash
Diffstat (limited to 'Compiler.cpp')
-rw-r--r-- | Compiler.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index d49807be..4e5b7f55 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -100,7 +100,7 @@ void Compiler::appendConstructorCall(FunctionDefinition const& _constructor) { m_context << u256(argumentSize); m_context.appendProgramSize(); - m_context << u256(g_functionIdentifierOffset); // copy it to byte four as expected for ABI calls + m_context << u256(CompilerUtils::dataStartOffset); // copy it to byte four as expected for ABI calls m_context << eth::Instruction::CODECOPY; appendCalldataUnpacker(_constructor, true); } @@ -119,30 +119,26 @@ set<FunctionDefinition const*> Compiler::getFunctionsNeededByConstructor(Functio void Compiler::appendFunctionSelector(ContractDefinition const& _contract) { map<FixedHash<4>, FunctionDefinition const*> interfaceFunctions = _contract.getInterfaceFunctions(); - vector<eth::AssemblyItem> callDataUnpackerEntryPoints; - - if (interfaceFunctions.size() > 4294967295) // 2 ** 32 - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("More than 4294967295 public functions for contract.")); + map<FixedHash<4>, const eth::AssemblyItem> callDataUnpackerEntryPoints; // retrieve the function signature hash from the calldata - m_context << u256(1) << u256(0) << (u256(1) << 224) // some constants - << eth::dupInstruction(2) << eth::Instruction::CALLDATALOAD - << eth::Instruction::DIV; + m_context << u256(1) << u256(0); + CompilerUtils(m_context).loadFromMemory(0, 4, false, true); // stack now is: 1 0 <funhash> - for (auto it = interfaceFunctions.cbegin(); it != interfaceFunctions.cend(); ++it) + // for (auto it = interfaceFunctions.cbegin(); it != interfaceFunctions.cend(); ++it) + for (auto const& it: interfaceFunctions) { - callDataUnpackerEntryPoints.push_back(m_context.newTag()); - m_context << eth::dupInstruction(1) << u256(FixedHash<4>::Arith(it->first)) << eth::Instruction::EQ; - m_context.appendConditionalJumpTo(callDataUnpackerEntryPoints.back()); + callDataUnpackerEntryPoints.insert(std::make_pair(it.first, m_context.newTag())); + m_context << eth::dupInstruction(1) << u256(FixedHash<4>::Arith(it.first)) << eth::Instruction::EQ; + m_context.appendConditionalJumpTo(callDataUnpackerEntryPoints.at(it.first)); } m_context << eth::Instruction::STOP; // function not found - unsigned funid = 0; - for (auto it = interfaceFunctions.cbegin(); it != interfaceFunctions.cend(); ++it, ++funid) + for (auto const& it: interfaceFunctions) { - FunctionDefinition const& function = *it->second; - m_context << callDataUnpackerEntryPoints[funid]; + FunctionDefinition const& function = *it.second; + m_context << callDataUnpackerEntryPoints.at(it.first); eth::AssemblyItem returnTag = m_context.pushNewTag(); appendCalldataUnpacker(function); m_context.appendJumpTo(m_context.getFunctionEntryLabel(function)); @@ -154,7 +150,7 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract) unsigned Compiler::appendCalldataUnpacker(FunctionDefinition const& _function, bool _fromMemory) { // We do not check the calldata size, everything is zero-padded. - unsigned dataOffset = g_functionIdentifierOffset; // the 4 bytes of the function hash signature + unsigned dataOffset = CompilerUtils::dataStartOffset; // the 4 bytes of the function hash signature //@todo this can be done more efficiently, saving some CALLDATALOAD calls for (ASTPointer<VariableDeclaration> const& var: _function.getParameters()) { |