diff options
Diffstat (limited to 'vm/vm.go')
-rw-r--r-- | vm/vm.go | 54 |
1 files changed, 25 insertions, 29 deletions
@@ -32,10 +32,17 @@ func New(env Environment) *Vm { return &Vm{debug: Debug, env: env, logTy: lt, Recoverable: true} } -func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) { +func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { + //func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) { self.env.SetDepth(self.env.Depth() + 1) - context := NewContext(caller, me, code, gas, price) + //context := NewContext(caller, me, code, gas, price) + var ( + caller = context.caller + code = context.Code + value = context.value + price = context.Price + ) self.Printf("(%d) (%x) %x (code=%d) gas: %v (d) %x", self.env.Depth(), caller.Address()[:4], context.Address(), len(code), context.Gas, callData).Endl() @@ -55,7 +62,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I }() } - if p := Precompiled[string(me.Address())]; p != nil { + if p := Precompiled[string(context.CodeAddr)]; p != nil { return self.RunPrecompiled(p, callData, context) } @@ -235,9 +242,9 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I stack.push(base) case SIGNEXTEND: - back := stack.pop().Uint64() - if back < 31 { - bit := uint(back*8 + 7) + back := stack.pop() + if back.Cmp(big.NewInt(31)) < 0 { + bit := uint(back.Uint64()*8 + 7) num := stack.pop() mask := new(big.Int).Lsh(ethutil.Big1, bit) mask.Sub(mask, ethutil.Big1) @@ -254,12 +261,10 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I stack.push(num) } case NOT: - base.Sub(Pow256, stack.pop()).Sub(base, ethutil.Big1) - - // Not needed - base = U256(base) - - stack.push(base) + stack.push(U256(new(big.Int).Not(stack.pop()))) + //base.Sub(Pow256, stack.pop()).Sub(base, ethutil.Big1) + //base = U256(base) + //stack.push(base) case LT: x, y := stack.pop(), stack.pop() self.Printf(" %v < %v", x, y) @@ -349,29 +354,27 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I stack.push(base) case ADDMOD: - x := stack.pop() y := stack.pop() z := stack.pop() - add := new(big.Int).Add(x, y) - if len(z.Bytes()) > 0 { // NOT 0x0 + if z.Cmp(Zero) > 0 { + add := new(big.Int).Add(x, y) base.Mod(add, z) - U256(base) + base = U256(base) } self.Printf(" %v + %v %% %v = %v", x, y, z, base) stack.push(base) case MULMOD: - x := stack.pop() y := stack.pop() z := stack.pop() - mul := new(big.Int).Mul(x, y) - if len(z.Bytes()) > 0 { // NOT 0x0 + if z.Cmp(Zero) > 0 { + mul := new(big.Int).Mul(x, y) base.Mod(mul, z) U256(base) @@ -383,7 +386,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I // 0x20 range case SHA3: - size, offset := stack.pop(), stack.pop() + offset, size := stack.pop(), stack.pop() data := crypto.Sha3(mem.Get(offset.Int64(), size.Int64())) stack.push(ethutil.BigD(data)) @@ -395,14 +398,8 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I self.Printf(" => %x", context.Address()) case BALANCE: - addr := stack.pop().Bytes() - var balance *big.Int - if statedb.GetStateObject(addr) != nil { - balance = statedb.GetBalance(addr) - } else { - balance = base - } + balance := statedb.GetBalance(addr) stack.push(balance) @@ -485,13 +482,12 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I } else { code = context.Code } - context := NewContext(nil, nil, code, ethutil.Big0, ethutil.Big0) var ( mOff = stack.pop().Uint64() cOff = stack.pop().Uint64() l = stack.pop().Uint64() ) - codeCopy := context.GetCode(cOff, l) + codeCopy := getCode(code, cOff, l) mem.Set(mOff, l, codeCopy) |