Skip to content

fix: validate cached quote nonce before reuse at send#14

Open
AlonzoRicardo wants to merge 2 commits into
tetherto:mainfrom
AlonzoRicardo:fix/validate-cached-quote-nonce
Open

fix: validate cached quote nonce before reuse at send#14
AlonzoRicardo wants to merge 2 commits into
tetherto:mainfrom
AlonzoRicardo:fix/validate-cached-quote-nonce

Conversation

@AlonzoRicardo

Copy link
Copy Markdown
Contributor

Description

Ports the consume-at-send nonce validation from wdk-wallet-evm-erc-4337 #98 to the 7702 gasless module. Before reusing a cached quote at send time, the quote's UserOperation nonce is checked against the live on-chain nonce; if the chain advanced since the quote, the cached quote is discarded and re-quoted at the current nonce. The common case (quote → immediate send, nonce unchanged) still reuses the cached op with only one extra fetchAccountNonce read.

Motivation and Context

On main, sendTransaction/transfer consume a cached quote and reuse its built sponsoredOp with no nonce validation. If the chain advances between quoteSendTransaction/quoteTransfer and the matching send — e.g. an intervening transaction mines — the cached op is submitted with a stale nonce.

This adds a _consumeFreshQuote(tx) step: consume the cached quote, and if its sponsoredOp.nonce no longer matches the on-chain nonce, drop it so the existing inline path re-quotes at the current nonce with a fresh fee. This is the same correctness guarantee the erc-4337 module gained in #98, adapted to this module's current structure (the post-send bump approach has already been removed here, so there is no _bumpCachedNonces to replace).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Verification

  • standard lint clean.
  • Integration suite green. The previously test.skip-ped regression (should not consume cached transfer fee when approve is called in between) is un-skipped and rewritten to assert re-quote-on-stale-nonce: a cached transfer quote is re-quoted (not blindly reused) once an intervening send has mined, while the common reuse path (nonce unchanged) is unaffected.

Related: tetherto/wdk-wallet-evm-erc-4337#98

A cached quote's built sponsoredOp was reused at send time with no nonce
check, so a quote whose nonce drifted before the matching send (e.g. an
intervening tx mined) was submitted with a stale nonce. Add _consumeFreshQuote,
which drops the cached quote when its sponsoredOp.nonce no longer matches the
on-chain nonce so the existing path re-quotes at the current nonce.

Un-skips and rewrites the previously-disabled regression test accordingly.

Ports the consume-at-send validation from tetherto/wdk-wallet-evm-erc-4337#98.
Addresses review feedback on the reference PR (tetherto/wdk-wallet-evm-erc-4337#98):
the cached-quote reuse path now does a lightweight on-chain nonce read, so the
JSDoc no longer implies the cached send skips all round-trips.
@AlonzoRicardo AlonzoRicardo self-assigned this Jun 15, 2026

@claudiovb claudiovb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Not scope of this PR but we should have a follow up task to fix the failover test to fix the linter.

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