-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WellUpgradeable#_authorizeUpgrade
should check tokens in the new implementation
#23
Comments
The Warden outlines an issue with the upgrade authorization methodology in relation to the tokens supported by the This particular submission is slightly difficult to properly assess fairly. A well's upgrade is meant to be an authorized action, meaning that a user upgrades the well they deployed. Attempting to upgrade a well with a token configuration of The main problem here is that upgrades are unrestricted entirely as demonstrated by the #52 issue group. Based on this fact as well as the ability to capitalize on an improper token configuration via swaps (i.e. reversing the reserve calculations), I am inclined to accept this submission as a valid medium-risk issue. |
alex-ppg marked the issue as satisfactory |
alex-ppg marked the issue as selected for report |
Hi @alex-ppg excellent judging. However, i believe this issue is valid but should be a low severity. The reason is based on the fact that upgrades are (or should be) an Admin task as explained by #52, so the issue of "wrong tokens" or "wrong order of tokens" would be an admin mistake . |
Hey, Here are my arguments about why this should be judged as a valid Medium issue:
|
Hi, By Admin i'm referring to the protocol itself ,so i believe trust is automatically implied. no? |
The contest page is the first source of truth, and it is specifically stated that there are no trusted roles, meaning WellUpdatable owners are not trusted as protocol admins. This, combined with the judge's statement that the misconfiguration could be capitalized, supports the decision to categorize the issue as Medium severity. |
Hi, I don't think this is true
Obviously the sponsors can shed some light on it, but If wellUpgradeable owners are untrusted then "wrong tokens" or "wrong order tokens" would be the least of the problems for anyone using such a pool. Owner can upgrade to entirely different logic while maintaining same tokens and token order and this cannot be prevented because the Aquifer is permissionless. If this is the case then i strongly advise the team against this. |
Hey @Honour-d-dev and @NicolaMirchev, thank you for your PJQA contributions. This particular issue as originally stated is tricky to judge due to the absence of trusted roles in the protocol. I am inclined to agree, however, that a malicious upgrade could result in significantly more problems than simply a token swap. The vulnerability is incidentally applicable due to upgrades requiring no privilege whatsoever as a result of #52, so I will proceed with grouping this issue there as a lower severity duplicate. To note, the Impact chapter of this exhibit does outline that the validation during an upgrade performed is weak which is why I consider it eligible as a duplicate, however, the medium-risk rating that was assigned to it showcases that the submitter was not fully aware of the implications of this weak validation. As such, a partial reward will be assigned per relevant C4 guidelines (i.e. same root cause being weak validation of upgrades but severity categorization being incorrect). |
alex-ppg marked the issue as duplicate of #52 |
alex-ppg marked the issue as partial-50 |
alex-ppg changed the severity to 3 (High Risk) |
We have the original issue submitted. |
alex-ppg marked the issue as not selected for report |
Lines of code
https://github.com/code-423n4/2024-07-basin/blob/7d5aacbb144d0ba0bc358dfde6e0cc913d25310e/src/WellUpgradeable.sol#L65-L85
Vulnerability details
Impact
The current composition of contracts and proxies is as follows:
(entry point) (delegateCalls) (minimalProxy) (delegateCalls and append immutableCallArgs) (original implementation)
ERC1967Proxy
->WellUpgradeable
->WellUpgradeable
If we want to upgrade the implementation of the
ERC1967Proxy
, we should deploy the newWellUpgradeable
and bore it from theAquifier
. The problem is that we may bore it by providing differenttokens
data when the new implementation is being cloned into minimalProxy.(NOTE There is a problem is we have same tokens, but their order is swapped) The next step is to pass the minimal proxy address to theERC1967Proxy#upgradeTo
function, which will only check if the implementation is "authorized" by theaquifer
address saved in the current minimal proxy and if the new implementation is validERC1967Proxy
implementation. If so,WellUpgradeable
minimal proxy is updated for theERC1967Proxy
. If thetokens
inside the new minimal proxy are different from the last, this may lead to a lot of problems, such as the inability for users to claim their original tokens liquidity.Another realistic scenario is to have the same tokens set, but in reversed order. This will also cause problems, because of the way
Well
reads from storage and lodsI and J
:Proof of Concept
Example:
Imagine we have a WellUpgradable with tokens set to [BEAN;USDC].
When we add liquidity, the contract will store corresponding reserves for the tokens in two consequent storage slots (RESERVES_STORAGE_SLOT -> BEAN Reserves; RESERVES_STORAGE_SLOT + 32 = USDC Reserves).
If the implementation is updated and the new minimal proxy received [USDC;BEAN] for tokens, this will result in the following miscalculations:
If we try to swap from BEAN -> USDC
i
will be 1 andj
will be 0_updatePumps
calls_getReserves
, which will read the reserves fromERC1967
storage (reserves[0] = bean reserves; reserves[1] = usdc reserves)reserves[I] + amountIn
corresponds to increasing the value of the slot responsible for usdc reserves, instead of the one, which holds beanTools Used
Manual Review
Recommended Mitigation Steps
Inise
_authorizeUpgrade
check ifnewImplmentation
tokens are the same and in the same order as the current minimal proxy.Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: