Report infinite gas for calls.

This commit is contained in:
chriseth 2016-11-14 16:02:57 +01:00
parent 68e7763387
commit c2c39239d6

View File

@ -128,24 +128,28 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item)
case Instruction::CALLCODE: case Instruction::CALLCODE:
case Instruction::DELEGATECALL: case Instruction::DELEGATECALL:
{ {
gas = GasCosts::callGas; // We assume that we do not know the target contract and thus, the consumption is infinite.
if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(0)))
gas += (*value);
else
gas = GasConsumption::infinite(); gas = GasConsumption::infinite();
if (_item.instruction() == Instruction::CALL) // gas = GasCosts::callGas;
gas += GasCosts::callNewAccountGas; // We very rarely know whether the address exists. // if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(0)))
int valueSize = _item.instruction() == Instruction::DELEGATECALL ? 0 : 1; // gas += (*value);
if (!classes.knownZero(m_state->relativeStackElement(-1 - valueSize))) // else
gas += GasCosts::callValueTransferGas; // gas = GasConsumption::infinite();
gas += memoryGas(-2 - valueSize, -3 - valueSize); // if (_item.instruction() == Instruction::CALL)
gas += memoryGas(-4 - valueSize, -5 - valueSize); // gas += GasCosts::callNewAccountGas; // We very rarely know whether the address exists.
// int valueSize = _item.instruction() == Instruction::DELEGATECALL ? 0 : 1;
// if (!classes.knownZero(m_state->relativeStackElement(-1 - valueSize)))
// gas += GasCosts::callValueTransferGas;
// gas += memoryGas(-2 - valueSize, -3 - valueSize);
// gas += memoryGas(-4 - valueSize, -5 - valueSize);
break; break;
} }
case Instruction::CREATE: case Instruction::CREATE:
gas = GasCosts::createGas; // We assume that we do not know the target contract and thus, the consumption is infinite.
gas += memoryGas(-1, -2); // gas = GasConsumption::infinite();
break; // gas = GasCosts::createGas;
// gas += memoryGas(-1, -2);
// break;
case Instruction::EXP: case Instruction::EXP:
gas = GasCosts::expGas; gas = GasCosts::expGas;
if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(-1))) if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(-1)))