Users can manipulate the observation creation
The contract only creates a new observation when the current period differs from the newest observation's period, so frequent small deposits within the same period overwrite the existing observation instead of adding a new one. An attacker could therefore manipulate their recorded average balance for a draw that ends within that period.
Submitted by Nyx
Users can alter the record of their balances.
Proof of Concept
If the users delegateBalance has changed, observations will be recorded. If there is a need for a new observation, the new observation will be created; otherwise, it will be overwritten.
A new observation creation will be decided in the _getNextObservationIndex() function.
if (currentPeriod == 0 || currentPeriod > newestObservationPeriod) {
return (
uint16(RingBufferLib.wrap(_accountDetails.nextObservationIndex, MAX_CARDINALITY)),
newestObservation,
true
);
}
newestObservationPeriod is the last observations period. currentPeriod is a period that calculated with uint32 currentTime = uint32(block.timestamp).
uint32 currentPeriod = _getTimestampPeriod(PERIOD_LENGTH, PERIOD_OFFSET, currentTime);
uint32 newestObservationPeriod = _getTimestampPeriod(
PERIOD_LENGTH,
PERIOD_OFFSET,
newestObservation.timestamp
);
function _getTimestampPeriod(
uint32 PERIOD_LENGTH,
uint32 PERIOD_OFFSET,
uint32 _timestamp
) private pure returns (uint32 period) {
if (_timestamp <= PERIOD_OFFSET) {
return 0;
}
// Shrink by 1 to ensure periods end on a multiple of PERIOD_LENGTH.
// Increase by 1 to start periods at # 1.
return ((_timestamp - PERIOD_OFFSET - 1) / PERIOD_LENGTH) + 1;
}
The problem is, if someone deposits a small amount frequently, currentPeriod and newestObservationPeriod will always be the same and a new observation won’t be created. Attackers can keep doing this until closeDraw and manipulate their balances.
According to the docs, if a draw were to start and end within a period, a user would be able to alter the record of their balance for that draw by overwriting an Observation.
It is important to note that due to Observation overwriting, average balances for a period are not finalized until a period ends. Therefore, if a draw ends but a period has not, a user would be able to manipulate their average balance for that final period of time after the draw ends. This would result in an inaccurate record of their balance held during the draw.
asselstine (PoolTogether) confirmed
Picodes (judge) decreased severity to Medium and commented:
If someone deposits a small amount frequently,
currentPeriodandnewestObservationPeriodwill always be the same and a new observation won’t be createdThis only works for small deposit within the samePERIOD_LENGTH`; otherwise, timestamp roundings will differ.This report shows how by leveraging the fact that new observations are not created if the previous observations falls within the same period, an attacker could modify its average balance for the final period if a draw ends within a period.
Aligned twab queries on period boundaries. PR: https://github.com/GenerationSoftware/pt-v5-twab-controller/pull/5
Status: Mitigation confirmed with comments. Full details in reports from dirk_y, 0xStalin 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 observation index logic only creates a new observation when the current period is greater than the newest observation's period, so multiple updates within the same period overwrite the existing observation rather than appending a new one.
Impact
An attacker could alter the record of their average balance for a draw that ends within a period, leading to an inaccurate balance history; the judge noted this only works for small deposits within the same period length.
What the attacker needed
Ability to make frequent small deposits; draw ends within the same period
The fix
The issue was mitigated by aligning TWAB queries on period boundaries.
How it was found
- Deposit a small amount frequently so that the current period stays the same as the newest observation period.
- Because the periods match, the existing observation is overwritten instead of a new one being created.
- Continue until closeDraw to manipulate the recorded average balance for that period.
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.
This is a smart contract that tracks users' average balances over time by saving 'observations' at certain moments. If a user makes many small deposits within the same short time window, the contract overwrites the previous observation instead of saving a new one. That lets the user change the balance history that is used to calculate rewards for a draw.
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.