DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

[G-1] Inefficient Storage Usage in `MultiSigWallet::approveTransaction()` (Direct Storage Modification -> Unnecessary Gas Costs)

Description:

In the approveTransaction(uint256 _txId) function, a Transaction struct is directly referenced in storage using:

function approveTransaction(uint256 _txId) external onlyOwners {
require(_txId < transactions.length, "Invalid transaction ID");
@> Transaction storage txn = transactions[_txId];
require(!txn.executed, "Transaction already executed");
if (msg.sender == owner1) {
if (txn.approvedByOwner1) revert AlreadyApproved();
txn.approvedByOwner1 = true;
} else {
if (txn.approvedByOwner2) revert AlreadyApproved();
txn.approvedByOwner2 = true;
}
emit TransactionApproved(_txId, msg.sender);
}

Since all modifications to txn are reflected directly in storage, every update incurs high gas costs. Instead, copying the struct to memory, making the necessary modifications, and then writing it back to storage at the end can significantly reduce gas consumption.

Impact

  • Increased gas costs due to multiple writes to storage within the function.

  • Inefficient state modification leads to unnecessary on-chain storage operations.

  • Can be optimized to reduce execution costs, making transactions more affordable for users.

Recommended Mitigation

function approveTransaction(uint256 _txId) external onlyOwners {
require(_txId < transactions.length, "Invalid transaction ID");
require(!transactions[_txId].executed, "Transaction already executed");
- Transaction storage txn = transactions[_txId];
+ Transaction memory txn = transactions[_txId];
if (msg.sender == owner1) {
if (txn.approvedByOwner1) revert AlreadyApproved();
txn.approvedByOwner1 = true;
} else {
if (txn.approvedByOwner2) revert AlreadyApproved();
txn.approvedByOwner2 = true;
}
+ transactions[_txId] = txn; // Single storage write to save gas
emit TransactionApproved(_txId, msg.sender);
}
Updates

Appeal created

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.