This repository was archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 270
Spec ExecutionState::STOP
#100
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c184d3
feat: implement STOP
han0110 5c4ec36
feat: move caller_id lookup into step_state_transition_to_restored_co…
han0110 1f44b43
chore: rename all state_write_counter to reversible_write_counter
han0110 8719c80
chore: remove assert instruction.next is not None
han0110 3289aad
fix: apply suggestion
han0110 6ce0bbe
fix: update
han0110 9d99202
fix: apply suggestion
han0110 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # STOP opcode | ||
|
|
||
| ## Procedure | ||
|
|
||
| ### EVM behavior | ||
|
|
||
| The `STOP` opcode terminates the call, then: | ||
|
|
||
| 1. If it's an root call, it ends the execution. | ||
| 2. Otherwise, it restores caller's context and switch to it. | ||
|
|
||
| ### Circuit behavior | ||
|
|
||
| The circuit first checks the `result` in call context is indeed success. Then: | ||
|
|
||
| 1. If it's an root call, it transits to `EndTx`. | ||
| 2. Otherwise, it restore caller's context by reading to `rw_table`, then does step state transition to it. | ||
|
|
||
| ## Code | ||
|
|
||
| Please refer to `src/zkevm_specs/evm/execution/stop.py`. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from ...util import FQ | ||
| from ..instruction import Instruction, Transition | ||
| from ..table import CallContextFieldTag | ||
| from ..execution_state import ExecutionState | ||
|
|
||
|
|
||
| def stop(instruction: Instruction): | ||
| # Note when transition to STOP, program_counter can only be increased by 1, | ||
| # (JUMP* will always transit to JUMPDEST, then to STOP if any) so when opcode | ||
| # fetching is out of range, the program_counter must be equal to code_length. | ||
| code_length = instruction.bytecode_length(instruction.curr.code_hash) | ||
| is_out_of_range = instruction.is_equal(code_length, instruction.curr.program_counter) | ||
| if is_out_of_range == FQ(0): | ||
| instruction.responsible_opcode_lookup(instruction.opcode_lookup(True)) | ||
|
|
||
| # When a call ends with STOP, this call must be successful, but it's not | ||
| # necessary persistent depends on if it's a sub-call of a failed call or not. | ||
| is_success = instruction.call_context_lookup(CallContextFieldTag.IsSuccess) | ||
| instruction.constrain_equal(is_success, FQ(1)) | ||
|
|
||
| # Go to EndTx only when is_root | ||
| is_to_end_tx = instruction.is_equal(instruction.next.execution_state, ExecutionState.EndTx) | ||
| instruction.constrain_equal(FQ(instruction.curr.is_root), is_to_end_tx) | ||
|
|
||
| if instruction.curr.is_root: | ||
| # When a transaction ends with STOP, this call must be persistent | ||
| is_persistent = instruction.call_context_lookup(CallContextFieldTag.IsPersistent) | ||
| instruction.constrain_equal(is_persistent, FQ(1)) | ||
|
|
||
| # Do step state transition | ||
| instruction.constrain_step_state_transition( | ||
| rw_counter=Transition.delta(2), | ||
| call_id=Transition.same(), | ||
| ) | ||
| else: | ||
| # There are 2 possible branch for internal call: | ||
| # 1. is_create: | ||
| # STOP returns empty bytes as deployment code, but when it's an internal creation call, | ||
| # the code_hash of callee must already be random linear combination of EMPTY_CODE_HASH, | ||
| # which doesn't need any update here. | ||
| # 2. not is_create: | ||
| # STOP returns empty bytes as return_data, which doesn't affect caller's memory at all. | ||
| # So we only need to restore caller's state as finishing this call. | ||
|
|
||
| # Restore caller state to next StepState | ||
| instruction.step_state_transition_to_restored_context( | ||
| rw_counter_delta=1, | ||
| return_data_offset=FQ(0), | ||
| return_data_length=FQ(0), | ||
| gas_left=instruction.curr.gas_left, | ||
| ) |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.