Skip to content

Commit

Permalink
Update EIP-7623: Clarify the gas refunds handling
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
chfast authored Jan 9, 2025
1 parent c63e59d commit 6b5c7cf
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions EIPS/eip-7623.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,45 @@ By introducing a floor cost dependent on the ratio of gas spent on EVM operation

## Specification

| Parameter | Value |
| - | - |
| `STANDARD_TOKEN_COST` | `4` |
| `TOTAL_COST_FLOOR_PER_TOKEN` | `10` |
| Parameter | Value |
|------------------------------|-------|
| `STANDARD_TOKEN_COST` | `4` |
| `TOTAL_COST_FLOOR_PER_TOKEN` | `10` |


Let `tokens_in_calldata = zero_bytes_in_calldata + nonzero_bytes_in_calldata * 4`.

Let `isContractCreation` be a boolean indicating the respective event.

The current formula for determining the gas used per transaction, typically described as `nonzero_bytes_in_calldata * 16 + zero_bytes_in_calldata * 4`, is equivalent to:
Let `execution_gas_used` be the gas used for EVM execution with the gas refund subtracted.

The current formula for determining the total gas used per transaction (`tx.gasUsed`) is equivalent to:

```python
tx.gasUsed = (
21000
+ STANDARD_TOKEN_COST * tokens_in_calldata
+ evm_gas_used
+ isContractCreation * (32000 + InitCodeWordGas * words(calldata))
+ STANDARD_TOKEN_COST * tokens_in_calldata
+ execution_gas_used
+ isContractCreation * (32000 + INITCODE_WORD_COST * words(calldata))
)
```

The formula for determining the gas used per transaction changes to:

```python
tx.gasUsed = {
tx.gasUsed = (
21000
+
max (
+
max(
STANDARD_TOKEN_COST * tokens_in_calldata
+ evm_gas_used
+ isContractCreation * (32000 + InitCodeWordGas * words(calldata)),
+ execution_gas_used
+ isContractCreation * (32000 + INITCODE_WORD_COST * words(calldata)),
TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata
)
)
```

Any transaction with a gas limit below `21000 + TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata` or below it's intrinsic gas cost (take the maximum of these two calculations) is considered invalid. This limitation exists because transactions must cover the floor price of their calldata without relying on the execution of the transaction. There are valid cases where `gasUsed` will be below this floor price, but the floor price needs to be reserved in the transaction gas limit.
Any transaction with a gas limit below `21000 + TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata` or below its intrinsic gas cost (take the maximum of these two calculations) is considered invalid. This limitation exists because transactions must cover the floor price of their calldata without relying on the execution of the transaction. There are valid cases where `gasUsed` will be below this floor price, but the floor price needs to be reserved in the transaction gas limit.

## Rationale

Expand Down

0 comments on commit 6b5c7cf

Please sign in to comment.