flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Audit] Duplicate/retried withdraw requests double-count `withdrawnAmount`

Open K1NGD4VID opened this issue 3 months ago • 8 comments

Filed from the second-wave repository audit (issue 14/100). See the audit summary for full category context.

  • Location: backend/src/routes/v1/streams/withdraw.ts:106-144
  • Problem: sorobanWithdraw returns a deterministic, non-unique txHash ('simulated-withdraw-' + streamId), so the StreamEvent upsert (keyed on transactionHash+eventType) correctly no-ops on a retry — but the adjacent prisma.stream.update that increments withdrawnAmount is not guarded by the same dedup check and runs unconditionally on every call.
  • Evidence: StreamEvent upsert has an update: {} no-op branch; the stream.update above it has no equivalent guard.
  • Suggested implementation: Wrap both writes in one transaction gated by the same duplicate-event check, or make the balance update itself idempotent (compute from indexed on-chain state rather than incrementing).
  • Acceptance criteria: Calling withdraw twice for the same claimable window increases withdrawnAmount by the claimed amount exactly once, verified by a new integration test.
  • Difficulty: M
  • Expected impact: Fixes a real fund-accounting bug reachable via a simple double-click or client retry.

K1NGD4VID avatar Aug 29 '26 18:08 K1NGD4VID

@Martinsbab has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

Hi maintainer, I would love to work on this issue

ℹ️ Repo Maintainers: To accept this application, review their application or assign @Martinsbab to this issue.

Martinsbab avatar Aug 29 '26 19:08 Martinsbab

@akinerin has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

I would love to work on this issue, please assign it to me

ℹ️ Repo Maintainers: To accept this application, review their application or assign @akinerin to this issue.

akinerin avatar Aug 29 '26 19:08 akinerin

@Rafiat30 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

i would love to work on this

ℹ️ Repo Maintainers: To accept this application, review their application or assign @Rafiat30 to this issue.

Rafiat30 avatar Aug 29 '26 19:08 Rafiat30

@Hamda-gbade has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

I can handle this if assigned to me

ℹ️ Repo Maintainers: To accept this application, review their application or assign @Hamda-gbade to this issue.

Hamda-gbade avatar Aug 29 '26 19:08 Hamda-gbade

@ayomustap has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

​Hi maintainer, I would love to work on this issue. I can get started on it right away.

ℹ️ Repo Maintainers: To accept this application, review their application or assign @ayomustap to this issue.

ayomustap avatar Aug 29 '26 19:08 ayomustap

Congratulations, @Martinsbab! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

🧑‍💻 @Martinsbab: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

🌊 Happy Wave 🌊

drips-wave[bot] avatar Aug 29 '26 20:08 drips-wave[bot]

🎉 This issue has been marked as completed on GrantFox!

@Martinsbab's PR #1410 was approved and merged by @K1NGD4VID.

🏆 @Martinsbab: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (245 total points). Track your full progress on GrantFox.

👏 Great work, @Martinsbab! Keep contributing to LabsCrypt.

grantfox-oss[bot] avatar Nov 28 '26 08:11 grantfox-oss[bot]

This issue has been completed by @Martinsbab as part of the Stellar Wave Program's 11th Wave 🥳

😎 @Martinsbab: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

drips-wave[bot] avatar Nov 28 '26 08:11 drips-wave[bot]