Platform: Code4rena
Start Date: 09/02/2024
Pot Size: $60,500 USDC
Total HM: 17
Participants: 283
Period: 12 days
Judge:
Id: 328
League: ETH
Rank: 151/283
Findings: 1
Award: $13.63
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xDetermination
Also found by: 0x11singh99, 0xAnah, 0xRiO, JcFichtner, K42, MatricksDeCoder, McToady, PetarTolev, Raihan, SAQ, SM3_SS, SY_S, Timenov, ahmedaghadi, al88nsk, dharma09, donkicha, emrekocak, favelanky, hunter_w3b, judeabara, kiqo, lrivo, lsaudit, merlinboii, mikesans, offside0011, oualidpro, peter, rekxor, shamsulhaq123, unique, yashgoel72, yovchev_yoan, ziyou-
13.6293 USDC - $13.63
Issue | Instances | Gas Savings | |
---|---|---|---|
[G-01] | The burnFrom function evaluates the value of allowance(account, msg.sender) multiple times | 1 | 237 |
[G-02] | The claimNRN function uses the value of numRoundsClaimed[msg.sender] multiple times | 1 | 344 |
[G-03] | The updateBattleRecord function uses 100 several times instead of setting a constant | 1 |
The burnFrom function evaluates the value of allowance(account, msg.sender) multiple times. It can be replaced by uint256 allow to avoid double calculations
File: src/Neuron.sol function burnFrom(address account, uint256 amount) public virtual { + uint256 allow = allowance(account, msg.sender); + require(allow >= amount,"ERC20: burn amount exceeds allowance"); - require( - allowance(account, msg.sender) >= amount, - "ERC20: burn amount exceeds allowance" - ); - uint256 decreasedAllowance = allowance(account, msg.sender) - amount; + uint256 decreasedAllowance = allow - amount; _burn(account, amount); _approve(account, msg.sender, decreasedAllowance); }
Before making changes [PASS] testBurnFrom() (gas: 103644)
After making changes [PASS] testBurnFrom() (gas: 103407)
The claimNRN function uses the value of numRoundsClaimed[msg.sender] multiple times.It can be replaced by uint32 _numRoundsClaimed to avoid double calculations.
File: src/RankedBattle.sol function claimNRN() external { - require(numRoundsClaimed[msg.sender] < roundId, "Already claimed NRNs for this period"); + uint32 _numRoundsClaimed = numRoundsClaimed[msg.sender]; + require(_numRoundsClaimed < roundId, "Already claimed NRNs for this period"); uint256 claimableNRN = 0; uint256 nrnDistribution; + uint32 lowerBound = _numRoundsClaimed; - uint32 lowerBound = numRoundsClaimed[msg.sender]; for (uint32 currentRound = lowerBound; currentRound < roundId; currentRound++) { nrnDistribution = getNrnDistribution(currentRound); claimableNRN += ( accumulatedPointsPerAddress[msg.sender][currentRound] * nrnDistribution ) / totalAccumulatedPoints[currentRound]; numRoundsClaimed[msg.sender] += 1; } if (claimableNRN > 0) { amountClaimed[msg.sender] += claimableNRN; _neuronInstance.mint(msg.sender, claimableNRN); emit Claimed(msg.sender, claimableNRN); } }
Before making changes [PASS] testClaimNRN() (gas: 1781228)
After making changes [PASS] testClaimNRN() (gas: 1780884)
File: src/RankedBattle.sol + uint256 public constant x = 100; + require(mergingPortion <= x); - require(mergingPortion <= 100); https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/RankedBattle.sol#L332
File: src/RankedBattle.sol + uint256 mergingPoints = (points * mergingPortion) / x; - uint256 mergingPoints = (points * mergingPortion) / 100; https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/RankedBattle.sol#L449
Before making changes [PASS] testSetNewRoundFromAdmin() (gas: 957090) [PASS] testClaimNRN() (gas: 1781228) [PASS] testGetBattleRecord() (gas: 874511) [PASS] testGetCurrentStakingData() (gas: 876469) [PASS] testgetUnclaimedNRN() (gas: 963071) [PASS] testUpdateBattleRecordPlayerLossBattle() (gas: 854453) [PASS] testUpdateBattleRecordPlayerTiedBattle() (gas: 754196) [PASS] testUpdateBattleRecordPlayerWonBattle() (gas: 958706)
After making changes [PASS] testSetNewRoundFromAdmin() (gas: 957067) [PASS] testClaimNRN() (gas: 1781226) [PASS] testGetBattleRecord() (gas: 874488) [PASS] testGetCurrentStakingData() (gas: 876424) [PASS] testgetUnclaimedNRN() (gas: 963070) [PASS] testUpdateBattleRecordPlayerLossBattle() (gas: 854430) [PASS] testUpdateBattleRecordPlayerTiedBattle() (gas: 754173) [PASS] testUpdateBattleRecordPlayerWonBattle() (gas: 958705).
#0 - raymondfam
2024-02-25T22:26:42Z
3G
#1 - c4-pre-sort
2024-02-25T22:26:46Z
raymondfam marked the issue as sufficient quality report
#2 - c4-judge
2024-03-19T07:45:36Z
HickupHH3 marked the issue as grade-b