On _createLoot there is a _getQuestAllocationForPeriod which check if(nbQuestForGauge == 0 || questTotalRewards == 0) then return Allocation(0, 0), currently this zero allocation is not being used for short-circuit return flow.
For example when a user want to createLoot for future period, entering _getQuestAllocationForPeriod, it will make questTotalRewards = 0 (since it's not set yet), thus it will return Allocation(0, 0). If there is no short-circuit return if the allocation is 0, then on Line 484, it will revert due to divide by zero.
Instead of revert, which might need to be catched by front-end ui, it's normal to just return, just like everything else like:
so, in this case, if(allocation == Allocation(0, 0)) return;
This early return is understandable, because the main op in _createLoot is the final line, creating loot, which main parameters are vars.userPalAmount and vars.userExtraAmount. These two parameters are affected by allocation.palPerVote & allocation.extraPerVote.
Further more, in Loot::createLoot(), there is if(palAmount == 0 && extraAmount == 0) return;, which is what we expect. Instead of consuming gas up to this point, it's better to immediate return when Allocation is 0.
Github username: @chainNue Twitter username: chainNue Submission hash (on-chain): 0x253b61a5ec1b171eb1bfd199fbdf4942aec3b7ab5f9158213f2bc58f20fd056e Severity: low
Description: Description
On
_createLoot
there is a_getQuestAllocationForPeriod
which checkif(nbQuestForGauge == 0 || questTotalRewards == 0)
then returnAllocation(0, 0)
, currently this zero allocation is not being used for short-circuit return flow.For example when a user want to
createLoot
for future period, entering_getQuestAllocationForPeriod
, it will makequestTotalRewards
= 0 (since it's not set yet), thus it will returnAllocation(0, 0)
. If there is no short-circuit return if the allocation is 0, then on Line 484, it will revert due to divide by zero.Instead of revert, which might need to be catched by front-end ui, it's normal to just
return
, just like everything else like:if(!allowedDistributors[distributor]) return;
if(!ILootVoteController(lootVoteController).isListedGauge(vars.gauge)) return;
if(vars.userPeriodRewards == 0) return;
so, in this case,
if(allocation == Allocation(0, 0)) return;
This early
return
is understandable, because the main op in_createLoot
is the final line, creating loot, which main parameters arevars.userPalAmount
andvars.userExtraAmount
. These two parameters are affected byallocation.palPerVote
&allocation.extraPerVote
.Further more, in
Loot::createLoot()
, there isif(palAmount == 0 && extraAmount == 0) return;
, which is what we expect. Instead of consuming gas up to this point, it's better to immediate return when Allocation is 0.Attack Scenario
Attachments
Proof of Concept (PoC) File
Revised Code File (Optional)
Recommendation
Consider to add immediate return when Allocation is 0