mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fallback takes constant amount of gas, and send to gas with send.
This commit is contained in:
parent
92eb04c6ec
commit
6667c67364
16
Compiler.cpp
16
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;
|
||||
|
@ -521,6 +521,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
break;
|
||||
case Location::Send:
|
||||
_functionCall.getExpression().accept(*this);
|
||||
m_context << u256(0); // do not send gas (there still is the stipend)
|
||||
arguments.front()->accept(*this);
|
||||
appendTypeConversion(*arguments.front()->getType(),
|
||||
*function.getParameterTypes().front(), true);
|
||||
@ -532,7 +533,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
strings(),
|
||||
Location::Bare,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true
|
||||
),
|
||||
{}
|
||||
|
Loading…
Reference in New Issue
Block a user