Platform: Code4rena
Start Date: 18/04/2024
Pot Size: $36,500 USDC
Total HM: 19
Participants: 183
Period: 7 days
Judge: Koolex
Id: 367
League: ETH
Rank: 147/183
Findings: 1
Award: $3.82
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xAlix2
Also found by: 0x486776, 0xabhay, 0xlucky, 0xtankr, Abdessamed, Circolors, CodeWasp, DarkTower, Egis_Security, Giorgio, Infect3d, Krace, KupiaSec, Limbooo, Maroutis, NentoR, Ryonen, SpicyMeatball, T1MOH, TheFabled, TheSavageTeddy, TheSchnilch, VAD37, XDZIBECX, btk, carrotsmuggler, cu5t0mpeo, dimulski, gumgumzum, iamandreiski, imare, itsabinashb, ke1caM, kennedy1030, lian886, n4nika, oakcobalt, sashik_eth, shaflow2, steadyman, web3km, windhustler, zhaojohnson
3.8221 USDC - $3.82
The Bug that's for negative collateral values can lead to loss of fund for users and the platform. the bug can manifest under specific conditions, significant withdrawals relative to the total vault value and existing Dyad supply, detecting a condition requires monitoring and understanding of the intricate dependencies and interactions within the contract. if malicious actors understand and can find the bug, they can manipulate withdrawal timings and amounts to induce the system into a negative collateral state, potentially profiting from these actions at the expense of other users and the platform's stability.
The function withdraw calculates the remaining collateral after a withdrawal and checks if it is sufficient to cover the minted Dyad tokens. The vulnerability becomes apparent when handling large withdrawals or in cases where the Dyad supply is already high relative to the TVL here is the vulnerable part :
Vault _vault = Vault(vault); uint value = amount * _vault.assetPrice() * 1e18 / 10**_vault.oracle().decimals() / 10**_vault.asset().decimals(); if (getNonKeroseneValue(id) - value < dyadMinted) revert NotEnoughExoCollat(); _vault.withdraw(id, to, amount); if (collatRatio(id) < MIN_COLLATERIZATION_RATIO) revert CrTooLow(); }
here under scenarios where the sum of the withdrawn amount (C_withdraw) and the Dyad supply (D_supply) exceeds the Total Vault Value (TVL) The bug arise due to a failure to sufficiently check and manage the collateral values post-withdrawal which result in a negative collateral value
here is a test show the bug :
from sympy import symbols, solve # Define symbols TVL, C_withdraw, D_supply, K_supply = symbols('TVL C_withdraw D_supply K_supply') # Expression for K_value_withdraw K_value_withdraw = (TVL - C_withdraw - D_supply) / K_supply # Test case where C_withdraw + D_supply exceeds TVL test_values_negative = { TVL: 100000, # Example TVL C_withdraw: 90000, # High withdrawal D_supply: 20000, # Existing Dyad supply K_supply: 10000 # Kerosene supply } # Evaluate K_value_withdraw with the test values result_negative = K_value_withdraw.subs(test_values_negative) result_negative
the result of the test where TVL = 100,000, C_withdraw = 90,000, D_supply = 20,000, and K_supply = 10,000 gives a Kerosene value of −1.
here : $ Kvaluewithdraw​=​(TVL−Cwithdraw​−Dsupply​)​/Ksupply $
in this calculation does not ensure that TVL - C_withdraw - D_supply remains non-negative this is a scenario where:
The calculation for Kerosene becomes:
$ Kvaluewithdraw​=(100,000−90,000−20,000)/10,000 ​=−1 $
Manual review
need to enforce checks to prevent negative collateral values
Other
#0 - c4-pre-sort
2024-04-29T07:28:37Z
JustDravee marked the issue as duplicate of #224
#1 - c4-pre-sort
2024-04-29T09:04:22Z
JustDravee marked the issue as sufficient quality report
#2 - c4-judge
2024-05-08T08:31:53Z
koolexcrypto marked the issue as duplicate of #308
#3 - c4-judge
2024-05-11T20:08:56Z
koolexcrypto marked the issue as satisfactory