Skip to content

Commit

Permalink
fix: basefee opcode pushes base_fee value (#956)
Browse files Browse the repository at this point in the history
* fix: basefee opcode pushes base_fee value

* remove custom name for contract target
  • Loading branch information
enitrat authored Sep 18, 2024
1 parent 058ac2d commit 2c2d12a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions crates/evm/src/instructions/block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ pub impl BlockInformation of BlockInformationTrait {
fn exec_basefee(ref self: VM) -> Result<(), EVMError> {
self.charge_gas(gas::BASE)?;

// Get the current base fee. (Kakarot doesn't use EIP 1559 so basefee
// doesn't really exists there so we just use the gas price)
self.stack.push(self.env.gas_price.into())
self.stack.push(self.env.base_fee.into())
}

/// 0x49 - BLOBHASH
Expand Down Expand Up @@ -284,16 +282,16 @@ mod tests {


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

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

// Then
assert(vm.stack.len() == 1, 'stack should have one element');
assert(vm.stack.peek().unwrap() == gas_price().into(), 'stack top should be gas_price');
assert_eq!(vm.stack.len(), 1);
assert_eq!(vm.stack.peek().unwrap(), vm.env.base_fee.into());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ pub fn tx_gas_limit() -> u64 {
constants::BLOCK_GAS_LIMIT
}

pub const BASE_FEE: u128 = 1000;
pub const BASE_FEE: u64 = 1000;

pub fn gas_price() -> u128 {
BASE_FEE + 1
BASE_FEE.into() + 1
}

pub fn value() -> u256 {
Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn preset_environment() -> Environment {
block_timestamp: block_info.block_timestamp,
block_gas_limit: constants::BLOCK_GAS_LIMIT,
coinbase: coinbase(),
base_fee: 0,
base_fee: BASE_FEE,
state: Default::default(),
}
}
Expand Down

0 comments on commit 2c2d12a

Please sign in to comment.