diff options
author | obscuren <geffobscura@gmail.com> | 2014-07-22 21:57:54 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-07-22 21:57:54 +0800 |
commit | 490ca410c01a1b8076214d00c21d2edf09c24f86 (patch) | |
tree | 9c206ffda9dcfc723ea25b26809a7371b08d328d | |
parent | 1e8b54abfb7129fcdf4812ad01b6a7cd61e4f65d (diff) | |
download | go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.tar go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.tar.gz go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.tar.bz2 go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.tar.lz go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.tar.xz go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.tar.zst go-tangerine-490ca410c01a1b8076214d00c21d2edf09c24f86.zip |
Minor improvements and fixes to the new vm structure
-rw-r--r-- | ethchain/asm.go | 4 | ||||
-rw-r--r-- | ethchain/vm.go | 5 | ||||
-rw-r--r-- | ethstate/state_object.go | 2 | ||||
-rw-r--r-- | ethvm/asm.go | 4 | ||||
-rw-r--r-- | ethvm/vm.go | 8 | ||||
-rw-r--r-- | ethvm/vm_test.go | 19 |
6 files changed, 18 insertions, 24 deletions
diff --git a/ethchain/asm.go b/ethchain/asm.go index 2697953fd..9f99b0c48 100644 --- a/ethchain/asm.go +++ b/ethchain/asm.go @@ -25,7 +25,7 @@ func Disassemble(script []byte) (asm []string) { pc.Add(pc, ethutil.Big1) a := int64(op) - int64(PUSH1) + 1 if int(pc.Int64()+a) > len(script) { - return nil + return } data := script[pc.Int64() : pc.Int64()+a] @@ -40,5 +40,5 @@ func Disassemble(script []byte) (asm []string) { pc.Add(pc, ethutil.Big1) } - return + return asm } diff --git a/ethchain/vm.go b/ethchain/vm.go index a9bed1eca..4cbb4e1c4 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -563,10 +563,9 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { } code := closure.Script[cOff : cOff+l] - //fmt.Println("len:", l, "code off:", cOff, "mem off:", mOff) + fmt.Println("len:", l, "code off:", cOff, "mem off:", mOff) mem.Set(mOff, l, code) - //fmt.Println(Code(mem.Get(mOff, l))) case GASPRICE: stack.Push(closure.Price) @@ -673,6 +672,8 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { stack.Push(pc) case MSIZE: stack.Push(big.NewInt(int64(mem.Len()))) + + vm.Printf(" => %v", mem.Len()).Endl() case GAS: stack.Push(closure.Gas) // 0x60 range diff --git a/ethstate/state_object.go b/ethstate/state_object.go index d8513f37d..6b00c5369 100644 --- a/ethstate/state_object.go +++ b/ethstate/state_object.go @@ -11,7 +11,7 @@ import ( type Code []byte func (self Code) String() string { - return "" //strings.Join(Disassemble(self), " ") + return string(self) //strings.Join(Disassemble(self), " ") } type Storage map[string]*ethutil.Value diff --git a/ethvm/asm.go b/ethvm/asm.go index fd559d1dc..7ff15a240 100644 --- a/ethvm/asm.go +++ b/ethvm/asm.go @@ -18,7 +18,7 @@ func Disassemble(script []byte) (asm []string) { // Get the opcode (it must be an opcode!) op := OpCode(val) - asm = append(asm, fmt.Sprintf("%04v: %v", pc, op)) + asm = append(asm, fmt.Sprintf("%v", op)) switch op { 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: @@ -32,7 +32,7 @@ func Disassemble(script []byte) (asm []string) { if len(data) == 0 { data = []byte{0} } - asm = append(asm, fmt.Sprintf("%04v: 0x%x", pc, data)) + asm = append(asm, fmt.Sprintf("0x%x", data)) pc.Add(pc, big.NewInt(a-1)) } diff --git a/ethvm/vm.go b/ethvm/vm.go index 2a83bae3d..1f0ae8991 100644 --- a/ethvm/vm.go +++ b/ethvm/vm.go @@ -48,7 +48,6 @@ type Environment interface { Coinbase() []byte Time() int64 Difficulty() *big.Int - Data() []string Value() *big.Int } @@ -420,7 +419,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { require(2) val, th := stack.Popn() if th.Cmp(big.NewInt(32)) < 0 && th.Cmp(big.NewInt(int64(len(val.Bytes())))) < 0 { - byt := big.NewInt(int64(val.Bytes()[th.Int64()])) + byt := big.NewInt(int64(ethutil.LeftPadBytes(val.Bytes(), 32)[th.Int64()])) stack.Push(byt) self.Printf(" => 0x%x", byt.Bytes()) @@ -530,10 +529,8 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { } code := closure.Code[cOff : cOff+l] - //fmt.Println("len:", l, "code off:", cOff, "mem off:", mOff) mem.Set(mOff, l, code) - //fmt.Println(Code(mem.Get(mOff, l))) case GASPRICE: stack.Push(closure.Price) @@ -638,7 +635,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { // Add the change to manifest self.env.State().Manifest().AddStorageChange(closure.Object(), loc.Bytes(), val) - self.Printf(" {0x%x : 0x%x}", loc, val) + self.Printf(" {0x%x : 0x%x}", loc.Bytes(), val.Bytes()) case JUMP: require(1) pc = stack.Pop() @@ -802,7 +799,6 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { return closure.Return(nil), nil default: vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op) - fmt.Println(ethstate.Code(closure.Code)) return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op) } diff --git a/ethvm/vm_test.go b/ethvm/vm_test.go index f0bdc8e2c..501d0c284 100644 --- a/ethvm/vm_test.go +++ b/ethvm/vm_test.go @@ -15,17 +15,14 @@ import ( type TestEnv struct { } -func (self TestEnv) GetObject() Object { return nil } -func (self TestEnv) Origin() []byte { return nil } -func (self TestEnv) BlockNumber() *big.Int { return nil } -func (self TestEnv) PrevHash() []byte { return nil } -func (self TestEnv) Coinbase() []byte { return nil } -func (self TestEnv) Time() int64 { return 0 } -func (self TestEnv) Difficulty() *big.Int { return nil } -func (self TestEnv) Data() []string { return nil } -func (self TestEnv) Value() *big.Int { return nil } -func (self TestEnv) GetBalance(addr []byte) *big.Int { return nil } -func (self TestEnv) State() *ethstate.State { return nil } +func (self TestEnv) Origin() []byte { return nil } +func (self TestEnv) BlockNumber() *big.Int { return nil } +func (self TestEnv) PrevHash() []byte { return nil } +func (self TestEnv) Coinbase() []byte { return nil } +func (self TestEnv) Time() int64 { return 0 } +func (self TestEnv) Difficulty() *big.Int { return nil } +func (self TestEnv) Value() *big.Int { return nil } +func (self TestEnv) State() *ethstate.State { return nil } func TestVm(t *testing.T) { ethlog.AddLogSystem(ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(4))) |