core/vm: improve JUMPDEST analysis

* JUMPDEST analysis is faster because less type conversions are performed.
* The map of JUMPDEST locations is now created lazily at the first JUMP.
* The result of the analysis is kept around for recursive invocations
  through CALL/CALLCODE.

Fixes #1147
This commit is contained in:
Felix Lange
2015-05-29 14:40:45 +02:00
parent b4818a003a
commit ea2718c946
3 changed files with 46 additions and 27 deletions

View File

@ -72,17 +72,16 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
}
var (
op OpCode
destinations = analyseJumpDests(context.Code)
mem = NewMemory()
stack = newStack()
pc = new(big.Int)
statedb = self.env.State()
op OpCode
codehash = crypto.Sha3Hash(code)
mem = NewMemory()
stack = newStack()
pc = new(big.Int)
statedb = self.env.State()
jump = func(from *big.Int, to *big.Int) error {
nop := context.GetOp(to)
if !destinations.Has(to) {
if !context.jumpdests.has(codehash, code, to) {
nop := context.GetOp(to)
return fmt.Errorf("invalid jump destination (%v) %v", nop, to)
}