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): increase calldata cost - EIP-7623 #1665

Merged
merged 11 commits into from
Jan 9, 2025
Merged

Conversation

tomip01
Copy link
Contributor

@tomip01 tomip01 commented Jan 8, 2025

Motivation

This Pull Request exists to make a floor cost for the gas usage in the transactions. This is specified in EIP-7623, and aims to reduce the maximum block size to make room for additional blobs or potential block gas limit increases. Also, it introduces that the gas limit has to be at least the floor cost.

Description

Here, for the Prague Spec adds the check in the prepare_execution to the gas limit be greater or equal to the max value of the intrinsic gas or TX_BASE_COST + TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata. Where TOTAL_COST_FLOOR_PER_TOKEN is a new constant with the value of 10.
A new error is added when the gas limit is too low, TxValidationError::GasLimitTooLow.

Then when creating the report, the gas usage for Prague is the max value of the gas usage or TX_BASE_COST + TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata.

State

The only tests for this EIP that fail are the test with type 4 transactions. This is because we don't have implemented them.

Closes #1640

* Check for gas limit restriction for being too low
* Adjust gas used if it is under the floor
* Adds TxValidationError for gas limit too low
@tomip01 tomip01 requested a review from a team as a code owner January 8, 2025 18:50
Copy link

github-actions bot commented Jan 8, 2025

+----------------------------------------------------------------+-------+------+
| File                                                           | Lines | Diff |
+----------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/levm/src/errors.rs   | 233   | +2   |
+----------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/levm/src/gas_cost.rs | 881   | +2   |
+----------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/vm/levm/src/vm.rs       | 1021  | +43  |
+----------------------------------------------------------------+-------+------+

Total lines changed: +47

@@ -169,6 +169,9 @@ pub const ACCESS_LIST_ADDRESS_COST: u64 = 2400;
// Precompile costs
pub const ECRECOVER_COST: u64 = 3000;

// Floor price gas used
pub const TOTAL_COST_FLOOR_PER_TOKEN: u64 = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this variable come from the EIP? If so, it'd be nice to link to were it comes from.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 9edc75d

}

fn add_intrinsic_gas(&mut self, initial_call_frame: &mut CallFrame) -> Result<(), VMError> {
// Intrinsic gas is the gas consumed by the transaction before the execution of the opcodes. Section 6.2 in the Yellow Paper.
Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks for clarfying from where this comes from.

Comment on lines 612 to 618
// tokens_in_calldata = tx_calldata / 4
let tokens_in_calldata: u64 = gas_cost::tx_calldata(&current_call_frame.calldata)
.map_err(VMError::OutOfGas)?
.checked_div(4)
.ok_or(VMError::Internal(InternalError::DivisionError))?;

// floor_gas_price = TX_BASE_COST + TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, where does this logic come from? Also, why divide by 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 0be370d

Copy link

github-actions bot commented Jan 8, 2025

Benchmark Results Comparison

PR Results

Benchmark Results: Factorial

Command Mean [s] Min [s] Max [s] Relative
revm_factorial 7.118 ± 0.034 7.089 7.190 1.00
levm_factorial 26.636 ± 0.090 26.476 26.730 3.74 ± 0.02

Benchmark Results: Fibonacci

Command Mean [s] Min [s] Max [s] Relative
revm_fibonacci 7.341 ± 0.897 6.920 9.890 1.00
levm_fibonacci 24.032 ± 0.157 23.810 24.372 3.27 ± 0.40

Main Results

Benchmark Results: Factorial

Command Mean [s] Min [s] Max [s] Relative
revm_factorial 7.376 ± 0.033 7.318 7.421 1.00
levm_factorial 26.799 ± 0.771 26.402 28.948 3.63 ± 0.11

Benchmark Results: Fibonacci

Command Mean [s] Min [s] Max [s] Relative
revm_fibonacci 7.143 ± 0.049 7.081 7.247 1.00
levm_fibonacci 24.064 ± 0.121 23.917 24.229 3.37 ± 0.03

@ilitteri
Copy link
Contributor

ilitteri commented Jan 8, 2025

Before reviewing the PR:

  • Remember to keep your branch up-to-date main.
  • Assign yourself to the PR
  • Add the corresponding labels
  • Link the corresponding project

The PR description looks very good!

@tomip01 tomip01 added ef-tests Hive tests, execution-spec-tests levm Lambda EVM implementation labels Jan 9, 2025
@tomip01 tomip01 self-assigned this Jan 9, 2025
@ilitteri ilitteri enabled auto-merge January 9, 2025 17:12
@ilitteri ilitteri added this pull request to the merge queue Jan 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Jan 9, 2025
@tomip01 tomip01 added this pull request to the merge queue Jan 9, 2025
Merged via the queue into main with commit 18ae6b9 Jan 9, 2025
10 checks passed
@tomip01 tomip01 deleted the levm/increase-call-cost branch January 9, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ef-tests Hive tests, execution-spec-tests levm Lambda EVM implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LEVM: Add support for the EIP-7623
3 participants