Skip to content

Conversation

wetkeyboard
Copy link
Contributor

closes #18871

set gas_used=gas_limit for the failed tx

@wetkeyboard
Copy link
Contributor Author

@mattsse please take a look

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

can you elaborate on why this fixes the issue?

unclear to me why gas used needs to be swapped with gaslimit here

maybe @rakita knows

@mattsse mattsse added C-bug An unexpected or incorrect behavior A-rpc Related to the RPC implementation labels Oct 13, 2025
@rakita
Copy link
Collaborator

rakita commented Oct 13, 2025

Hm maybe the expectation for gas returned is to return the max spent gas for the Halt, as halt spends all the gas. For Revert and Success it is not gas limit.

@mattsse
Copy link
Collaborator

mattsse commented Oct 14, 2025

@rakita shouldn't res.gas_used always have the actual gas used by the tx?

so unclear why this is different here

https://etherscan.io/tx/0x2a4b68d823b4468df290508f8466feaa588e8127b5680c0ebc99d22b4b0fed69

@wetkeyboard
Copy link
Contributor Author

Sorry, this fix is incorrect, I think it's a bug in revm, @rakita could you please take a look at bluealloy/revm#3100

let gas_limit = tx_env.gas_limit();
let res = self.eth_api().inspect(db, evm_env, tx_env, &mut inspector)?;
let gas_used =
if res.result.is_success() { res.result.gas_used() } else { gas_limit };
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be if res.result.is_halt() { gas_limit } else { res.result.gas_used() };

Revert version of return does not consume all the gas

@rakita
Copy link
Collaborator

rakita commented Oct 15, 2025

@mattsse i think, the assumption is that Halt would take all the gas (This is how it is done for subcalls, taking all gas means using gas limit), but for first call we return used gas and not all the the spend gas.

Etherscan link that you shared shows last used gas, so maybe it is fine to leave as it is. Not sure if this Fail means REVERT opcode is called or it is Halt, diff is that REVERT would not spend all the gas.

It would be good to check how alloy/evm handles this,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rpc Related to the RPC implementation C-bug An unexpected or incorrect behavior

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Mismatch between __gasUsed__ in __eth_getTransactionReceipt__ vs. __debug_traceTransaction__ (callTracer)

3 participants