Platform: Code4rena
Start Date: 12/08/2022
Pot Size: $35,000 USDC
Total HM: 10
Participants: 126
Period: 3 days
Judge: Justin Goro
Total Solo HM: 3
Id: 154
League: ETH
Rank: 30/126
Findings: 2
Award: $157.10
š Selected for report: 0
š Solo Findings: 0
š Selected for report: CertoraInc
Also found by: 0x1f8b, DecorativePineapple, cRat1st0s, carlitox477, joestakey, ladboy233, reassor, rvierdiiev
142.1501 USDC - $142.15
https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L403 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L418-L435 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L440 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L460-L462 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L471-L473 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L485-L488
Users can lose funds by sending a wrong _value parameter. The problems relays in casting _value to int128. Solidity does not check casting, just math operations. If a user tries to lock an amount greater than 2^128, the transaction won't be reverted and token will be transfered from the user to the contract
A similar problem can be seen in function increaseAmount
, and it is marked in the attached links
Change _value type to int128
Use library SafeCast from openzeppelin, or just check that _value <= 2^128
Change LockedBalance struct to
struct LockedBalance { uint256 amount; uint256 end; uint256 delegated; address delegatee; }
However, consider how this will affect other functions
#0 - lacoop6tu
2022-08-16T10:10:08Z
Duplicate of #228
#1 - gititGoro
2022-09-02T00:00:02Z
Duplicate upheld.
š Selected for report: IllIllI
Also found by: 0x040, 0x1f8b, 0xDjango, 0xHarry, 0xLovesleep, 0xNazgul, 0xNineDec, 0xSmartContract, 0xackermann, 0xbepresent, 2997ms, Amithuddar, Aymen0909, Bnke0x0, CRYP70, CertoraInc, Chom, CodingNameKiki, Deivitto, Dravee, ElKu, Fitraldys, Funen, GalloDaSballo, JC, JohnSmith, Junnon, LeoS, Metatron, MiloTruck, Noah3o6, NoamYakov, PaludoX0, RedOneN, Respx, ReyAdmirado, Rohan16, Rolezn, Ruhum, Sm4rty, SooYa, SpaceCake, TomJ, Tomio, Waze, Yiko, __141345__, a12jmx, ajtra, ak1, apostle0x01, asutorufos, bobirichman, brgltd, bulej93, c3phas, cRat1st0s, carlitox477, chrisdior4, csanuragjain, d3e4, defsec, delfin454000, djxploit, durianSausage, ellahi, erictee, fatherOfBlocks, gerdusx, gogo, ignacio, jag, ladboy233, m_Rassska, medikko, mics, natzuu, newfork01, oyc_109, paribus, pfapostol, rbserver, reassor, ret2basic, robee, rokinot, rvierdiiev, sach1r0, saian, sashik_eth, sikorico, simon135
14.9459 USDC - $14.95
Giving 2^128 = 2^7 * 2^111 * 2^10, MAXTIME = 365 days = 60 * 60 * 24 * 365 = 2^7 * 5^3 * 3^3, and that 2^7 * 5^3 * 3^3 * 2^111 * 2^10, we can avoid double casting int128(int256(MAXTIME)) to just int128(MAXTIME)
Giving that _oldLocked.end - block.timestamp <= MAXTIME, and previous justification, we can simplify this to just int128(_oldLocked.end - block.timestamp)
It is required that locked_.amount == 0, meaning that instead of doing locked_.amount += int128(int256(_value))
and locked_.delegated += int128(int256(_value));
, it would be better to just do an assignation:
locked_.amount = int128(int256(_value))
locked_.delegated = int128(int256(_value));