Skip to content

Commit

Permalink
Update EIP-7609: reduce SLOPE coefficient in eip-7609
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
charles-cooper authored and blacksnow2 committed Jul 21, 2024
1 parent a1ec0e6 commit 4c841a5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions EIPS/eip-7609.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ This EIP proposes a pricing model which charges additional gas per allocation, w

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174.

The gas cost for `TLOAD` is proposed to be 5 gas. The gas cost for `TSTORE` is proposed to be 8 gas + `expansion_cost`, where `expansion_cost` is calculated as `3 gas * len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas.
The gas cost for `TLOAD` is proposed to be 5 gas. The gas cost for `TSTORE` is proposed to be 8 gas + `expansion_cost`, where `expansion_cost` is calculated as `1 gas * len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas.

In pseudo-code:

```python
G_LOW = 5
G_MID = 8

SLOPE = 3
SLOPE = 1

def gas_tload(_key):
return G_LOW
Expand All @@ -61,9 +61,19 @@ No backward compatibility issues found.

## Security Considerations

The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,470 (solution to `x(x-1)/2*3 + 8*x = 30_000_000`), which totals 143KB.
The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 7,739 (solution to `x(x-1)/2*1 + 8*x = 30_000_000`), which totals 248KB.

The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of `TSTORE` is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB.
The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling new contracts (which each are designed to maximize transient storage allocation) once the cost of `TSTORE` is more than the cost of calling a cold contract (2600 gas), can be solved for as follows:

```
solve for SLOPE * <num slots> == 2600, => num_slots == 2600
gas_used_by_contract = 2600 + SLOPE * num_slots * (num_slots - 1) / 2 + G_MID * num_slots == 3402100
block_gas_limit = 30_000_000
num_calls_per_txn = block_gas_limit // gas_used_by_contract ~= 8.8
max_transient_slots = num_calls_per_txn * num_slots == 22927
```

Thus, the maximum number of transient slots which can be allocated in a single transaction with this method is roughly 23,000, which totals 736KB. Note that this cap scales linearly with the gas limit, which is a useful property when considering future block gas limit increases.

## Copyright

Expand Down

0 comments on commit 4c841a5

Please sign in to comment.