You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The share price of a given operator pool is an important component in our staking protocol, we use the share price to convert balance to share during deposit/withdraw/unlock.
The share price is added to the state during epoch transition except for a few cases:
The operator is pending slash or slashed, or deregistered
The operator has no new deposit/withdraw/reward in the epoch
And we make an assumption that if it is not the above cases and the share price is not available then we assume the epoch is not ending yet.
Issue
Unfortunately, there are edge cases that make the assumption broken, where we have insufficient checks to the withdraw/deposit amount and the user can successfully request withdraw/deposit 0 amount of funds, and during epoch transition, the share price won't be added for this operator.
This causes issues with withdrawal. The zero-withdrawal will create a WithdrawalInShares item and when the next non-zero withdraw comes, since we can't find the share price and thus can't convert the WithdrawalInShares to WithdrawalInBalance we assume the epoch is not ending yet and merge the non-zero withdraw to the previous WithdrawalInShares item even they are initiated in different epoch. Moreover the WithdrawalInShares refers to an epoch whose share price doesn't exist so even if the unlocking period is passed, the unlock_fund will still fail with MissingWithdrawal error.
For deposit, it has a similar situation where the share price is missing and merging deposits from different epochs, but when it merging deposits it uses the current epoch as the effective_domain_epoch instead of the zero-deposit epoch which doesn't have the share price.
Solution
Add check to withdraw and deposit to reject zero amount request
Explicitly check the share price existence when converting the previous epoch deposit/withdraw, and return error if the share price is unavailable while the epoch it refers to has already ended.
Migration on Taurus
In Taurus, a zero-withdrawal happens in block #1,434,952, in order to fix the issue we may need to manually insert share price in migration of the new runtime upgrade.
The missing share price is Operator 1, domainEpoch: [0, 8146], currentTotalShares: 186,504,781,826,675,866,347,230 / currentTotalStake: 186,505,937,012,273,200,789,523
The share price of a given operator pool is an important component in our staking protocol, we use the share price to convert balance to share during deposit/withdraw/unlock.
The share price is added to the state during epoch transition except for a few cases:
And we make an assumption that if it is not the above cases and the share price is not available then we assume the epoch is not ending yet.
Issue
Unfortunately, there are edge cases that make the assumption broken, where we have insufficient checks to the withdraw/deposit amount and the user can successfully request withdraw/deposit
0
amount of funds, and during epoch transition, the share price won't be added for this operator.This causes issues with withdrawal. The zero-withdrawal will create a
WithdrawalInShares
item and when the next non-zero withdraw comes, since we can't find the share price and thus can't convert theWithdrawalInShares
toWithdrawalInBalance
we assume the epoch is not ending yet and merge the non-zero withdraw to the previousWithdrawalInShares
item even they are initiated in different epoch. Moreover theWithdrawalInShares
refers to an epoch whose share price doesn't exist so even if the unlocking period is passed, theunlock_fund
will still fail withMissingWithdrawal
error.For deposit, it has a similar situation where the share price is missing and merging deposits from different epochs, but when it merging deposits it uses the current epoch as the
effective_domain_epoch
instead of the zero-deposit epoch which doesn't have the share price.Solution
WithdrawStake::All
can still be zero)Migration on Taurus
In Taurus, a zero-withdrawal happens in block
#1,434,952
, in order to fix the issue we may need to manually insert share price in migration of the new runtime upgrade.The missing share price is
Operator 1, domainEpoch: [0, 8146], currentTotalShares: 186,504,781,826,675,866,347,230 / currentTotalStake: 186,505,937,012,273,200,789,523
cc @vedhavyas @teor2345
The text was updated successfully, but these errors were encountered: