Seedelf-Wallet

Chunk 52 · The box rule, exact

Status: ✅ done (2026-11-20). Steps 1 to 4 merged as #396 (9c9e51d5); step 5 was 1.9.3’s release review, whose record is review-1.9.3.md, and its fixes ship in 1.9.3. For 1.9.3. Written 2026-11-19 on chunk 51’s branch, so a new session can pick it up once 1.9.2 ships. The owner: “We could write these as chunks then commit push and open that pr for merge then after release we handle those chunks for the 1.9.3 since it would be much smaller of a patch then what ended up happening here.”

Chunk 51’s calls round (its record) built the box rule: how a private spend merges the boxes back from Lovejoin. It is round six’s rule, the lead’s, set on the owner’s calls. In 1.9.2, rule 1 holds by construction: nothing 1e1b0647’s selection sent as one transaction is refused or split. Rules 2 to 4 hold among the orders the search tries.

Near the input limit, beside token boxes, the search can miss a set, and architecture.md’s The box rule names those margins. The cause is that one transaction weighs each box alone, but the least a set’s tokens need back as change is shared, 20 kinds of token to an output. So a set pays more or less than its boxes’ weights add up to.

Reviews six to eight of the calls round each found a new window, with 5, 3 and 4 mediums. Rounds seven to nine closed some of them. Then round nine narrowed the claims instead, by the lead’s call. This chunk makes the rule exact where a balance holds few boxes, which is nearly every wallet.

Start here

Steps

1. ✅ An exact search where a balance holds few boxes

Built (2026-11-20): EXACT_BOXES = 12, Exact in build.rs, called from apart where box_list holds at most 12.

2. ✅ The reviews’ shapes, pinned

Each must pick the rule’s best with the search on, and fail on 1.9.2’s build.rs:

box_rule_reference_test.rs checks rules 2 to 4 strictly for balances within N, in its default parts and in the ignored sweep.

Built (2026-11-20). l7merge#1’s A and B, l7still#1’s three, l7merge#2’s C and D, l8merge#2’s four and l8still#1’s E and H were already pinned by chunk 51 and pass on 1.9.2 too, so they can’t fail there; they pass with the search. The three 1.9.2 still missed are new pins in mint_test.rs, each failing on 1.9.2’s build.rs (run in a scratch worktree at origin/main) and passing with the search:

The reference’s plain choice is now the set of its level that adds the most (set_value, its own reckoning from the ledger’s least), and every check is strict for balances within N, the pair parts too (they were checked within round eight’s margin). Strict, it fails 1.9.2 in all three pair parts (31 picks) and passes with the search: default parts in 3.5 s release, the ignored sweep in 3 min 15 s (5,927 merges, 2,850 single-UTxO picks, 973 refusals).

3. ✅ The holders of a token being sent, by the box rule

This is l6words#1’s code option, the backlog’s The UTxOs holding a token being sent go by quantity.

Built (2026-11-20).

4. ✅ The words

Done (2026-11-20): privacy.md, architecture.md (Picking inputs, Merging, The box rule, and the box of unknown making’s line), flows.md’s Send and the WebAssembly’s README; the policy’s entry is dated 20 November 2026 with its Effective line: move both to the merge day in the PR’s last commit, one entry. The three extension tests now cite the 19 November entry.

5. ✅ The review, then the patch

The owner, 2026-11-20: “We will do a review on this before publishing. Maybe we can update the chunk to talk about a review so its very pinpointed about what it needs to verify. Then after the review for the patch we retire that chunk and publish it.”

Review the PR’s diff against main (1.9.2). A finding is real only if a reviewer reproduces it, with a test that fails on this branch; one inside a margin the docs name is a low (chunk 51’s stopping rule). Verify each:

  1. The bound never rules out a set that pays (Exact::first_built, Exact::bound, epsilon).
    • A fee is min_fee_a × size plus parts the same for every choice of as many inputs. A set’s cost counts its change’s bytes as its leasts size them, and its outpoints’ index bytes.
    • So two sets of one count differ in fee only by what epsilon covers: the least’s dummy base address against the change’s enterprise one (28 bytes an output), the change’s lovelace past 2³², even, and settle’s fixed point.
    • Check that list is whole. Check the carry to a larger count (per_input: computation_fee at SPEND_BUDGET_GUESS, exact a spend input).
    • Check the tried key: two builds of one count, worth and number of outputs end alike.
    • Check the large prune, (count, outputs) after a failure other than short or too many.
    • Named, not covered: a set that pays exactly, leaving no change at all, is found only where it’s built.
  2. A set’s cost is the build’s (change_cost, Around, Laid::cost).
    • The token order is the inputs’ as select_script_inputs hands them: base, then all the other money, then the boxes; or base, the boxes, then an order’s first k.
    • Laid::cost must equal the full merge wherever it answers: a kind sent whole, or one after the set’s, falls back; bumps into whole outputs change only an amount’s head; the phase of the outputs after.
    • Try to break a_sets_change_costed_from_its_layout_is_its_change_costed_in_full and a_changes_least_worked_out_from_its_tokens_is_the_ledgers with shapes they don’t draw: names past 64 bytes don’t exist, but quantities near u64::MAX and many policies in one output do.
  3. The search tries every set 1.9.2’s orders tried, in the rule’s order (apart’s exact block, Exact::level).
    • Each set goes beside all the other money (a) where one transaction takes it, else beside the fewest of each of c’s orders.
    • c is skipped after a short a only for other money of ADA alone (fewer of it pays less). Check that holds with last UTxOs and a funding’s last resorts.
    • The other money alone first (a’s, b’s and c’s orders at no box); the pass before the first box of unknown making kept; pass d and e after.
    • Rules 4 and 5: a set with more mixed is tried only beside the plain choice’s own other money (all of it, or that order’s first k_P). Check no fewer k could be one.
    • Balances past 12 boxes run the weighed orders exactly as 1.9.2 did (weighed_to).
  4. The holders by the rule never refuse or worsen a spend (holding_by_rule, select_script_inputs, box_key).
    • Both spends are built; the one returned must be the one whose inputs spent recorded.
    • more_mixed_built, fewer_built and the exact search’s rule-4 phase each return their last successful build. Check every path.
    • The comparison is by unknown, then boxes, then mixed only: ties keep the rule’s holders.
    • The CLI (Histories::default) is unchanged.
    • Per token, the greedy choice is the rule’s best by quantity alone (fewest of unknown making, fewest boxes, most mixed). Holders chosen with what pays beside them aren’t searched: the new backlog line.
  5. The parts (Worth’s histories, token_group, Worth::holder, max_inputs_apart).
    • Only parts by history see the histories; by worth they plan as 1.9.2, and by_history_first falls back to them.
    • In a chain, holder now sorts before rich. Find a balance a chain planned on 1.9.2 that this branch refuses or splits otherwise (test wallet A’s shape: the ADA with one holder, bundles at their least).
    • max_inputs_apart falls back to holding where the rule’s holders are more than a part takes.
  6. Time.
    • The worst sets to cost: 12 token boxes of 12 policies beside 400 kinds past the input limit, 0.1 s release.
    • A token send’s two selections; a payment in parts, each part’s rerun.
    • Measure in the WebAssembly (2 to 3 times native) on a slow machine, and hold the timing pins.
  7. The words.
    • privacy.md, architecture.md, flows.md, the WebAssembly’s README and the policy’s 20 November entry: each claim against the code.
    • “12 boxes or fewer” counts boxes that add something (a box that adds less than nothing isn’t one). “In one transaction” scopes the exact search, not parts.
    • The margins now hold past 12 boxes and in parts only. The policy says nothing the extension sends to a service changed.

Fixes go in this PR, each test-first (fails before, passes after). Then rerun Done means’ checks, the live flows, and a short look at the fixes alone.

Done (2026-11-20), as 1.9.3’s release review: #396 had merged by then (9c9e51d5), so the review ran on main with #397 beside it, and its fixes went on web-wallet/release-1.9.3. Its record is review-1.9.3.md.

Done means

Checks (2026-11-20, on the uncommitted tree): cargo test --workspace --locked 1,104 passed (chunk 51’s 1,095 and nine new); the box rule’s ignored pair (the strict sweep, and 200 + 200 boxes in parts) and the parts suite (payment_parts_shapes_test --ignored, 163 s) pass; cargo fmt --check and CI’s clippy pass. Typecheck; Vitest 3,949 and, preprod-only, 3,935; e2e 109 on the dev build, 3 on the data layer’s, 109 on the store build.

Live preprod flows (2026-11-20, on 2af17ab2’s dev build, the test wallet): all ten confirmed.