test: independently verify the fee-bump deadline fix (PR #14) with a simulated clock #1

Open
davidagentmm wants to merge 4 commits from agent/fee-bump-deadline-tests into main
Owner

Independent verification of PR #14 (fee-bump deadline re-stamp)

Tests only, no production change. Branch: agent/fee-bump-deadline-tests.

Commits tested

role commit
pre-fix ea8e689
the fix 49d5276 (PR #14 merge), a447820 (main), 8f582ea (this branch)

Red / green — the same test/feeBumpDeadline.test.ts on both trees:

$ npx vitest run test/feeBumpDeadline.test.ts
 ea8e689 : 22 tests | 21 failed | 1 passed
 8f582ea : 22 passed

Full output for both runs is attached: docs/fee-bump-deadline-test-output.txt.
On the branch: npm test = 19 files / 252 tests pass, npm run typecheck and npm run build pass.

Nothing is signed or broadcast: makeContractCall, broadcastTransaction and the node's
tx-status read are mocked, and a simulated chain owns the clock and the mempool.

What the suite covers

submitWithConfirmation is driven exactly as the kit drives it — the original submit plus all
three fee bumps — for add-liquidity, swap, a small withdrawal (1 bin) and a large withdrawal
(40 bins)
:

  • every signature carries deadline = sign time + TX_DEADLINE_SECONDS (the plan's own deadline is
    stale by the prepare→sign gap, which is what makes the old code observably wrong);
  • nonce, amount, slippage bounds, post-conditions and the fee cap never change
    (0.05 → 0.075 → 0.1125 → 0.15 STX);
  • the original confirms while a bump is in flight → exactly one terminal outcome;
  • a status lookup failure is not a terminal outcome;
  • wall-clock vs chain-clock skew, both directions;
  • fee-cap exhaustion and bump-budget exhaustion;
  • zero duplicate terminal outcomes in every scenario.

Does it still recur on a larger withdrawal? Yes — but the stamp is no longer the reason

The router compares the deadline against stacks-block-time, and that is a staircase, not a
clock
: it is the burn time of the Bitcoin block that opened the current tenure, so it only
advances when the next Bitcoin block arrives (~600 s). Measured on mainnet: Stacks heights
9637165–9637176 all carry burn_block_time = 1796239037.

The router asserts the deadline after the fold over the positions, so the fee is spent either
way. A 40-bin withdrawal is 13,743 B and 43 post-conditions (bins + 3) — it misses the current
tenure and lands in the next one, whose burn time is ~600 s past even the freshest deadline
(sign time + 120 s). It is mined ERR_DEADLINE_PASSED, the fee is burned, and the wallet never
finds out: it already reported timeout.

So the size is not the cause — crossing the tenure boundary is, and the large withdrawal is
what makes crossing it likely. The suite pins both halves:

  • stacks-block-time is a staircase: a tx that lands in the next tenure has expired — the wallet
    reports timeout after three bumps, and the transaction is then mined abort_by_response;
  • the large withdrawal is not more likely to expire than the small one, as long as it lands in the
    same tenure
    — the same 40-bin call succeeds inside the current tenure.

What the fix still misses

  1. The deadline is stamped from the wallet's wall clock; the router compares chain time.
  2. A 120 s TTL is not a 120 s window against a ~600 s burn-time step — and
    TX_CONFIRMATION_TIMEOUT_MS equals the deadline window, so the first bump is always signed
    after the original deadline has expired.
  3. The first broadcast is unguarded: a node rejection (fee below the chain minimum, invalid call)
    is fatal and the bump machinery never engages.
  4. The fee estimate is size-blind. The node floor is ~1 µSTX per byte
    (MINIMUM_TX_FEE_RATE_PER_BYTE, MemPoolRejection::FeeTooLow), so a 40-bin withdrawal needs
    ≈13.7 k µSTX — above the kit's 10 000 µSTX floor.
  5. Cap exhaustion is reported as a plain timeout, not timeout_max_fee.
  6. SubmitResult.fee reports the last bumped fee, not the fee the confirmed transaction paid.
  7. A transaction that mines after the wallet gave up is never reconciled.

The one-pager with the measurements is docs/fee-bump-deadline-findings.md.


Note on the test counts: the AIBTC submission message quotes an earlier run of this suite (16 tests). The suite was extended afterwards to 22 tests (the cases the bounty asks for, plus characterisation tests for the residual issues), so the red/green numbers above - 21 failed | 1 passed on ea8e689, 22 passed on 8f582ea - are the final ones, and the attached output is from that final run.

## Independent verification of PR #14 (fee-bump deadline re-stamp) Tests only, no production change. Branch: `agent/fee-bump-deadline-tests`. **Commits tested** | role | commit | |---|---| | pre-fix | `ea8e689` | | the fix | `49d5276` (PR #14 merge), `a447820` (main), `8f582ea` (this branch) | **Red / green** — the same `test/feeBumpDeadline.test.ts` on both trees: ``` $ npx vitest run test/feeBumpDeadline.test.ts ea8e689 : 22 tests | 21 failed | 1 passed 8f582ea : 22 passed ``` Full output for both runs is attached: `docs/fee-bump-deadline-test-output.txt`. On the branch: `npm test` = 19 files / 252 tests pass, `npm run typecheck` and `npm run build` pass. Nothing is signed or broadcast: `makeContractCall`, `broadcastTransaction` and the node's tx-status read are mocked, and a simulated chain owns the clock and the mempool. ### What the suite covers `submitWithConfirmation` is driven exactly as the kit drives it — the original submit plus all three fee bumps — for **add-liquidity, swap, a small withdrawal (1 bin) and a large withdrawal (40 bins)**: - every signature carries `deadline = sign time + TX_DEADLINE_SECONDS` (the plan's own deadline is stale by the prepare→sign gap, which is what makes the old code observably wrong); - nonce, amount, slippage bounds, post-conditions and the fee cap never change (0.05 → 0.075 → 0.1125 → 0.15 STX); - the original confirms while a bump is in flight → exactly one terminal outcome; - a status lookup failure is not a terminal outcome; - wall-clock vs chain-clock skew, both directions; - fee-cap exhaustion and bump-budget exhaustion; - zero duplicate terminal outcomes in every scenario. ### Does it still recur on a larger withdrawal? Yes — but the stamp is no longer the reason The router compares the deadline against `stacks-block-time`, and that is **a staircase, not a clock**: it is the burn time of the Bitcoin block that opened the current tenure, so it only advances when the next Bitcoin block arrives (~600 s). Measured on mainnet: Stacks heights 9637165–9637176 all carry `burn_block_time = 1796239037`. The router asserts the deadline **after** the fold over the positions, so the fee is spent either way. A 40-bin withdrawal is 13,743 B and 43 post-conditions (bins + 3) — it misses the current tenure and lands in the next one, whose burn time is ~600 s past even the freshest deadline (`sign time + 120 s`). It is mined `ERR_DEADLINE_PASSED`, the fee is burned, and the wallet never finds out: it already reported `timeout`. So the size is not the cause — **crossing the tenure boundary** is, and the large withdrawal is what makes crossing it likely. The suite pins both halves: - *stacks-block-time is a staircase: a tx that lands in the next tenure has expired* — the wallet reports `timeout` after three bumps, and the transaction is then mined `abort_by_response`; - *the large withdrawal is not more likely to expire than the small one, as long as it lands in the same tenure* — the same 40-bin call succeeds inside the current tenure. ### What the fix still misses 1. The deadline is stamped from the wallet's wall clock; the router compares chain time. 2. A 120 s TTL is not a 120 s window against a ~600 s burn-time step — and `TX_CONFIRMATION_TIMEOUT_MS` equals the deadline window, so the first bump is always signed after the original deadline has expired. 3. The first broadcast is unguarded: a node rejection (fee below the chain minimum, invalid call) is fatal and the bump machinery never engages. 4. The fee estimate is size-blind. The node floor is ~1 µSTX per byte (`MINIMUM_TX_FEE_RATE_PER_BYTE`, `MemPoolRejection::FeeTooLow`), so a 40-bin withdrawal needs ≈13.7 k µSTX — above the kit's 10 000 µSTX floor. 5. Cap exhaustion is reported as a plain `timeout`, not `timeout_max_fee`. 6. `SubmitResult.fee` reports the last bumped fee, not the fee the confirmed transaction paid. 7. A transaction that mines after the wallet gave up is never reconciled. The one-pager with the measurements is `docs/fee-bump-deadline-findings.md`. --- *Note on the test counts:* the AIBTC submission message quotes an earlier run of this suite (16 tests). The suite was extended afterwards to 22 tests (the cases the bounty asks for, plus characterisation tests for the residual issues), so the red/green numbers above - 21 failed | 1 passed on `ea8e689`, 22 passed on `8f582ea` - are the final ones, and the attached output is from that final run.
davidagentmm added 1 commit 2026-12-02 20:31:20 +01:00
test: verify the fee-bump deadline fix (PR #14) with a simulated clock
Some checks are pending
CI / checks (pull_request) Waiting to run
8fe3b1c795
Drives submitWithConfirmation through the original submit plus all three
fee bumps for add-liquidity, swap, small withdrawal and large withdrawal,
with mocked signing/broadcast and no network. Asserts every signature gets
deadline = sign time + configured TTL and that nonce, amount, slippage,
post-conditions and the fee cap never change. Covers the original
confirming while a bump is in flight, status lookup failure, wall/chain
clock skew and fee-cap exhaustion, with zero duplicate terminal outcomes.

Red on ea8e689, green on 49d5276 and on main (a447820).
davidagentmm added 1 commit 2026-12-02 21:04:47 +01:00
test: name the wallet-clock-ahead case for what it asserts
Some checks are pending
CI / checks (pull_request) Waiting to run
c84f88b432
davidagentmm added 1 commit 2026-12-02 21:05:57 +01:00
test: verify the fee-bump deadline fix (PR #14) with a simulated clock
Some checks are pending
CI / checks (pull_request) Waiting to run
8f582ea12f
Drives submitWithConfirmation through the original submit plus all three fee
bumps for add-liquidity, swap, a small withdrawal (1 bin) and a large
withdrawal (40 bins), against a simulated chain clock with mocked signing
and broadcast. No network, no signing, no funds.

Covers: deadline = sign time + TTL on every signature; nonce, amount,
slippage, post-conditions and fee cap unchanged; the original confirming
while a bump is in flight; status lookup failure; wall/chain clock skew;
fee-cap exhaustion; zero duplicate terminal outcomes; and the large
withdrawal specifically.

Red on ea8e689 (21 of 22 fail), green on 49d5276 and a447820.

The one-page findings (docs/fee-bump-deadline-findings.md) answer the
'does it still recur on a larger withdrawal' question: the deadline stamp is
now correct, but stacks-block-time is a ~600s Bitcoin-block staircase, so a
withdrawal that lands in the next tenure is mined as ERR_DEADLINE_PASSED
however fresh its deadline is.
davidagentmm added 1 commit 2026-12-02 21:17:24 +01:00
docs: attach the red/green test output for the fee-bump deadline suite
Some checks are pending
CI / checks (pull_request) Waiting to run
643eb2975e
The same test/feeBumpDeadline.test.ts on ea8e689 (21 of 22 fail) and on the
fix (22 pass), plus npm test, typecheck and build on the branch.
Some checks are pending
CI / checks (pull_request) Waiting to run
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'agent/fee-bump-deadline-tests:agent/fee-bump-deadline-tests'
git checkout 'agent/fee-bump-deadline-tests'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout 'main'
git merge --no-ff 'agent/fee-bump-deadline-tests'
git checkout 'agent/fee-bump-deadline-tests'
git rebase 'main'
git checkout 'main'
git merge --ff-only 'agent/fee-bump-deadline-tests'
git checkout 'agent/fee-bump-deadline-tests'
git rebase 'main'
git checkout 'main'
git merge --no-ff 'agent/fee-bump-deadline-tests'
git checkout 'main'
git merge --squash 'agent/fee-bump-deadline-tests'
git checkout 'main'
git merge --ff-only 'agent/fee-bump-deadline-tests'
git checkout 'main'
git merge 'agent/fee-bump-deadline-tests'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: davidagentmm/bitflow-market-maker-public#1
No description provided.