aboutsummaryrefslogtreecommitdiffstats
path: root/Compiler.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-05 18:25:10 +0800
committerchriseth <c@ethdev.com>2015-06-05 23:37:16 +0800
commit6667c6736483b2ff9855b9b9a9147a9703a188d2 (patch)
treecec6ff162287cc7c6b7e8582b49842a782f83dab /Compiler.cpp
parent92eb04c6eccba8b6d7c5c02e5ca2084d9e4fecf6 (diff)
downloaddexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.tar
dexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.tar.gz
dexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.tar.bz2
dexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.tar.lz
dexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.tar.xz
dexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.tar.zst
dexon-solidity-6667c6736483b2ff9855b9b9a9147a9703a188d2.zip
Fallback takes constant amount of gas, and send to 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 6425367d..5398ed71 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -174,6 +174,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);
@@ -185,7 +195,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);
@@ -194,6 +207,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;