From 23b5b5fa36530eb82543d7d877f8e9e1900232cf Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 4 Jul 2014 13:34:50 +0200 Subject: [PATCH 1/2] Length check --- ethutil/script.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethutil/script.go b/ethutil/script.go index aaa0f8ed8..fa05094e7 100644 --- a/ethutil/script.go +++ b/ethutil/script.go @@ -13,7 +13,7 @@ func Compile(script string) (ret []byte, err error) { if len(script) > 2 { line := strings.Split(script, "\n")[0] - if line[0:2] == "#!" { + if len(line) > 1 && line[0:2] == "#!" { switch line { case "#!serpent": byteCode, err := serpent.Compile(script) From 90eb4f1939f7b0389d5784b889cc0e5d2b3451f7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 4 Jul 2014 15:32:10 +0200 Subject: [PATCH 2/2] Debug output, minor fixes and tweaks * Script compile length fix * Transition fix --- ethchain/state_manager.go | 15 ++++++++++++++- ethchain/state_transition.go | 11 +++++------ ethchain/vm.go | 7 ++++--- ethpub/pub.go | 2 +- ethutil/script.go | 3 ++- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index cec424583..f3fd92913 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -181,11 +181,24 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) { if err != nil { if len(receipts) == len(block.Receipts()) { for i, receipt := range block.Receipts() { - statelogger.Debugf("diff (r) %v ~ %x <=> (c) %v ~ %x (%x)\n", receipt.CumulativeGasUsed, receipt.PostState[0:4], receipts[i].CumulativeGasUsed, receipts[i].PostState[0:4], receipt.Tx.Hash()) + statelogger.Infof("diff (r) %v ~ %x <=> (c) %v ~ %x (%x)\n", receipt.CumulativeGasUsed, receipt.PostState[0:4], receipts[i].CumulativeGasUsed, receipts[i].PostState[0:4], receipt.Tx.Hash()) } } else { statelogger.Warnln("Unable to print receipt diff. Length didn't match", len(receipts), "for", len(block.Receipts())) } + } else { + /* + for i, receipt := range receipts { + gu := new(big.Int) + if i != 0 { + gu.Sub(receipt.CumulativeGasUsed, receipts[i-1].CumulativeGasUsed) + } else { + gu.Set(receipt.CumulativeGasUsed) + } + + statelogger.Infof("[r] %v ~ %x (%x)\n", gu, receipt.PostState[0:4], receipt.Tx.Hash()) + } + */ } }() diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go index 16e1f124b..6ea9a837d 100644 --- a/ethchain/state_transition.go +++ b/ethchain/state_transition.go @@ -201,8 +201,7 @@ func (self *StateTransition) TransitionState() (err error) { // script section for the state object. self.data = nil - statelogger.Debugln("~> init") - code, err := self.Eval(receiver.Init(), receiver) + code, err := self.Eval(receiver.Init(), receiver, "init") if err != nil { //self.state.Set(snapshot) self.state.ResetStateObject(receiver) @@ -213,8 +212,7 @@ func (self *StateTransition) TransitionState() (err error) { receiver.script = code } else { if len(receiver.Script()) > 0 { - statelogger.Debugln("~> code") - _, err = self.Eval(receiver.Script(), receiver) + _, err = self.Eval(receiver.Script(), receiver, "code") if err != nil { //self.state.Set(snapshot) self.state.ResetStateObject(receiver) @@ -240,7 +238,7 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error return nil } -func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []byte, err error) { +func (self *StateTransition) Eval(script []byte, context *StateObject, typ string) (ret []byte, err error) { var ( block = self.block initiator = self.Sender() @@ -259,6 +257,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by Value: self.value, }) vm.Verbose = true + vm.Fn = typ ret, err = Call(vm, closure, self.data) @@ -279,7 +278,7 @@ func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error) { // TODO FIXME ASAP context.state.trie = t2 - statelogger.Debugln("Warn: PARANOIA: Different state object roots during copy") + statelogger.Infoln("Warn: PARANOIA: Different state object roots during copy") } } diff --git a/ethchain/vm.go b/ethchain/vm.go index 3a7aa8c58..cfedadb08 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -56,6 +56,7 @@ type Vm struct { Hook DebugHook BreakPoints []int64 Stepping bool + Fn string } type DebugHook func(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool @@ -107,7 +108,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { } }() - vmlogger.Debugf("(~) %x gas: %v (d) %x\n", closure.object.Address(), closure.Gas, closure.Args) + vmlogger.Debugf("(%s) %x gas: %v (d) %x\n", vm.Fn, closure.object.Address(), closure.Gas, closure.Args) var ( op OpCode @@ -577,7 +578,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { stack.Push(val.BigInt()) - vm.Printf(" {0x%x} 0x%x", loc.Bytes(), val.Bytes()) + vm.Printf(" {0x%x : 0x%x}", loc.Bytes(), val.Bytes()) case SSTORE: require(2) val, loc := stack.Popn() @@ -586,7 +587,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) { // Add the change to manifest vm.state.manifest.AddStorageChange(closure.Object(), loc.Bytes(), val) - vm.Printf(" {0x%x} 0x%x", loc, val) + vm.Printf(" {0x%x : 0x%x}", loc, val) case JUMP: require(1) pc = stack.Pop() diff --git a/ethpub/pub.go b/ethpub/pub.go index 4845b1d13..f409d136b 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -217,7 +217,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, sc if ethutil.IsHex(scriptStr) { script = ethutil.Hex2Bytes(scriptStr[2:]) } else { - script, err = ethutil.Compile(scriptStr) + script, err = ethutil.Compile(scriptStr, false) if err != nil { return nil, err } diff --git a/ethutil/script.go b/ethutil/script.go index fa05094e7..f5c53f84c 100644 --- a/ethutil/script.go +++ b/ethutil/script.go @@ -9,7 +9,7 @@ import ( ) // General compile function -func Compile(script string) (ret []byte, err error) { +func Compile(script string, silent bool) (ret []byte, err error) { if len(script) > 2 { line := strings.Split(script, "\n")[0] @@ -26,6 +26,7 @@ func Compile(script string) (ret []byte, err error) { } else { compiler := mutan.NewCompiler(backend.NewEthereumBackend()) + compiler.Silent = silent byteCode, errors := compiler.Compile(strings.NewReader(script)) if len(errors) > 0 { var errs string