From 1f16cbc8d1bae19d628d423afe865c33e3957aaa Mon Sep 17 00:00:00 2001 From: Roman Behma <13855864+begmaroman@users.noreply.github.com> Date: Wed, 24 May 2023 18:12:00 +0100 Subject: [PATCH] Introduce BASEFEE opcode (#1469) --- .../test-contracts/TestWriteBlockMetadata.sol | 2 +- state/runtime/evm/dispatch_table.go | 1 + state/runtime/evm/instructions.go | 10 ++++++++++ state/runtime/evm/opcodes.go | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/consensus/polybft/contractsapi/test-contracts/TestWriteBlockMetadata.sol b/consensus/polybft/contractsapi/test-contracts/TestWriteBlockMetadata.sol index 90fe2a2ee3..c24384b34b 100644 --- a/consensus/polybft/contractsapi/test-contracts/TestWriteBlockMetadata.sol +++ b/consensus/polybft/contractsapi/test-contracts/TestWriteBlockMetadata.sol @@ -13,7 +13,7 @@ contract TestWriteBlockMetadata { data.push(block.gaslimit); data.push(block.chainid); coinbase = block.coinbase; - // data.push(block.basefee); + data.push(block.basefee); // hash = blockhash(block.number); } } \ No newline at end of file diff --git a/state/runtime/evm/dispatch_table.go b/state/runtime/evm/dispatch_table.go index 7214a18dcd..e8afeae0f5 100644 --- a/state/runtime/evm/dispatch_table.go +++ b/state/runtime/evm/dispatch_table.go @@ -123,6 +123,7 @@ func init() { register(NUMBER, handler{opNumber, 0, 2}) register(DIFFICULTY, handler{opDifficulty, 0, 2}) register(GASLIMIT, handler{opGasLimit, 0, 2}) + register(BASEFEE, handler{opBaseFee, 0, 2}) register(SELFDESTRUCT, handler{opSelfDestruct, 1, 0}) diff --git a/state/runtime/evm/instructions.go b/state/runtime/evm/instructions.go index 9ef721115e..5c1bccf489 100644 --- a/state/runtime/evm/instructions.go +++ b/state/runtime/evm/instructions.go @@ -907,6 +907,16 @@ func opGasLimit(c *state) { c.push1().SetInt64(c.host.GetTxContext().GasLimit) } +func opBaseFee(c *state) { + if !c.config.London { + c.exit(errOpCodeNotFound) + + return + } + + c.push(c.host.GetTxContext().BaseFee) +} + func opSelfDestruct(c *state) { if c.inStaticCall() { c.exit(errWriteProtection) diff --git a/state/runtime/evm/opcodes.go b/state/runtime/evm/opcodes.go index 85bd02d1c5..409180d4dc 100644 --- a/state/runtime/evm/opcodes.go +++ b/state/runtime/evm/opcodes.go @@ -161,6 +161,9 @@ const ( // SELFBALANCE returns the balance of the current account SELFBALANCE = 0x47 + // BASEFEE returns the current base fee value + BASEFEE = 0x48 + // POP pops a (u)int256 off the stack and discards it POP = 0x50 @@ -308,6 +311,7 @@ var opCodeToString = map[OpCode]string{ NUMBER: "NUMBER", DIFFICULTY: "DIFFICULTY", GASLIMIT: "GASLIMIT", + BASEFEE: "BASEFEE", POP: "POP", MLOAD: "MLOAD", MSTORE: "MSTORE",