aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/contract.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2017-01-05 03:17:24 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2017-02-14 04:44:25 +0800
commitc12f4df910e2da1cc5dd28c5c4bbe2d8721e1057 (patch)
treeda94063644627d9da853a91c28bc37f2df341dd1 /core/vm/contract.go
parent72dcd3c58bec0a281280d5d42ed53b6e429ce4af (diff)
downloadgo-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar
go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.gz
go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.bz2
go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.lz
go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.xz
go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.zst
go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.zip
params: core, core/vm, miner: 64bit gas instructions
Reworked the EVM gas instructions to use 64bit integers rather than arbitrary size big ints. All gas operations, be it additions, multiplications or divisions, are checked and guarded against 64 bit integer overflows. In additon, most of the protocol paramaters in the params package have been converted to uint64 and are now constants rather than variables. * common/math: added overflow check ops * core: vmenv, env renamed to evm * eth, internal/ethapi, les: unmetered eth_call and cancel methods * core/vm: implemented big.Int pool for evm instructions * core/vm: unexported intPool methods & verification methods * core/vm: added memoryGasCost overflow check and test
Diffstat (limited to 'core/vm/contract.go')
-rw-r--r--core/vm/contract.go33
1 files changed, 9 insertions, 24 deletions
diff --git a/core/vm/contract.go b/core/vm/contract.go
index dfa93ab18..091106d84 100644
--- a/core/vm/contract.go
+++ b/core/vm/contract.go
@@ -24,7 +24,6 @@ import (
// ContractRef is a reference to the contract's backing object
type ContractRef interface {
- ReturnGas(*big.Int)
Address() common.Address
Value() *big.Int
SetCode(common.Hash, []byte)
@@ -48,7 +47,8 @@ type Contract struct {
CodeAddr *common.Address
Input []byte
- value, Gas, UsedGas *big.Int
+ Gas uint64
+ value *big.Int
Args []byte
@@ -56,7 +56,7 @@ type Contract struct {
}
// NewContract returns a new contract environment for the execution of EVM.
-func NewContract(caller ContractRef, object ContractRef, value, gas *big.Int) *Contract {
+func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract {
c := &Contract{CallerAddress: caller.Address(), caller: caller, self: object, Args: nil}
if parent, ok := caller.(*Contract); ok {
@@ -68,9 +68,8 @@ func NewContract(caller ContractRef, object ContractRef, value, gas *big.Int) *C
// Gas should be a pointer so it can safely be reduced through the run
// This pointer will be off the state transition
- c.Gas = gas //new(big.Int).Set(gas)
+ c.Gas = gas
c.value = new(big.Int).Set(value)
- c.UsedGas = new(big.Int)
return c
}
@@ -107,27 +106,13 @@ func (c *Contract) Caller() common.Address {
return c.CallerAddress
}
-// Finalise finalises the contract and returning any remaining gas to the original
-// caller.
-func (c *Contract) Finalise() {
- // Return the remaining gas to the caller
- c.caller.ReturnGas(c.Gas)
-}
-
// UseGas attempts the use gas and subtracts it and returns true on success
-func (c *Contract) UseGas(gas *big.Int) (ok bool) {
- ok = useGas(c.Gas, gas)
- if ok {
- c.UsedGas.Add(c.UsedGas, gas)
+func (c *Contract) UseGas(gas uint64) (ok bool) {
+ if c.Gas < gas {
+ return false
}
- return
-}
-
-// ReturnGas adds the given gas back to itself.
-func (c *Contract) ReturnGas(gas *big.Int) {
- // Return the gas to the context
- c.Gas.Add(c.Gas, gas)
- c.UsedGas.Sub(c.UsedGas, gas)
+ c.Gas -= gas
+ return true
}
// Address returns the contracts address