Platform: Code4rena
Start Date: 21/06/2022
Pot Size: $30,000 USDC
Total HM: 12
Participants: 96
Period: 3 days
Judge: HardlyDifficult
Total Solo HM: 5
Id: 140
League: ETH
Rank: 2/96
Findings: 4
Award: $3,019.73
π Selected for report: 1
π Solo Findings: 1
π Selected for report: WatchPug
Also found by: hansfriese
631.623 USDC - $631.62
https://github.com/code-423n4/2022-06-nibbl/blob/main/contracts/Twav/Twav.sol#L40
Twav._getTwav() might revert when it should work properly. In this case, the main functions like NibblVault.buy() and NibblVault.sell() will revert also.
According to the logic, Twav.lastBlockTimeStamp saves a modularized timestamp so current timestamp might be smaller than the previous one. So (_twavObservationCurrent.timestamp - _twavObservationPrev.timestamp) might meet the underflow error.
Solidity Visual Developer of VSCode
We can use unchecked calculation for the above calculation. We can modify L40 like below.
uint32 _timeElapsed; unchecked { _timeElapsed = _twavObservationCurrent.timestamp - _twavObservationPrev.timestamp; } _twav = (_twavObservationCurrent.cumulativeValuation - _twavObservationPrev.cumulativeValuation) / _timeElapsed;
#0 - HardlyDifficult
2022-07-03T23:12:34Z
π Selected for report: hansfriese
2339.3444 USDC - $2,339.34
The "if" condition of Twav._getTwav() is missing some edge cases. In this case, this function will return 0 which is different from the correct value and it will affect the main functions like NibblVault.buy() and NibblVault.sell().
I think this condition is to confirm at least 4 values were saved for twav calculation. Btw this timestamp would be zero even though there are more than 4 values properly as it's modularized by 2**32. In this case, the if condition will be false and this function will return 0.
Solidity Visual Developer of VSCode
I see "cumulativeValuation" is increasing all the time and recommend replacing "timestamp" with "cumulativeValuation".
if (twavObservations[TWAV_BLOCK_NUMBERS - 1].cumulativeValuation != 0) {
#0 - mundhrakeshav
2022-07-01T07:59:21Z
#1 - HardlyDifficult
2022-07-03T23:14:44Z
Interesting catch. This is related to #178 but presents a distinct issue.
π Selected for report: IllIllI
Also found by: 0x1f8b, 0x29A, 0x52, 0xNazgul, 0xNineDec, 0xc0ffEE, 0xf15ers, 0xkatana, BowTiedWardens, Chom, ElKu, Funen, GalloDaSballo, JC, JMukesh, JohnSmith, Lambda, Limbooo, MadWookie, MiloTruck, Nethermind, Noah3o6, Nyamcil, Picodes, PwnedNoMore, Randyyy, RoiEvenHaim, SmartSek, StErMi, Tadashi, TerrierLover, TomJ, Tomio, Treasure-Seeker, UnusualTurtle, Varun_Verma, Wayne, Waze, _Adam, apostle0x01, asutorufos, berndartmueller, c3phas, catchup, cccz, cloudjunky, codexploder, cryptphi, defsec, delfin454000, dipp, ellahi, exd0tpy, fatherOfBlocks, hansfriese, hyh, joestakey, kebabsec, kenta, masterchief, minhquanym, naps62, oyc_109, pashov, peritoflores, reassor, rfa, robee, sach1r0, saian, sashik_eth, shenwilly, simon135, slywaters, sorrynotsorry, sseefried, unforgiven, xiaoming90, ych18, zuhaibmohd, zzzitron
28.2782 USDC - $28.28
I've found 3 row-risk issues and some non-critical issues.
require(buyoutEndTime <= block.timestamp, "NibblVault: buyoutEndTime <= now"); It must be "NibblVault: buyoutEndTime > now".
require(block.timestamp >= minBuyoutTime, "NibblVault: minBuyoutTime < now"); It must be "NibblVault: minBuyoutTime > now".
IERC20(_asset).transfer(_to, IERC20(_asset).balanceOf(address(this)));
IERC20(_assets[i]).transfer(_to, IERC20(_assets[i]).balanceOf(address(this)));
IERC20(_token).transfer(msg.sender, IERC20(_token).balanceOf(address(this)));
IERC20(_tokens[i]).transfer(msg.sender, IERC20(_tokens[i]).balanceOf(address(this)));
#0 - HardlyDifficult
2022-07-04T16:06:18Z
Merging with https://github.com/code-423n4/2022-06-nibbl-findings/issues/110
Relevant improvements suggested, mostly NC.
π Selected for report: IllIllI
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 8olidity, ACai, BowTiedWardens, Chandr, Chom, ElKu, Fitraldys, Funen, IgnacioB, JC, Lambda, Limbooo, MiloTruck, Noah3o6, Nyamcil, Picodes, Randyyy, SmartSek, StErMi, TerrierLover, TomJ, Tomio, UnusualTurtle, Waze, _Adam, ajtra, c3phas, cRat1st0s, catchup, codexploder, cryptphi, defsec, delfin454000, ellahi, exd0tpy, fatherOfBlocks, hansfriese, joestakey, kebabsec, kenta, m_Rassska, minhquanym, oyc_109, pashov, reassor, rfa, robee, sach1r0, saian, sashik_eth, simon135, slywaters, ych18, ynnad, zuhaibmohd
20.4863 USDC - $20.49