From 59f984a313572dff33a9f757dcb245b5f694fa8a Mon Sep 17 00:00:00 2001 From: Aniket Date: Wed, 28 Jan 2026 23:25:33 +0530 Subject: [PATCH 1/2] Gas fee optimization --- contracts/src/Chainvoice.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/src/Chainvoice.sol b/contracts/src/Chainvoice.sol index 38cb04cd..52435cb8 100644 --- a/contracts/src/Chainvoice.sol +++ b/contracts/src/Chainvoice.sol @@ -203,7 +203,8 @@ contract Chainvoice { function payInvoice(uint256 invoiceId) external payable nonReentrant { require(invoiceId < invoices.length, "Invalid invoice ID"); - InvoiceDetails storage invoice = invoices[invoiceId]; + 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"); From b27d62796064a9c493ee25291747f949a06dfab5 Mon Sep 17 00:00:00 2001 From: Aniket Date: Wed, 28 Jan 2026 23:57:43 +0530 Subject: [PATCH 2/2] Code-Rabbit follow-up --- contracts/src/Chainvoice.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/src/Chainvoice.sol b/contracts/src/Chainvoice.sol index 52435cb8..b855122a 100644 --- a/contracts/src/Chainvoice.sol +++ b/contracts/src/Chainvoice.sol @@ -210,7 +210,7 @@ contract Chainvoice { require(!invoice.isCancelled, "Invoice is cancelled"); // Effects first for CEI (mark paid, bump fees), then interactions - invoice.isPaid = true; + invoiceStorage.isPaid = true; if (invoice.tokenAddress == address(0)) { require(msg.value == invoice.amountDue + fee, "Incorrect payment amount");