Update EIP-8037: fixed CPSB + frame accounting#11573
Update EIP-8037: fixed CPSB + frame accounting#11573misilva73 wants to merge 12 commits intoethereum:masterfrom
Conversation
|
✅ All reviewers have approved. |
|
|
||
| On **revert** or **exceptional halt** of the top-level frame, all state changes are reverted and no state gas is charged. On exceptional halt specifically, remaining `gas_left` is set to zero and `execution_regular_gas_used` is increased consistently. | ||
|
|
||
| ##### Top-level frame end (transaction end) |
There was a problem hiding this comment.
Thanks, this is very useful for creating temporary contracts, however, refunding gas at the end of the transaction will make this mechanism ineffective on Monad.
| - `execution_regular_gas_used` encodes the total regular-gas used by the transaction, and it is initialized as `execution_regular_gas_used = intrinsic_regular_gas`. | ||
| - `execution_state_gas_used` encodes the total state-gas used by the transaction, and it is initialized as `execution_state_gas_used = intrinsic_state_gas`. |
There was a problem hiding this comment.
Imo this does not belong here. I dont think evm is going to have those two counters as they are more specific for the block. So would propose to move those two inside Block-level gas accounting
There was a problem hiding this comment.
I added these counters because we need to know how much gas was spend on state and regular gas at the end of the transaction. I don't think we can derive it only from the gas_left and reservoir counters, right?
| Before transaction execution, inclusion of a transaction in a block requires that: | ||
|
|
||
| `intrinsic_regular_gas` and `intrinsic_state_gas` must be passed to `check_transaction` to perform the regular gas availability check. | ||
| 1. The transaction's **intrinsic costs are not higher than [EIP-7825](./eip-7825.md)'s transaction cap**. Concretely, `max(intrinsic_regular_gas, calldata_floor_gas_cost) <= TX_MAX_GAS_LIMIT`, where `intrinsic_regular_gas` includes all the intrinsic costs not associated with state created (i.e., base transaction cost, calldata, access lists, authorization base costs). |
There was a problem hiding this comment.
calldata_floor_cost is ambiguous because https://eips.ethereum.org/EIPS/eip-7981 adds authorization lists to floor costs
|
|
||
| For each storage slot whose value differs between the frame's entry and exit states, the frame is charged or refunded as follows: | ||
|
|
||
| - **New slot.** The slot's frame-exit value is non-zero and its transaction-entry value was zero. Charge `STATE_BYTES_PER_STORAGE_SET × CPSB` of state gas and increase `execution_state_gas_used` by the same amount. |
There was a problem hiding this comment.
(did not explicitly check this accounting)
Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>
|
|
||
| ##### Top-level frame end (transaction end) | ||
|
|
||
| At the end of a successful transaction, the top-level frame applies the frame-end accounting above and additionally performs deferred `SELFDESTRUCT` processing. [EIP-6780](./eip-6780.md) defers actual account removal to the end of the transaction for accounts that were created and self-destructed in the same transaction; the corresponding state-gas effect is therefore also computed only at this point. |
There was a problem hiding this comment.
I want the gas refund for selfdestruct to happen immediately, similar to sstore, accepting a partial semantic break of eip6780.
There was a problem hiding this comment.
This is not possible. A self-destructed account can still be called during execution and, in that scenario, the gas accounting will be a mess. We need to give the refund at the point where the account is destroyed, which is at the end of transaction.
There was a problem hiding this comment.
This is not possible. A self-destructed account can still be called during execution and, in that scenario, the gas accounting will be a mess. We need to give the refund at the point where the account is destroyed, which is at the end of transaction.
Can you provide more details about the implementation issues? According to eip6780, an account still has execution logic after a selfdestruct operation. However, we cannot redeploy that address due to eip684. Therefore, we are left with only one option: revert. We can apply similar semantics to sstore. I know this isn't ideal, but it's necessary to support temporary contracts because we don't have dedicated opcodes for them, and also because late refunds wouldn't be possible on Monad because the amount of gas consumed is based on the gas limit, not the amount of gas used. We also expect that the gas supply should be used as efficiently as possible, as it is locked in until the end of the transaction.
This is no longer required by the spec as per ethereum/EIPs#11573.
This is no longer required by the spec as per ethereum/EIPs#11573.
Co-authored-by: Copilot <copilot@github.com>
|
The commit 06b5c46 (as a parent of e632762) contains errors. |
Cost-per-state-byte: dynamic → fixed
cost_per_state_bytewith a single constantCPSB = 1174, derived from a 100 GiB/year target at a 96M-gas reference limit.TARGET_STATE_GROWTH_PER_YEAR,CPSB_SIGNIFICANT_BITS,CPSB_OFFSET, and the entire quantization section.STATE_BYTES_PER_STORAGE_SET,STATE_BYTES_PER_NEW_ACCOUNT,STATE_BYTES_PER_AUTH_BASE.State-gas accounting rules (opcode-level)
SSTORE: charged/refilled at end of opcode based on original/current/new value (handles the 0→x→0 case directly without a separate refund section).CALL*/CREATE/CREATE2: state-gas charged at end of successful call frame; reverted or exceptionally-halted frames produce no debit.SELFDESTRUCT: accounting deferred to end of transaction; refunds the account, code, and per-slot state-gas for accounts both created and destroyed in the same tx (per EIP-6780), bypassing the 20% refund cap.System contracts and system transactions
SYSTEM_CALL_GAS_LIMITto30M + STATE_BYTES_PER_STORAGE_SET × CPSB × SYSTEM_MAX_SSTORES_PER_CALLso existing system contracts retain their execution margin under the higher state-creation cost.