diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2016-10-08 06:23:45 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-10-15 00:09:17 +0800 |
commit | 64af2aafdaf16d0bab4c2b89573324b076602bab (patch) | |
tree | fb8f5d30ce7ff12ee8f56c3621254edea55885be /core/vm/gas.go | |
parent | eeb2a1a6e3c7a0c77ee6836f3103708cff4102ad (diff) | |
download | dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.tar dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.tar.gz dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.tar.bz2 dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.tar.lz dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.tar.xz dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.tar.zst dexon-64af2aafdaf16d0bab4c2b89573324b076602bab.zip |
core, core/vm: added gas price variance table
This implements 1b & 1c of EIP150 by adding a new GasTable which must be
returned from the RuleSet config method. This table is used to determine
the gas prices for the current epoch.
Please note that when the CreateBySuicide gas price is set it is assumed
that we're in the new epoch phase.
In addition this PR will serve as temporary basis while refactorisation
in being done in the EVM64 PR, which will substentially overhaul the gas
price code.
Diffstat (limited to 'core/vm/gas.go')
-rw-r--r-- | core/vm/gas.go | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/core/vm/gas.go b/core/vm/gas.go index eb2c16346..fdbc0df7f 100644 --- a/core/vm/gas.go +++ b/core/vm/gas.go @@ -35,8 +35,27 @@ var ( GasStop = big.NewInt(0) GasContractByte = big.NewInt(200) + + n64 = big.NewInt(64) ) +// calcGas returns the actual gas cost of the call. +// +// The cost of gas was changed during the homestead price change HF. To allow for EIP150 +// to be implemented. The returned gas is gas - base * 63 / 64. +func callGas(gasTable params.GasTable, availableGas, base, callCost *big.Int) *big.Int { + if gasTable.CreateBySuicide != nil { + availableGas = new(big.Int).Sub(availableGas, base) + g := new(big.Int).Div(availableGas, n64) + g.Sub(availableGas, g) + + if g.Cmp(callCost) < 0 { + return g + } + } + return callCost +} + // baseCheck checks for any stack error underflows func baseCheck(op OpCode, stack *Stack, gas *big.Int) error { // PUSH and DUP are a bit special. They all cost the same but we do want to have checking on stack push limit @@ -127,18 +146,19 @@ var _baseCheck = map[OpCode]req{ MSIZE: {0, GasQuickStep, 1}, GAS: {0, GasQuickStep, 1}, BLOCKHASH: {1, GasExtStep, 1}, - BALANCE: {1, GasExtStep, 1}, - EXTCODESIZE: {1, GasExtStep, 1}, - EXTCODECOPY: {4, GasExtStep, 0}, + BALANCE: {1, Zero, 1}, + EXTCODESIZE: {1, Zero, 1}, + EXTCODECOPY: {4, Zero, 0}, SLOAD: {1, params.SloadGas, 1}, SSTORE: {2, Zero, 0}, SHA3: {2, params.Sha3Gas, 1}, CREATE: {3, params.CreateGas, 1}, - CALL: {7, params.CallGas, 1}, - CALLCODE: {7, params.CallGas, 1}, - DELEGATECALL: {6, params.CallGas, 1}, - JUMPDEST: {0, params.JumpdestGas, 0}, + // Zero is calculated in the gasSwitch + CALL: {7, Zero, 1}, + CALLCODE: {7, Zero, 1}, + DELEGATECALL: {6, Zero, 1}, SUICIDE: {1, Zero, 0}, + JUMPDEST: {0, params.JumpdestGas, 0}, RETURN: {2, Zero, 0}, PUSH1: {0, GasFastestStep, 1}, DUP1: {0, Zero, 1}, |