|
|
@ -40,7 +40,7 @@ var Pow256 = ethutil.BigPow(2, 256) |
|
|
|
|
|
|
|
|
|
|
|
func (vm *Vm) RunClosure(closure *Closure) []byte { |
|
|
|
func (vm *Vm) RunClosure(closure *Closure) []byte { |
|
|
|
// If the amount of gas supplied is less equal to 0
|
|
|
|
// If the amount of gas supplied is less equal to 0
|
|
|
|
if closure.GetGas().Cmp(big.NewInt(0)) <= 0 { |
|
|
|
if closure.Gas.Cmp(big.NewInt(0)) <= 0 { |
|
|
|
// TODO Do something
|
|
|
|
// TODO Do something
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte { |
|
|
|
fee := new(big.Int) |
|
|
|
fee := new(big.Int) |
|
|
|
fee.Add(fee, big.NewInt(1000)) |
|
|
|
fee.Add(fee, big.NewInt(1000)) |
|
|
|
|
|
|
|
|
|
|
|
if closure.GetGas().Cmp(fee) < 0 { |
|
|
|
if closure.Gas.Cmp(fee) < 0 { |
|
|
|
return closure.Return(nil) |
|
|
|
return closure.Return(nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -192,25 +192,37 @@ func (vm *Vm) RunClosure(closure *Closure) []byte { |
|
|
|
|
|
|
|
|
|
|
|
// 0x30 range
|
|
|
|
// 0x30 range
|
|
|
|
case oADDRESS: |
|
|
|
case oADDRESS: |
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(closure.Object().Address())) |
|
|
|
case oBALANCE: |
|
|
|
case oBALANCE: |
|
|
|
|
|
|
|
stack.Push(closure.Value) |
|
|
|
case oORIGIN: |
|
|
|
case oORIGIN: |
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(vm.vars.origin)) |
|
|
|
case oCALLER: |
|
|
|
case oCALLER: |
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(closure.Callee().Address())) |
|
|
|
case oCALLVALUE: |
|
|
|
case oCALLVALUE: |
|
|
|
|
|
|
|
// FIXME: Original value of the call, not the current value
|
|
|
|
|
|
|
|
stack.Push(closure.Value) |
|
|
|
case oCALLDATA: |
|
|
|
case oCALLDATA: |
|
|
|
offset := stack.Pop() |
|
|
|
offset := stack.Pop() |
|
|
|
mem.Set(offset.Int64(), int64(len(closure.Args)), closure.Args) |
|
|
|
mem.Set(offset.Int64(), int64(len(closure.Args)), closure.Args) |
|
|
|
case oCALLDATASIZE: |
|
|
|
case oCALLDATASIZE: |
|
|
|
case oRETURNDATASIZE: |
|
|
|
stack.Push(big.NewInt(int64(len(closure.Args)))) |
|
|
|
case oTXGASPRICE: |
|
|
|
case oGASPRICE: |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
|
|
// 0x40 range
|
|
|
|
// 0x40 range
|
|
|
|
case oPREVHASH: |
|
|
|
case oPREVHASH: |
|
|
|
case oPREVNONCE: |
|
|
|
stack.Push(ethutil.BigD(vm.vars.prevHash)) |
|
|
|
case oCOINBASE: |
|
|
|
case oCOINBASE: |
|
|
|
|
|
|
|
stack.Push(ethutil.BigD(vm.vars.coinbase)) |
|
|
|
case oTIMESTAMP: |
|
|
|
case oTIMESTAMP: |
|
|
|
|
|
|
|
stack.Push(big.NewInt(vm.vars.time)) |
|
|
|
case oNUMBER: |
|
|
|
case oNUMBER: |
|
|
|
|
|
|
|
stack.Push(big.NewInt(int64(vm.vars.blockNumber))) |
|
|
|
case oDIFFICULTY: |
|
|
|
case oDIFFICULTY: |
|
|
|
|
|
|
|
stack.Push(vm.vars.diff) |
|
|
|
case oGASLIMIT: |
|
|
|
case oGASLIMIT: |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
|
|
// 0x50 range
|
|
|
|
// 0x50 range
|
|
|
|
case oPUSH: // Push PC+1 on to the stack
|
|
|
|
case oPUSH: // Push PC+1 on to the stack
|
|
|
@ -218,8 +230,13 @@ func (vm *Vm) RunClosure(closure *Closure) []byte { |
|
|
|
val := closure.GetMem(pc).BigInt() |
|
|
|
val := closure.GetMem(pc).BigInt() |
|
|
|
stack.Push(val) |
|
|
|
stack.Push(val) |
|
|
|
case oPOP: |
|
|
|
case oPOP: |
|
|
|
|
|
|
|
stack.Pop() |
|
|
|
case oDUP: |
|
|
|
case oDUP: |
|
|
|
|
|
|
|
stack.Push(stack.Peek()) |
|
|
|
case oSWAP: |
|
|
|
case oSWAP: |
|
|
|
|
|
|
|
x, y := stack.Popn() |
|
|
|
|
|
|
|
stack.Push(y) |
|
|
|
|
|
|
|
stack.Push(x) |
|
|
|
case oMLOAD: |
|
|
|
case oMLOAD: |
|
|
|
offset := stack.Pop() |
|
|
|
offset := stack.Pop() |
|
|
|
stack.Push(ethutil.BigD(mem.Get(offset.Int64(), 32))) |
|
|
|
stack.Push(ethutil.BigD(mem.Get(offset.Int64(), 32))) |
|
|
@ -228,7 +245,13 @@ func (vm *Vm) RunClosure(closure *Closure) []byte { |
|
|
|
val, mStart := stack.Popn() |
|
|
|
val, mStart := stack.Popn() |
|
|
|
mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(val, 256)) |
|
|
|
mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(val, 256)) |
|
|
|
case oMSTORE8: |
|
|
|
case oMSTORE8: |
|
|
|
|
|
|
|
val, mStart := stack.Popn() |
|
|
|
|
|
|
|
base.And(val, new(big.Int).SetInt64(0xff)) |
|
|
|
|
|
|
|
mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(base, 256)) |
|
|
|
case oSLOAD: |
|
|
|
case oSLOAD: |
|
|
|
|
|
|
|
loc := stack.Pop() |
|
|
|
|
|
|
|
val := closure.GetMem(loc.Int64()) |
|
|
|
|
|
|
|
stack.Push(val.BigInt()) |
|
|
|
case oSSTORE: |
|
|
|
case oSSTORE: |
|
|
|
case oJUMP: |
|
|
|
case oJUMP: |
|
|
|
case oJUMPI: |
|
|
|
case oJUMPI: |
|
|
|