diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-08-15 16:23:23 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-08-15 18:03:49 +0800 |
commit | 3d123bcde67973b57c0a9e7edc219cc2ea589443 (patch) | |
tree | e806ab2faae07184fdcdfe23488b7111e75a9057 /core/vm/gas_table.go | |
parent | 9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2 (diff) | |
download | dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.tar dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.tar.gz dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.tar.bz2 dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.tar.lz dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.tar.xz dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.tar.zst dexon-3d123bcde67973b57c0a9e7edc219cc2ea589443.zip |
core/vm: implement metropolis static call opcode
Diffstat (limited to 'core/vm/gas_table.go')
-rw-r--r-- | core/vm/gas_table.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index 761ca4450..8a6c2741d 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -423,6 +423,33 @@ func gasDelegateCall(gt params.GasTable, evm *EVM, contract *Contract, stack *St return gas, nil } +func gasStaticCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { + gas, err := memoryGasCost(mem, memorySize) + if err != nil { + return 0, err + } + var overflow bool + if gas, overflow = math.SafeAdd(gas, gt.Calls); overflow { + return 0, errGasUintOverflow + } + + cg, err := callGas(gt, contract.Gas, gas, stack.Back(0)) + if err != nil { + return 0, err + } + // Replace the stack item with the new gas calculation. This means that + // either the original item is left on the stack or the item is replaced by: + // (availableGas - gas) * 63 / 64 + // We replace the stack item so that it's available when the opCall instruction is + // called. + stack.data[stack.len()-1] = new(big.Int).SetUint64(cg) + + if gas, overflow = math.SafeAdd(gas, cg); overflow { + return 0, errGasUintOverflow + } + return gas, nil +} + func gasPush(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { return GasFastestStep, nil } |