LiquidationKeeper::checkUpkeep
and LiquidationKeeper::performUpkeep
due to encoding mistakeIncompatibility between LiquidationKeeper::checkUpkeep
and LiquidationKeeper::performUpkeep
due to an encoding mistake
The LiquidationKeeper::checkUpkeep
and LiquidationKeeper::performUpkeep
are two key functions utilized by the LiquidationKeeper to carry out liquidations across various markets.
The issue is with how the performData
used by LiquidationKeeper::performUpkeep
is encoded by LiquidationKeeper::checkUpkeep
. The function encodes the performData differently (with address(this
) from what is expected to be decoded and used in performUpkeep.
The encoding:
Encodes a uint128 array with the address(this).
https://github.com/Cyfrin/2024-07-zaros/blob/69ccf428b745058bea08804b3f3d961d31406ba8/src/external/chainlink/keepers/liquidation/LiquidationKeeper.sol#L71-L87
The decoding:
Only expects only a uint128 array
https://github.com/Cyfrin/2024-07-zaros/blob/69ccf428b745058bea08804b3f3d961d31406ba8/src/external/chainlink/keepers/liquidation/LiquidationKeeper.sol#L101
The LiquidationKeeper::performUpkeep
won't work due to incompatibility issue with LiquidationKeeper::checkUpkeep
.
Manual
Encode the performData
correctly
AccountNFT inherits the non-upgradable version of the Openzeppelin library, restricting its full upgradability with the PerpEngine.
Zaros is an upgradeable smart contract system with functionalities for upgrading the different parts of the system. However, one key part of it that isn't upgradable is the AccountNFT contract. AccountNFT is an ERC721Enumerable contract that utilizes Openzeppelin. The problem is the contract inherits the non-upgradable version of the library, which is not the recommended approach to using the Oppenzeppelin library on upgradable systems.
Area of interest: https://github.com/Cyfrin/2024-07-zaros/blob/69ccf428b745058bea08804b3f3d961d31406ba8/src/account-nft/AccountNFT.sol#L9
The GlobalConfigurationBranch::setTradingAccountToken
function which enables the admin to update the address of the account token NFT contract, is a clear suggestion that the protocol might desire to upgrade the AccountNFT contract in the future. But using the setTradingAccountToken
to make such upgrades, can expose the system to several risks, considering how intertwined with PerpEngine the contract is. For instance, there could be a mismatch of users and their trading accounts after such an upgrade.
Inability to upgrade the AccountNFT contract with the rest of PerpEngine.
Manual
Inherit the upgradable version of Openzeppelin ERC721Enumerable.
Low
The protocol currently does not enforce USDz as a collateral token. This omission can result in inaccurate accounting of trading account margin balances.
On Zaros, profitable traders receive USDz when their positions are settled, and this amount is added to their margin balance. This setup necessitates USDz as a required collateral token to accurately reflect trading account margin balances. However, the protocol fails to enforce this requirement, potentially leading to undercounted margin balances. Consequently, traders may face difficulties withdrawing their profits. The automatic issuance of PnL in USDz mandates support for USDz as a margin token, yet this requirement is not enforced in the code. This oversight increases the risk of compromising traders' positions due to unforeseen circumstances, potentially resulting in false liquidation of trading accounts.
Undercounting of trading account collateral balances can lead to false liquidation of accounts.
Manual
It is recommended to enforce the inclusion of USDz as an acceptable collateral type in the protocol's codebase. This change should be made mandatory and immutable to ensure accurate accounting of trading account margin balances and prevent potential false liquidations.
The current referral code system allows users to change their referral code each time they create a new account, leading to a potential loss of rewards for the original affiliate who onboarded the user.
In the current system, a trader can specify a different referral code each time they create a new account. Since the protocol only recognizes one affiliate per user, if a user chooses a different affiliate when creating a new account, the original affiliate who did the initial work of onboarding the user misses out on the rewards that should have been attributed to them.
Loss of rewards for network affiliates, which can discourage their continued participation in the referral program.
Manual
Implement stricter rules for referral codes, such as binding the user to the original affiliate who onboarded them or limiting the ability to change referral codes across accounts.
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.