Skip to content

Commit 83663ed

Browse files
committed
Renames for chain, updated VM, moved methods
* Renamed a couple more chain => core * Updated VM `pc` to be uint64 rather than big int * XEth interface cleanup
1 parent 9008b15 commit 83663ed

9 files changed

Lines changed: 90 additions & 98 deletions

File tree

‎cmd/ethereum/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"os"
2323
"runtime"
2424

25-
"github.com/ethereum/go-ethereum/chain/types"
2625
"github.com/ethereum/go-ethereum/cmd/utils"
26+
"github.com/ethereum/go-ethereum/core/types"
2727
"github.com/ethereum/go-ethereum/ethutil"
2828
"github.com/ethereum/go-ethereum/logger"
2929
)

‎core/chain_manager_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/ethereum/go-ethereum/chain/types"
9+
"github.com/ethereum/go-ethereum/core/types"
1010
"github.com/ethereum/go-ethereum/ethdb"
1111
"github.com/ethereum/go-ethereum/ethutil"
1212
"github.com/ethereum/go-ethereum/state"

‎core/helper_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"container/list"
55
"fmt"
66

7-
"github.com/ethereum/go-ethereum/chain/types"
7+
"github.com/ethereum/go-ethereum/core/types"
88
"github.com/ethereum/go-ethereum/crypto"
99
"github.com/ethereum/go-ethereum/ethdb"
1010
"github.com/ethereum/go-ethereum/ethutil"

‎tests/helper/vm.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package helper
33
import (
44
"math/big"
55

6-
"github.com/ethereum/go-ethereum/chain"
6+
"github.com/ethereum/go-ethereum/core"
77
"github.com/ethereum/go-ethereum/crypto"
88
"github.com/ethereum/go-ethereum/ethutil"
99
"github.com/ethereum/go-ethereum/state"
@@ -66,9 +66,9 @@ func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
6666
return vm.Transfer(from, to, amount)
6767
}
6868

69-
func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *chain.Execution {
69+
func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
7070
evm := vm.New(self, vm.DebugVmTy)
71-
exec := chain.NewExecution(evm, addr, data, gas, price, value)
71+
exec := core.NewExecution(evm, addr, data, gas, price, value)
7272
exec.SkipTransfer = self.skipTransfer
7373

7474
return exec

‎tests/vm/gh_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strconv"
77
"testing"
88

9-
"github.com/ethereum/go-ethereum/chain/types"
9+
"github.com/ethereum/go-ethereum/core/types"
1010
"github.com/ethereum/go-ethereum/ethutil"
1111
"github.com/ethereum/go-ethereum/state"
1212
"github.com/ethereum/go-ethereum/tests/helper"

‎vm/analysis.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import (
66
"github.com/ethereum/go-ethereum/ethutil"
77
)
88

9-
func analyseJumpDests(code []byte) (dests map[int64]*big.Int) {
10-
dests = make(map[int64]*big.Int)
9+
func analyseJumpDests(code []byte) (dests map[uint64]*big.Int) {
10+
dests = make(map[uint64]*big.Int)
1111

1212
lp := false
1313
var lpv *big.Int
14-
for pc := int64(0); pc < int64(len(code)); pc++ {
14+
for pc := uint64(0); pc < uint64(len(code)); pc++ {
1515
var op OpCode = OpCode(code[pc])
1616
switch op {
1717
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:
18-
a := int64(op) - int64(PUSH1) + 1
19-
if int64(len(code)) > pc+1+a {
18+
a := uint64(op) - uint64(PUSH1) + 1
19+
if uint64(len(code)) > pc+1+a {
2020
lpv = ethutil.BigD(code[pc+1 : pc+1+a])
2121
}
2222

‎vm/closure.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
4141
return c
4242
}
4343

44-
func (c *Closure) GetValue(x *big.Int) *ethutil.Value {
45-
return c.GetRangeValue(x, big.NewInt(1))
44+
func (c *Closure) GetValue(x uint64) *ethutil.Value {
45+
return c.GetRangeValue(x, 1)
4646
}
4747

48-
func (c *Closure) GetOp(x int) OpCode {
48+
func (c *Closure) GetOp(x uint64) OpCode {
4949
return OpCode(c.GetByte(x))
5050
}
5151

52-
func (c *Closure) GetByte(x int) byte {
53-
if x > -1 && x < len(c.Code) {
52+
func (c *Closure) GetByte(x uint64) byte {
53+
if x < uint64(len(c.Code)) {
5454
return c.Code[x]
5555
}
5656

@@ -65,12 +65,12 @@ func (c *Closure) GetBytes(x, y int) []byte {
6565
return c.Code[x : x+y]
6666
}
6767

68-
func (c *Closure) GetRangeValue(x, y *big.Int) *ethutil.Value {
69-
if x.Int64() >= int64(len(c.Code)) || y.Int64() >= int64(len(c.Code)) {
68+
func (c *Closure) GetRangeValue(x, y uint64) *ethutil.Value {
69+
if x >= uint64(len(c.Code)) || y >= uint64(len(c.Code)) {
7070
return ethutil.NewValue(0)
7171
}
7272

73-
partial := c.Code[x.Int64() : x.Int64()+y.Int64()]
73+
partial := c.Code[x : x+y]
7474

7575
return ethutil.NewValue(partial)
7676
}

‎vm/vm_debug.go‎

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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())) {

‎xeth/pipe.go‎

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func New(obj core.EthManager) *XEth {
3939
return pipe
4040
}
4141

42+
/*
43+
* State / Account accessors
44+
*/
4245
func (self *XEth) Balance(addr []byte) *ethutil.Value {
4346
return ethutil.NewValue(self.World().safeGet(addr).Balance)
4447
}
@@ -47,32 +50,6 @@ func (self *XEth) Nonce(addr []byte) uint64 {
4750
return self.World().safeGet(addr).Nonce
4851
}
4952

50-
func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
51-
return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price)
52-
}
53-
54-
func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
55-
var (
56-
initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address())
57-
block = self.blockChain.CurrentBlock
58-
)
59-
60-
self.Vm.State = self.World().State().Copy()
61-
62-
vmenv := NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address())
63-
return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt())
64-
/*
65-
evm := vm.New(, vm.Type(ethutil.Config.VmType))
66-
67-
msg := vm.NewExecution(evm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt())
68-
ret, err := msg.Exec(object.Address(), initiator)
69-
70-
fmt.Println("returned from call", ret, err)
71-
72-
return ret, err
73-
*/
74-
}
75-
7653
func (self *XEth) Block(hash []byte) *types.Block {
7754
return self.blockChain.GetBlock(hash)
7855
}
@@ -81,6 +58,11 @@ func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value {
8158
return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr))
8259
}
8360

61+
func (self *XEth) Exists(addr []byte) bool {
62+
return self.World().Get(addr) != nil
63+
}
64+
65+
// Converts the given private key to an address
8466
func (self *XEth) ToAddress(priv []byte) []byte {
8567
pair, err := crypto.NewKeyPairFromSec(priv)
8668
if err != nil {
@@ -90,10 +72,28 @@ func (self *XEth) ToAddress(priv []byte) []byte {
9072
return pair.Address()
9173
}
9274

93-
func (self *XEth) Exists(addr []byte) bool {
94-
return self.World().Get(addr) != nil
75+
/*
76+
* Execution helpers
77+
*/
78+
func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
79+
return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price)
80+
}
81+
82+
func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
83+
var (
84+
initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address())
85+
block = self.blockChain.CurrentBlock
86+
)
87+
88+
self.Vm.State = self.World().State().Copy()
89+
90+
vmenv := NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address())
91+
return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt())
9592
}
9693

94+
/*
95+
* Transactional methods
96+
*/
9797
func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) {
9898
// Check if an address is stored by this address
9999
var hash []byte
@@ -149,13 +149,6 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
149149
}
150150

151151
return tx, nil
152-
153-
//acc := self.blockManager.TransState().GetOrNewStateObject(key.Address())
154-
//self.obj.TxPool().QueueTransaction(tx)
155-
156-
//acc.Nonce += 1
157-
//self.blockManager.TransState().UpdateStateObject(acc)
158-
159152
}
160153

161154
func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) {

0 commit comments

Comments
 (0)