code-423n4 / 2021-10-pooltogether-findings

0 stars 0 forks source link

Unnecessary decrement (DrawCalculator.sol) #57

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

ye0lde

Vulnerability details

Impact

Gas savings and code clarity

Proof of Concept

DrawCalculator.sol: "_prizeTierIndex - 1" is used and then "_prizeTierIndex" is decremented. Those two operations can be combined. https://github.com/pooltogether/v4-core/blob/35b00f710db422a6193131b7dc2de5202dc4677c/contracts/DrawCalculator.sol#L422-L425

Tools Used

Visual Studio Code, Remix

Recommended Mitigation Steps

Replace this https://github.com/pooltogether/v4-core/blob/35b00f710db422a6193131b7dc2de5202dc4677c/contracts/DrawCalculator.sol#L422-L425 with this while (_prizeTierIndex > 0) { numberOfPrizesForIndex -= bitRangeDecimal**(--_prizeTierIndex); }

PierrickGT commented 3 years ago

Duplicate of https://github.com/code-423n4/2021-10-pooltogether-findings/issues/33 The formula has been changed so this issue doesn't apply anymore.

GalloDaSballo commented 3 years ago

Agree with finding, will not mark as duplicate as this finding missed the broader high severity issue, will set to gas