In the SabilityPool.sol the updateAllocation
function allows the contract owner to update a manager’s allocation. However, if the new allocation entered is the same as the existing allocation, the function still executes and emits an event, even though no actual state change occurs. This results in unnecessary gas consumption, reducing contract efficiency.
Deploy the contract and assign an allocation to a manager (e.g., managerAllocation[0x1234] = 100
).
Call updateAllocation(0x1234, 100);
(same allocation value as before).
The transaction is processed, gas is consumed, and the event AllocationUpdated
is emitted despite no actual change.
If the new allocation matches the existing allocation, the function should exit early without modifying state or emitting an event.
The function executes fully, performing redundant calculations and emitting an event, leading to unnecessary gas usage.
Saves Gas: Reduces gas costs by preventing unnecessary transactions.
Enhances Efficiency: Avoids redundant state updates and event emissions.
Improves UX: Prevents users from unknowingly wasting gas on meaningless updates.
Manuel Review
Add a check at the start of the function to prevent redundant updates:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.