aboutsummaryrefslogtreecommitdiffstats
path: root/vm/vm.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-13 20:44:15 +0800
committerobscuren <geffobscura@gmail.com>2015-03-13 20:44:15 +0800
commitf76cc6699ecd995d78cfd980b229473101191137 (patch)
treed91ea0c1725b080062cb6eb2b294e61af02cacc2 /vm/vm.go
parent80592f244da3f7323b7fa3e75a17c8e37c97fe8d (diff)
downloaddexon-f76cc6699ecd995d78cfd980b229473101191137.tar
dexon-f76cc6699ecd995d78cfd980b229473101191137.tar.gz
dexon-f76cc6699ecd995d78cfd980b229473101191137.tar.bz2
dexon-f76cc6699ecd995d78cfd980b229473101191137.tar.lz
dexon-f76cc6699ecd995d78cfd980b229473101191137.tar.xz
dexon-f76cc6699ecd995d78cfd980b229473101191137.tar.zst
dexon-f76cc6699ecd995d78cfd980b229473101191137.zip
Changed context and ADDMOD, MULMOD
* Cleaned up VM execution. VM run now takes a context * ADDMOD/MULMOD - removed incorrect cast
Diffstat (limited to 'vm/vm.go')
-rw-r--r--vm/vm.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/vm/vm.go b/vm/vm.go
index a818ac47d..58aebeedb 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -32,10 +32,17 @@ func New(env Environment) *Vm {
return &Vm{debug: Debug, env: env, logTy: lt, Recoverable: true}
}
-func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) {
+func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
+ //func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) {
self.env.SetDepth(self.env.Depth() + 1)
- context := NewContext(caller, me, code, gas, price)
+ //context := NewContext(caller, me, code, gas, price)
+ var (
+ caller = context.caller
+ code = context.Code
+ value = context.value
+ price = context.Price
+ )
self.Printf("(%d) (%x) %x (code=%d) gas: %v (d) %x", self.env.Depth(), caller.Address()[:4], context.Address(), len(code), context.Gas, callData).Endl()
@@ -55,7 +62,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
}()
}
- if p := Precompiled[string(me.Address())]; p != nil {
+ if p := Precompiled[string(context.CodeAddr)]; p != nil {
return self.RunPrecompiled(p, callData, context)
}
@@ -352,7 +359,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
z := stack.pop()
if z.Cmp(Zero) > 0 {
- add := U256(new(big.Int).Add(x, y))
+ add := new(big.Int).Add(x, y)
base.Mod(add, z)
base = U256(base)
@@ -362,13 +369,12 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
stack.push(base)
case MULMOD:
-
x := stack.pop()
y := stack.pop()
z := stack.pop()
- mul := new(big.Int).Mul(x, y)
- if len(z.Bytes()) > 0 { // NOT 0x0
+ if z.Cmp(Zero) > 0 {
+ mul := new(big.Int).Mul(x, y)
base.Mod(mul, z)
U256(base)
@@ -476,13 +482,12 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
} else {
code = context.Code
}
- context := NewContext(nil, nil, code, ethutil.Big0, ethutil.Big0)
var (
mOff = stack.pop().Uint64()
cOff = stack.pop().Uint64()
l = stack.pop().Uint64()
)
- codeCopy := context.GetCode(cOff, l)
+ codeCopy := getCode(code, cOff, l)
mem.Set(mOff, l, codeCopy)