QA Report #30
Labels
bug
Something isn't working
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Codebase Impressions & Summary
Overall, code quality for the PrePO contracts is very high. The contracts are well modularised and are clear enough to follow. The provided documentation was adequate in explaining key concepts like the pricing formulas for the long and short tokens, and valuation ranges. Special mention for providing a video walkthrough as well!
The contracts have 100% coverage, which unfortunately isn’t the norm. Kudos for having adequate tests to fully test the core contracts!
In total, there were 1 high, 2 medium and 5 low findings reported. The high severity issue pertains to a vault related edge case that describes a scenario where a malicious actor is able to DOS other users by artificially inflating the value of a single unit of collateral token. That aside, the quantity of other findings appropriately reflect the quality of the source code as it conforms closely to smart contract best practices.
Low Severity Findings
L01: Ensure
_ceilingValuation
>_floorValuation
Line References
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarket.sol#L78-L79
Description
No check was performed that the
_ceilingValuation
exceeds_floorValuation
. While it bears no impact to functionality, it would be ideal to ensure that the valuations are correctly set.Recommended Mitigation Steps
L02: PrePOMarketFactory’s
createMarket()
has different parameter order in interface and contractLine References
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarketFactory.sol#L45-L46
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/interfaces/IPrePOMarketFactory.sol#L52-L53
Description
The
_governance
and_collateral
parameters are swapped in the interface and implementation. There is thankfully a check to ensure that the collateral is whitelisted before the market can be created (so market creation would have reverted). Otherwise, the variables would have been set incorrectly.Recommended Mitigation Steps
Swap
_governance
and_collateral
parameters in the interface.L03: Duplicate
shortToken
param natspec inIPrePOMarket
Line References
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/interfaces/IPrePOMarket.sol#L18-L19
Description
shortToken
parameter is duplicated.Recommended Mitigation Steps
Remove either instance.
L04:
_delayedWithdrawalExpiry
adds unnecessary complexity and potentially griefs usersLine References
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L124-L127
Description
The main motivation for
_delayedWithdrawalExpiry
is to mitigate flash loan attacks. In our opinion, having a validity period for withdrawals provides negligible protection.The
_delayedWithdrawalExpiry
variable potentially griefs a majority of users if it is set a low value (1 block for example), where it becomes difficult for the average user to perform withdrawals.Recommended Mitigation Steps
Remove
_delayedWithdrawalExpiry
and its corresponding check. A better way to mitigate flash loans is to prevent users from depositing and withdrawing in the same block.L05: Set
_governance
and_treasury
in factoryLine References
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarketFactory.sol#L45-L46
Description
The governance and treasury addresses are passed in as parameters whenever a market is created. It would be safer to save and retrieve these addresses to / from storage to avoid input errors.
Note that we are aware that it is mentioned in the README that gas optimization will not be awarded for struct packing but this low issue pertains to having a canonical source to retrieve the
_governance
and_treasury
address (within the factory) to make it impossible for the owner to accidentally use the wrong address.Recommended Mitigation Steps
To counter the dreaded stack too deep problem, we pack the parameters into a struct. This avoids the need to first initialize the treasury address as the governance address as well.
Suggestions
S01: Make
Collateral
contract EIP4626 CompliantDescription
The EIP4626 standard has just been finalised. We recommend making the
Collateral
contract compliant to the standard. As our favourite optimisoooor @t11s succinctly puts it, “there are a terrifying amount of pitfalls that you can run into when writing a vault from scratch, i learned this first hand working on them at rari. If you want to sleep at night, skip that bs and use 4626”References
Twitter thread by @t11s shilling EIP4626
Solmate’s base implementation
OpenZeppelin’s draft EIP
The text was updated successfully, but these errors were encountered: