@@ -75,35 +75,35 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
7575 var (
7676 op OpCode
7777
78- destinations = analyseJumpDests (closure .Code )
79- mem = NewMemory ()
80- stack = NewStack ()
81- pc = big . NewInt ( 0 )
82- step = 0
83- prevStep = 0
84- statedb = self .env .State ()
85- require = func (m int ) {
78+ destinations = analyseJumpDests (closure .Code )
79+ mem = NewMemory ()
80+ stack = NewStack ()
81+ pc uint64 = 0
82+ step = 0
83+ prevStep = 0
84+ statedb = self .env .State ()
85+ require = func (m int ) {
8686 if stack .Len () < m {
8787 panic (fmt .Sprintf ("%04v (%v) stack err size = %d, required = %d" , pc , op , stack .Len (), m ))
8888 }
8989 }
9090
91- jump = func (from , to * big.Int ) {
92- p := int ( to .Int64 () )
91+ jump = func (from uint64 , to * big.Int ) {
92+ p := to .Uint64 ( )
9393
9494 self .Printf (" ~> %v" , to )
9595 // Return to start
9696 if p == 0 {
97- pc = big . NewInt ( 0 )
97+ pc = 0
9898 } else {
9999 nop := OpCode (closure .GetOp (p ))
100- if ! (nop == JUMPDEST || destinations [from . Int64 () ] != nil ) {
100+ if ! (nop == JUMPDEST || destinations [from ] != nil ) {
101101 panic (fmt .Sprintf ("JUMP missed JUMPDEST (%v) %v" , nop , p ))
102102 } else if nop == JUMP || nop == JUMPI {
103103 panic (fmt .Sprintf ("not allowed to JUMP(I) in to JUMP" ))
104104 }
105105
106- pc = to
106+ pc = to . Uint64 ()
107107
108108 }
109109
@@ -125,26 +125,28 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
125125
126126 step ++
127127 // Get the memory location of pc
128- op = closure .GetOp (int (pc .Uint64 ()))
128+ op = closure .GetOp (pc )
129+
130+ /*
131+ // XXX Leave this Println intact. Don't change this to the log system.
132+ // Used for creating diffs between implementations
133+ if self.logTy == LogTyDiff {
134+ switch op {
135+ case STOP, RETURN, SUICIDE:
136+ statedb.GetStateObject(closure.Address()).EachStorage(func(key string, value *ethutil.Value) {
137+ value.Decode()
138+ fmt.Printf("%x %x\n", new(big.Int).SetBytes([]byte(key)).Bytes(), value.Bytes())
139+ })
140+ }
129141
130- // XXX Leave this Println intact. Don't change this to the log system.
131- // Used for creating diffs between implementations
132- if self .logTy == LogTyDiff {
133- switch op {
134- case STOP , RETURN , SUICIDE :
135- statedb .GetStateObject (closure .Address ()).EachStorage (func (key string , value * ethutil.Value ) {
136- value .Decode ()
137- fmt .Printf ("%x %x\n " , new (big.Int ).SetBytes ([]byte (key )).Bytes (), value .Bytes ())
138- })
139- }
142+ b := pc.Bytes()
143+ if len(b) == 0 {
144+ b = []byte{0}
145+ }
140146
141- b := pc .Bytes ()
142- if len (b ) == 0 {
143- b = []byte {0 }
147+ fmt.Printf("%x %x %x %x\n", closure.Address(), b, []byte{byte(op)}, closure.Gas.Bytes())
144148 }
145-
146- fmt .Printf ("%x %x %x %x\n " , closure .Address (), b , []byte {byte (op )}, closure .Gas .Bytes ())
147- }
149+ */
148150
149151 gas := new (big.Int )
150152 addStepGasUsage := func (amount * big.Int ) {
@@ -735,13 +737,15 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
735737
736738 // 0x50 range
737739 case PUSH1 , PUSH2 , PUSH3 , PUSH4 , PUSH5 , PUSH6 , PUSH7 , PUSH8 , PUSH9 , PUSH10 , PUSH11 , PUSH12 , PUSH13 , PUSH14 , PUSH15 , PUSH16 , PUSH17 , PUSH18 , PUSH19 , PUSH20 , PUSH21 , PUSH22 , PUSH23 , PUSH24 , PUSH25 , PUSH26 , PUSH27 , PUSH28 , PUSH29 , PUSH30 , PUSH31 , PUSH32 :
738- a := big .NewInt (int64 (op ) - int64 (PUSH1 ) + 1 )
739- pc .Add (pc , ethutil .Big1 )
740- data := closure .GetRangeValue (pc , a )
740+ //a := big.NewInt(int64(op) - int64(PUSH1) + 1)
741+ a := uint64 (op - PUSH1 + 1 )
742+ //pc.Add(pc, ethutil.Big1)
743+ data := closure .GetRangeValue (pc + 1 , a )
741744 val := ethutil .BigD (data .Bytes ())
742745 // Push value to stack
743746 stack .Push (val )
744- pc .Add (pc , a .Sub (a , big .NewInt (1 )))
747+ pc += a
748+ //pc.Add(pc, a.Sub(a, big.NewInt(1)))
745749
746750 step += int (op ) - int (PUSH1 ) + 1
747751
@@ -750,13 +754,9 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
750754 stack .Pop ()
751755 case DUP1 , DUP2 , DUP3 , DUP4 , DUP5 , DUP6 , DUP7 , DUP8 , DUP9 , DUP10 , DUP11 , DUP12 , DUP13 , DUP14 , DUP15 , DUP16 :
752756 n := int (op - DUP1 + 1 )
753- v := stack .Dupn (n )
757+ stack .Dupn (n )
754758
755759 self .Printf (" => [%d] 0x%x" , n , stack .Peek ().Bytes ())
756-
757- if OpCode (closure .GetValue (new (big.Int ).Add (pc , ethutil .Big1 )).Uint ()) == POP && OpCode (closure .GetValue (new (big.Int ).Add (pc , big .NewInt (2 ))).Uint ()) == POP {
758- fmt .Println (toValue (v ))
759- }
760760 case SWAP1 , SWAP2 , SWAP3 , SWAP4 , SWAP5 , SWAP6 , SWAP7 , SWAP8 , SWAP9 , SWAP10 , SWAP11 , SWAP12 , SWAP13 , SWAP14 , SWAP15 , SWAP16 :
761761 n := int (op - SWAP1 + 2 )
762762 x , y := stack .Swapn (n )
@@ -811,7 +811,6 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
811811
812812 self .Printf (" {0x%x : 0x%x}" , loc .Bytes (), val .Bytes ())
813813 case JUMP :
814-
815814 jump (pc , stack .Pop ())
816815
817816 continue
@@ -826,7 +825,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
826825
827826 case JUMPDEST :
828827 case PC :
829- stack .Push (pc )
828+ stack .Push (big . NewInt ( int64 ( pc )) )
830829 case MSIZE :
831830 stack .Push (big .NewInt (int64 (mem .Len ())))
832831 case GAS :
@@ -940,13 +939,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
940939 return closure .Return (nil ), fmt .Errorf ("Invalid opcode %x" , op )
941940 }
942941
943- pc . Add ( pc , ethutil . Big1 )
942+ pc ++
944943
945944 self .Endl ()
946945
947946 if self .Dbg != nil {
948947 for _ , instrNo := range self .Dbg .BreakPoints () {
949- if pc . Cmp ( big . NewInt ( instrNo )) == 0 {
948+ if pc == uint64 ( instrNo ) {
950949 self .Stepping = true
951950
952951 if ! self .Dbg .BreakHook (prevStep , op , mem , stack , statedb .GetStateObject (closure .Address ())) {
0 commit comments