Skip to content

feat: add a way for precompiles to revert#2711

Merged
rakita merged 1 commit intomainfrom
klkvr/precompile-revert
Jul 15, 2025
Merged

feat: add a way for precompiles to revert#2711
rakita merged 1 commit intomainfrom
klkvr/precompile-revert

Conversation

@klkvr
Copy link
Collaborator

@klkvr klkvr commented Jul 15, 2025

Adds reverted flag to PrecompileOutput that allows precompiles to revert

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 15, 2025

CodSpeed Performance Report

Merging #2711 will not alter performance

Comparing klkvr/precompile-revert (b0c475d) with main (356b138)

Summary

✅ 159 untouched benchmarks

Comment on lines +19 to +20
/// Whether the precompile reverted
pub reverted: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems like the least invasive option to me,

the use case here is valid, since there exist precompiles that act as revert

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

lgtm

@rakita rakita merged commit 2eea4e9 into main Jul 15, 2025
29 checks passed
@rakita rakita deleted the klkvr/precompile-revert branch July 15, 2025 10:16
This was referenced Jul 15, 2025
This was referenced Jul 21, 2025
InstructionResult::Revert
} else {
InstructionResult::Return
};

Choose a reason for hiding this comment

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

https://github.com/alloy-rs/evm/blob/666cb3bf0a6511e210e93b1d2e88d80fcf85708c/crates/evm/src/precompiles.rs#L370-L392

     let precompile_result = precompile.call(PrecompileInput {
         data: input_bytes,
         gas: gas_limit,
         caller: inputs.caller_address,
         value: inputs.call_value,
         internals: EvmInternals::new(journal, &context.block),
     });


     match precompile_result {
         Ok(output) => {
             let underflow = result.gas.record_cost(output.gas_used);
             assert!(underflow, "Gas underflow is not possible");
             result.result = InstructionResult::Return;
             result.output = output.bytes;
         }
         Err(PrecompileError::Fatal(e)) => return Err(e),
         Err(e) => {
             result.result = if e.is_oog() {
                 InstructionResult::PrecompileOOG
             } else {
                 InstructionResult::PrecompileError
             };
         }

Does alloy-rs/evm need to handle the revert error?

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.

4 participants