Y2k Finance contest - rvierdiiev's results

A suite of structured products for assessing pegged asset risk.

General Information

Platform: Code4rena

Start Date: 14/09/2022

Pot Size: $50,000 USDC

Total HM: 25

Participants: 110

Period: 5 days

Judge: hickuphh3

Total Solo HM: 9

Id: 162

League: ETH

Y2k Finance

Findings Distribution

Researcher Performance

Rank: 15/110

Findings: 3

Award: $782.96

🌟 Selected for report: 1

πŸš€ Solo Findings: 0

Findings Information

🌟 Selected for report: rvierdiiev

Also found by: async

Labels

bug
2 (Med Risk)
sponsor disputed
selected for report

Awards

693.5137 USDC - $693.51

External Links

Lines of code

https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L345-L359 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L136 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L152 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L187-L190

Vulnerability details

Impact

VaultFactory allows admin to change controller for marketId(hedge and risk vaults) using VaultFactory.changeController. This method then set controller to both vaults. This address is important for Vault contract as it allows to call different functions.

VaultFactory take care about different pair vaults through indexVaults mapping. Controller can get info about pairs vaults only through the correct VaultFactory that is provided to Controller in constructor.

It's possible that VaultFactory.changeController will set controller whose vaultFactory field is not equal to current VaultFactory. That means that when Controller.triggerDepeg or Controller.triggerEndEpoch will be called they will not be able to find the market. So current controller will not be able to call hedge and risk vaults.

Proof of Concept

This is how the controller is set to vaults. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L345-L359

Controller depends on VaultFactory to find vault for market. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L136 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L152

Tools Used

Use same check as you used in VaultFactory.createNewMarket https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L187-L190

#0 - HickupHH3

2022-11-03T14:38:06Z

Agree with the issue that the incoming Controller's VaultFactory should be verified to be the VaultFactory's address itself. Otherwise, there's a loss of functionality.

  1. Cache getLatestPrice(vault.tokenInsured()) into variable as you use it int 2 places. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L96-L99
  2. Use external modifier instead of public if you don’t call method from a contract to save deployment gas. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L148 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L217 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L277 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L287 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L295 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L307 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L336 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L350 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L360 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L439 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L186 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L180 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L253 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L295 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L308 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L327 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L345 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L366 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L385
  3. Use if (answer > 0) to save gas. Do not create Boolean variable. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L277-L280
  4. Use > instead of !=0 to save gas. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L157 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L159 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L215 https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L217
  5. Use ++i instead of i++ for loops. Also cache epochsLength() into variable. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L443

#0 - HickupHH3

2022-11-09T11:57:38Z

Cache getLatestPrice(vault.tokenInsured()) into variable as you use it int 2 places. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L96-L99

Multiple calls: 11k gas saved

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax Β© 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter