Skip to content

[BUG] Race condition in payment deduplication - concurrent workers can double-execute rules #8

Description

@thisisouvik

Description

In backend/src/engine/processor.ts, step 1 performs a deduplication check:

const existing = await sql`SELECT 1 FROM AutomatedTransaction WHERE txHash = ${paymentHorizonId} LIMIT 1`;
if (existing.length > 0) return { skipped: true };

However, there is no database-level UNIQUE constraint on txHash. Under concurrent BullMQ workers (concurrency: 5), two workers can both pass the SELECT check before either inserts - causing the same payment event to be processed twice, resulting in duplicate on-chain transactions and double vault deposits.

Steps to Reproduce

  1. Configure BullMQ with concurrency: 5.
  2. Send a payment to a monitored wallet.
  3. Observe two identical rows in AutomatedTransaction with the same txHash.

Suggested Fix

ALTER TABLE AutomatedTransaction 
ADD CONSTRAINT AutomatedTransaction_txHash_key UNIQUE (txHash);

Then handle the unique violation error in the processor as a skip.

Impact

Critical - Users can have funds double-moved from their vaults on every incoming payment.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveMarked as Stellar Wavebug: criticalCritical priority bugengineRelated to the rule processing enginesecuritySecurity vulnerability or concernstellar-networkRelated to Stellar network interaction

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions