Updated the VM & VM tests
* Stack Error shouldn't revert to previous state * Updated VM Test tool * Added Transfer method to VM Env
This commit is contained in:
@ -39,7 +39,7 @@ var (
|
||||
S256 = ethutil.S256
|
||||
)
|
||||
|
||||
const MaxCallDepth = 1024
|
||||
const MaxCallDepth = 1025
|
||||
|
||||
func calcMemSize(off, l *big.Int) *big.Int {
|
||||
if l.Cmp(ethutil.Big0) == 0 {
|
||||
|
@ -13,6 +13,7 @@ type Execution struct {
|
||||
address, input []byte
|
||||
Gas, price, value *big.Int
|
||||
object *ethstate.StateObject
|
||||
SkipTransfer bool
|
||||
}
|
||||
|
||||
func NewExecution(vm VirtualMachine, address, input []byte, gas, gasPrice, value *big.Int) *Execution {
|
||||
@ -49,17 +50,17 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte,
|
||||
})
|
||||
|
||||
from, to := caller.Object(), env.State().GetOrNewStateObject(self.address)
|
||||
err = env.Transfer(from, to, self.value)
|
||||
// Skipping transfer is used on testing for the initial call
|
||||
if !self.SkipTransfer {
|
||||
err = env.Transfer(from, to, self.value)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
caller.ReturnGas(self.Gas, self.price)
|
||||
|
||||
err = fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance)
|
||||
} else {
|
||||
self.object = to
|
||||
|
||||
//caller.Object().SubAmount(self.value)
|
||||
//stateObject.AddAmount(self.value)
|
||||
|
||||
// Pre-compiled contracts (address.go) 1, 2 & 3.
|
||||
naddr := ethutil.BigD(caddr).Uint64()
|
||||
if p := Precompiled[naddr]; p != nil {
|
||||
@ -73,14 +74,13 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte,
|
||||
c.exe = self
|
||||
|
||||
if self.vm.Depth() == MaxCallDepth {
|
||||
c.UseGas(c.Gas)
|
||||
c.UseGas(self.Gas)
|
||||
|
||||
return c.Return(nil), fmt.Errorf("Max call depth exceeded (%d)", MaxCallDepth)
|
||||
}
|
||||
|
||||
// Executer the closure and get the return value (if any)
|
||||
ret, _, err = c.Call(self.vm, self.input)
|
||||
|
||||
msg.Output = ret
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,6 @@ const (
|
||||
CALLCODE = 0xf3
|
||||
|
||||
// 0x70 range - other
|
||||
LOG = 0xfe // XXX Unofficial
|
||||
SUICIDE = 0xff
|
||||
)
|
||||
|
||||
@ -300,7 +299,6 @@ var opCodeToString = map[OpCode]string{
|
||||
CALLCODE: "CALLCODE",
|
||||
|
||||
// 0x70 range - other
|
||||
LOG: "LOG",
|
||||
SUICIDE: "SUICIDE",
|
||||
}
|
||||
|
||||
|
4
vm/vm.go
4
vm/vm.go
@ -660,8 +660,6 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
|
||||
// Get the arguments from the memory
|
||||
args := mem.Get(inOffset.Int64(), inSize.Int64())
|
||||
|
||||
//snapshot := self.env.State().Copy()
|
||||
|
||||
var executeAddr []byte
|
||||
if op == CALLCODE {
|
||||
executeAddr = closure.Address()
|
||||
@ -673,8 +671,6 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
|
||||
ret, err := msg.Exec(addr.Bytes(), closure)
|
||||
if err != nil {
|
||||
stack.Push(ethutil.BigFalse)
|
||||
|
||||
//self.env.State().Set(snapshot)
|
||||
} else {
|
||||
stack.Push(ethutil.BigTrue)
|
||||
|
||||
|
@ -237,10 +237,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
|
||||
mem.Resize(newMemSize.Uint64())
|
||||
|
||||
switch op {
|
||||
case LOG:
|
||||
stack.Print()
|
||||
mem.Print()
|
||||
// 0x20 range
|
||||
// 0x20 range
|
||||
case ADD:
|
||||
require(2)
|
||||
x, y := stack.Popn()
|
||||
|
Reference in New Issue
Block a user