Commit e6f4aea
committed
fix(bonds): address arkanaai review — deployment guards + dust-mint defence
Follow-up to the merged PR #37. Addresses the three actionable items from
arkanaai's automated review (#pullrequestreview-4404098591), one P1 and
two P2.
P1 — auctionWindow > 0 deployment guard (issue + rollIn)
Without it, `auctionWindow = 0` collapses the auction time gate
`tx.time >= maturity AND tx.time < maturity` to the empty set, so no
defaulted vault can EVER be settled via acceptAuction. mintedAmount
stays in totalDebitOutstanding forever and credit holders absorb
100% of every default. Same class of deployment invariant as the
existing initRatioBps > liqThresholdBps and liqThresholdBps > 0
checks; co-located with them at the top of issue() and rollIn().
P2 — auctionDiscountBps validation at deployment (issue + rollIn)
Previously checked only at runtime in liquidate() and acceptAuction().
An out-of-range discount bricks both settlement paths, leaving the
pool unsettleable — yet a vault could still be issued. Moved
require(auctionDiscountBps >= 0 && < 10000) into the issuance
deployment-safety block; runtime checks retained as defense-in-depth.
P2 — Dust-issuance ceiling division on origination floor (issue + rollIn)
required = amount * initRatioBps / 10000 floors to 1 for
amount=1, initRatioBps=14999, letting 1 sat of collateral mint
1 credit + 1 debit. Attacker floods the auction window with
thousands of dust defaults that are unprofitable for auctioneers to
settle (gas > profit), leaving them as permanent deadweight in
totalDebitOutstanding. Replaced with ceiling:
required = (amount * initRatioBps + 9999) / 10000
Ceiling rounds UP so 1 * 14999 / 10000 → 2, breaking the
unit-boundary mint hole. A configurable minAmount/minCollateral floor
remains follow-up R1 (the ceiling alone is necessary but not
sufficient for very-small-but-non-dust amounts).
Tests
- test_issue_enforces_liq_threshold_invariants renamed to
test_issue_enforces_deployment_invariants. OP_GREATERTHAN
count updated from 5 to 6 (added auctionWindow > 0). New
OP_GREATERTHANOREQUAL64 >= 1 floor for the auctionDiscountBps
deployment check.
- test_roll_pair_enforces_both_threshold_invariants renamed to
test_roll_pair_enforces_all_deployment_invariants; same updates.
- New test_issue_uses_ceiling_division_on_required_collateral
asserts the literal `9999` token appears in both issue and rollIn
ASM — a regression to floor (or to a different bias) trips it.
Docs
- docs/bonds.md §Enforced deployment invariants expanded from two
invariants to four (adds auctionWindow > 0 and auctionDiscountBps
bounds) and now applies to rollIn as well as issue.
- New paragraph on the ceiling-division origination floor.
- Follow-up R2 marked WIRED with reference to the new regression
test; R1 kept as a separate open item (configurable minimums).
Out of scope here: the bot's P2.4 (loan_vault.ark still uses >= burn
checks) is a separate contract and a separate PR.
Tests: 255 -> 256 (one new ceiling-division regression test added).
All suites green; cargo fmt --check clean.1 parent 7dc8b7d commit e6f4aea
3 files changed
Lines changed: 145 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
265 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| |||
274 | 275 | | |
275 | 276 | | |
276 | 277 | | |
277 | | - | |
278 | | - | |
279 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
280 | 305 | | |
281 | 306 | | |
282 | 307 | | |
| |||
442 | 467 | | |
443 | 468 | | |
444 | 469 | | |
445 | | - | |
446 | | - | |
| 470 | + | |
| 471 | + | |
447 | 472 | | |
448 | 473 | | |
449 | 474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
137 | 148 | | |
138 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
139 | 153 | | |
140 | 154 | | |
141 | 155 | | |
| |||
150 | 164 | | |
151 | 165 | | |
152 | 166 | | |
153 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
154 | 176 | | |
155 | 177 | | |
156 | 178 | | |
| |||
326 | 348 | | |
327 | 349 | | |
328 | 350 | | |
| 351 | + | |
| 352 | + | |
329 | 353 | | |
330 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
331 | 358 | | |
332 | 359 | | |
333 | 360 | | |
| |||
339 | 366 | | |
340 | 367 | | |
341 | 368 | | |
342 | | - | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
343 | 372 | | |
344 | 373 | | |
345 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
246 | 253 | | |
247 | 254 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
253 | 260 | | |
254 | 261 | | |
255 | 262 | | |
256 | 263 | | |
257 | | - | |
258 | | - | |
259 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
260 | 267 | | |
261 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
262 | 309 | | |
263 | 310 | | |
264 | 311 | | |
| |||
628 | 675 | | |
629 | 676 | | |
630 | 677 | | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
636 | 684 | | |
637 | 685 | | |
638 | 686 | | |
639 | | - | |
640 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
641 | 690 | | |
642 | | - | |
643 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
644 | 698 | | |
645 | 699 | | |
646 | 700 | | |
| |||
0 commit comments