Platform: Code4rena
Start Date: 12/12/2022
Pot Size: $36,500 USDC
Total HM: 8
Participants: 103
Period: 7 days
Judge: berndartmueller
Id: 193
League: ETH
Rank: 86/103
Findings: 1
Award: $14.83
π Selected for report: 0
π Solo Findings: 0
π Selected for report: Rolezn
Also found by: 0x1f8b, 0xAgro, 0xSmartContract, 0xab00, 0xhacksmithh, Aymen0909, Bnke0x0, Breeje, Diana, HardlyCodeMan, IllIllI, JC, JrNet, Madalad, NoamYakov, RaymondFam, ReyAdmirado, SleepingBugs, UdarTeam, c3phas, carlitox477, cryptonue, gz627, lukris02, millersplanet, oyc_109, pavankv, ret2basic, saneryee, tnevler
14.833 USDC - $14.83
Issue | Instances | |
---|---|---|
GAS-1 | x += y costs more gas than x = x + y for state variables | 3 |
GAS-2 | Splitting require() statements that use && saves gas | 1 |
GAS-3 | Add Unchecked {} For Subtractions Where The Operands Cannot Underflow Because Of A Previous Require() Or If-statement | 1 |
GAS-4 | Functions Guaranteed To Revert When Called By Normal Users Can Be Marked Payable | 2 |
use = + or = - instead to save gas
Instances (3):
File: src/Pair.sol 448: balanceOf[from] -= amount; 453: balanceOf[to] += amount;
File: src/lib/SafeERC20Namer.sol 35: charCount += uint8(b[i]);
Saves 16 gas per instance. If youβre using the Optimizer at 200, instead of using the && operator in a single require statement to check multiple conditions, multiple require statements with 1 condition per require statement should be used to save gas.
Instances (1):
File: src/Pair.sol 71: require(baseTokenAmount > 0 && fractionalTokenAmount > 0, "Input token amount is zero");
The unchecked keyword can saves 30-40 gas per line.
Instances (1):
File: src/Pair.sol 168: uint256 refundAmount = maxInputAmount - inputAmount;
If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.
Instances (2):
File: src/LpToken.sol 19: function mint(address to, uint256 amount) public onlyOwner { 26: function burn(address from, uint256 amount) public onlyOwner {
#0 - c4-judge
2023-01-14T17:12:52Z
berndartmueller marked the issue as grade-b