aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-10 18:51:19 +0800
committerobscuren <geffobscura@gmail.com>2014-07-10 18:51:19 +0800
commit67e5689f874940c99e4742a5c8c2a6a194cb2003 (patch)
tree5ca58a3dfb75d2bb2a5ac620e2f6508e756a3421 /ethchain
parent794e65b60e3d9cd954f9d2aa082d18fe9431c200 (diff)
downloadgo-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.tar
go-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.tar.gz
go-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.tar.bz2
go-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.tar.lz
go-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.tar.xz
go-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.tar.zst
go-tangerine-67e5689f874940c99e4742a5c8c2a6a194cb2003.zip
Fixed BYTE opcode
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/vm.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 71605b069..3b58d6106 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -22,6 +22,9 @@ var (
GasMemory = big.NewInt(1)
GasData = big.NewInt(5)
GasTx = big.NewInt(500)
+
+ LogTyPretty byte = 0x1
+ LogTyDiff byte = 0x2
)
type Debugger interface {
@@ -44,6 +47,7 @@ type Vm struct {
Verbose bool
+ logTy byte
logStr string
err error
@@ -69,7 +73,7 @@ type RuntimeVars struct {
}
func (self *Vm) Printf(format string, v ...interface{}) *Vm {
- if self.Verbose {
+ if self.Verbose && self.logTy == LogTyPretty {
self.logStr += fmt.Sprintf(format, v...)
}
@@ -77,7 +81,7 @@ func (self *Vm) Printf(format string, v ...interface{}) *Vm {
}
func (self *Vm) Endl() *Vm {
- if self.Verbose {
+ if self.Verbose && self.logTy == LogTyPretty {
vmlogger.Debugln(self.logStr)
self.logStr = ""
}
@@ -86,7 +90,7 @@ func (self *Vm) Endl() *Vm {
}
func NewVm(state *State, stateManager *StateManager, vars RuntimeVars) *Vm {
- return &Vm{vars: vars, state: state, stateManager: stateManager}
+ return &Vm{vars: vars, state: state, stateManager: stateManager, logTy: LogTyPretty}
}
var Pow256 = ethutil.BigPow(2, 256)
@@ -132,6 +136,17 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Get the opcode (it must be an opcode!)
op = OpCode(val.Uint())
+ // XXX Leave this Println intact. Don't change this to the log system.
+ // Used for creating diffs between implementations
+ if vm.logTy == LogTyDiff {
+ b := pc.Bytes()
+ if len(b) == 0 {
+ b = []byte{0}
+ }
+
+ fmt.Printf("%x %x %x %x\n", closure.object.Address(), b, []byte{byte(op)}, closure.Gas.Bytes())
+ }
+
gas := new(big.Int)
addStepGasUsage := func(amount *big.Int) {
if amount.Cmp(ethutil.Big0) >= 0 {
@@ -415,7 +430,10 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
require(2)
val, th := stack.Popn()
if th.Cmp(big.NewInt(32)) < 0 {
- stack.Push(big.NewInt(int64(len(val.Bytes())-1) - th.Int64()))
+ byt := big.NewInt(int64(val.Bytes()[th.Int64()]))
+ stack.Push(byt)
+
+ vm.Printf(" => 0x%x", byt.Bytes())
} else {
stack.Push(ethutil.BigFalse)
}
@@ -562,8 +580,9 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
case MSTORE8:
require(2)
val, mStart := stack.Popn()
- base.And(val, new(big.Int).SetInt64(0xff))
- mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(base, 256))
+ //base.And(val, new(big.Int).SetInt64(0xff))
+ //mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(base, 256))
+ mem.store[mStart.Int64()] = byte(val.Int64() & 0xff)
vm.Printf(" => 0x%x", val)
case SLOAD: