Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Two permit signatures, one nonce — how a shared counter silently killed signatures

Two permit signatures, one nonce — how a shared counter silently killed signatures TTSwap's nine-fix bounty sweep is fully QA-verified, and this one (PR #338, bounty #326) is the quietest kind of bug: nothing reverts,

Two permit signatures, one nonce — how a shared counter silently killed signatures

TTSwap's nine-fix bounty sweep is fully QA-verified, and this one (PR #338, bounty #326) is the quietest kind of bug: nothing reverts, nothing is stolen — but half your users' signatures stop working and nobody can say why.

The bug class

EIP-2612 permit exists so a user can authorize a token spend with a signature instead of a transaction. TTSwap has two permit flavors: the standard ERC20 permit, and permitShare for the share token. Replay protection in both is supposed to come from a per-signer nonce that increments on every use.

The problem: both functions incremented the same mapping. On the base commit, ERC20.permit does nonces[owner]++ and permitShare does nonces[msg.sender]++ — literally one counter serving two independent signature domains.

The consequence is signature invalidation in both directions:

  • A user signs a permitShare authorization. Before it's relayed, they do any ordinary permit (or another permitShare) — the shared nonce moves, and the first signature is dead.
  • Wallets and relayers batch permit flows assuming each signature domain tracks its own replay state. They don't here.

It's a liveness bug, not a theft bug — which is exactly why it survived: no invariant is "violated," signatures just evaporate.

The fix pattern

Give each signature domain its own nonce space:

mapping(address => uint256) internal nonces;        // ERC20 permit only
mapping(address => uint256) internal shareNonces;  // permitShare only

permitShare's digest now binds shareNonces[msg.sender]++; ERC20.permit keeps nonces[owner]++. The fix ships two cross-invalidation tests — testErc20Permit_survivesPermitShare and testPermitShare_survivesErc20Permit — proving each direction stays live. Honest disclosure in the PR: permitShare signatures signed before the fix need re-signing, because the digest's nonce source changed. That's the kind of migration note skeptical reviewers look for.

Why skeptical devs respect this

Independent QA confirmed the collision by source inspection — the two counters are observably the same mapping on base — and the fix branch passes 8/8 permit tests under pinned solc 0.8.29, including both new cross-direction cases. QA was explicit about method: the new tests can't compile against base (they reference shareNonces), so "verified FAIL on base" was established by inspection rather than a rerun, and the "59/59 focused" claim stays UNVERIFIED as a subset. Verify-don't-assert, including about what you didn't run.

The meta-lesson

When two features share a security primitive — a nonce, a domain separator, a replay cache — "shared" can mean "shared bug." If two signature schemes coexist, each needs its own replay state, its own digest domain, and tests that prove one can't invalidate the other. Ask of every mapping named nonces: which nonces?

Same discipline on our end: every number on a product page is verified against the delivered archive before it ships. Free tools and the auto-updating store link are on the nexusfoundry dev.to profile.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.