Platform: Code4rena
Start Date: 25/01/2022
Pot Size: $50,000 USDT
Total HM: 17
Participants: 39
Period: 3 days
Judge: LSDan
Total Solo HM: 9
Id: 79
League: ETH
Rank: 38/39
Findings: 1
Award: $2.38
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: WatchPug
Also found by: Dravee, Jujic, Rhynorater, TomFrenchBlockchain, defsec, hyh, ye0lde
ye0lde
Save Gas With The Unchecked Keyword (LaunchEvent.sol)
Redundant arithmetic underflow/overflow checks can be avoided when an underflow/overflow cannot happen.
The "unchecked" keyword can be applied here since there is an "if" statement to ensure the arithmetic operations would not cause an integer underflow or overflow. https://github.com/code-423n4/2022-01-trader-joe/blob/a1579f6453bc4bf9fb0db9c627beaa41135438ed/contracts/LaunchEvent.sol#L327-L333
Change the code at 327 to:
unchecked { if (newAllocation > user.allocation) { // Burn tokens and update allocation. rJoeNeeded = getRJoeAmount(newAllocation - user.allocation); // Set allocation to the current balance as it's impossible // to buy more allocation without sending AVAX too user.allocation = newAllocation; } }
A similar change can be made here around line 361: https://github.com/code-423n4/2022-01-trader-joe/blob/a1579f6453bc4bf9fb0db9c627beaa41135438ed/contracts/LaunchEvent.sol#L361
Visual Studio Code, Remix
Add the "unchecked" keyword as shown above.
#0 - cryptofish7
2022-01-31T11:56:24Z
Duplicate of #233