Delegated amounts can be forcefully removed from anyone in the TwabController
The sponsor function in the Vault contract allowed anyone to force another user's delegation to the sponsor address by depositing zero tokens, removing their delegated power. An attacker could do this for every user, making the total delegated supply zero, and then hold all delegated power to manipulate the lottery.
Submitted by 0xkasper, also found by minhtrng, qpzm, Aymen0909, Jeiwan, GREY-HAWK-REACH, 0xStalin, 0xbepresent, 3docSec, and Co0nan
The sponsor function in the Vault.sol contract allows anyone to remove another user’s delegation by forcing them to delegate to the sponsor address. _sponsor will deposit some amount from the caller for the target user and then force a delegation to the sponsor address (address(1)).
However, this amount can just be 0 and so it becomes a function to simply force a removal of a delegation. The full delegated power gets removed, because delegations to the sponsor address are not tracked.
As such, it becomes possible to call the sponsor function for every user and make the total delegated power supply in the TwabController equal to 0. The attacker can then be the only one with some delegated amount that is equal to 100% of the total supply, manipulating the process of the lottery.
Rectifying the delegation requires manual interaction from the user and the exploit can be repeated anytime and continuously, further manipulating the values in the TwabController.
Proof of Concept
function testPoCDelegateRemoval() public {
address SPONSORSHIP_ADDRESS = address(1);
uint96 BALANCE = 100_000_000 ether;
token.approve(address(vault), BALANCE);
vault.deposit(BALANCE, address(this));
assertEq(address(this), twab_controller.delegateOf(address(vault), address(this)));
assertEq(BALANCE, twab_controller.delegateBalanceOf(address(vault), address(this)));
// As attacker, call sponsor with 0 amount and victim address
vm.prank(address(0xdeadbeef));
vault.sponsor(0, address(this));
// Delegated balance is now gone
assertEq(SPONSORSHIP_ADDRESS, twab_controller.delegateOf(address(vault), address(this)));
assertEq(0, twab_controller.delegateBalanceOf(address(vault), address(this)));
assertEq(0, twab_controller.delegateBalanceOf(address(vault), SPONSORSHIP_ADDRESS));
}
Tools Used
VSCode, Foundry.
Recommended Mitigation Steps
The sponsor function should only accept deposits if the receiver has already delegated to the sponsorship address. Otherwise, the deposit is accepted, but the delegation should not be forced.
asselstine (PoolTogether) confirmed via duplicate issue #393
PierrickGT (PoolTogether) commented via duplicate issue #393:
I’ve removed the
receiverparam in the following PR: https://github.com/GenerationSoftware/pt-v5-vault/pull/19.This way, only the
msg.sendercan sponsor the Vault by depositing into it and delegating to the sponsorship address, if it is not already the case. If the user wants to deposit on behalf of another user, they can still use thedepositfunction. Funds will then be delegated to any address set by thereceiver.
Removed recipient param. PR: https://github.com/GenerationSoftware/pt-v5-vault/pull/19
Status: Mitigation error. Full details in report from rvierdiiev, and in the Mitigation Review section below.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The sponsor function allowed a zero-amount deposit and unconditionally forced the recipient's delegation to the sponsor address, without checking if the recipient had already delegated there.
Impact
An attacker could remove all delegated power from every user, become the sole holder of delegated power, and manipulate the lottery; the exploit could be repeated continuously and required manual user action to fix.
What the attacker needed
Attacker has a small or zero token balance; victim has delegated tokens
The fix
The sponsor function was changed to remove the receiver parameter, so only the caller can sponsor themselves; if depositing for another user, the deposit function is used and delegation is not forced.
How it was found
- The victim deposits tokens and delegates to themselves.
- The attacker calls the sponsor function with zero amount and the victim's address.
- The victim's delegation is changed to the sponsor address and their delegated balance becomes zero.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this system, users can delegate their voting or lottery power to someone else. A function meant to let sponsors deposit tokens on behalf of others also forced the recipient to delegate to the sponsor, even if the deposit was zero. An attacker could call this for any user, wiping out their delegation and gaining control of the total delegated power.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.