From 88af879f7ae55249ff7a9669184b52a611e4fb20 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 19 Dec 2014 01:18:22 +0100 Subject: [PATCH 1/6] version bump --- cmd/ethereum/main.go | 2 +- cmd/mist/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 9efc8e9dc..2a3c46054 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -30,7 +30,7 @@ import ( const ( ClientIdentifier = "Ethereum(G)" - Version = "0.7.9" + Version = "0.7.10" ) var clilogger = logger.NewLogger("CLI") diff --git a/cmd/mist/main.go b/cmd/mist/main.go index 14336b4e8..eaf0af0c7 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -31,7 +31,7 @@ import ( const ( ClientIdentifier = "Mist" - Version = "0.7.9" + Version = "0.7.10" ) var ethereum *eth.Ethereum From 5da5db5a0a149235c742748aa4b3b94d13d6910f Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 19 Dec 2014 13:34:21 +0100 Subject: [PATCH 2/6] Added authors --- cmd/mist/assets/qml/main.qml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/mist/assets/qml/main.qml b/cmd/mist/assets/qml/main.qml index 9f1f214a6..a08a8b4ef 100644 --- a/cmd/mist/assets/qml/main.qml +++ b/cmd/mist/assets/qml/main.qml @@ -786,8 +786,8 @@ ApplicationWindow { title: "About" minimumWidth: 350 maximumWidth: 350 - maximumHeight: 200 - minimumHeight: 200 + maximumHeight: 280 + minimumHeight: 280 Image { id: aboutIcon @@ -797,7 +797,7 @@ ApplicationWindow { smooth: true source: "../facet.png" x: 10 - y: 10 + y: 30 } Text { @@ -806,7 +806,7 @@ ApplicationWindow { anchors.top: parent.top anchors.topMargin: 30 font.pointSize: 12 - text: "

Mist (0.6.5)

Amalthea


Development

Jeffrey Wilcke
Viktor Trón

Building

Maran Hidskes" + text: "

Mist (0.7.10)


Development

Jeffrey Wilcke
Viktor Trón
Felix Lange
Taylor Gerring
Daniel Nagy

UX

Alex van de Sande
" } } From 0e93b98533968f4a0033ec6214391f5ca647a956 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 19 Dec 2014 13:34:53 +0100 Subject: [PATCH 3/6] Transaction was generating incorrect hash because of var changes --- core/state_transition.go | 2 +- core/types/transaction.go | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 9e81ddf28..a54246eba 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -112,7 +112,7 @@ func (self *StateTransition) BuyGas() error { sender := self.From() if sender.Balance().Cmp(MessageGasValue(self.msg)) < 0 { - return fmt.Errorf("Insufficient funds to pre-pay gas. Req %v, has %v", MessageGasValue(self.msg), sender.Balance()) + return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address()[:4], MessageGasValue(self.msg), sender.Balance()) } coinbase := self.Coinbase() diff --git a/core/types/transaction.go b/core/types/transaction.go index c64fb69f0..f6ad0774b 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -47,7 +47,7 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction { } func (tx *Transaction) Hash() []byte { - data := []interface{}{tx.Nonce, tx.gasPrice, tx.gas, tx.recipient, tx.Value, tx.Data} + data := []interface{}{tx.nonce, tx.gasPrice, tx.gas, tx.recipient, tx.value, tx.data} return crypto.Sha3(ethutil.NewValue(data).Encode()) } @@ -108,8 +108,8 @@ func (tx *Transaction) PublicKey() []byte { sig := append(r, s...) sig = append(sig, v-27) - pubkey := crypto.Ecrecover(append(hash, sig...)) - //pubkey, _ := secp256k1.RecoverPubkey(hash, sig) + //pubkey := crypto.Ecrecover(append(hash, sig...)) + pubkey, _ := secp256k1.RecoverPubkey(hash, sig) return pubkey } @@ -138,9 +138,7 @@ func (tx *Transaction) Sign(privk []byte) error { } func (tx *Transaction) RlpData() interface{} { - data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.recipient, tx.Value, tx.Data} - - // TODO Remove prefixing zero's + data := []interface{}{tx.nonce, tx.gasPrice, tx.gas, tx.recipient, tx.value, tx.data} return append(data, tx.v, new(big.Int).SetBytes(tx.r).Bytes(), new(big.Int).SetBytes(tx.s).Bytes()) } @@ -184,6 +182,7 @@ func (tx *Transaction) String() string { V: 0x%x R: 0x%x S: 0x%x + Hex: %x `, tx.Hash(), len(tx.recipient) == 0, @@ -192,11 +191,13 @@ func (tx *Transaction) String() string { tx.nonce, tx.gasPrice, tx.gas, - tx.Value, - tx.Data, + tx.value, + tx.data, tx.v, tx.r, - tx.s) + tx.s, + ethutil.Encode(tx), + ) } // Transaction slice type for basic sorting From f5b8f3d41b533d51eb81e895ed9b6aa31d7aaaef Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 19 Dec 2014 13:59:49 +0100 Subject: [PATCH 4/6] Removed OOG check. Revert should always happen. --- core/block_manager.go | 2 +- core/execution.go | 4 +--- core/state_transition.go | 11 +++++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/block_manager.go b/core/block_manager.go index 8d319f84e..20285f8f0 100644 --- a/core/block_manager.go +++ b/core/block_manager.go @@ -129,7 +129,6 @@ done: statelogger.Infoln(err) erroneous = append(erroneous, tx) err = nil - continue } } @@ -215,6 +214,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I receiptSha := types.DeriveSha(receipts) if bytes.Compare(receiptSha, block.ReceiptSha) != 0 { + chainlogger.Debugln(receipts) err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha) return } diff --git a/core/execution.go b/core/execution.go index 0b5e0558f..44dbd3ace 100644 --- a/core/execution.go +++ b/core/execution.go @@ -56,9 +56,7 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret snapshot := env.State().Copy() defer func() { - if vm.IsOOGErr(err) { - env.State().Set(snapshot) - } + env.State().Set(snapshot) chainlogger.Debugf("post state %x\n", env.State().Root()) }() diff --git a/core/state_transition.go b/core/state_transition.go index a54246eba..a60f31e3e 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -189,12 +189,19 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) { self.rec = MakeContract(msg, self.state) ret, err, ref = vmenv.Create(sender, self.rec.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value) - ref.SetCode(ret) + if err == nil { + dataGas := big.NewInt(int64(len(ret))) + dataGas.Mul(dataGas, vm.GasCreateByte) + if err = self.UseGas(dataGas); err == nil { + ref.SetCode(ret) + } + } } else { ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value) } + if err != nil { - statelogger.Debugln(err) + self.UseGas(self.gas) } return From 1508a23a6fe3cc50f718bfd6c62caae056534c09 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 20 Dec 2014 02:21:13 +0100 Subject: [PATCH 5/6] Minor updates on gas and removed/refactored old code. --- core/block_manager.go | 4 +++- core/execution.go | 15 ++++++--------- core/state_transition.go | 25 ++++++++++++------------ state/state.go | 7 +++++++ vm/environment.go | 5 +++++ vm/vm_debug.go | 41 +++++++++++++++++++++------------------- 6 files changed, 55 insertions(+), 42 deletions(-) diff --git a/core/block_manager.go b/core/block_manager.go index 20285f8f0..2567e39c4 100644 --- a/core/block_manager.go +++ b/core/block_manager.go @@ -142,6 +142,7 @@ done: receipt := types.NewReceipt(state.Root(), cumulative) receipt.SetLogs(state.Logs()) receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) + chainlogger.Debugln(receipt) // Notify all subscribers if !transientProcess { @@ -214,7 +215,8 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I receiptSha := types.DeriveSha(receipts) if bytes.Compare(receiptSha, block.ReceiptSha) != 0 { - chainlogger.Debugln(receipts) + //chainlogger.Debugf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha) + fmt.Printf("%x\n", ethutil.Encode(receipts)) err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha) return } diff --git a/core/execution.go b/core/execution.go index 44dbd3ace..b7eead0dd 100644 --- a/core/execution.go +++ b/core/execution.go @@ -3,6 +3,7 @@ package core import ( "fmt" "math/big" + "time" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/vm" @@ -12,7 +13,6 @@ type Execution struct { env vm.Environment address, input []byte Gas, price, value *big.Int - object *state.StateObject SkipTransfer bool } @@ -35,8 +35,6 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret env := self.env evm := vm.New(env, vm.DebugVmTy) - chainlogger.Debugf("pre state %x\n", env.State().Root()) - if env.Depth() == vm.MaxCallDepth { // Consume all gas (by not returning it) and return a depth error return nil, vm.DepthError{} @@ -55,13 +53,12 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret } snapshot := env.State().Copy() - defer func() { - env.State().Set(snapshot) - chainlogger.Debugf("post state %x\n", env.State().Root()) - }() - - self.object = to + start := time.Now() ret, err = evm.Run(to, caller, code, self.value, self.Gas, self.price, self.input) + if err != nil { + env.State().Set(snapshot) + } + chainlogger.Debugf("vm took %v\n", time.Since(start)) return } diff --git a/core/state_transition.go b/core/state_transition.go index a60f31e3e..7b7026c29 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -186,13 +186,13 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) { vmenv := self.VmEnv() var ref vm.ClosureRef if MessageCreatesContract(msg) { - self.rec = MakeContract(msg, self.state) - - ret, err, ref = vmenv.Create(sender, self.rec.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value) + contract := MakeContract(msg, self.state) + ret, err, ref = vmenv.Create(sender, contract.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value) if err == nil { dataGas := big.NewInt(int64(len(ret))) dataGas.Mul(dataGas, vm.GasCreateByte) if err = self.UseGas(dataGas); err == nil { + //self.state.SetCode(ref.Address(), ret) ref.SetCode(ret) } } @@ -218,20 +218,19 @@ func MakeContract(msg Message, state *state.StateDB) *state.StateObject { } func (self *StateTransition) RefundGas() { - coinbaseSub := new(big.Int).Set(self.gas) - uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2) - for addr, ref := range self.state.Refunds() { - refund := ethutil.BigMin(uhalf, ref) - coinbaseSub.Add(self.gas, refund) - self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice())) - } - coinbase, sender := self.Coinbase(), self.From() - coinbase.RefundGas(coinbaseSub, self.msg.GasPrice()) - // Return remaining gas remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice()) sender.AddAmount(remaining) + + uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2) + for addr, ref := range self.state.Refunds() { + refund := ethutil.BigMin(uhalf, ref) + self.gas.Add(self.gas, refund) + self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice())) + } + + coinbase.RefundGas(self.gas, self.msg.GasPrice()) } func (self *StateTransition) GasUsed() *big.Int { diff --git a/state/state.go b/state/state.go index a8d611668..f77da72f0 100644 --- a/state/state.go +++ b/state/state.go @@ -94,6 +94,13 @@ func (self *StateDB) GetCode(addr []byte) []byte { return nil } +func (self *StateDB) SetCode(addr, code []byte) { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + stateObject.SetCode(code) + } +} + func (self *StateDB) GetState(a, b []byte) []byte { stateObject := self.GetStateObject(a) if stateObject != nil { diff --git a/vm/environment.go b/vm/environment.go index d77fb1419..969bc5e43 100644 --- a/vm/environment.go +++ b/vm/environment.go @@ -2,6 +2,7 @@ package vm import ( "errors" + "fmt" "math/big" "github.com/ethereum/go-ethereum/ethutil" @@ -74,3 +75,7 @@ func (self *Log) Data() []byte { func (self *Log) RlpData() interface{} { return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data} } + +func (self *Log) String() string { + return fmt.Sprintf("[A=%x T=%x D=%x]", self.address, self.topics, self.data) +} diff --git a/vm/vm_debug.go b/vm/vm_debug.go index fd16a3895..aa3291e66 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -108,13 +108,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * } ) + vmlogger.Debugf("(%d) (%x) %x (code=%d) gas: %v (d) %x\n", self.env.Depth(), caller.Address()[:4], closure.Address(), len(code), closure.Gas, callData) + // Don't bother with the execution if there's no code. if len(code) == 0 { return closure.Return(nil), nil } - vmlogger.Debugf("(%d) (%x) %x gas: %v (d) %x\n", self.env.Depth(), caller.Address()[:4], closure.Address(), closure.Gas, callData) - for { prevStep = step // The base for all big integer arithmetic @@ -134,6 +134,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * addStepGasUsage(GasStep) var newMemSize *big.Int = ethutil.Big0 + var additionalGas *big.Int = new(big.Int) // Stack Check, memory resize & gas phase switch op { // Stack checks only @@ -213,22 +214,24 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2]) case SHA3: require(2) - gas.Set(GasSha) - newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2]) + additionalGas.Set(stack.data[stack.Len()-2]) case CALLDATACOPY: require(2) newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3]) + additionalGas.Set(stack.data[stack.Len()-3]) case CODECOPY: require(3) newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3]) + additionalGas.Set(stack.data[stack.Len()-3]) case EXTCODECOPY: require(4) newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-4]) + additionalGas.Set(stack.data[stack.Len()-4]) case CALL, CALLCODE: require(7) gas.Set(GasCall) @@ -245,20 +248,23 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-3]) } + switch op { + case CALLDATACOPY, CODECOPY, EXTCODECOPY: + additionalGas.Add(additionalGas, u256(31)) + additionalGas.Div(additionalGas, u256(32)) + addStepGasUsage(additionalGas) + case SHA3: + additionalGas.Add(additionalGas, u256(31)) + additionalGas.Div(additionalGas, u256(32)) + additionalGas.Mul(additionalGas, GasSha3Byte) + addStepGasUsage(additionalGas) + } + if newMemSize.Cmp(ethutil.Big0) > 0 { newMemSize.Add(newMemSize, u256(31)) newMemSize.Div(newMemSize, u256(32)) newMemSize.Mul(newMemSize, u256(32)) - switch op { - case CALLDATACOPY, CODECOPY, EXTCODECOPY: - addStepGasUsage(new(big.Int).Div(newMemSize, u256(32))) - case SHA3: - g := new(big.Int).Div(newMemSize, u256(32)) - g.Mul(g, GasSha3Byte) - addStepGasUsage(g) - } - if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 { memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len()))) memGasUsage.Mul(GasMemory, memGasUsage) @@ -643,9 +649,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * case CODECOPY, EXTCODECOPY: var code []byte if op == EXTCODECOPY { - addr := stack.Pop().Bytes() - - code = statedb.GetCode(addr) + code = statedb.GetCode(stack.Pop().Bytes()) } else { code = closure.Code } @@ -663,12 +667,11 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * } else if cOff+l > size { l = uint64(math.Min(float64(cOff+l), float64(size))) } - codeCopy := code[cOff : cOff+l] mem.Set(mOff, l, codeCopy) - self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, code[cOff:cOff+l]) + self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, codeCopy) case GASPRICE: stack.Push(closure.Price) @@ -891,7 +894,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price * size, offset := stack.Popn() ret := mem.Get(offset.Int64(), size.Int64()) - self.Printf(" => (%d) 0x%x", len(ret), ret).Endl() + self.Printf(" => [%v, %v] (%d) 0x%x", offset, size, len(ret), ret).Endl() return closure.Return(ret), nil case SUICIDE: From 0a9dc1536c5d776844d6947a0090ff7e1a7c6ab4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 20 Dec 2014 02:33:45 +0100 Subject: [PATCH 6/6] Increased peer from 10 to 30 --- cmd/ethereum/flags.go | 2 +- cmd/mist/flags.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index 783944cf2..85aca47c3 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -85,7 +85,7 @@ func Init() { flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") flag.StringVar(&OutboundPort, "port", "30303", "listening port") flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") - flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") + flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index 2ae0a0487..e49408181 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -104,7 +104,7 @@ func Init() { flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") flag.StringVar(&OutboundPort, "port", "30303", "listening port") flag.BoolVar(&UseUPnP, "upnp", true, "enable UPnP support") - flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") + flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")