Submitted by dirk_y, also found by KupiaSec, Jeiwan, 0xkasper, 0xbepresent, bin2chen, rvierdiiev, and xuwinnie
https://github.com/GenerationSoftware/pt-v5-twab-controller/blob/0145eeac23301ee5338c659422dd6d69234f5d50/src/TwabController.sol#L596-L599
https://github.com/GenerationSoftware/pt-v5-twab-controller/blob/0145eeac23301ee5338c659422dd6d69234f5d50/src/TwabController.sol#L648-L664
The default delegate value for a user is address(0), which maps to the user delegating to themselves. If a user had delegated to another address and wanted to reset their delegated balance back to themselves, they would lose all of their funds contributed to the vault.
As mentioned above, the default behaviour for a user is that they delegate their balance to themselves, where the actual default value in storage is the 0 address:
When a user wants to delegate their balance, they call delegate in TwabController.sol and specify which vault they want to delegate the balance of and to which address they want to delegate to. This calls _delegate under the hood:
If a user wanted to reset the delegation to themselves, they would specify _to as address(0). However, the issue with this is that the underlying _transferDelegateBalance call will mistakenly move the delegated user funds to the 0 address.
At this point, the user might try to call delegate again with their actual address; however, now the (_to == _currentDelegate) check will be true and revert because of the behaviour specified earlier. The user also cant delegate to any other address because they dont own their own delegate balance anymore. Their funds are officially lost forever.
Below is a change to the existing test suite that can be executed with forge test -vvv --match-path test/unit/Vault/Withdraw.t.sol to demonstrate this issue:
Foundry
The simplest way to fix this issue is to prevent delegating back to the 0 address. If a user delegates away from the default, then they can delegate back to themselves by specifying their own address:
Invalid Validation
asselstine (PoolTogether) confirmed via duplicate issue #293
Picodes (judge) commented via duplicate issue #293:
PoolTogether mitigated:
Status: Mitigation confirmed with comments. Full details in reports from 0xStalin, dirk_y and rvierdiiev.
