Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
feat: blobhash opcode (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Sep 3, 2024
1 parent 3cf7809 commit 0d8d406
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/evm/src/gas.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const INITCODE_WORD_COST: u128 = 2;

const CALL_STIPEND: u128 = 2300;

// EIP-4844
pub const BLOB_HASH_COST: u128 = 3;

/// Defines the gas cost and stipend for executing call opcodes.
///
/// # Struct fields
Expand Down
25 changes: 25 additions & 0 deletions crates/evm/src/instructions/block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ impl BlockInformation of BlockInformationTrait {
self.stack.push(self.env.gas_price.into())
}

/// 0x49 - BLOBHASH
/// Returns the value of the blob hash of the current block
/// Always returns Zero in the context of Kakarot
/// # Specification: https://www.evm.codes/#49?fork=cancun
fn exec_blobhash(ref self: VM) -> Result<(), EVMError> {
self.charge_gas(gas::BLOB_HASH_COST)?;

self.stack.push(0)
}

/// 0x4A - BLOBBASEFEE
/// Returns the value of the blob base-fee of the current block
/// Always returns Zero in the context of Kakarot
Expand Down Expand Up @@ -333,6 +343,20 @@ mod tests {
assert(result == 0x00, 'stack top should be zero');
}

#[test]
fn test_blobhash_should_return_zero() {
// Given
let mut vm = VMBuilderTrait::new_with_presets().build();

// When
vm.exec_blobhash().unwrap();

// Then
assert_eq!(vm.stack.len(), 1);
assert_eq!(vm.stack.peek().unwrap(), 0);
}


#[test]
fn test_blobbasefee_should_return_zero() {
// Given
Expand All @@ -346,6 +370,7 @@ mod tests {
assert(vm.stack.peek().unwrap() == 0, 'stack top should be 0');
}


// *************************************************************************
// 0x41: COINBASE
// *************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions crates/evm/src/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ impl EVMImpl of EVMTrait {
// BASEFEE
return self.exec_basefee();
}
if opcode == 73 {
// BLOBHASH
return self.exec_blobhash();
}
if opcode == 74 {
// BLOBBASEFEE
return self.exec_blobbasefee();
Expand Down

0 comments on commit 0d8d406

Please sign in to comment.