DEV Community

One default constant that bricked every swap - TTSwap's safeLineUpper DoS

The starkest bug in TTSwap's nine-fix bounty sweep (PR #335, bounty #319): out of the box, at default configuration, every buy and every sell reverted.

Not an edge case - complete trading DoS for any newly initialized good. The fix is a single constant. The story of how it shipped is the story of packed config fields.

The bug class

TTSwap goods carry a packed goodConfig - thresholds and limits bit-packed into storage to save gas. One field, safeLineUpper, bounds how far the pool's quote-side balance (Q) can drift from baseline before swaps are allowed.

The shipped default was 100. That default made the safe-line check unsatisfiable: buyGood and payGood both revert TTSwapError(55) on any attempt at default config.

Independent QA reproduced it exactly - both swap tests fail on base with error 55, and pass 3/3 on the fix branch with no config relaxation needed. A High-severity DoS claim, verified end-to-end under pinned solc 0.8.29.

The fix pattern

One constant in L_GoodConfig.sol's initial_config: safeLineUpper 100 → 150 (bits ~219-212 of the packed field), plus a doc comment.

Minimal blast radius - it only changes the default for newly initialized goods; existing deployments keep their stored config.

Worth noting the honesty in the submission: 150 sits within the issue's suggested 120-150 range, and the worker flagged that the choice is judgment, not math-verified optimal. They fixed the DoS and said plainly where the remaining uncertainty lives.

Why skeptical devs respect this

This is what verify-don't-assert looks like at its best: base reproduces the exact claimed error on both swap directions, fix passes dedicated tests plus adjacent suites:

  • buyERC20ByERC20 8/8
  • payERC20ByERC20 3/3
  • testBuySafeLine 2/2
  • testDisinvestProof 20/20 - 33+3 green, 0 fail per the submission

And the residual risk is disclosed rather than hidden: the new default could mask a different misconfiguration, which is why the value choice is called out as judgment.

The meta-lesson

Packed bit-fields are where defaults go to die quietly. A constant buried at bit offset 219-212 doesn't show up in a config file review - it shows up when a user tries to trade and gets error 55 forever.

If your protocol packs config into words, the defaults deserve their own test: initialize a good with zero overrides and try to use it. The cheapest integration test is the one that catches the default nobody read.

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 on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.