Skip to content

Incorrect Update in undelegate Method: Amount Should Be Decreased #724

@GingerLiu123

Description

@GingerLiu123

Summary:
In the undelegate method, the amount of a delegatee’s delegation is incorrectly increased rather than decreased, which causes issues in the delegation amount tracking.

Root Cause:
In the undelegate method, instead of subtracting the undelegated amount from the delegatee’s amount, the code mistakenly adds the amount to delegateeDelegations[delegatee].amount. This is incorrect because when a delegator undelegates, the amount should be removed from the delegatee’s total amount, not added.

Reproduce Steps:
1. A delegator delegates a certain amount to a delegatee.
2. The reward starts, and delegators’ shares are updated.
3. The delegator calls the undelegate function to undelegate a portion of their staked tokens.
4. Upon execution, the delegatee’s amount incorrectly increases due to the line delegateeDelegations[delegatee].amount += amount; in the undelegate function.
5. The expected behavior should be to decrease the delegateeDelegations[delegatee].amount by the undelegated amount.

code in L2Staking.sol with PR693

uint256 _tshare = delegateeDelegations[delegatee].share;
uint256 _tAmount = delegateeDelegations[delegatee].amount;
uint256 _uShare = delegatorDelegations[delegatee][_msgSender()].share;

delegatorDelegations[delegatee][_msgSender()].share = _uShare - (amount * _tshare) / _tAmount;

delegateeDelegations[delegatee].amount += amount;
delegateeDelegations[delegatee].share = _tshare - (amount * _tshare) / _tAmount;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions