Max callstack

This commit is contained in:
obscuren 2014-10-11 00:41:37 +02:00
parent cb845b9bc8
commit 2e894b668a
2 changed files with 11 additions and 4 deletions

View File

@ -348,7 +348,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block {
return block return block
} }
func (block *Block) Trie() *ethrie.Trie { func (block *Block) Trie() *ethtrie.Trie {
return block.state.Trie return block.state.Trie
} }

View File

@ -12,6 +12,8 @@ import (
// Shortcut :-) // Shortcut :-)
var To256 = ethutil.To256 var To256 = ethutil.To256
const MaxCallDepth = 1024
type Debugger interface { type Debugger interface {
BreakHook(step int, op OpCode, mem *Memory, stack *Stack, object *ethstate.StateObject) bool BreakHook(step int, op OpCode, mem *Memory, stack *Stack, object *ethstate.StateObject) bool
StepHook(step int, op OpCode, mem *Memory, stack *Stack, object *ethstate.StateObject) bool StepHook(step int, op OpCode, mem *Memory, stack *Stack, object *ethstate.StateObject) bool
@ -37,6 +39,8 @@ type Vm struct {
Fn string Fn string
Recoverable bool Recoverable bool
depth int
} }
type Environment interface { type Environment interface {
@ -80,6 +84,8 @@ func u256(n int64) *big.Int {
} }
func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
self.depth++
if self.Recoverable { if self.Recoverable {
// Recover from any require exception // Recover from any require exception
defer func() { defer func() {
@ -766,9 +772,6 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Generate a new address // Generate a new address
addr := ethcrypto.CreateAddress(closure.Address(), closure.object.Nonce) addr := ethcrypto.CreateAddress(closure.Address(), closure.object.Nonce)
//for i := uint64(0); self.env.State().GetStateObject(addr) != nil; i++ {
// ethcrypto.CreateAddress(closure.Address(), closure.object.Nonce+i)
//}
closure.object.Nonce++ closure.object.Nonce++
self.Printf(" (*) %x", addr).Endl() self.Printf(" (*) %x", addr).Endl()
@ -953,6 +956,10 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
ret = p.Call(self.input) ret = p.Call(self.input)
} }
} else { } else {
if self.vm.depth == MaxCallDepth {
return nil, fmt.Errorf("Max call depth exceeded (%d)", MaxCallDepth)
}
// Retrieve the executing code // Retrieve the executing code
code := self.vm.env.State().GetCode(codeAddr) code := self.vm.env.State().GetCode(codeAddr)