Skip to content

feat(precompiles): unbounded buffer with cascading cleanup for expiring nonces#2157

Closed
gakonst wants to merge 13 commits intomainfrom
tanishk/temporary-nonces-unbounded-buffer
Closed

feat(precompiles): unbounded buffer with cascading cleanup for expiring nonces#2157
gakonst wants to merge 13 commits intomainfrom
tanishk/temporary-nonces-unbounded-buffer

Conversation

@gakonst
Copy link
Copy Markdown
Contributor

@gakonst gakonst commented Jan 18, 2026

Summary

This PR implements two improvements to the txhash replay protection buffer, as discussed in #2121:

1. Unbounded buffer with head/tail pointers

Instead of a fixed-size circular buffer with EXPIRING_NONCE_SET_CAPACITY = 300,000, use dynamically growing/shrinking storage:

  • Tail pointer: Where new transaction hashes are appended
  • Head pointer: Points to the oldest entry (for cleanup)

Every write to the tail also checks the head and clears expired entries. Since we're not charging for fresh SSTOREs in the precompile anyway, growing the array has no gas cost disadvantage.

2. Cascading cleanup

When checking the head for expiry, if it's expired, also check the next entry. This cascades up to MAX_CASCADE_CLEANUP = 10 entries per write.

This allows the buffer to shrink quickly during low-traffic periods.

Benefits

  • No capacity limit: Buffer grows as needed under high load
  • Space efficient: Buffer shrinks when entries expire
  • No failure mode: Removed ExpiringNonceSetFull error since buffer is unbounded

Changes

  • crates/precompiles/src/nonce/mod.rs: Updated storage layout and algorithm
  • crates/contracts/src/precompiles/nonce.rs: Removed ExpiringNonceSetFull error
  • docs/pages/protocol/tips/tip-1009.mdx: Updated documentation

Testing

Added new tests:

  • test_expiring_nonce_cascading_cleanup: Verifies multiple entries are cleaned in one write
  • test_expiring_nonce_unbounded_growth: Verifies buffer can grow beyond old capacity

Stacked on #2121

legion2002 and others added 13 commits January 16, 2026 17:59
- Skip mark_invalid for expiring nonce txs (they're independent)
- Fix remove_transactions_by_sender to remove expiring nonce txs
- Fix senders_iter to include expiring nonce txs
- Update assert_invariants to account for expiring nonce txs
Unfortunally pushed old
[tip1000](#2116) branch to
staging-revm so needed new branch

---------

Co-authored-by: 0xKitsune <0xKitsune@protonmail.com>
…ng nonces

This PR implements two improvements to the txhash replay protection buffer:

1. **Unbounded buffer with head/tail pointers**: Instead of a fixed-size circular
   buffer, use dynamically growing/shrinking storage. The tail pointer tracks
   where new entries are appended, while the head pointer tracks the oldest
   entry for cleanup. This removes the risk of running out of space.

2. **Cascading cleanup**: When writing a new entry, check expired entries at the
   head. If an entry is expired, check the next one too (up to MAX_CASCADE_CLEANUP=10).
   This allows the buffer to shrink quickly during low-traffic periods.

Benefits:
- No fixed capacity limit - buffer grows under high load
- Space-efficient - buffer shrinks when entries expire
- No 'buffer full' error condition

Stacked on #2121
@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
tempo-docs Error Error Jan 18, 2026 10:01pm

Request Review

@legion2002 legion2002 force-pushed the tanishk/temporary-nonces branch from a9138b6 to 1bcc84a Compare January 21, 2026 10:31
@legion2002 legion2002 force-pushed the tanishk/temporary-nonces branch from 1bcc84a to c77380f Compare January 21, 2026 10:34
Base automatically changed from tanishk/temporary-nonces to main January 21, 2026 15:23
@dankrad
Copy link
Copy Markdown
Contributor

dankrad commented Jan 26, 2026

Great way to make it unbounded while keeping the invariants. Need to update TIP-1009 docs

@jenpaff jenpaff added the T1 label Feb 9, 2026
@jenpaff jenpaff closed this Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants