Skip to content

Commit

Permalink
fix(levm): eip4844 tests fix (#1720)
Browse files Browse the repository at this point in the history
**Motivation**

We still need to fix some tests to use the levm feature by default
**Description**

Pending tests to fix:

- [x] parse_and_execute::eip4844_blobs/blob_txs/invalid_normal_gas.json
- [x]
parse_and_execute::eip4844_blobs/blobhash_opcode/blobhash_invalid_blob_index.json
- [x]
parse_and_execute::eip4844_blobs/blobhash_opcode/blobhash_gas_cost.json
- [x]
parse_and_execute::eip4844_blobs/blobhash_opcode/blobhash_multiple_txs_in_block.json
- [x]
parse_and_execute::eip4844_blobs/excess_blob_gas/correct_decreasing_blob_gas_costs.json
- [x]
parse_and_execute::eip4844_blobs/excess_blob_gas/correct_increasing_blob_gas_costs.json
- [x]
parse_and_execute::eip4844_blobs/blobhash_opcode_contexts/blobhash_opcode_contexts.json
- [x]
parse_and_execute::eip4844_blobs/blobhash_opcode/blobhash_scenarios.json

You can double check with:
```sh
cargo test  -p ef_tests-levm --workspace --features levm  --exclude ethrex-prover --exclude ethrex-levm --exclude ef_tests-levm --exclude ethrex-l2 -- --nocapture --skip test_contract_compilation
```
  • Loading branch information
fkrause98 authored Jan 16, 2025
1 parent 21eb55e commit 0f2a7ee
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/common/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl Transaction {
TxType::EIP4844 => {
let priority_fee_per_gas = min(
self.max_priority_fee()?,
self.max_fee_per_gas()? - base_fee_per_gas?,
self.max_fee_per_gas()?.saturating_sub(base_fee_per_gas?),
);
Some(priority_fee_per_gas + base_fee_per_gas?)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/levm/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub const MAX_BLOB_NUMBER_PER_BLOCK: usize = 6;

// Blob constants
pub const TARGET_BLOB_GAS_PER_BLOCK: U256 = U256([393216, 0, 0, 0]); // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
pub const MIN_BASE_FEE_PER_BLOB_GAS: u64 = 1;
pub const BLOB_BASE_FEE_UPDATE_FRACTION: u64 = 3338477;
pub const MIN_BASE_FEE_PER_BLOB_GAS: U256 = U256::one();
pub const BLOB_BASE_FEE_UPDATE_FRACTION: U256 = U256([3338477, 0, 0, 0]);
pub const MAX_BLOB_COUNT: usize = 6;
pub const VALID_BLOB_PREFIXES: [u8; 2] = [0x01, 0x02];

Expand Down
10 changes: 5 additions & 5 deletions crates/vm/levm/src/gas_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,16 @@ pub fn staticcall(
calculate_cost_and_gas_limit_call(true, gas_from_stack, gas_left, call_gas_costs, 0)
}

pub fn fake_exponential(factor: u64, numerator: u64, denominator: u64) -> Result<u64, VMError> {
let mut i = 1;
let mut output: u64 = 0;
pub fn fake_exponential(factor: U256, numerator: U256, denominator: U256) -> Result<U256, VMError> {
let mut i = U256::one();
let mut output: U256 = U256::zero();

// Initial multiplication: factor * denominator
let mut numerator_accum = factor
.checked_mul(denominator)
.ok_or(InternalError::ArithmeticOperationOverflow)?;

while numerator_accum > 0 {
while !numerator_accum.is_zero() {
// Safe addition to output
output = output
.checked_add(numerator_accum)
Expand All @@ -828,7 +828,7 @@ pub fn fake_exponential(factor: u64, numerator: u64, denominator: u64) -> Result
))?;

i = i
.checked_add(1)
.checked_add(U256::one())
.ok_or(InternalError::ArithmeticOperationOverflow)?;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/levm/src/opcode_handlers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl VM {
let index = current_call_frame.stack.pop()?;

let blob_hashes = &self.env.tx_blob_hashes;
if index > blob_hashes.len().into() {
if index >= blob_hashes.len().into() {
current_call_frame.stack.push(U256::zero())?;
return Ok(OpcodeSuccess::Continue);
}
Expand Down
7 changes: 1 addition & 6 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,9 @@ impl VM {
pub fn get_base_fee_per_blob_gas(&self) -> Result<U256, VMError> {
fake_exponential(
MIN_BASE_FEE_PER_BLOB_GAS,
self.env
.block_excess_blob_gas
.unwrap_or_default()
.try_into()
.map_err(|_| VMError::VeryLargeNumber)?, //Maybe replace unwrap_or_default for sth else later.
self.env.block_excess_blob_gas.unwrap_or_default(),
BLOB_BASE_FEE_UPDATE_FRACTION,
)
.map(|ok_value| ok_value.into())
}

/// ## Description
Expand Down

0 comments on commit 0f2a7ee

Please sign in to comment.