Skip to content

docs(tip-1040): epoch-scoped temporary storage precompile#3366

Draft
decofe wants to merge 12 commits intomainfrom
tip/1040
Draft

docs(tip-1040): epoch-scoped temporary storage precompile#3366
decofe wants to merge 12 commits intomainfrom
tip/1040

Conversation

@decofe
Copy link
Copy Markdown
Member

@decofe decofe commented Mar 30, 2026

Adds TIP-1040: a precompile for epoch-scoped temporary key-value storage. Values are available for 2^16 to 2^17 blocks then automatically expire. Nodes can prune anything older than the previous epoch.

Key design points:

  • Epochs are 2^16 blocks. Current + previous epoch storage are live; older epochs are forgotten.
  • Storage slot = keccak256(sender || key) scoped per uint16(epoch) — sender-isolated, no cross-contract collisions.
  • Store costs a flat 40k gas (no state gas). Load follows EIP-2929 cold/warm model (2,100 / 100 gas).
  • Load checks current epoch first, falls back to previous epoch, returns zero if both miss.

Prompted by: dankrad

decofe added 2 commits March 30, 2026 13:49
Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
@decofe decofe closed this Mar 30, 2026
@decofe decofe reopened this Mar 30, 2026
decofe added 6 commits March 30, 2026 14:15
Overwrites to slots already nonzero in the current epoch use SSTORE-equivalent
hot/cold pricing instead of the flat 40k. A nonzero value in the previous
epoch only does not qualify — still incurs the 40k new-slot cost.

Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
Storage key is uint16(epoch) ++ keccak256(sender || key)[0:30] in the
precompile's own storage trie. Adds a full reference Solidity mock
demonstrating the key derivation and epoch fallback logic.

Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
EVM convention is to keep the low-order (rightmost) bytes when truncating
hashes (e.g. address = keccak256(pubkey)[12:32]). Updated spec text from
[0:30] to [2:32] to match — the Solidity mock was already correct.

Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
uint16 wraps after 2^16 epochs (2^32 blocks). uint32 supports 2^32 epochs
(2^48 blocks) before wrap-around, removing any practical lifetime concern.
Hash truncation goes from 30 to 28 bytes (224 bits), still more than enough.

Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3f00-3838-7357-870f-e511f80eb152
Replaces the prefixed-key-in-single-account layout with separate accounts
per epoch (PRECOMPILE_ADDRESS + n + 1). This lets nodes prune expired
epochs by dropping entire accounts instead of scanning individual slots.

Co-authored-by: Derek Cofausper <256792747+decofe@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d3fed-b1f0-71ac-bbe2-1caeabc2bf51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants