Redundant Security Checks & Code Bloat->Replace with Modifiers#130
Redundant Security Checks & Code Bloat->Replace with Modifiers#130aniket866 wants to merge 2 commits intoStabilityNexus:mainfrom
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughIntroduced four reusable modifiers ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@contracts/src/Chainvoice.sol`:
- Around line 70-89: Replace the string-require checks in the modifiers
validInvoice, onlyCreator, onlyPayer, and invoiceActive with custom error
reverts to save gas and match existing contract style: use revert
InvalidInvoice() instead of require(invoiceId < invoices.length, "..."); revert
NotInvoiceCreator() for onlyCreator, revert NotPayer() for onlyPayer, and for
invoiceActive replace the two requires with revert InvoiceAlreadyPaid() and
revert InvoiceCancelled() respectively; ensure those custom error types are
declared (or reuse existing ones) and update any tests/usage accordingly.
|
@DengreSarthak @kumawatkaran523 This is a clean maintainability improvement (less duplication, clearer access rule) and the implementation code looks correct to me |
|
Please resolve the merge conflicts before review. Your PR will only be reviewed by a maintainer after all conflicts have been resolved. 📺 Watch this video to understand why conflicts occur and how to resolve them: |
Addressed Issues:
closes #93
1. The "Is this a real invoice?" Check
What it was: require(invoiceId < invoices.length, "Invalid invoice ID"); was written inside 4 different functions.
What it changed to: We created a modifier called validInvoice. Now, we just type validInvoice(invoiceId) at the top of the function, and we deleted the require line from inside the functions.
2. The "Are you the creator?" Check
What it was: require(msg.sender == invoice.from, "Only invoice creator can cancel"); inside the cancelInvoice function.
What it changed to: We created the onlyCreator modifier. We attached it to the cancelInvoice door, ensuring only the sender can enter.
3. The "Are you the payer?" Check
What it was: require(msg.sender == invoice.to, "Not authorized"); inside the payInvoice function.
What it changed to: We created the onlyPayer modifier. We attached it to the payInvoice door, ensuring random people can't pay invoices meant for someone else.
4. The "Is the invoice still active?" Check
- What it was: Two lines checking require(!invoice.isPaid, "Already paid"); and require(!invoice.isCancelled, "Invoice is cancelled"); inside multiple functions.
Checklist
AI Usage Disclosure
Check one of the checkboxes below:
I have used the following AI models and tools: TODO
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
Summary by CodeRabbit
Refactor
Bug Fixes