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: return actual gas charged to the transaction caller for zkVM transactions #592

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

elfedy
Copy link
Contributor

@elfedy elfedy commented Sep 25, 2024

Motivation

When vm is on zkVM mode, Calls/Creates on EVM are intercepted and run as transactions on the zkVM made by the caller of the test contract. There are currently two problems related to gas visibility for them:

  1. gas_used value being returned is the computational gas spent by a bootloader program run on OneTx mode with that transaction on its heap. This includes the gas for general setup and transaction validation + execution. This value does not make sense in neither the case where we would want to interpret the intercepted call as a CALL opcode, because it would include setup + validation costs, nor for when we want to interpret it as an actual transaction (like done on evm tests when run on isolate mode), because it includes non transaction related gas and does not account for neither pubdata nor intrinsic costs.
  2. Gas sent back to the revm via InterpreterResult represents 0 gas spent. This value is then used in traces which result in them showing 0 gas cost and gas report stats not showing any meaningful value.

Solution

  1. Treat intercepted calls/creates as transactions, yielding the gas charged to user making the transaction as the gas_used.
  2. Account for this gas in the gas returned in InterpreterResult.

Copy link
Contributor

@Jrigada Jrigada left a comment

Choose a reason for hiding this comment

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

Nice!

@elfedy elfedy merged commit d1b59e9 into main Sep 26, 2024
14 checks passed
@elfedy elfedy deleted the elfedy-gas-report branch September 26, 2024 16:28
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.

2 participants