Skip to content

Commit 88ff13c

Browse files
committed
Spec changes.
* All errors during state transition result in an invalid tx
1 parent ca1093f commit 88ff13c

4 files changed

Lines changed: 37 additions & 7 deletions

File tree

‎core/error.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,19 @@ func IsKnownBlockErr(e error) bool {
146146
_, ok := e.(*KnownBlockError)
147147
return ok
148148
}
149+
150+
type ValueTransferError struct {
151+
message string
152+
}
153+
154+
func ValueTransferErr(str string, v ...interface{}) *ValueTransferError {
155+
return &ValueTransferError{fmt.Sprintf(str, v...)}
156+
}
157+
158+
func (self *ValueTransferError) Error() string {
159+
return self.message
160+
}
161+
func IsValueTransferErr(e error) bool {
162+
_, ok := e.(*ValueTransferError)
163+
return ok
164+
}

‎core/execution.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package core
22

33
import (
4-
"fmt"
54
"math/big"
65
"time"
76

@@ -26,7 +25,10 @@ func (self *Execution) Addr() []byte {
2625

2726
func (self *Execution) Call(codeAddr []byte, caller vm.ContextRef) ([]byte, error) {
2827
// Retrieve the executing code
29-
code := self.env.State().GetCode(codeAddr)
28+
var code []byte
29+
if self.env.State().GetStateObject(codeAddr) != nil {
30+
code = self.env.State().GetCode(codeAddr)
31+
}
3032

3133
return self.exec(code, codeAddr, caller)
3234
}
@@ -55,7 +57,7 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret
5557

5658
caller.ReturnGas(self.Gas, self.price)
5759

58-
return nil, fmt.Errorf("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
60+
return nil, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
5961
}
6062

6163
snapshot := env.State().Copy()

‎core/state_transition.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package core
33
import (
44
"fmt"
55
"math/big"
6+
67
"github.com/ethereum/go-ethereum/crypto"
78
"github.com/ethereum/go-ethereum/ethutil"
89
"github.com/ethereum/go-ethereum/state"
@@ -185,7 +186,7 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
185186
}
186187
}
187188
if err = self.UseGas(big.NewInt(dgas)); err != nil {
188-
return
189+
return nil, InvalidTxError(err)
189190
}
190191

191192
//stateCopy := self.env.State().Copy()
@@ -231,10 +232,16 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
231232
*/
232233
}
233234

234-
if err != nil {
235-
self.UseGas(self.gas)
235+
if err != nil && IsValueTransferErr(err) {
236+
return nil, InvalidTxError(err)
236237
}
237238

239+
/*
240+
if err != nil {
241+
self.UseGas(self.gas)
242+
}
243+
*/
244+
238245
return
239246
}
240247

‎vm/vm.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
408408
case BALANCE:
409409

410410
addr := stack.Pop().Bytes()
411-
balance := statedb.GetBalance(addr)
411+
var balance *big.Int
412+
if statedb.GetStateObject(addr) != nil {
413+
balance = statedb.GetBalance(addr)
414+
} else {
415+
balance = base
416+
}
412417

413418
stack.Push(balance)
414419

0 commit comments

Comments
 (0)