Skip to content

[BUG]: Unbounded Loop in getSentInvoices / getReceivedInvoices (Potential DoS) --->add pagination #120

Description

@aniket866

Bug Description

Unbounded Loop in getSentInvoices / getReceivedInvoices (Potential DoS)

Location

Chainvoice.sol

  • getSentInvoices()
  • getReceivedInvoices()
  • _getInvoices()

Issue Summary

The functions getSentInvoices() and getReceivedInvoices() rely on _getInvoices(), which iterates over the entire invoice ID array:

function _getInvoices(uint256[] storage ids) internal view returns (InvoiceDetails[] memory) {
    InvoiceDetails[] memory result = new InvoiceDetails[](ids.length);
    for (uint256 i = 0; i < ids.length; i++) {
        result[i] = invoices[ids[i]];
    }
    return result;
}

Fix:Replace getSentInvoices and getReceivedInvoices

function getSentInvoices(
    address user,
    uint256 offset,
    uint256 limit
) external view returns (InvoiceDetails[] memory) {
    return _getInvoicesPaginated(sentInvoices[user], offset, limit);
}

function getReceivedInvoices(
    address user,
    uint256 offset,
    uint256 limit
) external view returns (InvoiceDetails[] memory) {
    return _getInvoicesPaginated(receivedInvoices[user], offset, limit);
}

Steps to Reproduce

N/A

Logs and Screenshots

N/A

Environment Details

N/a

Impact

High - Major feature is broken

Code of Conduct

  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions