Skip to content

Commit 9a7639e

Browse files
r0qscameel
andcommitted
Add blobhash opcode
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
1 parent 814225e commit 9a7639e

27 files changed

+195
-4
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 0.8.24 (unreleased)
22

33
Language Features:
4+
* Yul: Introduce builtin ``blobhash()`` for retrieving a versioned blob hash of a given blob index within the transaction.
45

56

67
Compiler Features:

docs/grammar/SolidityLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ YulEVMBuiltin:
305305
| 'delegatecall' | 'staticcall' | 'return' | 'revert' | 'selfdestruct' | 'invalid'
306306
| 'log0' | 'log1' | 'log2' | 'log3' | 'log4' | 'chainid' | 'origin' | 'gasprice'
307307
| 'blockhash' | 'coinbase' | 'timestamp' | 'number' | 'difficulty' | 'prevrandao'
308-
| 'gaslimit' | 'basefee';
308+
| 'gaslimit' | 'basefee' | 'blobhash';
309309
310310
YulLBrace: '{' -> pushMode(YulMode);
311311
YulRBrace: '}' -> popMode;

docs/yul.rst

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

754754
Opcodes marked with ``-`` do not return a result and all others return exactly one value.
755-
Opcodes marked with ``F``, ``H``, ``B``, ``C``, ``I``, ``L`` and ``P`` are present since Frontier,
756-
Homestead, Byzantium, Constantinople, Istanbul, London or Paris respectively.
755+
Opcodes marked with ``F``, ``H``, ``B``, ``C``, ``I``, ``L``, ``P`` and ``N`` are present since Frontier,
756+
Homestead, Byzantium, Constantinople, Istanbul, London, Paris or Cancun respectively.
757757

758758
In the following, ``mem[a...b)`` signifies the bytes of memory starting at position ``a`` up to
759759
but not including position ``b`` and ``storage[p]`` signifies the storage contents at slot ``p``.
@@ -925,6 +925,8 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a
925925
+-------------------------+-----+---+-----------------------------------------------------------------+
926926
| blockhash(b) | | F | hash of block nr b - only for last 256 blocks excluding current |
927927
+-------------------------+-----+---+-----------------------------------------------------------------+
928+
| blobhash(i) | | N | versioned hash of transaction's i-th blob |
929+
+-------------------------+-----+---+-----------------------------------------------------------------+
928930
| coinbase() | | F | current mining beneficiary |
929931
+-------------------------+-----+---+-----------------------------------------------------------------+
930932
| timestamp() | | F | timestamp of the current block in seconds since the epoch |

libevmasm/Instruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
8181
{ "CHAINID", Instruction::CHAINID },
8282
{ "SELFBALANCE", Instruction::SELFBALANCE },
8383
{ "BASEFEE", Instruction::BASEFEE },
84+
{ "BLOBHASH", Instruction::BLOBHASH },
8485
{ "POP", Instruction::POP },
8586
{ "MLOAD", Instruction::MLOAD },
8687
{ "MSTORE", Instruction::MSTORE },
@@ -230,6 +231,7 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
230231
{ Instruction::CHAINID, { "CHAINID", 0, 0, 1, false, Tier::Base } },
231232
{ Instruction::SELFBALANCE, { "SELFBALANCE", 0, 0, 1, false, Tier::Low } },
232233
{ Instruction::BASEFEE, { "BASEFEE", 0, 0, 1, false, Tier::Base } },
234+
{ Instruction::BLOBHASH, { "BLOBHASH", 0, 1, 1, false, Tier::VeryLow } },
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
@@ -89,6 +89,7 @@ enum class Instruction: uint8_t
8989
CHAINID, ///< get the config's chainid param
9090
SELFBALANCE, ///< get balance of the current account
9191
BASEFEE, ///< get the block's basefee
92+
BLOBHASH = 0x49, ///< get a versioned hash of one of the blobs associated with the transaction
9293

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

libevmasm/SemanticInformation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction)
473473
case Instruction::CALLVALUE:
474474
case Instruction::CHAINID:
475475
case Instruction::BASEFEE:
476+
case Instruction::BLOBHASH:
476477
case Instruction::GAS:
477478
case Instruction::GASPRICE:
478479
case Instruction::EXTCODESIZE:

libevmasm/SimplificationRule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct EVMBuiltins
127127
static auto constexpr CHAINID = PatternGenerator<Instruction::CHAINID>{};
128128
static auto constexpr SELFBALANCE = PatternGenerator<Instruction::SELFBALANCE>{};
129129
static auto constexpr BASEFEE = PatternGenerator<Instruction::BASEFEE>{};
130+
static auto constexpr BLOBHASH = PatternGenerator<Instruction::BLOBHASH>{};
130131
static auto constexpr POP = PatternGenerator<Instruction::POP>{};
131132
static auto constexpr MLOAD = PatternGenerator<Instruction::MLOAD>{};
132133
static auto constexpr MSTORE = PatternGenerator<Instruction::MSTORE>{};

liblangutil/EVMVersion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ bool EVMVersion::hasOpcode(Instruction _opcode) const
4949
return hasSelfBalance();
5050
case Instruction::BASEFEE:
5151
return hasBaseFee();
52+
case Instruction::BLOBHASH:
53+
return hasBlobHash();
5254
default:
5355
return true;
5456
}

liblangutil/EVMVersion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class EVMVersion:
103103
bool hasBaseFee() const { return *this >= london(); }
104104
bool hasPrevRandao() const { return *this >= paris(); }
105105
bool hasPush0() const { return *this >= shanghai(); }
106+
bool hasBlobHash() const { return *this >= cancun(); }
106107

107108
bool hasOpcode(evmasm::Instruction _opcode) const;
108109

libyul/AsmAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
727727
errorForVM(7721_error, "only available for Istanbul-compatible");
728728
else if (_instr == evmasm::Instruction::BASEFEE && !m_evmVersion.hasBaseFee())
729729
errorForVM(5430_error, "only available for London-compatible");
730+
else if (_instr == evmasm::Instruction::BLOBHASH && !m_evmVersion.hasBlobHash())
731+
errorForVM(3502_error, "only available for Cancun-compatible");
730732
else if (_instr == evmasm::Instruction::PC)
731733
m_errorReporter.error(
732734
2450_error,

0 commit comments

Comments
 (0)