V45 Gate 13: Deterministic BTD Quote Conservation#216
Conversation
Add a package-owned BTD scalar-volume quote-conservation bridge that computes Need-relative fixed-point measurement rows, deterministic quote audits, BTD range projection, and source-to-shares conservation readback from selected Fits. Cover final-BTD blocker requirements, one-Fit and many-Fit source-to-shares conservation, export the primitive, and wire the Gate 13 closure checker plus parity readback.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64436300d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| BigInt(weightBps) * | ||
| BigInt(input.admittedFitQualityBps); | ||
| const denominator = BPS_SCALE_BIGINT * BPS_SCALE_BIGINT; | ||
| const scalarMicroBtd = numerator / denominator; |
There was a problem hiding this comment.
Preserve fractional row remainders before quote comparison
When a valid quote is produced by buildShareToFeePreview, it rounds the total weighted admitted volume after summing the measurement vector, but this path floors each row to micro-BTD before summing. For fractional measurement volumes whose per-row micro remainders add up, e.g. two 50% rows with volume: 1.000001 and quality 1, the existing quote builder can emit 1,000,001 sats at 1,000,000 sats/volume while this audit computes 1,000,000 and adds quote_conservation_failed, so valid settlement-bound quotes are rejected.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| function selectedFitIds(selectedFits: readonly BtdScalarVolumeSelectedFitInput[]): string[] { | ||
| return uniqueStrings(selectedFits.map((fit) => firstString(fit.depositId, fit.assetId))); |
There was a problem hiding this comment.
Detect duplicate selected fits before deduping IDs
For an input with duplicate selected Fit IDs, this helper collapses duplicates before the blocker check later compares selectedIds.length to new Set(selectedIds).size, making that duplicate check unreachable. The projection then reaches buildSourceToSharesProof, which throws Duplicate source-to-shares fit deposit instead of returning a fail-closed final_btd_scalar_volume_blocked projection with selected_fit_set_required, so malformed Fit-set data can crash callers that expect blocker readback.
Useful? React with 👍 / 👎.
Summary
Verification