Slashing may sometimes fail for stETH vaults due to its 1-2 wei corner problem #56
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-07-karak/blob/f5e52fdcb4c20c4318d532a9f08f7876e9afb321/src/SlashingHandler.sol#L56
Vulnerability details
Impact
Slashing stETH vaults may sometimes fail and always revert due to its innate 1-2 wei corner issue.
Proof of Concept
The protocol plans on working with all ERC20 tokens, and that includes stETH. stETH however, has intrinsic rounding down problems. It's a known issue, and the stETH balance of an account could be lower of 1-2 wei because of rounding down. As such the amount received during transfer can be short 1 or 2 wei. This isn't much, but in context of slashing, in which an amount is transferred from the vault is also expected to be the amount transferred to address(0), this can mean unexpected failure of the
handleSlashing
function, potentially dossing/delaying slashing of malicious operators.In SlashingHandler.sol, we see the
handleSlashing
function. The function transfers the amount of tokens to slash from the vault to the handler. After, the function attempts to transfer the "same" amount address(0).Final effect
As explained that the amount received during transfer can be 1 or 2 wei shorter, the function's attempt to send the same amount fails and slashing is not completed.
Runnable POC
The gist link below contains modifications of some of the provided tests, including a mock token that simulates stETH losing 1 wei upon transfers, and instructions on how to run them.
https://gist.github.com/ZanyBonzy/033ee1ca8aae4969a676d8ce83a68c9d
The expected should look like this with an error that reads ERC20InsufficientBalance
Tools Used
Manual Review
Recommended Mitigation Steps
Recommend querying token balances before and after every transfer, and transferring the difference between them instead.
Assessed type
Token-Transfer
The text was updated successfully, but these errors were encountered: