Skip to content

Commit 264c68d

Browse files
committed
core/vm: BLOBHASH opcode 0x49 ethereum#27356
1 parent 21bca3e commit 264c68d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

core/vm/eips.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,38 @@ func opMcopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
256256
return nil, nil
257257
}
258258

259+
// opBlobHash implements the BLOBHASH opcode
260+
func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
261+
index := scope.Stack.peek()
262+
// xdc chain have no blob hash, so len(interpreter.evm.TxContext.BlobHashes) is always 0
263+
// and index.LtUint64(uint64(len(interpreter.evm.TxContext.BlobHashes))) is always false
264+
// if index.LtUint64(uint64(len(interpreter.evm.TxContext.BlobHashes))) {
265+
// blobHash := interpreter.evm.TxContext.BlobHashes[index.Uint64()]
266+
// index.SetBytes32(blobHash[:])
267+
// } else {
268+
// index.Clear()
269+
// }
270+
index.Clear()
271+
return nil, nil
272+
}
273+
259274
// opBlobBaseFee implements BLOBBASEFEE opcode
260275
func opBlobBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
261276
blobBaseFee := new(uint256.Int)
262277
scope.Stack.push(blobBaseFee)
263278
return nil, nil
264279
}
265280

281+
// enable4844 applies EIP-4844 (BLOBHASH opcode)
282+
func enable4844(jt *JumpTable) {
283+
jt[BLOBHASH] = &operation{
284+
execute: opBlobHash,
285+
constantGas: GasFastestStep,
286+
minStack: minStack(1, 1),
287+
maxStack: maxStack(1, 1),
288+
}
289+
}
290+
266291
// enable7516 applies EIP-7516 (BLOBBASEFEE opcode)
267292
func enable7516(jt *JumpTable) {
268293
jt[BLOBBASEFEE] = &operation{

core/vm/jump_table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type JumpTable [256]*operation
6363

6464
func newCancunInstructionSet() JumpTable {
6565
instructionSet := newEip1559InstructionSet()
66+
enable4844(&instructionSet) // EIP-4844 (BLOBHASH opcode)
6667
enable7516(&instructionSet) // EIP-7516 (BLOBBASEFEE opcode)
6768
enable1153(&instructionSet) // EIP-1153 "Transient Storage"
6869
enable5656(&instructionSet) // EIP-5656 (MCOPY opcode)

core/vm/opcodes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const (
100100
CHAINID OpCode = 0x46
101101
SELFBALANCE OpCode = 0x47
102102
BASEFEE OpCode = 0x48
103+
BLOBHASH OpCode = 0x49
103104
BLOBBASEFEE OpCode = 0x4a
104105
)
105106

@@ -285,6 +286,7 @@ var opCodeToString = [256]string{
285286
CHAINID: "CHAINID",
286287
SELFBALANCE: "SELFBALANCE",
287288
BASEFEE: "BASEFEE",
289+
BLOBHASH: "BLOBHASH",
288290
BLOBBASEFEE: "BLOBBASEFEE",
289291

290292
// 0x50 range - 'storage' and execution.
@@ -459,6 +461,7 @@ var stringToOp = map[string]OpCode{
459461
"GASLIMIT": GASLIMIT,
460462
"SELFBALANCE": SELFBALANCE,
461463
"BASEFEE": BASEFEE,
464+
"BLOBHASH": BLOBHASH,
462465
"BLOBBASEFEE": BLOBBASEFEE,
463466
"POP": POP,
464467
"MLOAD": MLOAD,

0 commit comments

Comments
 (0)