Keep old code.

This commit is contained in:
chriseth 2016-11-14 23:28:26 +01:00
parent c2c39239d6
commit bf5b0dc2d2
2 changed files with 30 additions and 21 deletions

View File

@ -39,7 +39,7 @@ GasMeter::GasConsumption& GasMeter::GasConsumption::operator+=(GasConsumption co
return *this; return *this;
} }
GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item) GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _includeExternalCosts)
{ {
GasConsumption gas; GasConsumption gas;
switch (_item.type()) switch (_item.type())
@ -128,28 +128,36 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item)
case Instruction::CALLCODE: case Instruction::CALLCODE:
case Instruction::DELEGATECALL: case Instruction::DELEGATECALL:
{ {
// We assume that we do not know the target contract and thus, the consumption is infinite. if (_includeExternalCosts)
gas = GasConsumption::infinite(); // We assume that we do not know the target contract and thus, the consumption is infinite.
// gas = GasCosts::callGas; gas = GasConsumption::infinite();
// if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(0))) else
// gas += (*value); {
// else gas = GasCosts::callGas;
// gas = GasConsumption::infinite(); if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(0)))
// if (_item.instruction() == Instruction::CALL) gas += (*value);
// gas += GasCosts::callNewAccountGas; // We very rarely know whether the address exists. else
// int valueSize = _item.instruction() == Instruction::DELEGATECALL ? 0 : 1; gas = GasConsumption::infinite();
// if (!classes.knownZero(m_state->relativeStackElement(-1 - valueSize))) if (_item.instruction() == Instruction::CALL)
// gas += GasCosts::callValueTransferGas; gas += GasCosts::callNewAccountGas; // We very rarely know whether the address exists.
// gas += memoryGas(-2 - valueSize, -3 - valueSize); int valueSize = _item.instruction() == Instruction::DELEGATECALL ? 0 : 1;
// gas += memoryGas(-4 - valueSize, -5 - valueSize); 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:
// We assume that we do not know the target contract and thus, the consumption is infinite. if (_includeExternalCosts)
// gas = GasConsumption::infinite(); // We assume that we do not know the target contract and thus, the consumption is infinite.
// gas = GasCosts::createGas; gas = GasConsumption::infinite();
// gas += memoryGas(-1, -2); else
// 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)))

View File

@ -102,7 +102,8 @@ public:
/// @returns an upper bound on the gas consumed by the given instruction and updates /// @returns an upper bound on the gas consumed by the given instruction and updates
/// the state. /// the state.
GasConsumption estimateMax(AssemblyItem const& _item); /// @param _inculdeExternalCosts if true, include costs caused by other contracts in calls.
GasConsumption estimateMax(AssemblyItem const& _item, bool _includeExternalCosts = true);
u256 const& largestMemoryAccess() const { return m_largestMemoryAccess; } u256 const& largestMemoryAccess() const { return m_largestMemoryAccess; }