This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add spec for TLOAD and TSTORE * update evm-proof and state-proof specs * create OOG spec * use SLOAD_GAS variable * fix busmapping lookups count
- Loading branch information
Showing
4 changed files
with
146 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# ErrorOutOfGasTloadTstore state for both TLOAD and TSTORE OOG errors | ||
|
||
## Procedure | ||
|
||
Handle the corresponding out of gas errors for both `TLOAD` and `TSTORE` opcodes. | ||
|
||
### EVM behavior | ||
|
||
The out of gas error may occur for `constant gas`. | ||
|
||
#### TLOAD gas cost | ||
|
||
For this gadget, TLOAD gas cost in EIP-1153 is specified as the cost of hot SLOAD, currently `100`. | ||
|
||
#### TSTORE gas cost | ||
|
||
For this gadget, TSTORE gas cost in EIP-1153 is specified as the cost of SSTORE on an already SSTOREd slot, currently `100`. | ||
|
||
### Constraints | ||
|
||
1. For TLOAD, constrain `gas_left < gas_cost`. | ||
2. For TSTORE, constrain `gas_left < gas_cost`. | ||
3. Only for TSTORE, constrain `is_static == false`. | ||
4. Current call must fail. | ||
5. If it's a root call, it transits to `EndTx`. | ||
6. If it isn't a root call, it restores caller's context by reading to `rw_table`, then does step state transition to it. | ||
7. Constrain `rw_counter_end_of_reversion = rw_counter_end_of_step + reversible_counter`. | ||
|
||
### Lookups | ||
|
||
7 bus-mapping lookups for TLOAD and 8 for TSTORE: | ||
|
||
1. 5 call context lookups for `tx_id`, `is_static`, `callee_address`, `is_success` and `rw_counter_end_of_reversion`. | ||
2. 1 stack read for `transient_storage_key`. | ||
3. Only for TSTORE, 1 stack read for `value_to_store`. | ||
4. Only for TSTORE, 1 account transient storage read. | ||
|
||
## Code | ||
|
||
> TODO |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# TLOAD & TSTORE opcodes | ||
|
||
## Variables definition | ||
|
||
| Name | Value | | ||
| - | - | | ||
| SLOAD_GAS | 100 | | ||
|
||
## Constraints | ||
|
||
1. opcodeId checks | ||
1. opId === OpcodeId(0x5c) for `TLOAD` | ||
2. opId === OpcodeId(0x5d) for `TSTORE` | ||
2. state transition: | ||
- gc | ||
- `TLOAD`: +7 | ||
- 4 call_context read | ||
- 2 stack operations | ||
- 1 transient storage reads | ||
- `TSTORE`: +8 | ||
- 5 call_context read | ||
- 2 stack operations | ||
- 1 transient storage reads/writes | ||
- stack_pointer | ||
- `TLOAD`: remains the same | ||
- `TSTORE`: -2 | ||
- pc + 1 | ||
- reversible_write_counter | ||
- `TLOAD`: +0 | ||
- `TSTORE`: +1 (for transient storage) | ||
- gas: | ||
- `TLOAD`: | ||
- gas + SLOAD_GAS | ||
- `SSTORE`: | ||
- gas + SLOAD_GAS | ||
3. lookups: | ||
- `TLOAD`: 7 busmapping lookups | ||
- call_context: | ||
- `tx_id`: Read the `tx_id` for this tx. | ||
- `rw_counter_end_of_reversion`: Read the `rw_counter_end` if this tx get reverted. | ||
- `is_persistent`: Read if this tx will be reverted. | ||
- `callee_address`: Read the `callee_address` of this call. | ||
- stack: | ||
- `key` is popped off the top of the stack | ||
- `value` is pushed on top of the stack | ||
- transient storage: The 32 bytes of `value` are read from storage at `key` | ||
- `TSTORE`: 8 busmapping lookups | ||
- call_context: | ||
- `tx_id`: Read the `tx_id` for this tx. | ||
- `is_static`: Read the call's property `is_static` | ||
- `rw_counter_end_of_reversion`: Read the `rw_counter_end` if this tx get reverted. | ||
- `is_persistent`: Read if this tx will be reverted. | ||
- `callee_address`: Read the `callee_address` of this call. | ||
- stack: | ||
- `key` is popped off the top of the stack | ||
- `value` is popped off the top of the stack | ||
- transient storage: | ||
- The 32 bytes of new `value` are written to transient storage at `key`, with the previous `value` and `committed_value` | ||
|
||
## Exceptions | ||
|
||
1. gas out: remaining gas is not enough | ||
2. stack underflow: | ||
- the stack is empty: `1024 == stack_pointer` | ||
- only for `TSTORE`: contains a single value: `1023 == stack_pointer` | ||
3. context error | ||
- only for `TSTORE`: the current execution context is from a `STATICCALL` (since Cancun fork). |
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