From 2d2a5ff3683a8d915a1f347cac01fc474e179158 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 06:38:24 -0600 Subject: [PATCH] fix(id): reject reserved transfer IDs (0 / u128::MAX) in currency_poc executor preflight (#6194) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ConversionExecutor::preflight validated transfer_ids count and duplicates only, so a request carrying transfer ID 0 or u128::MAX — values real TigerBeetle refuses outright (#6135) — built a write-ahead intent that strands as a poison Submitted record against the real backend, and posted silently against InMemoryLedger. Preflight now rejects any transfer_ids entry equal to 0 or u128::MAX, in the same loop as the duplicate check (one validation site, so prepare inherits it), with an error naming the offending ID, before any intent is persisted or anything is submitted. Tests: reserved_transfer_ids_fail_preflight_before_persisting_intent covers 0 and u128::MAX in each leg position (T1, fee, T3) plus the sane-ID control (601/602/603) executing identically. --- pkgs/id/src/currency_poc/executor.rs | 10 +++++++ pkgs/id/src/currency_poc/tests.rs | 41 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/pkgs/id/src/currency_poc/executor.rs b/pkgs/id/src/currency_poc/executor.rs index bf92c66c82..4b780bee64 100644 --- a/pkgs/id/src/currency_poc/executor.rs +++ b/pkgs/id/src/currency_poc/executor.rs @@ -171,6 +171,16 @@ impl ConversionExecutor { let mut transfer_ids = HashSet::with_capacity(request.transfer_ids.len()); for id in &request.transfer_ids { + // TigerBeetle reserves 0 and u128::MAX as transfer IDs + // and refuses them outright at submission (#6194, the + // #6135 finding): reject them here, in preflight, before + // any intent is persisted — otherwise the write-ahead + // intent strands as a poison Submitted record. + if *id == 0 || *id == u128::MAX { + bail!( + "preflight: transfer ID {id} is reserved (zero and u128::MAX are refused by TigerBeetle)" + ); + } if !transfer_ids.insert(*id) { bail!("preflight: duplicate transfer ID {id}"); } diff --git a/pkgs/id/src/currency_poc/tests.rs b/pkgs/id/src/currency_poc/tests.rs index d1daa9f6c9..318d85df1b 100644 --- a/pkgs/id/src/currency_poc/tests.rs +++ b/pkgs/id/src/currency_poc/tests.rs @@ -790,6 +790,47 @@ fn duplicate_t1_and_t3_transfer_ids_fail_preflight_before_persisting_intent() { ); } +#[test] +fn reserved_transfer_ids_fail_preflight_before_persisting_intent() { + // Oracle: #6194 — real TigerBeetle refuses transfer IDs 0 and + // u128::MAX outright, so preflight must reject them in every leg + // position (T1, fee, T3), naming the offending ID, before any + // intent is persisted or anything is submitted. Pre-fix, the + // creator probe executed all of these Ok Posted. + for position in 0..3 { + for reserved in [0, u128::MAX] { + let mut executor = executor(); + let mut bad = request(); + bad.transfer_ids[position] = reserved; + + let error = executor + .prepare(&bad) + .expect_err("a reserved transfer ID must fail preflight"); + assert!( + error + .to_string() + .contains(&format!("transfer ID {reserved} is reserved")), + "the error must name the reserved ID, got: {error}" + ); + assert!(executor.store.get(777).unwrap().is_none()); + assert!( + executor + .backend + .transfers_with_user_data_128(777) + .is_empty() + ); + } + } + + // The sane-ID control (the probe's 601/602/603) still executes + // identically: the rejection did not widen to ordinary IDs. + let mut executor = executor(); + let record = executor + .execute(&request()) + .expect("sane transfer IDs must still post"); + assert_eq!(record.state, IntentState::Posted); +} + #[test] fn fee_without_account_fails_preflight_before_persisting_intent() { let mut executor = executor();