Vault.updateVaultAndCreditDelegationWeight()
updates incorrect creditDelegation.weight
to connected markets, as a result that markets'
totalDelegatedCreditUsd
will be overestimated, therefore affecting CreditDelegationBranch.withdrawUsdTokenFromMarket()
and CreditDelegationBranch.getAdjustedProfitForMarketId()
.
As the name implies Vault.recalculateVaultsCreditCapacity()
is a function responsible to update markets connected to a specific vault. It function performs four main operations:
Calls updateVaultAndCreditDelegationWeight()
to update each market's creditDelegation.weight
and the vault's totalCreditDelegationWeight
.
Calls _recalculateConnectedMarketsState()
to compute changes to various vault state parameters, such as realized/unrealized debt and USDC credit.
Updates vault storage based on the calculations from step 2.
Calls _updateCreditDelegations()
to update the totalDelegatedCreditUsd
for each market.
The problem lies in updateVaultAndCreditDelegationWeight()
, which incorrectly assigns the same value (totalCreditDelegationWeight
) to all connected markets' creditDelegation.weight
. (See code snippet below)
Later in the code, when Vault._updateCreditDelegations()
is called, it calculates the share of credit that each market receives from the vault (see code below). However, as we demonstrated earlier, during updateVaultAndCreditDelegationWeight()
, all markets' creditDelegation.weight
values are set to totalCreditDelegationWeight
. This means that creditDelegationShareX18
will always evaluate to 1 (or 1e18 in Zaros' internal precision). As a result, each market will receive the full amount of credit that the vault has available for delegation, leading to an overestimation of each market’s totalDelegatedCreditUsd
.
Check the following POC (Move the test contents to the test/
folder and run forge build && forge test --match-test POC
). Note how at the end of the testPOC
test, the total credit delegated to all markets combined is bigger than that vault's total credit capacity.
This leads to over-delegation of credit, meaning the vault does not have enough funds to cover all markets' delegated credit. Additionally, the inflated totalDelegatedCreditUsd
affects several calculations in CreditDelegationBranch
(See Impact section).
Markets will receive more delegated credit than expected because the totalDelegatedCreditUsd
value for each market will be overestimated. This overestimation impacts various functions within the CreditDelegationBranch
, such as:
CreditDelegationBranch.withdrawUsdTokenFromMarket()
: The amount that can be withdrawn is determined by the market's totalDelegatedCreditUsd
. If this value is overestimated, more USDZ will be withdrawn than should be allowed.
CreditDelegationBranch.getAdjustedProfitForMarketId()
: The adjusted profit calculation relies on the auto-deleverage factor, which in turn depends on the market's totalDelegatedCreditUsd
. Overestimating this value affects the adjusted profit of positions in that market.
Manual Review
Consider modifying Vault.updateVaultAndCreditDelegationWeight()
to ensure it correctly sets the weight values for each market connected to a vault.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.