Skip to content

Commit b2a304e

Browse files
feat(levm): implement EIP7691 - Blob throughput increase (#1782)
**Motivation** LEVM needs to support the changes introduced in [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691). **Description** This EIP introduces changes to some of the blob hashes' constants values. With this PR, the values for blob hash calculations in LEVM will depend on the spec being used. Closes #1783 Closes #1776
1 parent e340bd9 commit b2a304e

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

crates/common/types/block.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ fn check_gas_limit(gas_limit: u64, parent_gas_limit: u64) -> bool {
340340
&& gas_limit >= GAS_LIMIT_MINIMUM
341341
}
342342

343-
// Calculates the base fee per blob gas for the current block based on it's parent excess blob gas
343+
/// Calculates the base fee per blob gas for the current block based on
344+
/// it's parent excess blob gas.
345+
/// NOTE: BLOB_BASE_FEE_UPDATE_FRACTION has a different value after
346+
/// prague fork. See
347+
/// [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691#specification).
344348
pub fn calculate_base_fee_per_blob_gas(parent_excess_blob_gas: u64) -> u64 {
345349
fake_exponential(
346350
MIN_BASE_FEE_PER_BLOB_GAS,

crates/vm/levm/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Implementation of a simple Ethereum Virtual Machine in Rust.
66

77
| Fork | Status |
88
| -------------- | ------ |
9-
| Prague | 🏗|
9+
| Prague | |
1010
| Cancun ||
1111
| Shanghai ||
1212
| Paris (Merge) ||
@@ -78,14 +78,16 @@ There are a lot of EIPs schedule to include in this upgrade but for `levm` we'll
7878

7979
- EIP-2537: Precompile for BLS12-381 curve operations
8080
- EIP-7623: Increase calldata cost
81+
- EIP-7691: Blob throughput increase
8182
- EIP-7702: Set EOA account code
8283

8384
| Task Description | Status |
8485
| ------------------------- | ------ |
8586
| Implement EIP-2537 ||
8687
| Implement EIP-7623 ||
87-
| Implement EIP-7702 ||
88-
| Make Prague EF tests pass ||
88+
| Implement EIP-7691 | ✅️ |
89+
| Implement EIP-7702 | ✅️ |
90+
| Make Prague EF tests pass ||
8991

9092
### Milestone 5: Integrate `ethrex L2` <> `levm`
9193

crates/vm/levm/src/constants.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,24 @@ pub mod create_opcode {
4343
}
4444

4545
pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01;
46-
pub const MAX_BLOB_NUMBER_PER_BLOCK: usize = 6;
4746

4847
// Blob constants
4948
pub const TARGET_BLOB_GAS_PER_BLOCK: U256 = U256([393216, 0, 0, 0]); // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
49+
pub const TARGET_BLOB_GAS_PER_BLOCK_PECTRA: U256 = U256([786432, 0, 0, 0]); // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
50+
5051
pub const MIN_BASE_FEE_PER_BLOB_GAS: U256 = U256::one();
52+
53+
// WARNING: Do _not_ use the BLOB_BASE_FEE_UPDATE_FRACTION_* family of
54+
// constants as is. Use the `get_blob_base_fee_update_fraction_value`
55+
// function instead
5156
pub const BLOB_BASE_FEE_UPDATE_FRACTION: U256 = U256([3338477, 0, 0, 0]);
57+
pub const BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE: U256 = U256([5007716, 0, 0, 0]); // Defined in [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691)
58+
59+
// WARNING: Do _not_ use the MAX_BLOB_COUNT_* family of constants as
60+
// is. Use the `max_blobs_per_block` function instead
5261
pub const MAX_BLOB_COUNT: usize = 6;
62+
pub const MAX_BLOB_COUNT_ELECTRA: usize = 9;
63+
5364
pub const VALID_BLOB_PREFIXES: [u8; 2] = [0x01, 0x02];
5465

5566
// Block constants

crates/vm/levm/src/vm.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl VM {
741741
fake_exponential(
742742
MIN_BASE_FEE_PER_BLOB_GAS,
743743
self.env.block_excess_blob_gas.unwrap_or_default(),
744-
BLOB_BASE_FEE_UPDATE_FRACTION,
744+
get_blob_base_fee_update_fraction_value(self.env.spec_id),
745745
)
746746
}
747747

@@ -934,7 +934,7 @@ impl VM {
934934
}
935935

936936
// (14) TYPE_3_TX_BLOB_COUNT_EXCEEDED
937-
if blob_hashes.len() > MAX_BLOB_COUNT {
937+
if blob_hashes.len() > max_blobs_per_block(self.env.spec_id) {
938938
return Err(VMError::TxValidation(
939939
TxValidationError::Type3TxBlobCountExceeded,
940940
));
@@ -1684,3 +1684,29 @@ fn eip7702_recover_address(auth_tuple: &AuthorizationTuple) -> Result<Option<Add
16841684
.map_err(|_| VMError::Internal(InternalError::ConversionError))?;
16851685
Ok(Some(Address::from_slice(&authority_address_bytes)))
16861686
}
1687+
1688+
/// After EIP-7691 the maximum number of blob hashes changes. For more
1689+
/// information see
1690+
/// [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691#specification).
1691+
pub const fn max_blobs_per_block(specid: SpecId) -> usize {
1692+
match specid {
1693+
SpecId::PRAGUE => MAX_BLOB_COUNT_ELECTRA,
1694+
SpecId::PRAGUE_EOF => MAX_BLOB_COUNT_ELECTRA,
1695+
_ => MAX_BLOB_COUNT,
1696+
}
1697+
}
1698+
1699+
/// According to EIP-7691
1700+
/// (https://eips.ethereum.org/EIPS/eip-7691#specification):
1701+
///
1702+
/// "These changes imply that get_base_fee_per_blob_gas and
1703+
/// calc_excess_blob_gas functions defined in EIP-4844 use the new
1704+
/// values for the first block of the fork (and for all subsequent
1705+
/// blocks)."
1706+
pub const fn get_blob_base_fee_update_fraction_value(specid: SpecId) -> U256 {
1707+
match specid {
1708+
SpecId::PRAGUE => BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
1709+
SpecId::PRAGUE_EOF => BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
1710+
_ => BLOB_BASE_FEE_UPDATE_FRACTION,
1711+
}
1712+
}

0 commit comments

Comments
 (0)