Browse Source

Prevent integer overflow in some gas calculations

cl-refactor
Paweł Bylica 10 years ago
parent
commit
465e682dc6
  1. 2
      libethereum/Executive.cpp
  2. 2
      libethereum/Interface.h
  3. 4
      libevm/VM.h

2
libethereum/Executive.cpp

@ -66,7 +66,7 @@ bool Executive::setup(bytesConstRef _rlp)
}
// Check gas cost is enough.
u256 gasCost = m_t.data.size() * c_txDataGas + c_txGas;
u256 gasCost = u256(m_t.data.size()) * c_txDataGas + c_txGas;
if (m_t.gas < gasCost)
{

2
libethereum/Interface.h

@ -123,7 +123,7 @@ public:
virtual Addresses addresses(int _block) const = 0;
/// Get the fee associated for a transaction with the given data.
static u256 txGas(unsigned _dataCount, u256 _gas = 0) { return c_txDataGas * _dataCount + c_txGas + _gas; }
static u256 txGas(unsigned _dataCount, u256 _gas = 0) { return u256(c_txDataGas) * _dataCount + c_txGas + _gas; }
/// Get the remaining gas limit in this block.
virtual u256 gasLimitRemaining() const = 0;

4
libevm/VM.h

@ -168,13 +168,13 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
case Instruction::CALL:
require(7);
runGas = c_callGas + m_stack[m_stack.size() - 1];
runGas = bigint(c_callGas) + m_stack[m_stack.size() - 1];
newTempSize = std::max(memNeed(m_stack[m_stack.size() - 6], m_stack[m_stack.size() - 7]), memNeed(m_stack[m_stack.size() - 4], m_stack[m_stack.size() - 5]));
break;
case Instruction::CALLCODE:
require(7);
runGas = c_callGas + m_stack[m_stack.size() - 1];
runGas = bigint(c_callGas) + m_stack[m_stack.size() - 1];
newTempSize = std::max(memNeed(m_stack[m_stack.size() - 6], m_stack[m_stack.size() - 7]), memNeed(m_stack[m_stack.size() - 4], m_stack[m_stack.size() - 5]));
break;

Loading…
Cancel
Save