Update EIP-8037: Fix bugs from bal-devnet-6#11611
Conversation
|
✅ All reviewers have approved. |
| @@ -139,7 +139,9 @@ State-gas accounting for `SSTORE` is performed at the end of the opcode executio | |||
| | `CREATE`/`CREATE2` with bytecode size of `L` | `(STATE_BYTES_PER_NEW_ACCOUNT + L) × CPSB` charged | | |||
| | `SELFDESTRUCT` where balance transfer creates a new account | `STATE_BYTES_PER_NEW_ACCOUNT × CPSB` charged | | |||
There was a problem hiding this comment.
You should add a case where SELFDESTRUCT occurs within the CREATE/CREATE2 frame but without transferring ether to create a new account, to clarify the gas effect.
There was a problem hiding this comment.
Can you given more details on this example? From my understanding, if there is no transfer to new account, there are no state gas charges or refills
There was a problem hiding this comment.
What I mean is, how would you handle the SELFDESTRUCT case in the CREATE/CREATE2 constructor? Would you still charge the state gas and then defer it until the end of the transaction, or would you not charge it because the net state is zero (gas for transfer to new account via SELFDESTRUCT are not discussed here)? I looked at the latest bal devnet and it seems they intend to delay charging/refunding when creating the state, so the second option is most likely more reasonable.
There was a problem hiding this comment.
If I understand correctly, that case fits within the sections "State gas refills for SELFDESTRUCT" -> state gas is charged during CREATE/CREATE2 and then if there is a SELFDESTRUCT on those accounts, refills are provided at the end of the transaction.
There was a problem hiding this comment.
I've viewed through the ethrex implementation notes, and if I understand correctly, does that mean gas calculation in the latest version will be deferred instead of being calculated upfront at the start of a frame? In the case of SELFDESTRUCT in the CREATEx's constructor, the net state accounting is 0 when end frame instead of calculating the upfront fee and then refunding it at the transaction end, right?
- Deferred-on-success state-gas charging for CREATE/CREATE2/CALL* (would require deleting most of the state_gas_spill* / credit_state_gas_refund plumbing in vm.rs:449-510 and default_hook.rs:240-280, 360-420)
- Parameter-table rename (state-gas vs regular-gas split column naming)
|
|
||
| ##### Gas accounting for authorizations | ||
|
|
||
| For [EIP-7702](./eip-7702.md) authorizations, the intrinsic state-gas assumes account creation for each authorization, i.e., `(STATE_BYTES_PER_NEW_ACCOUNT + STATE_BYTES_PER_AUTH_BASE) × CPSB` per authorization. When the `authority` is not empty (i.e., non-zero nonce, non-zero balance, or non-empty code), the `STATE_BYTES_PER_NEW_ACCOUNT × CPSB` portion is refilled directly to `state_gas_reservoir` during authorization processing and `execution_state_gas_used` decreases by the corresponding amount. |
There was a problem hiding this comment.
If an account only resets the authorization indicator, it doesn't create additional state, meaning it must include the refund of STATE_BYTES_PER_AUTH_BASE * cpsb when the EOA's codeHash is not emptyHash, right?
There was a problem hiding this comment.
You are correct. Will fix it in the next push 🙏
|
|
||
| ##### Gas accounting for authorizations | ||
|
|
||
| For [EIP-7702](./eip-7702.md) authorizations, the intrinsic state-gas assumes account creation for each authorization, i.e., `(STATE_BYTES_PER_NEW_ACCOUNT + STATE_BYTES_PER_AUTH_BASE) × CPSB` per authorization. During authorization processing: |
There was a problem hiding this comment.
According to EIP-7702, when authorization resolving fails, it consumes the entire gas allocated to that authorization tuple. However, this EIP separates the cost of creating the state from the cost of execution, so it is necessary to consider refilling that entire cost, similar to invalid in the EVM runtime.
There was a problem hiding this comment.
In this EIP, we are not changing on refunds happen for the regular gas components. I will add a comment to clarify this
|
@eth-bot rerun |
eth-bot
left a comment
There was a problem hiding this comment.
All Reviewers Have Approved; Performing Automatic Merge...
Address four bugs surfaced by the bal-devnet-6 implementation and tests:
STATE_BYTES_PER_NEW_ACCOUNT × CPSBportion ofintrinsic_state_gaswhen a contract-creation transaction reverts or halts, mirroring the existing inner-CREATE rule.gas_leftconsumed in full,execution_regular_gas_usedupdated, new-account state-gas refunded.execution_state_gas_usedmay go below zero, and offered the equivalent implementation pattern of tracking the refill separately and subtracting it fromtx_state_gas.In addition, we remove the state refills originally provided for
SELFDESTRUCT.