A purchase whose post-swap value cannot cover price_per_step x purchase_min_steps is refused after Receive, absorbing the note

Aperta
#847 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
payments

Direzione di ricerca

Start with the swapFeeSatsBounded pre-check block in src/merchant/merchant.go, and trace where calculateAllotment runs relative to Receive in the PurchaseSession path. Check how price_per_step and purchase_min_steps are read from AcceptedMints. Done means a note that cannot cover the minimum purchase after the swap fee is refused before Receive, and the residual fee-unknown branch has a defined outcome that keeps the value. The issue leaves that residual behaviour open, so settle it with a maintainer first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

calculateAllotment is called on the post-swap amount, i.e. after Receive has already taken the note into the operator's wallet. When the amount cannot cover price_per_step * purchase_min_steps, the purchase is refused there — with the note spent, no session granted, and no owed-grant record written (that machinery is only reached when grantSessionAccess fails, not when pricing fails). The customer's value is absorbed with no recovery path.

This contradicts this repo's own fund-safety rule (AGENTS.md):

Do not perform irreversible monetary operations (swap, mint, melt, LN settlement) before validations that can be done locally — token decode, spending-condition check, swap-fee pre-check, MAC/NDS pre-flight all run before Receive on purpose (#403, #409).

Both sides of the comparison are knowable locally at the existing pre-check: the mint's swap fee was just read (swapFeeSatsBounded), and price_per_step / purchase_min_steps come from AcceptedMints.

Reproduced at b6f7aa74

Config: price_per_step = 210, purchase_min_steps = 1. Note worth 210 sat; the mint charges a 1 sat swap fee.

Before the fix, PurchaseSession returns notice code session-error:

Failed to calculate allotment: payment only covers 0 steps, but minimum purchase is 1 steps

and Receive was called — the note is in the operator's wallet by then.

The existing pre-check (src/merchant/merchant.go, the swapFeeSatsBounded block) only covers tokenAmount <= fee ("nothing left to spend"). A fee smaller than the note that still pushes the post-swap value below the minimum purchase is not covered.

The same happens on a fee-free mint: any note below the minimum purchase is refused after Receive.

Residual case

When the fee cannot be determined locally (cdk adapter, unreachable mint, or the 3s swapFeePrecheckBudget overrun against a wedged mint, #525) the pre-check can only compare the note's face value, which is optimistic. A note that passes can still fall below the minimum once the mint takes its fee. That branch must not silently drop the value either.

Lingua principale
Go
Stelle
12
Fork
14
Merge medio
3g 20h
PR unite (30g)
261

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenTollGate/tollgate-module-basic-go

Tutte le issue di OpenTollGate/tollgate-module-basic-go

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.