The exchange rate is adjusted unfairly in the _decreaseBalance function when a node owner lacks sufficient shares to burn.
Proof of Concept
When decreasing balance of a node owner, he may have fewer shares than what should be burned. In this case, all of his shares are burned. However, totalAssets is still reduced by the original amount of assets, so the subtracted amount from totalAssets is larger than the amount corresponding to the actually burning shares.
As a result, the exchange rate is changed unfairly, resulting in the loss of fund to remaining users.
Lines of code
https://github.com/karak-network/karak-restaking/tree/v2/src/entities/NativeVault.sol#L509-L517
Vulnerability details
Impact
The exchange rate is adjusted unfairly in the
_decreaseBalance
function when a node owner lacks sufficient shares to burn.Proof of Concept
When decreasing balance of a node owner, he may have fewer shares than what should be burned. In this case, all of his shares are burned. However,
totalAssets
is still reduced by the original amount of assets, so the subtracted amount fromtotalAssets
is larger than the amount corresponding to the actually burning shares. As a result, the exchange rate is changed unfairly, resulting in the loss of fund to remaining users.Consider the following scenario:
Alice add a validator with 32 ETH and successfully complete a snapshot, and Bob adds two validators with 32 ETH and successfully complete a snapshot.
totalAssets : 96
Slashing of 6 ETHER occurs.
totalAssets : 96 - 6 = 90 ETHER convertToAssets(balanceOf(Alice)) : 30 ETHER convertToAssets(balanceOf(Bob)) : 60 ETHER
Alice's validator loses all its funds, so
totalDeltaWei
is -32 ETHER.A snapshot is done for Alice's node.
totalDeltaWei : -32 ETHER totalAssets : 90 - 32 = 58 ETHER convertToAssets(balanceOf(Bob)) : 58 ETHER (Bob has all remaining shares.)
In the described scenario, Bob incurs an additional loss of 60 - 58 = 2 ETHER (plus 2 ETHER from slashing).
Tools Used
Manual review
Recommended Mitigation Steps
Only the amount corresponding to burning shares should be subtracted from
totalAssets
.Assessed type
Other