Skip to content

Commit 0fc3e2d

Browse files
authored
Merge pull request #11647 from ethereum/basefee
Implement London EVMVersion and the BASEFEE opcode
2 parents 13b2694 + 43605d9 commit 0fc3e2d

File tree

23 files changed

+103
-10
lines changed

23 files changed

+103
-10
lines changed

.circleci/soltest_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ set -e
2828

2929
REPODIR="$(realpath "$(dirname "$0")"/..)"
3030

31-
EVM_VALUES=(homestead byzantium constantinople petersburg istanbul berlin)
31+
EVM_VALUES=(homestead byzantium constantinople petersburg istanbul berlin london)
3232
DEFAULT_EVM=berlin
3333
[[ " ${EVM_VALUES[*]} " =~ $DEFAULT_EVM ]]
3434
OPTIMIZE_VALUES=(0 1)

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
### 0.8.7 (unreleased)
22

33
Language Features:
4+
* Introduce global ``block.basefee`` for retrieving the base fee of the current block.
5+
* Yul: Introduce builtin ``basefee()`` for retrieving the base fee of the current block.
46

57

68
Compiler Features:

docs/cheatsheet.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Global Variables
8484
to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
8585
- ``bytes.concat(...) returns (bytes memory)``: :ref:`Concatenates variable number of
8686
arguments to one byte array<bytes-concat>`
87+
- ``block.basefee`` (``uint``): current block's base fee (`EIP-3198 <https://eips.ethereum.org/EIPS/eip-3198>`_ and `EIP-1559 <https://eips.ethereum.org/EIPS/eip-1559>`_)
8788
- ``block.chainid`` (``uint``): current chain id
8889
- ``block.coinbase`` (``address payable``): current block miner's address
8990
- ``block.difficulty`` (``uint``): current block difficulty

docs/grammar/SolidityLexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ YulEVMBuiltin:
284284
| 'returndatacopy' | 'extcodehash' | 'create' | 'create2' | 'call' | 'callcode'
285285
| 'delegatecall' | 'staticcall' | 'return' | 'revert' | 'selfdestruct' | 'invalid'
286286
| 'log0' | 'log1' | 'log2' | 'log3' | 'log4' | 'chainid' | 'origin' | 'gasprice'
287-
| 'blockhash' | 'coinbase' | 'timestamp' | 'number' | 'difficulty' | 'gaslimit';
287+
| 'blockhash' | 'coinbase' | 'timestamp' | 'number' | 'difficulty' | 'gaslimit'
288+
| 'basefee';
288289
289290
YulLBrace: '{' -> pushMode(YulMode);
290291
YulRBrace: '}' -> popMode;

docs/units-and-global-variables.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Block and Transaction Properties
7272
--------------------------------
7373

7474
- ``blockhash(uint blockNumber) returns (bytes32)``: hash of the given block when ``blocknumber`` is one of the 256 most recent blocks; otherwise returns zero
75+
- ``block.basefee`` (``uint``): current block's base fee (`EIP-3198 <https://eips.ethereum.org/EIPS/eip-3198>`_ and `EIP-1559 <https://eips.ethereum.org/EIPS/eip-1559>`_)
7576
- ``block.chainid`` (``uint``): current chain id
7677
- ``block.coinbase`` (``address payable``): current block miner's address
7778
- ``block.difficulty`` (``uint``): current block difficulty

docs/yul.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ This document does not want to be a full description of the Ethereum virtual mac
717717
Please refer to a different document if you are interested in the precise semantics.
718718

719719
Opcodes marked with ``-`` do not return a result and all others return exactly one value.
720-
Opcodes marked with ``F``, ``H``, ``B``, ``C`` or ``I`` are present since Frontier, Homestead,
721-
Byzantium, Constantinople or Istanbul, respectively.
720+
Opcodes marked with ``F``, ``H``, ``B``, ``C``, ``I`` and ``L`` are present since Frontier, Homestead,
721+
Byzantium, Constantinople, Istanbul or London respectively.
722722

723723
In the following, ``mem[a...b)`` signifies the bytes of memory starting at position ``a`` up to
724724
but not including position ``b`` and ``storage[p]`` signifies the storage contents at slot ``p``.
@@ -879,7 +879,9 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a
879879
| log4(p, s, t1, t2, t3, | `-` | F | log with topics t1, t2, t3, t4 and data mem[p...(p+s)) |
880880
| t4) | | | |
881881
+-------------------------+-----+---+-----------------------------------------------------------------+
882-
| chainid() | | I | ID of the executing chain (EIP 1344) |
882+
| chainid() | | I | ID of the executing chain (EIP-1344) |
883+
+-------------------------+-----+---+-----------------------------------------------------------------+
884+
| basefee() | | L | current block's base fee (EIP-3198 and EIP-1559) |
883885
+-------------------------+-----+---+-----------------------------------------------------------------+
884886
| origin() | | F | transaction sender |
885887
+-------------------------+-----+---+-----------------------------------------------------------------+

libevmasm/Instruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
8484
{ "GASLIMIT", Instruction::GASLIMIT },
8585
{ "CHAINID", Instruction::CHAINID },
8686
{ "SELFBALANCE", Instruction::SELFBALANCE },
87+
{ "BASEFEE", Instruction::BASEFEE },
8788
{ "POP", Instruction::POP },
8889
{ "MLOAD", Instruction::MLOAD },
8990
{ "MSTORE", Instruction::MSTORE },
@@ -230,6 +231,7 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
230231
{ Instruction::GASLIMIT, { "GASLIMIT", 0, 0, 1, false, Tier::Base } },
231232
{ Instruction::CHAINID, { "CHAINID", 0, 0, 1, false, Tier::Base } },
232233
{ Instruction::SELFBALANCE, { "SELFBALANCE", 0, 0, 1, false, Tier::Low } },
234+
{ Instruction::BASEFEE, { "BASEFEE", 0, 0, 1, false, Tier::Base } },
233235
{ Instruction::POP, { "POP", 0, 1, 0, false, Tier::Base } },
234236
{ Instruction::MLOAD, { "MLOAD", 0, 1, 1, true, Tier::VeryLow } },
235237
{ Instruction::MSTORE, { "MSTORE", 0, 2, 0, true, Tier::VeryLow } },

libevmasm/Instruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ enum class Instruction: uint8_t
8888
GASLIMIT, ///< get the block's gas limit
8989
CHAINID, ///< get the config's chainid param
9090
SELFBALANCE, ///< get balance of the current account
91+
BASEFEE, ///< get the block's basefee
9192

9293
POP = 0x50, ///< remove item from stack
9394
MLOAD, ///< load word from memory

libevmasm/SemanticInformation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction)
353353
case Instruction::CALLER:
354354
case Instruction::CALLVALUE:
355355
case Instruction::CHAINID:
356+
case Instruction::BASEFEE:
356357
case Instruction::GAS:
357358
case Instruction::GASPRICE:
358359
case Instruction::EXTCODESIZE:

liblangutil/EVMVersion.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ class EVMVersion:
5151
static EVMVersion petersburg() { return {Version::Petersburg}; }
5252
static EVMVersion istanbul() { return {Version::Istanbul}; }
5353
static EVMVersion berlin() { return {Version::Berlin}; }
54+
static EVMVersion london() { return {Version::London}; }
5455

5556
static std::optional<EVMVersion> fromString(std::string const& _version)
5657
{
57-
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin()})
58+
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin(), london()})
5859
if (_version == v.name())
5960
return v;
6061
return std::nullopt;
@@ -75,6 +76,7 @@ class EVMVersion:
7576
case Version::Petersburg: return "petersburg";
7677
case Version::Istanbul: return "istanbul";
7778
case Version::Berlin: return "berlin";
79+
case Version::London: return "london";
7880
}
7981
return "INVALID";
8082
}
@@ -87,6 +89,7 @@ class EVMVersion:
8789
bool hasExtCodeHash() const { return *this >= constantinople(); }
8890
bool hasChainID() const { return *this >= istanbul(); }
8991
bool hasSelfBalance() const { return *this >= istanbul(); }
92+
bool hasBaseFee() const { return *this >= london(); }
9093

9194
bool hasOpcode(evmasm::Instruction _opcode) const;
9295

@@ -95,7 +98,7 @@ class EVMVersion:
9598
bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); }
9699

97100
private:
98-
enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople, Petersburg, Istanbul, Berlin };
101+
enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople, Petersburg, Istanbul, Berlin, London };
99102

100103
EVMVersion(Version _version): m_version(_version) {}
101104

0 commit comments

Comments
 (0)