-
Notifications
You must be signed in to change notification settings - Fork 0
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
Double Decrease of totalAssets During Slashing and Snapshot #250
Comments
Could someone please take a look at this? |
This one is similar to the code-423n4/2024-07-karak-findings#31 As far as I understood they can be duplicates. @MiloTruck Can you please check it? |
This is invalid.
This is incorrect. If Karak slashing occurs, the validator on the beacon chain will still have 32 ETH staked, so |
Thank you for the answer, @MiloTruck. To fully understand, I was thinking about cases where the user does not have 32 ETH in the Beacon Chain, such as in the case of an initial penalty (it is being issued immediately) In this case, the balance would be 31 ETH, so the delta -1 ETH, so at the end, the shares would be 31, but total assets would also be 30. Am I right? |
I think you're confusing between Karak slashing and beacon chain slashing. |
Yeah, I thought the DSS should slash the user when they are penalized/slashed from the beacon chain. |
Lines of code
https://github.com/code-423n4/2024-07-karak/blob/f5e52fdcb4c20c4318d532a9f08f7876e9afb321/src/NativeVault.sol#L299-L318
https://github.com/code-423n4/2024-07-karak/blob/f5e52fdcb4c20c4318d532a9f08f7876e9afb321/src/NativeVault.sol#L507-L515
Vulnerability details
The
slashAssets()
and_decreaseBalance()
functions in theNativeVault.sol
both reduce thetotalAssets
in the contract, causing an incorrect decrease in the total assets. This results in double-counting the slashed assets, leading to an incorrect final state of total assets and shares.In the current implementation, when
slashAssets
is called, it decreasestotalAssets
by the slashed amount. Following this, and in case there is still no assets in the node to be withdrawn, during the snapshot process, at the end_decreaseBalance
is called, which again decreasestotalAssets
by the same amount, resulting in a double reduction, but shares are being burnt once, only in the_decreaseBalance
function.Impact
This bug causes an incorrect final state of
totalAssets
andtotalShares
. For example, starting with 32 ETH assets and 32 shares, if 2 ETH is slashed, the system ends up with 28 ETH (32-2-2) and 30 (32-2) shares, leading to an inaccurate representation of the vault's state. This can affect user balances and protocol functionality, potentially causing financial discrepancies and loss of trust in the system.Proof of Concept
Let's assume the user has 32 ETH assets staked in the beacon chain and 32 shares and is slashed 2 ETH:
Here we have 30 ETH
totalassets
, and still 32 shares.Then calling
startSnapshot
it started calculating which amount it can slash, but as there is no assets in the node, the function processes with 0s:After this the user calls
validateSnapshotProofs()
, which in turn calls_updateSnapshot()
this in turn calls_updateBalance()
with -2 delta, and this calls_decreaseBalance()
:So now the shares will be 30 (30-2) and
totalAssets
decreased twice 28 (32-2-2) ETH.Tools Used
Manual review.
Recommended Mitigation Steps
Ensure that
totalAssets
is only decreased once during the entire slashing and snapshot process.Assessed type
Other
The text was updated successfully, but these errors were encountered: