-
-
Notifications
You must be signed in to change notification settings - Fork 37
Unbounded Loop in getSentInvoices / getReceivedInvoices (Potential DoS) --->add pagination #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ contract ChainvoiceTest is Test { | |
| } | ||
|
|
||
| /* ------------------------------------------------------------ */ | ||
| /* CREATE INVOICE */ | ||
| /* CREATE INVOICE */ | ||
| /* ------------------------------------------------------------ */ | ||
|
|
||
| function testCreateInvoice_Native() public { | ||
|
|
@@ -31,12 +31,16 @@ contract ChainvoiceTest is Test { | |
| "hash123" | ||
| ); | ||
|
|
||
| // FIX: Added offset (0) and limit (10) for pagination | ||
| Chainvoice.InvoiceDetails[] memory sent = chainvoice.getSentInvoices( | ||
| alice | ||
| alice, | ||
| 0, | ||
| 10 | ||
| ); | ||
|
|
||
| // FIX: Added offset (0) and limit (10) for pagination | ||
| Chainvoice.InvoiceDetails[] memory received = chainvoice | ||
| .getReceivedInvoices(bob); | ||
| .getReceivedInvoices(bob, 0, 10); | ||
|
Comment on lines
+34
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Add test coverage for pagination edge cases. The updated test only verifies the happy path with
🤖 Prompt for AI Agents |
||
|
|
||
| assertEq(sent.length, 1); | ||
| assertEq(received.length, 1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -359,7 +359,8 @@ function BatchPayment() { | |
|
|
||
| const contract = new Contract(contractAddress, ChainvoiceABI, signer); | ||
|
|
||
| const res = await contract.getReceivedInvoices(address); | ||
| // Fetching the first 100 invoices (Offset: 0, Limit: 100) | ||
| const res = await contract.getReceivedInvoices(address, 0, 100); | ||
|
Comment on lines
+362
to
+363
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded pagination limits users to first 100 invoices. With Consider implementing:
💡 Example: Load more implementation+ const [contractOffset, setContractOffset] = useState(0);
+ const CONTRACT_PAGE_SIZE = 100;
+ const [hasMore, setHasMore] = useState(true);
- const res = await contract.getReceivedInvoices(address, 0, 100);
+ const res = await contract.getReceivedInvoices(address, contractOffset, CONTRACT_PAGE_SIZE);
+ if (res.length < CONTRACT_PAGE_SIZE) {
+ setHasMore(false);
+ }
// Add a "Load More" button in the UI when hasMore is true🤖 Prompt for AI Agents |
||
|
|
||
| if (!res || !Array.isArray(res) || res.length === 0) { | ||
| setReceivedInvoices([]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -686,7 +686,8 @@ function ReceivedInvoice() { | |
|
|
||
| const contract = new Contract(contractAddress, ChainvoiceABI, signer); | ||
|
|
||
| const res = await contract.getReceivedInvoices(address); | ||
| // Fetching the first 100 invoices (Offset: 0, Limit: 100) | ||
| const res = await contract.getReceivedInvoices(address, 0, 100); | ||
|
Comment on lines
+689
to
+690
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same hardcoded pagination limitation as BatchPayment.jsx. Users with more than 100 invoices won't see older records. Apply the same fix pattern as suggested for 🤖 Prompt for AI Agents |
||
|
|
||
| if (!res || !Array.isArray(res) || res.length === 0) { | ||
| setReceivedInvoice([]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 1670
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 1808
🏁 Script executed:
Repository: StabilityNexus/Chainvoice
Length of output: 1178
Update ABI definitions and SentInvoice.jsx to match new function signatures.
The contract's
getSentInvoicesandgetReceivedInvoicesfunctions now require three parameters:(address user, uint256 offset, uint256 limit). However,frontend/src/contractsABI/ChainvoiceABI.jsstill declares only a singleuserparameter for both functions, causing ethers.js to encode/decode calls incorrectly at runtime.Additionally,
frontend/src/page/SentInvoice.jsx(line 181) callsgetSentInvoices(address)with only one argument and must be updated to passoffsetandlimitparameters like the other call sites. Note thatReceivedInvoice.jsx(line 690) andBatchPayment.jsx(line 363) have already been updated to use the correct three-parameter signature.🤖 Prompt for AI Agents