diff options
author | chriseth <chris@ethereum.org> | 2016-11-15 18:32:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-15 18:32:42 +0800 |
commit | 634b0998ba5a6b5d655dd86614da679fb51109d7 (patch) | |
tree | 4fbf14115e317f0a3b641a62ad039e8977242b7a /libevmasm/GasMeter.cpp | |
parent | 1208279914f313f62cd57b0b36245eadff0b3f44 (diff) | |
parent | bf5b0dc2d27a3c4139894daf627cf63b8cfb1864 (diff) | |
download | dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.tar dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.tar.gz dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.tar.bz2 dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.tar.lz dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.tar.xz dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.tar.zst dexon-solidity-634b0998ba5a6b5d655dd86614da679fb51109d7.zip |
Merge pull request #1369 from ethereum/callcosts
Report infinite gas for calls.
Diffstat (limited to 'libevmasm/GasMeter.cpp')
-rw-r--r-- | libevmasm/GasMeter.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp index 51f3cf1d..da8b41e3 100644 --- a/libevmasm/GasMeter.cpp +++ b/libevmasm/GasMeter.cpp @@ -39,7 +39,7 @@ GasMeter::GasConsumption& GasMeter::GasConsumption::operator+=(GasConsumption co return *this; } -GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item) +GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _includeExternalCosts) { GasConsumption gas; switch (_item.type()) @@ -128,23 +128,35 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item) case Instruction::CALLCODE: case Instruction::DELEGATECALL: { - gas = GasCosts::callGas; - if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(0))) - gas += (*value); - else + if (_includeExternalCosts) + // We assume that we do not know the target contract and thus, the consumption is infinite. gas = GasConsumption::infinite(); - if (_item.instruction() == Instruction::CALL) - 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); + else + { + gas = GasCosts::callGas; + if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(0))) + gas += (*value); + else + gas = GasConsumption::infinite(); + if (_item.instruction() == Instruction::CALL) + 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; } case Instruction::CREATE: - gas = GasCosts::createGas; - gas += memoryGas(-1, -2); + if (_includeExternalCosts) + // We assume that we do not know the target contract and thus, the consumption is infinite. + gas = GasConsumption::infinite(); + else + { + gas = GasCosts::createGas; + gas += memoryGas(-1, -2); + } break; case Instruction::EXP: gas = GasCosts::expGas; |