Platform: Code4rena
Start Date: 08/03/2023
Pot Size: $60,500 USDC
Total HM: 2
Participants: 123
Period: 7 days
Judge: hansfriese
Id: 220
League: ETH
Rank: 100/123
Findings: 1
Award: $29.67
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xSmartContract
Also found by: 0x1f8b, 0x6980, 0xAgro, 0xSolus, 0xhacksmithh, 0xkazim, ABA, BPZ, BowTiedOriole, ChainReview, DadeKuma, DeFiHackLabs, Deathstore, DevABDee, Diana, Dravee, Dug, Englave, Go-Langer, Haipls, IceBear, Inspex, Jeiwan, Kek, Kresh, Madalad, MatricksDeCoder, MyFDsYours, RaymondFam, Rolezn, SAAJ, Sathish9098, Taloner, Udsen, Viktor_Cortess, atharvasama, ayden, brgltd, btk, carlitox477, catellatech, chaduke, codeislight, deadrxsezzz, descharre, erictee, fatherOfBlocks, favelanky, glcanvas, handsomegiraffe, jasonxiale, jekapi, joestakey, lemonr, luxartvinsec, martin, matrix_0wl, minhquanym, mrpathfindr, nadin, oyc_109, parsely, peanuts, pfedprog, rbserver, rokso, saian, santipu_, scokaf, slvDev, tsvetanovv, ubl4nk, ulqiorra, yamapyblack, zaskoh
29.6697 USDC - $29.67
According to the definition of AssetType
in NeoTokyoStaker.sol
:
(line https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L266)
enum AssetType { S1_CITIZEN, <--- 0 S2_CITIZEN, <--- 1 BYTES, <--- 2 LP <--- 3 }
There is one mistake while checking the type of asset (line https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L1205) (line https://github.com/code-423n4/2023-03-neotokyo/blob/dfa5887062e47e2d0c801ef33062d44c09f6f36e/contracts/staking/NeoTokyoStaker.sol#L1668)
if (uint8(_assetType) > 4) { revert InvalidAssetType(uint256(_assetType)); }
The asset type can not be 4, our maximum _assetType number can be 3 not 4. The code can be modified as follows:
if (uint8(_assetType) > 3) { revert InvalidAssetType(uint256(_assetType)); }
OR
if (uint8(_assetType) >= 4) { revert InvalidAssetType(uint256(_assetType)); }
Check: divide-before-multiply
Severity: Medium
Confidence: Medium
Description: Solidity's integer division truncates. Thus, performing division before multiplication can lead to precision loss.
Recommendation: Consider ordering multiplication before division.
NeoTokyoStaker._stakeLP(uint256) (contracts/staking/NeoTokyoStaker.sol#1124-1174) performs a multiplication on the result of a division: - points = amount * 100 / 1e18 * timelockMultiplier / _DIVISOR (contracts/staking/NeoTokyoStaker.sol#1155)
NeoTokyoStaker.getPoolReward(NeoTokyoStaker.AssetType,address) (contracts/staking/NeoTokyoStaker.sol#1264-1396) performs a multiplication on the result of a division: - share = points * _PRECISION / pool.totalPoints * totalReward (contracts/staking/NeoTokyoStaker.sol#1388)
NeoTokyoStaker._withdrawLP() (contracts/staking/NeoTokyoStaker.sol#1597-1644) performs a multiplication on the result of a division: - points = amount * 100 / 1e18 * lpPosition.multiplier / _DIVISOR (contracts/staking/NeoTokyoStaker.sol#1623)
#0 - c4-judge
2023-03-16T16:05:17Z
hansfriese marked the issue as grade-c
#1 - c4-judge
2023-03-24T16:11:26Z
hansfriese marked the issue as grade-b