-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: AVM witgen track gas for nested calls and external halts (#10731)
Resolves #10033 Resolves #10374 This PR does the following: - Witgen handles out-of-gas errors for all opcodes - all halts (return/revert/exceptional) work as follows: - charge gas for the problematic instruction as always, adding a row to the gas trace - pop the parent/caller's latest gas from the stack - call a helper function on the gas trace to mutate that most recent gas row, returning to the parent's latest gas minus any consumed gas (all gas consumed on exceptional halt) - `GasTraceEntry` includes a field `is_halt_or_first_row_in_nested_call` which lets us break gas rules on a halt or when starting a nested call because in both cases gas will jump. - `constrain_gas` returns a bool `out_of_gas` so that opcode implementations can handle out of gas - `write_to_memory` now has an option to skip the "jump back to correct pc" which was problematic when halting because the `jump` wouldn't result in a next row with the right pc Explanation on how gas works for calls: - Parent snapshots its gas right before a nested call in `ctx.*_gas_left` - Nested call is given a `ctx.start_*_gas_left` and the gas trace is forced to that same value - throughout the nested call, the gas trace operates normally, charging per instruction - when any halt is encountered, the instruction that halted must have its gas charged normally, but then we call a helper function on the gas trace to mutate the most recent row, flagging it to eventually become a sort of "fake" row that skips some constraints - the mutation of the halting row resets the gas to the parents last gas before the call (minus however much gas was consumed by the nested call... if exceptional halt, that is _all_ allocated gas) Follow-up work - properly constrain gas for nested calls, returns, reverts and exceptional halts - if `jump` exceptionally halts (i.e. out of gas), it should be okay that the next row doesn't have the target pc - Handle the edge case when an error is encountered on return/revert/call, but after the stack has already been modified
- Loading branch information
Showing
16 changed files
with
738 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.