Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly Related Issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
contracts/src/Chainvoice.sol (1)
206-213: Critical bug:isPaidstate change is never persisted to storage.The memory copy
invoiceis modified on line 213, but this change is never written back to storage. The storage variableinvoiceStorageremains unchanged, meaningisPaidstaysfalsepermanently.Impact: The same invoice can be paid an unlimited number of times since the
require(!invoice.isPaid, "Already paid")check will always pass. This allows attackers to drain funds from payers.🔒 Proposed fix
InvoiceDetails storage invoiceStorage = invoices[invoiceId]; //(read once from storage) InvoiceDetails memory invoice = invoiceStorage; // now read all from this invoice(memory) require(msg.sender == invoice.to, "Not authorized"); require(!invoice.isPaid, "Already paid"); require(!invoice.isCancelled, "Invoice is cancelled"); // Effects first for CEI (mark paid, bump fees), then interactions - invoice.isPaid = true; + invoiceStorage.isPaid = true;Note: Compare with the correct pattern used in
payInvoicesBatchat line 281:invoices[invoiceIds[i]].isPaid = truewhich writes directly to storage.
This PR addresses Following change:
In simple terms previously we are reading from :
Gas Waste (Before) The original function accessed storage fields 14 times during execution. Each access triggers an SLOAD operation (expensive).
Total Storage Reads: ~14 SLOADs (Warm access = 100 gas each) -> ~1,400 Gas overhead
#after:
Savings: ~1,350+ Gas per transaction.
@kumawatkaran523 Please checkout this Optimization, thankyou
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.