Browse Source

Stack limit.

cl-refactor
Gav Wood 10 years ago
parent
commit
15f236282a
  1. 1
      libethcore/Params.cpp
  2. 1
      libethcore/Params.h
  3. 2
      libethereum/Transaction.cpp
  4. 1
      libethereum/Transaction.h
  5. 36
      libevm/VM.cpp
  6. 1
      libevm/VMFace.h

1
libethcore/Params.cpp

@ -37,6 +37,7 @@ u256 const c_gasLimitBoundDivisor = 1024;
u256 const c_minimumDifficulty = 131072; u256 const c_minimumDifficulty = 131072;
u256 const c_difficultyBoundDivisor = 2048; u256 const c_difficultyBoundDivisor = 2048;
u256 const c_durationLimit = 8; u256 const c_durationLimit = 8;
u256 const c_stackLimit = 1024;
u256 const c_tierStepGas[] = {0, 2, 3, 5, 8, 10, 20, 0}; u256 const c_tierStepGas[] = {0, 2, 3, 5, 8, 10, 20, 0};
u256 const c_expGas = 10; u256 const c_expGas = 10;
u256 const c_expByteGas = 10; u256 const c_expByteGas = 10;

1
libethcore/Params.h

@ -38,6 +38,7 @@ extern u256 const c_gasLimitBoundDivisor;
extern u256 const c_minimumDifficulty; extern u256 const c_minimumDifficulty;
extern u256 const c_difficultyBoundDivisor; extern u256 const c_difficultyBoundDivisor;
extern u256 const c_durationLimit; extern u256 const c_durationLimit;
extern u256 const c_stackLimit;
extern u256 const c_tierStepGas[8]; ///< Once per operation, for a selection of them. extern u256 const c_tierStepGas[8]; ///< Once per operation, for a selection of them.
extern u256 const c_expGas; ///< Once per EXP instuction. extern u256 const c_expGas; ///< Once per EXP instuction.

2
libethereum/Transaction.cpp

@ -46,6 +46,8 @@ TransactionException dev::eth::toTransactionException(VMException const& _e)
return TransactionException::BadJumpDestination; return TransactionException::BadJumpDestination;
if (!!dynamic_cast<OutOfGas const*>(&_e)) if (!!dynamic_cast<OutOfGas const*>(&_e))
return TransactionException::OutOfGas; return TransactionException::OutOfGas;
if (!!dynamic_cast<OutOfStack const*>(&_e))
return TransactionException::OutOfStack;
if (!!dynamic_cast<StackUnderflow const*>(&_e)) if (!!dynamic_cast<StackUnderflow const*>(&_e))
return TransactionException::StackUnderflow; return TransactionException::StackUnderflow;
return TransactionException::Unknown; return TransactionException::Unknown;

1
libethereum/Transaction.h

@ -56,6 +56,7 @@ enum class TransactionException
BadInstruction, BadInstruction,
BadJumpDestination, BadJumpDestination,
OutOfGas, ///< Ran out of gas executing code of the transaction. OutOfGas, ///< Ran out of gas executing code of the transaction.
OutOfStack, ///< Ran out of stack executing code of the transaction.
StackUnderflow StackUnderflow
}; };

36
libevm/VM.cpp

@ -52,6 +52,8 @@ static array<InstructionMetric, 256> metrics()
bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{ {
m_stack.reserve((unsigned)c_stackLimit);
static const array<InstructionMetric, 256> c_metrics = metrics(); static const array<InstructionMetric, 256> c_metrics = metrics();
auto memNeed = [](u256 _offset, dev::u256 _size) { return _size ? (bigint)_offset + _size : (bigint)0; }; auto memNeed = [](u256 _offset, dev::u256 _size) { return _size ? (bigint)_offset + _size : (bigint)0; };
@ -183,6 +185,40 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
runGas = c_expGas + c_expByteGas * (32 - (h256(expon).firstBitSet() / 8)); runGas = c_expGas + c_expByteGas * (32 - (h256(expon).firstBitSet() / 8));
break; break;
} }
case Instruction::PUSH1:
case Instruction::PUSH2:
case Instruction::PUSH3:
case Instruction::PUSH4:
case Instruction::PUSH5:
case Instruction::PUSH6:
case Instruction::PUSH7:
case Instruction::PUSH8:
case Instruction::PUSH9:
case Instruction::PUSH10:
case Instruction::PUSH11:
case Instruction::PUSH12:
case Instruction::PUSH13:
case Instruction::PUSH14:
case Instruction::PUSH15:
case Instruction::PUSH16:
case Instruction::PUSH17:
case Instruction::PUSH18:
case Instruction::PUSH19:
case Instruction::PUSH20:
case Instruction::PUSH21:
case Instruction::PUSH22:
case Instruction::PUSH23:
case Instruction::PUSH24:
case Instruction::PUSH25:
case Instruction::PUSH26:
case Instruction::PUSH27:
case Instruction::PUSH28:
case Instruction::PUSH29:
case Instruction::PUSH30:
case Instruction::PUSH31:
case Instruction::PUSH32:
if (m_stack.size() > c_stackLimit)
BOOST_THROW_EXCEPTION(OutOfStack());
default:; default:;
} }

1
libevm/VMFace.h

@ -31,6 +31,7 @@ struct BreakPointHit: virtual VMException {};
struct BadInstruction: virtual VMException {}; struct BadInstruction: virtual VMException {};
struct BadJumpDestination: virtual VMException {}; struct BadJumpDestination: virtual VMException {};
struct OutOfGas: virtual VMException {}; struct OutOfGas: virtual VMException {};
struct OutOfStack: virtual VMException {};
struct StackUnderflow: virtual VMException {}; struct StackUnderflow: virtual VMException {};
/// EVM Virtual Machine interface /// EVM Virtual Machine interface

Loading…
Cancel
Save