AfEth collaterals cannot be balanced after ratio is changed
The AfEth contract allows the ratio between its two collateral types to be changed, but there is no mechanism to rebalance the existing assets to match the new ratio. An attacker could exploit this by depositing after a ratio change, knowing that the actual balance does not reflect the intended ratio, potentially gaining an unfair advantage.
Submitted by adriro
The AfEth ratio between the collaterals can be modified but there is no direct way to balance the assets to follow the new ratio.
Impact
The AfEth contract contains a configurable parameter ratio that indicates the intended balance between the two collaterals, SafEth and the Votium strategy. For example, a value of 3e17 means that 30% of the TVL should go to SafEth, and 70% should go to Votium.
This ratio is followed when new deposits are made. The deposited ETH is splitted according to the ratio and channeled in proportion to each collateral. The ratio is also checked when rewards are deposited to direct them to the proper collateral.
The ratio can also be modified by the admins of the protocol using the setRatio() function.
https://github.com/code-423n4/2023-09-asymmetry/blob/main/contracts/AfEth.sol#L90-L92
90: function setRatio(uint256 _newRatio) public onlyOwner {
91: ratio = _newRatio;
92: }
However, there is no way to balance the assets once a new ratio is defined. The implementation will need to rely on new deposits and reward compounding to slowly correct the offset, which may take a lot of time and may be impractical for most cases.
Proof of Concept
Let’s assume the protocol is deployed with a ratio of 3e17.
- Deposits follow the configured ratio and split the TVL in 30% for SafEth and 70% for Votium.
- At some point, the protocol decides to switch to 50%-50% and sets a new ratio of
5e17. - New deposits will follow the new ratio and split 50% for each collateral, but these have potentially accumulated a large amount of TVL with the previous split. The existing difference will continue, new deposits can’t correct this offset.
Recommendation
Similar to how it is done in SafEth, the AfEth contract could have a rebalancing function which withdraws the proper amount from one collateral and deposits it in the other collateral, in order to correct the offset and target the new configured ratio. This function should be admin controlled, and support slippage control to correctly handle potentially large amounts of swaps.
An alternative could be to also correct a potential deviation in the ratio using new deposits. This could help speed up the correction by not only relying on rewards, but will also endure a delay in the convergence.
elmutt (Asymmetry) acknowledged, but disagreed with severity and commented:
It’s hard to rebalance because of the locked convex. We have discussed this internally and consider it an acceptable risk for now so im acknowledging this issue instead of confirming.
0xleastwood (Judge) commented:
In this instance, the implementation of the ratio mechanism with respect to rebalancing between
vEthandsafEthis a design decision that has flaws and potentially needs to be redesigned. However, the warden has identified that the current implementation does not enforce the ratio as what might be expected from users. For example, once the ratio has been changed, it takes some time for this to be fully in effect and as a result, users may be depositing into the protocol with the expectation of some ratio but that isn’t what is currently in place. Performing instant rebalances is a design decision done bysafEthso maybe this is the right way to be consistent? Even if users are potentially retroactively affected, provided the delay is sufficient, users should be able to exit the protocol if they do not agree with the new ratio.For these reasons, I would still like to keep this issue as medium severity because I think this mechanism is ultimately flawed and can be realistically improved. My decision is final on this.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the contract lacks a rebalancing function to adjust existing collateral when the ratio is changed, relying only on new deposits and rewards to correct the offset.
Impact
Users may deposit expecting a certain ratio but the actual ratio remains off, potentially causing unfairness; the text does not claim direct financial loss, and the admin acknowledged it as an acceptable risk.
What the attacker needed
Admin changes ratio; users deposit after change
The fix
The contract should have an admin-controlled rebalancing function that withdraws from one collateral and deposits into the other to correct the offset, with slippage control.
How it was found
- Deploy the protocol with a ratio of 3e17 (30% SafEth, 70% Votium).
- Deposits follow the configured ratio and split the TVL accordingly.
- Admin changes the ratio to 5e17 (50%-50%).
- New deposits follow the new ratio, but existing assets remain unbalanced, so the overall ratio stays off.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
AfEth is a smart contract that holds two types of collateral (SafEth and Votium). The protocol sets a target ratio (e.g., 30% SafEth, 70% Votium) that new deposits follow. However, if the ratio is changed, the existing assets are not automatically rebalanced, so the actual ratio remains off until enough new deposits or rewards slowly correct it. This means users might deposit expecting one ratio but get another, which could be unfair.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.