|
|
@ -13,10 +13,6 @@ import ( |
|
|
|
"github.com/ethereum/go-ethereum/params" |
|
|
|
"github.com/ethereum/go-ethereum/params" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const tryJit = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var () |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* The State transitioning model |
|
|
|
* The State transitioning model |
|
|
|
* |
|
|
|
* |
|
|
@ -69,10 +65,6 @@ func MessageCreatesContract(msg Message) bool { |
|
|
|
return msg.To() == nil |
|
|
|
return msg.To() == nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func MessageGasValue(msg Message) *big.Int { |
|
|
|
|
|
|
|
return new(big.Int).Mul(msg.Gas(), msg.GasPrice()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IntrinsicGas computes the 'intrisic gas' for a message
|
|
|
|
// IntrinsicGas computes the 'intrisic gas' for a message
|
|
|
|
// with the given data.
|
|
|
|
// with the given data.
|
|
|
|
func IntrinsicGas(data []byte) *big.Int { |
|
|
|
func IntrinsicGas(data []byte) *big.Int { |
|
|
@ -104,7 +96,7 @@ func NewStateTransition(env vm.Environment, msg Message, coinbase *state.StateOb |
|
|
|
env: env, |
|
|
|
env: env, |
|
|
|
msg: msg, |
|
|
|
msg: msg, |
|
|
|
gas: new(big.Int), |
|
|
|
gas: new(big.Int), |
|
|
|
gasPrice: new(big.Int).Set(msg.GasPrice()), |
|
|
|
gasPrice: msg.GasPrice(), |
|
|
|
initialGas: new(big.Int), |
|
|
|
initialGas: new(big.Int), |
|
|
|
value: msg.Value(), |
|
|
|
value: msg.Value(), |
|
|
|
data: msg.Data(), |
|
|
|
data: msg.Data(), |
|
|
@ -148,26 +140,22 @@ func (self *StateTransition) AddGas(amount *big.Int) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (self *StateTransition) BuyGas() error { |
|
|
|
func (self *StateTransition) BuyGas() error { |
|
|
|
var err error |
|
|
|
mgas := self.msg.Gas() |
|
|
|
|
|
|
|
mgval := new(big.Int).Mul(mgas, self.gasPrice) |
|
|
|
|
|
|
|
|
|
|
|
sender, err := self.From() |
|
|
|
sender, err := self.From() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if sender.Balance().Cmp(MessageGasValue(self.msg)) < 0 { |
|
|
|
if sender.Balance().Cmp(mgval) < 0 { |
|
|
|
return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address().Bytes()[:4], MessageGasValue(self.msg), sender.Balance()) |
|
|
|
return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address().Bytes()[:4], mgval, sender.Balance()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err = self.Coinbase().SubGas(mgas, self.gasPrice); err != nil { |
|
|
|
coinbase := self.Coinbase() |
|
|
|
|
|
|
|
err = coinbase.SubGas(self.msg.Gas(), self.msg.GasPrice()) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
self.AddGas(mgas) |
|
|
|
self.AddGas(self.msg.Gas()) |
|
|
|
self.initialGas.Set(mgas) |
|
|
|
self.initialGas.Set(self.msg.Gas()) |
|
|
|
sender.SubBalance(mgval) |
|
|
|
sender.SubBalance(MessageGasValue(self.msg)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -245,15 +233,15 @@ func (self *StateTransition) refundGas() { |
|
|
|
coinbase := self.Coinbase() |
|
|
|
coinbase := self.Coinbase() |
|
|
|
sender, _ := self.From() // err already checked
|
|
|
|
sender, _ := self.From() // err already checked
|
|
|
|
// Return remaining gas
|
|
|
|
// Return remaining gas
|
|
|
|
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice()) |
|
|
|
remaining := new(big.Int).Mul(self.gas, self.gasPrice) |
|
|
|
sender.AddBalance(remaining) |
|
|
|
sender.AddBalance(remaining) |
|
|
|
|
|
|
|
|
|
|
|
uhalf := new(big.Int).Div(self.gasUsed(), common.Big2) |
|
|
|
uhalf := remaining.Div(self.gasUsed(), common.Big2) |
|
|
|
refund := common.BigMin(uhalf, self.state.Refunds()) |
|
|
|
refund := common.BigMin(uhalf, self.state.Refunds()) |
|
|
|
self.gas.Add(self.gas, refund) |
|
|
|
self.gas.Add(self.gas, refund) |
|
|
|
self.state.AddBalance(sender.Address(), refund.Mul(refund, self.msg.GasPrice())) |
|
|
|
self.state.AddBalance(sender.Address(), refund.Mul(refund, self.gasPrice)) |
|
|
|
|
|
|
|
|
|
|
|
coinbase.AddGas(self.gas, self.msg.GasPrice()) |
|
|
|
coinbase.AddGas(self.gas, self.gasPrice) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (self *StateTransition) gasUsed() *big.Int { |
|
|
|
func (self *StateTransition) gasUsed() *big.Int { |
|
|
|