Skip to content

fix: prevent duplicate invoice ID double payment in payInvoicesBatch - #203

Open
g-k-s-03 wants to merge 1 commit into
StabilityNexus:mainfrom
g-k-s-03:fix/batch-payment-duplicate-invoice-id
Open

fix: prevent duplicate invoice ID double payment in payInvoicesBatch#203
g-k-s-03 wants to merge 1 commit into
StabilityNexus:mainfrom
g-k-s-03:fix/batch-payment-duplicate-invoice-id

Conversation

@g-k-s-03

Copy link
Copy Markdown
Contributor

Fixes #202

Bug

payInvoicesBatch() validated all invoice IDs in one loop (checking
isPaid/isCancelled) before marking any of them paid in a separate,
later loop. If the input array contained a duplicate invoice ID, both
occurrences passed validation since neither had been marked paid yet —
causing the payout loop to transfer funds twice for the same invoice.

Fix

Merged the validate and mark-paid loops into a single pass, so
invoices[id].isPaid = true is set immediately after the isPaid/isCancelled
check for that id, in the same iteration. A duplicate id's second occurrence
now correctly reverts on its second pass through the loop.

Testing

Added testPayInvoicesBatch_RevertOnDuplicateId(), which creates an invoice
and calls payInvoicesBatch with a duplicate id, asserting it reverts
instead of double-paying.

Merge the validate and mark-paid loops in payInvoicesBatch into a single
pass so isPaid is set immediately after the isPaid/isCancelled check for
each id. Previously validation and mark-paid ran in separate loops, so a
duplicate id in the batch would pass validation twice before either
occurrence was marked paid, causing the payout loop to transfer funds to
the same invoice's issuer twice.

Adds a regression test asserting payInvoicesBatch reverts with
AlreadySettled when the input array contains a duplicate invoice id.

Fixes StabilityNexus#202

Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 39 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9e3df0fc-1acf-4667-88be-852b89e42410

📥 Commits

Reviewing files that changed from the base of the PR and between 904f971 and 7359a99.

📒 Files selected for processing (2)
  • contracts/src/Chainvoice.sol
  • contracts/test/Chainvoice.t.sol

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Duplicate invoice IDs in payInvoicesBatch() cause double payment

1 participant