Balance invariant between the individual and total twabs can be broken
The TwabController._transferBalance function mishandles transfers to the SPONSORSHIP_ADDRESS, causing the total balance for a vault to decrease even though it should not. This breaks the invariant between individual and total twabs, skewing the odds in favour of winning and draining the reserve faster than intended.
Submitted by minhtrng
An edge case in the TwabController._transferBalance can cause the total balance for a vault account to decrease; although, it did not actually decrease. This will cause the sum of the individual delegateBalances for a vault to be greater than the registered total for that vault. This again will skew the odds in favor of winning a price, causing the reserve to be drained faster over the time intended.
Proof of Concept
The TwabController._transferBalance function handles the case incorrectly, where _to is equal to the SPONSORSHIP_ADDRESS. First, assume the _from address is an address that has a balance and delegates to itself (the default). Then, the function will decrease the balance and delegateBalance of _from. It will also decrease the total balances of the vault account (note: that _toDelegate will be SPONSORSHIP_ADDRESS due to default):
if (_from != address(0)) {
bool _isFromDelegate = _fromDelegate == _from;
_decreaseBalances(_vault, _from, _amount, _isFromDelegate ? _amount : 0);
if (!_isFromDelegate && _fromDelegate != SPONSORSHIP_ADDRESS) {
_decreaseBalances(_vault, _fromDelegate, 0, _amount);
}
if (
_to == address(0) ||
(_toDelegate == SPONSORSHIP_ADDRESS && _fromDelegate != SPONSORSHIP_ADDRESS)
) {
_decreaseTotalSupplyBalances(
_vault,
_to == address(0) ? _amount : 0,
(_to == address(0) && _fromDelegate != SPONSORSHIP_ADDRESS) ||
(_toDelegate == SPONSORSHIP_ADDRESS && _fromDelegate != SPONSORSHIP_ADDRESS)
? _amount
: 0
);
}
}
Then, the balance and delegateBalance of SPONSORSHIP_ADDRESS will be increased by the same amount. This is not supposed to happen in the first place, as this address is not meant to have any balances. However, the issue described is due to the fact that the total balances of the vault account will not be adjusted, because the condition _toDelegate != SPONSORSHIP_ADDRESS is not met:
if (_to != address(0)) {
bool _isToDelegate = _toDelegate == _to;
_increaseBalances(_vault, _to, _amount, _isToDelegate ? _amount : 0);
if (!_isToDelegate && _toDelegate != SPONSORSHIP_ADDRESS) {
_increaseBalances(_vault, _toDelegate, 0, _amount);
}
if (
_from == address(0) ||
(_fromDelegate == SPONSORSHIP_ADDRESS && _toDelegate != SPONSORSHIP_ADDRESS)
) {
_increaseTotalSupplyBalances(
_vault,
_from == address(0) ? _amount : 0,
(_from == address(0) && _toDelegate != SPONSORSHIP_ADDRESS) ||
(_fromDelegate == SPONSORSHIP_ADDRESS && _toDelegate != SPONSORSHIP_ADDRESS)
? _amount
: 0
);
}
}
The ratio of _userTwab and _vaultTwabTotalSupply plays a role when determining a winner in TierCalculationLib.isWinner and the underlying model assumes the invariant to hold true:
uint256 constrainedRandomNumber = _userSpecificRandomNumber % (_vaultTwabTotalSupply);
uint256 winningZone = calculateWinningZone(_userTwab, _vaultContributionFraction, _tierOdds);
If the sum of the individual twabs is higher than the sum, there will be more winners than intended, causing the described drainage of the reserve.
Recommended Mitigation Steps
Disallow _to to be SPONSORSHIP_ADDRESS.
Assessed type
Invalid Validation
asselstine (PoolTogether) confirmed
Reject transfers to the sponsorship address. PR: https://github.com/GenerationSoftware/pt-v5-twab-controller/pull/6
Status: Mitigation confirmed. Full details in reports from 0xStalin, dirk_y and rvierdiiev.
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
Likely the transfer logic fails to adjust the vault's total supply balance when the recipient is the sponsorship address, because the condition checking for the sponsorship address is not met.
Impact
The sum of individual delegate balances can exceed the registered total, skewing win odds and causing the reserve to be drained faster over time.
What the attacker needed
A vault with a balance; transfer to SPONSORSHIP_ADDRESS
The fix
The mitigation rejects transfers to the sponsorship address.
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 a prize pool, each user's chance of winning depends on their share of the total deposits. The code that tracks these balances has a bug when someone sends funds to a special sponsorship address: it wrongly reduces the recorded total, making individual shares add up to more than the total. This means more winners than intended, which can drain the prize reserve faster.
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.