From 16e8fc7427115e67096c6056b2ad9401803fcb44 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 23 Jun 2014 16:11:55 +0200 Subject: [PATCH 1/3] Logging order --- ethchain/state_object.go | 1 - ethchain/vm.go | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ethchain/state_object.go b/ethchain/state_object.go index 0a2e28ded..270c9a7f8 100644 --- a/ethchain/state_object.go +++ b/ethchain/state_object.go @@ -91,7 +91,6 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) { func (c *StateObject) SetStorage(num *big.Int, val *ethutil.Value) { addr := ethutil.BigToBytes(num, 256) - // FIXME This should be handled in the Trie it self if val.BigInt().Cmp(ethutil.Big0) == 0 { c.state.trie.Delete(string(addr)) diff --git a/ethchain/vm.go b/ethchain/vm.go index 432bc4e6d..4c6c5e24d 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -93,7 +93,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro if r := recover(); r != nil { ret = closure.Return(nil) err = fmt.Errorf("%v", r) - fmt.Println("vm err", err) + fmt.Println(err) } }() @@ -106,11 +106,11 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro require := func(m int) { if stack.Len() < m { isRequireError = true - panic(fmt.Sprintf("stack = %d, req = %d", stack.Len(), m)) + panic(fmt.Sprintf("stack err = %d, req = %d", stack.Len(), m)) } } - // Instruction pointer + // Program counter pc := big.NewInt(0) // Current step count step := 0 @@ -593,16 +593,18 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro // Generate a new address addr := ethutil.CreateAddress(closure.caller.Address(), closure.caller.N()) + + vm.Printf(" (*) %x", addr).Endl() + // Create a new contract contract := vm.state.NewStateObject(addr) contract.Amount = value // Set the init script - contract.initScript = mem.Get(offset.Int64(), size.Int64()) + contract.initScript = ethutil.BigD(mem.Get(offset.Int64(), size.Int64())).Bytes() // Transfer all remaining gas to the new // contract so it may run the init script gas := new(big.Int).Set(closure.Gas) - //closure.UseGas(gas) // Create the closure c := NewClosure(closure.caller, @@ -613,6 +615,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro closure.Price) // Call the closure and set the return value as // main script. + var err error c.Script, gas, err = c.Call(vm, nil, hook) if err != nil { From 9dae1a17324df671bf2223ae80257a310cecfea5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 25 Jun 2014 09:47:19 +0200 Subject: [PATCH 2/3] Removed BlockDo Method --- ethereum.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/ethereum.go b/ethereum.go index 77a7c92c7..a6cb78b1f 100644 --- a/ethereum.go +++ b/ethereum.go @@ -113,24 +113,6 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) { return ethereum, nil } -// Replay block -func (self *Ethereum) BlockDo(hash []byte) error { - block := self.blockChain.GetBlock(hash) - if block == nil { - return fmt.Errorf("unknown block %x", hash) - } - - parent := self.blockChain.GetBlock(block.PrevHash) - - _, err := self.stateManager.ApplyDiff(parent.State(), parent, block) - if err != nil { - return err - } - - return nil - -} - func (s *Ethereum) Reactor() *ethutil.ReactorEngine { return s.reactor } From b0dc50c2a0e25bf88901f3dd481f14bc3375adc5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 25 Jun 2014 17:26:34 +0200 Subject: [PATCH 3/3] New mutan implementation --- ethutil/script.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/ethutil/script.go b/ethutil/script.go index c8b1da51c..235498df2 100644 --- a/ethutil/script.go +++ b/ethutil/script.go @@ -3,6 +3,7 @@ package ethutil import ( "fmt" "github.com/obscuren/mutan" + "github.com/obscuren/mutan/backends" "github.com/obscuren/serpent-go" "strings" ) @@ -19,7 +20,9 @@ func Compile(script string) (ret []byte, err error) { return byteCode, nil } else { - byteCode, errors := mutan.Compile(strings.NewReader(script), false) + compiler := mutan.NewCompiler(backend.NewEthereumBackend()) + byteCode, errors := compiler.Compile(strings.NewReader(script)) + //byteCode, errors := mutan.Compile(strings.NewReader(script), false) if len(errors) > 0 { var errs string for _, er := range errors { @@ -33,21 +36,3 @@ func Compile(script string) (ret []byte, err error) { return byteCode, nil } } - -func CompileScript(script string) ([]byte, []byte, error) { - // Preprocess - mainInput, initInput := mutan.PreParse(script) - // Compile main script - mainScript, err := Compile(mainInput) - if err != nil { - return nil, nil, err - } - - // Compile init script - initScript, err := Compile(initInput) - if err != nil { - return nil, nil, err - } - - return mainScript, initScript, nil -}