Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(levm): add support for EIP-7840 and add EVMConfig to LEVM. #1860

Merged
merged 37 commits into from
Feb 3, 2025

Conversation

lima-limon-inc
Copy link
Contributor

@lima-limon-inc lima-limon-inc commented Jan 31, 2025

Motivation

PR #1810 introduced support for EIP-7840 in L1. That EIP introduced the notion that certain blobhash related constants could be modified by Genesis file (for more information see commit: 8610b4c).

Description

This introduces a new struct called EVMConfig to LEVM. It only holds the current Fork and the desired ForkBlobSchedule.

In most cases, the default ForkBlobSchedule will want to be used (for that purpose, the EVMConfig::canonical_values(fork: Fork) -> ForkBlobSchedule functions exists). This is unless you want to use a custom ForkBlobSchedule like described in EIP-7840.

Closes #1813

@lima-limon-inc lima-limon-inc added the levm Lambda EVM implementation label Jan 31, 2025
@lima-limon-inc lima-limon-inc self-assigned this Jan 31, 2025
Copy link

github-actions bot commented Jan 31, 2025

| File                                                                    | Lines | Diff |
+-------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/cmd/ef_tests/levm/runner/levm_runner.rs | 395   | +3   |
+-------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/blockchain/payload.rs            | 646   | +10  |
+-------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/levm/src/environment.rs       | 37    | +1   |
+-------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/levm/src/utils.rs             | 431   | -13  |
+-------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/levm/src/vm.rs                | 761   | +59  |
+-------------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/vm.rs                         | 841   | +3   |
+-------------------------------------------------------------------------+-------+------+

Total lines added: +76
Total lines removed: 13
Total lines changed: 89

Copy link

github-actions bot commented Jan 31, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 239.1 ± 3.1 235.1 243.2 1.00
levm_Factorial 907.0 ± 8.8 899.3 925.3 3.79 ± 0.06

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.494 ± 0.071 1.427 1.655 1.00
levm_FactorialRecursive 15.584 ± 0.027 15.559 15.636 10.43 ± 0.50

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 209.5 ± 1.2 208.4 211.9 1.00
levm_Fibonacci 919.3 ± 26.4 895.0 967.8 4.39 ± 0.13

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 8.8 ± 0.1 8.7 8.8 1.00
levm_ManyHashes 18.1 ± 0.3 17.8 18.7 2.06 ± 0.03

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.229 ± 0.023 3.203 3.264 1.00
levm_BubbleSort 6.046 ± 0.031 6.001 6.092 1.87 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 252.9 ± 0.8 251.4 254.1 1.00
levm_ERC20Transfer 3223.6 ± 23.5 3188.8 3262.3 12.74 ± 0.10

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 143.2 ± 0.4 142.6 143.8 1.00
levm_ERC20Mint 1692.0 ± 12.8 1676.8 1709.7 11.82 ± 0.10

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.048 ± 0.009 1.037 1.067 1.00
levm_ERC20Approval 11.383 ± 0.099 11.268 11.525 10.86 ± 0.13

Main Results

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Factorial 236.8 ± 0.7 235.6 238.0 1.00
levm_Factorial 905.7 ± 11.2 895.7 927.7 3.82 ± 0.05

Benchmark Results: Factorial - Recursive

Command Mean [s] Min [s] Max [s] Relative
revm_FactorialRecursive 1.561 ± 0.088 1.431 1.706 1.00
levm_FactorialRecursive 15.599 ± 0.032 15.559 15.661 9.99 ± 0.56

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
revm_Fibonacci 209.4 ± 1.2 208.3 211.8 1.00
levm_Fibonacci 918.3 ± 20.0 891.8 963.3 4.39 ± 0.10

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ManyHashes 9.1 ± 0.9 8.7 11.7 1.00
levm_ManyHashes 18.2 ± 0.1 18.1 18.4 2.01 ± 0.21

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
revm_BubbleSort 3.258 ± 0.033 3.224 3.312 1.00
levm_BubbleSort 6.061 ± 0.036 6.018 6.125 1.86 ± 0.02

Benchmark Results: ERC20 - Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Transfer 253.9 ± 2.3 251.7 259.0 1.00
levm_ERC20Transfer 3219.1 ± 28.9 3182.7 3249.4 12.68 ± 0.16

Benchmark Results: ERC20 - Mint

Command Mean [ms] Min [ms] Max [ms] Relative
revm_ERC20Mint 144.0 ± 1.1 142.6 146.0 1.00
levm_ERC20Mint 1698.4 ± 10.0 1679.7 1707.0 11.79 ± 0.12

Benchmark Results: ERC20 - Approval

Command Mean [s] Min [s] Max [s] Relative
revm_ERC20Approval 1.061 ± 0.014 1.047 1.090 1.00
levm_ERC20Approval 11.350 ± 0.117 11.241 11.502 10.70 ± 0.18

Copy link

Copy link

@lima-limon-inc lima-limon-inc changed the title feat(levm): add support for EIP-7840 and add ChainConfig to LEVM. feat(levm): add support for EIP-7840 and add EVMConfig to LEVM. Jan 31, 2025
crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ilitteri ilitteri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left some comments about the documentation

lima-limon-inc and others added 2 commits February 3, 2025 09:27
Copy link
Contributor

@fborello-lambda fborello-lambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

github-actions bot commented Feb 3, 2025

@lima-limon-inc lima-limon-inc marked this pull request as draft February 3, 2025 14:17
crates/blockchain/payload.rs Show resolved Hide resolved
crates/vm/vm.rs Show resolved Hide resolved
@lima-limon-inc lima-limon-inc marked this pull request as ready for review February 3, 2025 15:01
Comment on lines +48 to +62
pub const TARGET_BLOB_GAS_PER_BLOCK: u64 = 393216; // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
pub const TARGET_BLOB_GAS_PER_BLOCK_PECTRA: u64 = 786432; // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB

pub const MIN_BASE_FEE_PER_BLOB_GAS: U256 = U256::one();

// WARNING: Do _not_ use the BLOB_BASE_FEE_UPDATE_FRACTION_* family of
// constants as is. Use the `get_blob_base_fee_update_fraction_value`
// function instead
pub const BLOB_BASE_FEE_UPDATE_FRACTION: U256 = U256([3338477, 0, 0, 0]);
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)
pub const BLOB_BASE_FEE_UPDATE_FRACTION: u64 = 3338477;
pub const BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE: u64 = 5007716; // Defined in [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691)

// WARNING: Do _not_ use the MAX_BLOB_COUNT_* family of constants as
// is. Use the `max_blobs_per_block` function instead
pub const MAX_BLOB_COUNT: usize = 6;
pub const MAX_BLOB_COUNT_ELECTRA: usize = 9;
pub const MAX_BLOB_COUNT: u64 = 6;
pub const MAX_BLOB_COUNT_ELECTRA: u64 = 9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes from U256 to u64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those functions are now only used int the EVMConfig struct. That struct has a ForkBlobSchedule inside it, which uses u64 for all it fields (Note: ForkBlobSchedule is used by the L1).

So, it the constants were left as U256 they were needed to be cast down; which returned a Result, whose Err case needed to be handled. This made it difficult to create a config since it could "technically" fail, even though it was casting down a constant.

I decided to change them to u64 in order to make it easier to use ForkBlobSchedule. Furthermore, casting a u64 to U256 doesn't return a Result; so there was no Err to handle.

Comment on lines -303 to -326
pub const fn max_blobs_per_block(fork: Fork) -> usize {
match fork {
Fork::Prague => MAX_BLOB_COUNT_ELECTRA,
Fork::PragueEof => MAX_BLOB_COUNT_ELECTRA,
_ => MAX_BLOB_COUNT,
}
}

/// According to EIP-7691
/// (https://eips.ethereum.org/EIPS/eip-7691#specification):
///
/// "These changes imply that get_base_fee_per_blob_gas and
/// calc_excess_blob_gas functions defined in EIP-4844 use the new
/// values for the first block of the fork (and for all subsequent
/// blocks)."

pub const fn get_blob_base_fee_update_fraction_value(fork: Fork) -> U256 {
match fork {
Fork::Prague => BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
Fork::PragueEof => BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE,
_ => BLOB_BASE_FEE_UPDATE_FRACTION,
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand why we removed these functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

/// According to [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691#specification):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work documenting the corresponding EIPs 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 😊

Copy link

github-actions bot commented Feb 3, 2025

@lima-limon-inc lima-limon-inc added this pull request to the merge queue Feb 3, 2025
Merged via the queue into main with commit dec0119 Feb 3, 2025
34 checks passed
@lima-limon-inc lima-limon-inc deleted the levm/feat/eip7840 branch February 3, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
levm Lambda EVM implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LEVM: add support for EIP-7840
5 participants