The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Higher gas fees due to the low Loop Efficiency in the `LiquidationPool :: deletePendingStake` function.

Description:
as the length of PendingStakes increases, it will take higher computaional gas fees to delete a stake from the pendingStakes array.

Impact: the gas fees required to delete a stake will greatly increase as the number of stakes increase.

Proof of Concept: add this code to your test

describe("Gas Cost Comparison", function () {
let contract;
beforeEach(async function () {
const Contract = await ethers.getContractFactory("LiquidationPool");
contract = await Contract.deploy();
await contract.deployed();
});
it("gas cost of deletePendingSakes should be less than deletePendingStake", async function () {
const tx1 = await contract.deletePendingSakes(0);
const receipt1 = await tx1.wait();
const tx2 = await contract.deletePendingStake(0);
const receipt2 = await tx2.wait();
console.log("Gas used for deletePendingSakes:", receipt1.gasUsed.toNumber());
console.log("Gas used for deletePendingStake:", receipt2.gasUsed.toNumber());
expect(receipt1.gasUsed.toNumber()).to.be.lessThan(receipt2.gasUsed.toNumber());
});
});

Recommended Mitigation

- for (uint256 i = _i; i < pendingStakes.length - 1; i++) {
- pendingStakes[i] = pendingStakes[i + 1];
- }
+ // check for updates
+ pendingStakes[_i] = pendingStake[pendingStake.length - 1];
+ pendingSakes.pop();
Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

informational/invalid

Support

FAQs

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