Price of sfrxEth derivative is calculated incorrectly
The ethPerDerivative function in the SfrxEth derivative contract multiplied by 10^18 and divided by the price oracle, instead of the reverse, causing incorrect pricing of sfrxEth. This could lead to users receiving too much or too little safEth when staking, or increased slippage and potential locked funds when withdrawing.
Submitted by lukris02, also found by joestakey, rbserver, qpzm, RedTiger, Bauer, T1MOH, dec3ntraliz3d, HollaDieWaldfee, reassor, and koxuan
In the ethPerDerivative(), the calculated frxAmount is multiplied by (10 ** 18) and divided by price_oracle, but it must be multiplied by price_oracle and divided by (10 ** 18).
The impact is severe as ethPerDerivative() function is used in stake(), one of two main functions a user will interact with. The value returned by ethPerDerivative() affects the calculations of mintAmount. The incorrect calculation may over or understate the amount of safEth received by the user.
ethPerDerivative() is also used in the withdraw() function when calculating minOut. So, incorrect calculation of ethPerDerivative() may increase/decrease slippage. This can cause unexpected losses or function revert. If withdraw() function reverts, the function unstake() is unavailable => assets are locked.
Proof of Concept
We need to calculate: (10 ** 18) sfrxEth = X Eth.
For example, we convertToAssets(10 ** 18) and get frxAmount = 1031226769652703996. price_oracle returns 998827832404234820. So, (10 ** 18) frxEth costs 998827832404234820 Eth. Thus, (10 ** 18) sfrxEth costs frxAmount * price_oracle / 10 ** 18 = 1031226769652703996 * 998827832404234820 / 10 ** 18 Eth (1030017999049431492 Eth).
But this function:
function ethPerDerivative(uint256 _amount) public view returns (uint256) {
uint256 frxAmount = IsFrxEth(SFRX_ETH_ADDRESS).convertToAssets(
10 ** 18
);
return ((10 ** 18 * frxAmount) /
IFrxEthEthPool(FRX_ETH_CRV_POOL_ADDRESS).price_oracle());
}
calculates the cost of sfrxEth as 10 ** 18 * frxAmount / price_oracle = 10 ** 18 * 1031226769652703996 / 998827832404234820 Eth (1032436958800480269 Eth). The current difference ~ 0.23% but it can be more/less.
Recommended Mitigation Steps
Change these lines:
return ((10 ** 18 * frxAmount) /
IFrxEthEthPool(FRX_ETH_CRV_POOL_ADDRESS).price_oracle());
to:
return (frxAmount * IFrxEthEthPool(FRX_ETH_CRV_POOL_ADDRESS).price_oracle() / 10 ** 18);
toshiSat (Asymmetry) disputed via duplicate issue #698
To protect against oracle attacks we assume FRX is 1:1 with ETH and revert if the oracle says otherwise since there is no chainlink for FRX.
Status: Mitigation confirmed with comments. Full details in reports from d3e4 and adriro.
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
Impact
The incorrect price could over- or understate the safEth minted when staking, and could increase slippage or cause withdrawals to revert, potentially locking funds.
What the attacker needed
None
The fix
The calculation should be changed to multiply frxAmount by the price oracle and divide by 10^18; the team later mitigated by assuming FRX is 1:1 with ETH and reverting if the oracle disagrees.
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.
This smart contract calculates how much Ethereum (ETH) a certain amount of a derivative token (sfrxEth) is worth. It used the wrong formula, multiplying and dividing by the wrong numbers, so the price it reported was off by a small percentage. That could cause users to get a wrong amount of shares when they put money in, or lose money when they take it out.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.