From 078375061b4171e802b506af5f193c7fc5e448f6 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 11 Nov 2019 12:12:58 +0700 Subject: [PATCH] implement EIP 1884 stub --- nimbus/vm/interpreter/gas_costs.nim | 9 ++++++++- nimbus/vm/interpreter/opcode_values.nim | 1 + nimbus/vm/interpreter/opcodes_impl.nim | 5 +++++ nimbus/vm/interpreter_dispatch.nim | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/nimbus/vm/interpreter/gas_costs.nim b/nimbus/vm/interpreter/gas_costs.nim index 8193b1e46..d84820ae0 100644 --- a/nimbus/vm/interpreter/gas_costs.nim +++ b/nimbus/vm/interpreter/gas_costs.nim @@ -604,10 +604,17 @@ func spuriousGasFees(previous_fees: GasFeeSchedule): GasFeeSchedule = result = previous_fees result[GasExpByte] = 50 +func istanbulGasFees(previous_fees: GasFeeSchedule): GasFeeSchedule = + # https://eips.ethereum.org/EIPS/eip-1884 + result[GasSload] = 800 + result[GasExtCodeHash] = 700 + result[GasBalance] = 700 + const HomesteadGasFees = BaseGasFees.homesteadGasFees TangerineGasFees = HomesteadGasFees.tangerineGasFees SpuriousGasFees = TangerineGasFees.spuriousGasFees + IstanbulGasFees = SpuriousGasFees.istanbulGasFees gasFees*: array[Fork, GasFeeSchedule] = [ FkFrontier: BaseGasFees, @@ -618,7 +625,7 @@ const FkSpurious: SpuriousGasFees, FkByzantium: SpuriousGasFees, FkConstantinople: SpuriousGasFees, - FkIstanbul: SpuriousGasFees + FkIstanbul: IstanbulGasFees ] diff --git a/nimbus/vm/interpreter/opcode_values.nim b/nimbus/vm/interpreter/opcode_values.nim index 3bc7b8ebe..0de3b2bc4 100644 --- a/nimbus/vm/interpreter/opcode_values.nim +++ b/nimbus/vm/interpreter/opcode_values.nim @@ -80,6 +80,7 @@ fill_enum_holes: GasLimit = 0x45, # Get the block's gas limit. ChainID = 0x46, # Get current chain’s EIP-155 unique identifier. + SelfBalance = 0x47, # Get current contract's balance. # 50s: Stack, Memory, Storage and Flow Operations Pop = 0x50, # Remove item from stack. diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 8ed57fd1e..a7dfddb12 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -377,6 +377,11 @@ op chainID, inline = true: # TODO: this is a stub push: 0 +op selfBalance, inline = true: + ## 0x47, Get current contract's balance. + # TODO: this is a stub + push: 0 + # ########################################## # 50s: Stack, Memory, Storage and Flow Operations diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index 82fcd2622..c3832b5e0 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -218,6 +218,7 @@ let ConstantinopleOpDispatch {.compileTime.}: array[Op, NimNode] = genConstantin proc genIstanbulJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} = result = ops result[ChainID] = newIdentNode "chainID" + result[SelfBalance] = newIdentNode "selfBalance" let IstanbulOpDispatch {.compileTime.}: array[Op, NimNode] = genIstanbulJumpTable(ConstantinopleOpDispatch)