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): fix validation errors (part 2) and some extra things #1345

Merged
merged 66 commits into from
Dec 3, 2024

Conversation

JereSalo
Copy link
Contributor

@JereSalo JereSalo commented Nov 28, 2024

Motivation
The main motivation is to fix validation related tests. Return a validation exception everytime that is necessary (while being careful of not returning them in cases in which they are not expected).
It also fixes/changes some things that I find along the way and I consider appropriate changing.

Description

  • Adds function add_intrinsic_gas()
  • Uses our gas_price as an effective gas price. So it works for transactions Type 2 and 3.
  • Implements blob gas cost
  • Implements calculation of base fee per blob gas and it's associated validation.
  • Fixes add_gas_with_max for report
  • It implements somewhat of a revert for create, but I'm not sure if it is well done because cache's purpose has recently changed.

Diffs for add_intrinsic_gas and validate_transaction don't look very good. I recommend to watch the code directly for those functions.

End Result

✓ Ethereum Foundation Tests: 1466 passed 2635 failed 4101 total run - 39:12
✓ Summary: 1466/4101 (35.75)

Cancun: 1356/3578 (37.90%)
Shanghai: 55/221 (24.89%)
Homestead: 0/17 (0.00%)
Istanbul: 0/34 (0.00%)
London: 19/39 (48.72%)
Byzantium: 0/33 (0.00%)
Berlin: 17/35 (48.57%)
Constantinople: 0/66 (0.00%)
Merge: 19/62 (30.65%)
Frontier: 0/16 (0.00%)

After mergin main into branch:

Summary: 1471/4101 (35.87)
Cancun: 1361/3578 (38.04%)

Closes #issue_number

crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
/// To get the maximum fee per gas that the user is willing to pay, independently of the actual gas price
/// For legacy transactions the max fee per gas is the gas price
fn max_fee_per_gas_or_gasprice(&self) -> U256 {
self.env.tx_max_fee_per_gas.unwrap_or(self.env.gas_price)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ok? Generally, the gas price is either the transaction type 0 or 1 gas price or the transaction type 2 or 3 max_fee_per_gas but not the reciprocal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed necessary for validations only. Not for execution.
For example there's a validation named INSUFFICIENT_MAX_FEE_PER_GAS that checks if the max fee per gas is less than the base fee per gas. The problem is that we also have to return that error for type 0 and 1 transactions when gas price is less than base fee per gas.
We also need it the most for the calculation of the up-front cost, where Tp is gas price and Tm is max fee per gas. I made the function to simplify that. I could even delete it cause it's only used twice and won't be used more times than that I guess.
image

crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
crates/vm/levm/src/vm.rs Outdated Show resolved Hide resolved
crates/vm/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.

The PR looks good. Left some questions, suggestions and change requests

@JereSalo JereSalo changed the title feat(levm): keep on fixing execution problems feat(levm): fix validation errors (part 2) Dec 3, 2024
@JereSalo JereSalo changed the title feat(levm): fix validation errors (part 2) feat(levm): fix validation errors (part 2) and some extra things Dec 3, 2024
@JereSalo JereSalo requested a review from ilitteri December 3, 2024 13:34
Copy link
Contributor

@maximopalopoli maximopalopoli left a comment

Choose a reason for hiding this comment

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

After the fix I mentioned, lgtm

value,
Bytes::new(),
Copy link
Contributor

Choose a reason for hiding this comment

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

In a create tx calldata should be an empty set of bytes, not the calldata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Didn't know that
Fixed it here:
79fc4e0

@ilitteri ilitteri added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit c6acab4 Dec 3, 2024
20 checks passed
@ilitteri ilitteri deleted the levm/transact-refactor branch December 3, 2024 15:46
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.

3 participants