-
Notifications
You must be signed in to change notification settings - Fork 6
feat: vm.Hooks.PreprocessingGasCharge()
#235
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Introduces a new EVM preprocessing hook mechanism to charge additional gas before transaction execution begins. This enables charging gas between core.IntrinsicGas and EVM execution, supporting Warp functionality in SAE without modifying the core intrinsic gas calculation.
- Adds
PreprocessingGasCharge()method to VM hooks interface for custom gas charging - Modifies
EVM.Call()andEVM.Create()to spend preprocessing gas before execution - Provides comprehensive integration tests covering both success and error scenarios
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| libevm/ethtest/evm.go | Refactors state database creation into reusable helper function |
| libevm/ethtest/dummy.go | Adds dummy implementations for chain context and consensus engine |
| core/vm/preprocess.libevm_test.go | Comprehensive integration tests for preprocessing gas charging |
| core/vm/interface.libevm.go | Defines StateDBRemainder interface for transaction context access |
| core/vm/interface.go | Extends StateDB interface with StateDBRemainder methods |
| core/vm/hooks.libevm.go | Adds Preprocessor interface and NOOPHooks implementation |
| core/vm/evm.libevm_test.go | Updates test hook to implement new Preprocessor interface |
| core/vm/evm.libevm.go | Implements preprocessing gas spending logic in EVM operations |
| core/vm/evm.go | Renames methods to support preprocessing wrapper functions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]> Signed-off-by: Arran Schlosberg <[email protected]>
Why this should be merged
In lieu of modifications to
core.IntrinsicGas(), required for support of Warp in SAE.If we were to introduce variadic
options.Options toIntrinsicGas(), it's impossible to guarantee that they would always be passed. Thetypes.Transactionitself isn't actually passed toIntrinsicGas()either, so we can't rely on it to carry payloads/hooks.How this works
vm.Hooksare extended to includePreprocessingGasCharge(tx common.Hash) (uint64, error), which returns the amount of gas to be charged betweencore.IntrinsicGasandvm.EVMexecution charges. The two entry points to execution,vm.EVM.Call()andvm.EVM.Create()are modified to first spend said charge before running upstream logic.The new hook is defined on a separate interface definition, embedded in
vm.Hooks, to allow types to implement just that method and enforce it with thevar _ vm.Preprocessor = (*impl)(nil)pattern.How this was tested
Integration tests via both
core.ApplyTransaction()andcore.ApplyMessage(). The former is more comprehensive, while the latter allows for inspection of interim error values.