StabilityNexus / StabilityNexus/Chainvoice
[CRITICAL]: ERC20 batch payments send funds to last invoice recipient only
@dhruvi-16-me is already working on this.
Since Feb 18, 2026.
- Dominant language
- JavaScript
- Stars
- 10
- Forks
- 47
- Avg merge
- 17h 47m
- Merged PRs (30d)
- 4
Description
Description
The payInvoicesBatch function contains a critical logic bug in the ERC20 payment path that causes all ERC20 transfers in a batch to be sent to the last invoice’s recipient only, regardless of which invoices are being paid.
This issue is independent of the already-reported batch payment race condition in #59.
Even if the Checks–Effects–Interactions ordering is fixed, this bug will still persist and cause incorrect fund transfers.
Problem Explanation
In payInvoicesBatch, invoice validation is done in an initial loop where an InvoiceDetails storage inv variable is declared.
Later, during the ERC20 transfer loop, the same inv variable is reused without being reassigned per iteration. As a result:
-
invcontinues to reference the last invoice from the validation loop -
All
transferFromcalls use:- the last invoice’s
fromaddress - the last invoice’s
amountDue
- the last invoice’s
-
Other invoice issuers never receive their tokens
This happens deterministically on every ERC20 batch payment.
Expected Behavior
Each ERC20 transfer should:
- Use the current invoice’s
fromaddress - Use the current invoice’s
amountDue
Each invoice issuer should receive exactly the amount owed to them.
Current Behavior
- All ERC20 transfers in a batch go to the last invoice’s issuer only
- Other issuers receive nothing
- Funds are permanently misrouted
Impact
- Guaranteed fund loss / misrouting
- Affects all ERC20 batch payments
- Breaks trust in batch payment functionality
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.