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): implement precompile sha2-256 #1520

Merged
merged 53 commits into from
Dec 18, 2024

Conversation

maximopalopoli
Copy link
Contributor

@maximopalopoli maximopalopoli commented Dec 16, 2024

Motivation

The goal is to implement the sha2 256 precompile.

Description

For this precompile I struggled to add unit tests, but the EF tests related to sha2 256 precompile are passing.

ilitteri and others added 30 commits December 10, 2024 13:07
…ass/ethrex into precompiles_support_scaffolding
The tests were not passing because the addresses assigned for the
 contracts were the reserved for the precompiles
@maximopalopoli maximopalopoli requested a review from a team as a code owner December 16, 2024 21:35
@JereSalo
Copy link
Contributor

Was it necessary to link precompiles branches to one another? Also, it would be good to have a basic unit test for sha-256

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.

Left some suggestions. It looks good though

) -> Result<Bytes, VMError> {
Ok(Bytes::new())
let data_size: u64 = calldata
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a usize instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll end up doing the conversion anyways but doing it inside of the gas cost function its cleaner in my opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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


*consumed_gas = consumed_gas
.checked_add(cost)
.ok_or(PrecompileError::GasConsumedOverflow)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be an internal error in this scenario? It shouldn't ever happen, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion it can happen because we pass a pointer to the consumed gas, although it is as possible as the other uses of GasConsumedOverflow throughout the vm (that should not happen since they should be lower than gas limit)

Comment on lines 187 to 193
if gas_for_call < cost {
return Err(VMError::PrecompileError(PrecompileError::NotEnoughGas));
}

*consumed_gas = consumed_gas
.checked_add(cost)
.ok_or(PrecompileError::GasConsumedOverflow)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can abstract this behavior into a function that receives gas_for_call, consumed_gas and the cost, sending the consumed_gas as mutable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree we have to do this in every precompile so a dedicated function would be nice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@LeanSerra LeanSerra left a comment

Choose a reason for hiding this comment

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

Nice work, left some small comments.

Comment on lines 187 to 193
if gas_for_call < cost {
return Err(VMError::PrecompileError(PrecompileError::NotEnoughGas));
}

*consumed_gas = consumed_gas
.checked_add(cost)
.ok_or(PrecompileError::GasConsumedOverflow)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree we have to do this in every precompile so a dedicated function would be nice

) -> Result<Bytes, VMError> {
Ok(Bytes::new())
let data_size: u64 = calldata
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll end up doing the conversion anyways but doing it inside of the gas cost function its cleaner in my opinion

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.

This PR is looking very good now. Great job!

Copy link
Contributor

@LeanSerra LeanSerra left a comment

Choose a reason for hiding this comment

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

LGTM :)

Base automatically changed from levm/feat/impl-precompile-ecrecover to main December 18, 2024 13:36
@JereSalo JereSalo added this pull request to the merge queue Dec 18, 2024
Merged via the queue into main with commit ca83a90 Dec 18, 2024
17 checks passed
@JereSalo JereSalo deleted the levm/feat/impl-precompile-sha2-256 branch December 18, 2024 14:28
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.

4 participants