|
35 | 35 | GasStop = big.NewInt(0) |
36 | 36 |
|
37 | 37 | GasContractByte = big.NewInt(200) |
| 38 | + |
| 39 | + n64 = big.NewInt(64) |
38 | 40 | ) |
39 | 41 |
|
| 42 | +// calcGas returns the actual gas cost of the call. |
| 43 | +// |
| 44 | +// The cost of gas was changed during the homestead price change HF. To allow for EIP150 |
| 45 | +// to be implemented. The returned gas is gas - base * 63 / 64. |
| 46 | +func callGas(gasTable params.GasTable, availableGas, base, callCost *big.Int) *big.Int { |
| 47 | + if gasTable.CreateBySuicide != nil { |
| 48 | + availableGas = new(big.Int).Sub(availableGas, base) |
| 49 | + g := new(big.Int).Div(availableGas, n64) |
| 50 | + g.Sub(availableGas, g) |
| 51 | + |
| 52 | + if g.Cmp(callCost) < 0 { |
| 53 | + return g |
| 54 | + } |
| 55 | + } |
| 56 | + return callCost |
| 57 | +} |
| 58 | + |
40 | 59 | // baseCheck checks for any stack error underflows |
41 | 60 | func baseCheck(op OpCode, stack *Stack, gas *big.Int) error { |
42 | 61 | // 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{ |
127 | 146 | MSIZE: {0, GasQuickStep, 1}, |
128 | 147 | GAS: {0, GasQuickStep, 1}, |
129 | 148 | BLOCKHASH: {1, GasExtStep, 1}, |
130 | | - BALANCE: {1, GasExtStep, 1}, |
131 | | - EXTCODESIZE: {1, GasExtStep, 1}, |
132 | | - EXTCODECOPY: {4, GasExtStep, 0}, |
| 149 | + BALANCE: {1, Zero, 1}, |
| 150 | + EXTCODESIZE: {1, Zero, 1}, |
| 151 | + EXTCODECOPY: {4, Zero, 0}, |
133 | 152 | SLOAD: {1, params.SloadGas, 1}, |
134 | 153 | SSTORE: {2, Zero, 0}, |
135 | 154 | SHA3: {2, params.Sha3Gas, 1}, |
136 | 155 | CREATE: {3, params.CreateGas, 1}, |
137 | | - CALL: {7, params.CallGas, 1}, |
138 | | - CALLCODE: {7, params.CallGas, 1}, |
139 | | - DELEGATECALL: {6, params.CallGas, 1}, |
140 | | - JUMPDEST: {0, params.JumpdestGas, 0}, |
| 156 | + // Zero is calculated in the gasSwitch |
| 157 | + CALL: {7, Zero, 1}, |
| 158 | + CALLCODE: {7, Zero, 1}, |
| 159 | + DELEGATECALL: {6, Zero, 1}, |
141 | 160 | SUICIDE: {1, Zero, 0}, |
| 161 | + JUMPDEST: {0, params.JumpdestGas, 0}, |
142 | 162 | RETURN: {2, Zero, 0}, |
143 | 163 | PUSH1: {0, GasFastestStep, 1}, |
144 | 164 | DUP1: {0, Zero, 1}, |
|
0 commit comments