Submitted by leastwood
The maintenanceInvariant modifier in Collateral aims to check if a user meets the margin requirements to withdraw collateral by checking its current and next maintenance. maintenanceInvariant inevitably calls AccountPosition.maintenance which uses the oracles price to calculate the margin requirements for a given position. Hence, if the oracle has not synced in a long time, maintenanceInvariant may end up utilising an outdated price for a withdrawal. This may allow a user to withdraw collateral on an undercollaterized position.
https://github.com/code-423n4/2021-12-perennial/blob/main/protocol/contracts/collateral/Collateral.sol#L67-L76
https://github.com/code-423n4/2021-12-perennial/blob/main/protocol/contracts/collateral/Collateral.sol#L233-L241
https://github.com/code-423n4/2021-12-perennial/blob/main/protocol/contracts/product/types/position/AccountPosition.sol#L71-L75
Manual code review.
Consider adding settleForAccount(msg.sender) to the Collateral.withdrawTo function to ensure the most up to date oracle price is used when assessing an accounts margin requirements.
kbrizzle (Perennial) confirmed:
Alex the Entreprenerd (judge) commented:
