aboutsummaryrefslogtreecommitdiffstats
path: root/Compiler.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-06 06:45:47 +0800
committerchriseth <c@ethdev.com>2015-06-06 06:45:47 +0800
commitb51ef4a357b4b60fc01038b0e97280fb9ecca01e (patch)
tree729b53241b687f435209b6f45d3aa3b0faf5dce9 /Compiler.cpp
parent779e793d60f2076fbd35b34f0c2073e92c058eef (diff)
parent651d755e562dc8b5bc12e42b0b808ff1046f5d43 (diff)
downloaddexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.tar
dexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.tar.gz
dexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.tar.bz2
dexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.tar.lz
dexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.tar.xz
dexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.tar.zst
dexon-solidity-b51ef4a357b4b60fc01038b0e97280fb9ecca01e.zip
Merge pull request #2096 from chriseth/sol_constantFallback
Fallback takes constant amount of gas, and send no gas with send.
Diffstat (limited to 'Compiler.cpp')
-rw-r--r--Compiler.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/Compiler.cpp b/Compiler.cpp
index 6dc72840..40ed1fd8 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -178,6 +178,16 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
map<FixedHash<4>, FunctionTypePointer> interfaceFunctions = _contract.getInterfaceFunctions();
map<FixedHash<4>, const eth::AssemblyItem> callDataUnpackerEntryPoints;
+ FunctionDefinition const* fallback = _contract.getFallbackFunction();
+ eth::AssemblyItem notFound = m_context.newTag();
+ // shortcut messages without data if we have many functions in order to be able to receive
+ // ether with constant gas
+ if (interfaceFunctions.size() > 5 || fallback)
+ {
+ m_context << eth::Instruction::CALLDATASIZE << eth::Instruction::ISZERO;
+ m_context.appendConditionalJumpTo(notFound);
+ }
+
// retrieve the function signature hash from the calldata
if (!interfaceFunctions.empty())
CompilerUtils(m_context).loadFromMemory(0, IntegerType(CompilerUtils::dataStartOffset * 8), true);
@@ -189,7 +199,10 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
m_context << eth::dupInstruction(1) << u256(FixedHash<4>::Arith(it.first)) << eth::Instruction::EQ;
m_context.appendConditionalJumpTo(callDataUnpackerEntryPoints.at(it.first));
}
- if (FunctionDefinition const* fallback = _contract.getFallbackFunction())
+ m_context.appendJumpTo(notFound);
+
+ m_context << notFound;
+ if (fallback)
{
eth::AssemblyItem returnTag = m_context.pushNewTag();
fallback->accept(*this);
@@ -198,6 +211,7 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
}
else
m_context << eth::Instruction::STOP; // function not found
+
for (auto const& it: interfaceFunctions)
{
FunctionTypePointer const& functionType = it.second;