VaultFactoryV2#changeTreasury misconfigures the vault
The changeTreasury function in VaultFactoryV2 set the vault treasury to the factory's own treasury variable instead of the address passed in by the caller. This could make the controller's triggerDepeg call fail when sending tokens, so a valid depeg event might not be paid out in time.
Source: https://github.com/sherlock-audit/2023-03-Y2K-judging/issues/435
Found by
0x52, 0xnirlin, Dug, ElKu, TrungOre, ast3ros, holyhansss, ni8mare, roguereddwarf, spyrosonic10, volodya, warRoom
Summary
VaultFactoryV2#changeTreasury misconfigures the vault because the setTreasury subcall uses the wrong variable
Vulnerability Detail
function changeTreasury(uint256 _marketId, address _treasury)
public
onlyTimeLocker
{
if (_treasury == address(0)) revert AddressZero();
address[2] memory vaults = marketIdToVaults[_marketId];
if (vaults[0] == address(0) || vaults[1] == address(0)) {
revert MarketDoesNotExist(_marketId);
}
IVaultV2(vaults[0]).whiteListAddress(_treasury);
IVaultV2(vaults[1]).whiteListAddress(_treasury);
IVaultV2(vaults[0]).setTreasury(treasury);
IVaultV2(vaults[1]).setTreasury(treasury);
emit AddressWhitelisted(_treasury, _marketId);
}
When setting the treasury for the underlying vault pair it accidentally use the treasury variable instead of _treasury. This means it uses the local VaultFactoryV2 treasury rather than the function input.
ControllerPeggedAssetV2.sol#L111-L123
premiumVault.sendTokens(_epochId, premiumFee, treasury);
premiumVault.sendTokens(
_epochId,
premiumTVL - premiumFee,
address(collateralVault)
);
// strike price is reached so collateral is still entitled to premiumTVL - premiumFee but looses collateralTVL
collateralVault.sendTokens(_epochId, collateralFee, treasury);
collateralVault.sendTokens(
_epochId,
collateralTVL - collateralFee,
address(premiumVault)
);
This misconfiguration can be damaging as it may cause the triggerDepeg call in the controller to fail due to the sendToken subcall. Additionally the time lock is the one required to call it which has a minimum of 3 days wait period. The result is that valid depegs may not get paid out since they are time sensitive.
Impact
Valid depegs may be missed due to misconfiguration
Code Snippet
ControllerPeggedAssetV2.sol#L51-L138
Tool used
Manual Review
Recommendation
Set to _treasury rather than treasury.
Discussion
3xHarry
good catch!
3xHarry
fix PR: https://github.com/Y2K-Finance/Earthquake/pull/132
IAm0x52
Fix looks good. setTreasury now correctly uses _treasury rather than treasury
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The function passed the contract's own treasury state variable to setTreasury instead of the _treasury function argument.
Impact
Valid depegs may be missed because the misconfigured treasury can make the controller's sendTokens subcall fail, and the time lock has a minimum three-day wait.
What the attacker needed
Caller must be the time locker; market must exist
The fix
The code was fixed so setTreasury uses the _treasury argument rather than the treasury variable.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A factory contract is meant to update the treasury address on a pair of vaults. Instead of using the new address given to the function, the code used a different, stored address. That wrong address can break later payouts when the system tries to send funds.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.