Platform: Code4rena
Start Date: 21/08/2023
Pot Size: $125,000 USDC
Total HM: 26
Participants: 189
Period: 16 days
Judge: GalloDaSballo
Total Solo HM: 3
Id: 278
League: ETH
Rank: 172/189
Findings: 1
Award: $0.01
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: klau5
Also found by: 0x3b, 0xCiphky, 0xDING99YA, 0xWaitress, 0xbranded, 0xc0ffEE, 0xklh, 0xsurena, 0xvj, ABA, AkshaySrivastav, Anirruth, Aymen0909, Baki, Blockian, BugzyVonBuggernaut, DanielArmstrong, Evo, GangsOfBrahmin, HChang26, Inspex, Jiamin, Juntao, Kow, Krace, KrisApostolov, LFGSecurity, LokiThe5th, Mike_Bello90, Norah, Nyx, QiuhaoLi, RED-LOTUS-REACH, SBSecurity, Snow24, SpicyMeatball, T1MOH, Tendency, Toshii, Udsen, Yanchuan, __141345__, ak1, asui, auditsea, ayden, bart1e, bin2chen, blutorque, carrotsmuggler, chaduke, chainsnake, circlelooper, clash, codegpt, crunch, degensec, dirk_y, ge6a, gjaldon, grearlake, jasonxiale, juancito, ke1caM, kodyvim, kutugu, ladboy233, lanrebayode77, mahdikarimi, max10afternoon, mert_eren, nirlin, nobody2018, oakcobalt, parsely, peakbolt, pks_, pontifex, ravikiranweb3, rokinot, rvierdiiev, said, savi0ur, sces60107, sh1v, sl1, spidy730, tapir, tnquanghuy0512, ubermensch, visualbits, volodya, wintermute
0.0098 USDC - $0.01
Anyone can front-run a settle
function causing DoS and making protocol not functional. Protocol will not be able to settle options.
Faulty code is located in PerpetualAtlanticVaultLP
contract, exactly in subtractLoss
function. The require
statement checks if the collateral balance of this contract is equal to contract's total collateral - loss (collateral.balanceOf(address(this)) == _totalCollateral - loss
). An attacker can send the smallest amount of collateral token like 1
and make this require statement revert
every time. Direct transfer will not update _totalCollateral
variable. This makes it impossible to successfully call settle
. In PerpetualAtlanticVaultLP
contract there is no sync
function (like in other contracts) or any other way to directly balance the _totalCollateral
state. Protocol could find a way to sync the values but then another direct transfer would cause another revert
.
settle
with optionsIds
parameter.PerpetualAtlanticVaultLP
.settle
in PerpetualAtlanticVault
contract passing down ipnut data.PerpetualAtlanticVault
settle
function checks if contract is paused, if the sender is eligible, calls updateFunding()
and starts looping through optionIds calculating ethAmount
(and other variables that are not relevant in this exploit scenario).ethAmount
from vault
to core
contract and rdpxAmount
from core
contract to vault
.subtractLoss
in PerpetualAtlanticVaultLP
is called with ethAmount
as a parameter.subtractLoss
checks if contract token balance is equal to total collateral - loss (collateral.balanceOf(address(this)) == _totalCollateral - loss
) and reverts because of inequality caused by direct transfer, by the attacker, to the PerpetualAtlanticVaultLP
contract.https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L764-L783 https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/perp-vault/PerpetualAtlanticVault.sol#L315-L368 https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/perp-vault/PerpetualAtlanticVaultLP.sol#L200-L203
As a result options can't be settled and the perks of these settlements won't be avalible to users (such as receiving rdpx). Protocol functionality and some fundamental operations are disturbed.
Manual analysis, Foundry
Implement sync function similar to function in RdpxV2Core. This function will synchronize token balance of the contract with _totalCollateral
variable. Calling it before transfering tokens will ensure that the direct transfers are not a threat to internal accounting.
DoS
#0 - c4-pre-sort
2023-09-09T05:56:21Z
bytes032 marked the issue as duplicate of #619
#1 - c4-pre-sort
2023-09-11T16:14:00Z
bytes032 marked the issue as sufficient quality report
#2 - c4-pre-sort
2023-09-11T16:14:00Z
bytes032 marked the issue as sufficient quality report
#3 - c4-judge
2023-10-20T19:35:14Z
GalloDaSballo marked the issue as satisfactory