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

fix(levm): change gas type from U256 to u64 #1528

Merged
merged 50 commits into from
Dec 20, 2024
Merged

fix(levm): change gas type from U256 to u64 #1528

merged 50 commits into from
Dec 20, 2024

Conversation

lima-limon-inc
Copy link
Contributor

@lima-limon-inc lima-limon-inc commented Dec 18, 2024

Motivation

The execution client uses u64 for measuring gas, while LEVM uses U256. This PR makes LEVM also use u64 for gas

Description

Closes #1499

@lima-limon-inc lima-limon-inc changed the title A small step for man, a large leap for mankind fix(levm): change gas type from U256 to u64 Dec 18, 2024
@lima-limon-inc lima-limon-inc self-assigned this Dec 18, 2024
@lima-limon-inc
Copy link
Contributor Author

We'll see when it finishes running, but in theory all the uses of gas have been changed to u64.

The files that relate to parsing the tests and running the benchmarks remain in U256, simply to maintain how the parsing works. Those values are cast to u64 when the tests run.

@lima-limon-inc
Copy link
Contributor Author

lima-limon-inc commented Dec 19, 2024

PS: Note to reviewers

I used the "VeryLargeNumber" when a function couldn't cast a value from U256 u64. Should I return a different error?
What error should it be?

Changed here: 7b3bccc

@lima-limon-inc lima-limon-inc marked this pull request as ready for review December 19, 2024 13:44
@lima-limon-inc lima-limon-inc requested a review from a team as a code owner December 19, 2024 13:44
Copy link
Contributor

@damiramirez damiramirez left a comment

Choose a reason for hiding this comment

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

LGTM

@lima-limon-inc lima-limon-inc marked this pull request as draft December 19, 2024 15:40
Copy link
Contributor

@JereSalo JereSalo left a comment

Choose a reason for hiding this comment

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

Great job! There was a lot of effort in this

.stack
.pop()?
.try_into()
.map_err(|_| VMError::Internal(InternalError::ConversionError))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be internal

.stack
.pop()?
.try_into()
.map_err(|_| VMError::Internal(InternalError::ConversionError))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

.stack
.pop()?
.try_into()
.map_err(|_| VMError::Internal(InternalError::ConversionError))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

.stack
.pop()?
.try_into()
.map_err(|_| VMError::Internal(InternalError::ConversionError))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@lima-limon-inc
Copy link
Contributor Author

I left some suggestions. If possible re-review the PR yourself and see if you find anything out of place. I think other than the things I mentioned it looks good

Hello Jere, thank you very much for your feedback. I incorporated your suggestions and re-reviewed the PR. Let me know if you find anything else that need correction.

PS: I also found some other places (ef21d78) where I had created a variable where there wasn't any before. I rolled back those changes so that is more aligned with the previous style.

LMKWYT!

fn get_max_blob_gas_cost(&self) -> Result<U256, VMError> {
let blob_gas_used = U256::from(self.env.tx_blob_hashes.len())
fn get_max_blob_gas_price(&self) -> Result<U256, VMError> {
let blob_gas_used: u64 = self
Copy link
Contributor

@JereSalo JereSalo Dec 20, 2024

Choose a reason for hiding this comment

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

I know you rewrite this variable but this is not blob_gas_used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, I changed it to blob_gas_amout (e0a5eec), what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it is actually not blob_gas_amount, in that case it is just the length of the blob hash list! Not related to gas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry Jere, it was reading the variable name wrong in my head. It's been a rough day! Haha,

Changed here: 341ca8d

fn get_blob_gas_cost(&self) -> Result<U256, VMError> {
let blob_gas_used = U256::from(self.env.tx_blob_hashes.len())
fn get_blob_gas_price(&self) -> Result<U256, VMError> {
let blob_gas_used: u64 = self
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto ditto: e235e99

}

pub fn get_base_fee_per_blob_gas(&self) -> Result<U256, VMError> {
pub fn get_base_fee_per_blob_gas(&self) -> Result<u64, VMError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

this sounds like it should be an U256 because it is a fee. I am not 100% sure but I think it should because in the validations you are comparing it against tx_max_fee_per_blob_gas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello Jere, this was changed here: 96b9bf5

I added an additional let binding (let blob_gas_price: U256 = blob_gas_price.into();, 96b9bf5#diff-e20d30a6efb08393eee586d44f3bc4a8df6cbd53ec8ea5bb4d5def88c9487de1R655) simply out of necessity. It was the cleanest way I could think of to cast the value to U256.

Suggested-by: Jeremias Salomon <jeremias.salomon@lambdaclass.com>
Suggested-by: Jeremias Salomon <jeremias.salomon@lambdaclass.com>
Copy link
Contributor

@JereSalo JereSalo left a comment

Choose a reason for hiding this comment

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

nice! sorry if I was pretty annoying with the suggestions. good work

@JereSalo JereSalo added this pull request to the merge queue Dec 20, 2024
@lima-limon-inc
Copy link
Contributor Author

nice! sorry if I was pretty annoying with the suggestions. good work

Please Jere, no need to apologize! On the contrary, I not only value your diligence, I also admire it!

I have never taken any offense from your comments. Thank you very much for all your dedication!

😊

Merged via the queue into main with commit 2bb8fa9 Dec 20, 2024
18 checks passed
@JereSalo JereSalo deleted the fix/levm/gas_type branch December 20, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

levm: replace gas type from U256 to u64
3 participants