diff options
Diffstat (limited to 'vm')
-rw-r--r-- | vm/context.go | 22 | ||||
-rw-r--r-- | vm/environment.go | 8 | ||||
-rw-r--r-- | vm/types.go | 4 | ||||
-rw-r--r-- | vm/vm_debug.go | 25 |
4 files changed, 27 insertions, 32 deletions
diff --git a/vm/context.go b/vm/context.go index ccbadabda..d14df1aa7 100644 --- a/vm/context.go +++ b/vm/context.go @@ -5,7 +5,6 @@ import ( "math/big" "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/state" ) type ContextRef interface { @@ -15,10 +14,9 @@ type ContextRef interface { } type Context struct { - caller ContextRef - object ContextRef - Code []byte - message *state.Message + caller ContextRef + object ContextRef + Code []byte Gas, UsedGas, Price *big.Int @@ -26,8 +24,8 @@ type Context struct { } // Create a new context for the given data items -func NewContext(msg *state.Message, caller ContextRef, object ContextRef, code []byte, gas, price *big.Int) *Context { - c := &Context{message: msg, caller: caller, object: object, Code: code, Args: nil} +func NewContext(caller ContextRef, object ContextRef, code []byte, gas, price *big.Int) *Context { + c := &Context{caller: caller, object: object, Code: code, Args: nil} // Gas should be a pointer so it can safely be reduced through the run // This pointer will be off the state transition @@ -40,13 +38,13 @@ func NewContext(msg *state.Message, caller ContextRef, object ContextRef, code [ return c } -func (c *Context) GetOp(x uint64) OpCode { - return OpCode(c.GetByte(x)) +func (c *Context) GetOp(n uint64) OpCode { + return OpCode(c.GetByte(n)) } -func (c *Context) GetByte(x uint64) byte { - if x < uint64(len(c.Code)) { - return c.Code[x] +func (c *Context) GetByte(n uint64) byte { + if n < uint64(len(c.Code)) { + return c.Code[n] } return 0 diff --git a/vm/environment.go b/vm/environment.go index 01bbd56ce..8ec13ee41 100644 --- a/vm/environment.go +++ b/vm/environment.go @@ -14,11 +14,10 @@ type Environment interface { Origin() []byte BlockNumber() *big.Int - PrevHash() []byte + GetHash(n uint64) []byte Coinbase() []byte Time() int64 Difficulty() *big.Int - BlockHash() []byte GasLimit() *big.Int Transfer(from, to Account, amount *big.Int) error AddLog(state.Log) @@ -31,11 +30,6 @@ type Environment interface { Create(me ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, ContextRef) } -type Object interface { - GetStorage(key *big.Int) *ethutil.Value - SetStorage(key *big.Int, value *ethutil.Value) -} - type Account interface { SubBalance(amount *big.Int) AddBalance(amount *big.Int) diff --git a/vm/types.go b/vm/types.go index ec9c7e74e..1ea80a212 100644 --- a/vm/types.go +++ b/vm/types.go @@ -59,7 +59,7 @@ const ( const ( // 0x40 range - block operations - PREVHASH OpCode = 0x40 + iota + BLOCKHASH OpCode = 0x40 + iota COINBASE TIMESTAMP NUMBER @@ -216,7 +216,7 @@ var opCodeToString = map[OpCode]string{ GASPRICE: "TXGASPRICE", // 0x40 range - block operations - PREVHASH: "PREVHASH", + BLOCKHASH: "BLOCKHASH", COINBASE: "COINBASE", TIMESTAMP: "TIMESTAMP", NUMBER: "NUMBER", diff --git a/vm/vm_debug.go b/vm/vm_debug.go index 6ad385fd0..92e4154e4 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -42,12 +42,12 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * msg := self.env.State().Manifest().AddMessage(&state.Message{ To: me.Address(), From: caller.Address(), - Input: callData, - Origin: self.env.Origin(), - Block: self.env.BlockHash(), Timestamp: self.env.Time(), Coinbase: self.env.Coinbase(), Number: self.env.BlockNumber(), + Input: callData, + Origin: self.env.Origin(), + Timestamp: self.env.Time(), Coinbase: self.env.Coinbase(), Number: self.env.BlockNumber(), Value: value, }) - context := NewContext(msg, caller, me, code, gas, price) + context := NewContext(caller, me, code, gas, price) if self.Recoverable { // Recover from any require exception @@ -83,7 +83,7 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * jump = func(from uint64, to *big.Int) { p := to.Uint64() - nop := OpCode(context.GetOp(p)) + nop := context.GetOp(p) if !destinations.Has(p) { panic(fmt.Sprintf("invalid jump destination (%v) %v", nop, p)) } @@ -516,12 +516,15 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * self.Printf(" => %v", context.Price) // 0x40 range - case PREVHASH: - prevHash := self.env.PrevHash() - - stack.Push(ethutil.BigD(prevHash)) + case BLOCKHASH: + num := stack.Pop() + if num.Cmp(new(big.Int).Sub(self.env.BlockNumber(), ethutil.Big256)) < 0 { + stack.Push(ethutil.Big0) + } else { + stack.Push(ethutil.BigD(self.env.GetHash(num.Uint64()))) + } - self.Printf(" => 0x%x", prevHash) + self.Printf(" => 0x%x", stack.Peek().Bytes()) case COINBASE: coinbase := self.env.Coinbase() @@ -614,7 +617,7 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * val, loc := stack.Popn() statedb.SetState(context.Address(), loc.Bytes(), val) - context.message.AddStorageChange(loc.Bytes()) + msg.AddStorageChange(loc.Bytes()) self.Printf(" {0x%x : 0x%x}", loc.Bytes(), val.Bytes()) case JUMP: |