Unpausing with accrue timestamp reset can remove the accrual between last recorded accrue time and pausing time
The updatePause function allows resetting the accrual timestamp when unpausing, which can erase interest accrual for the period between the last accrual and the pause. An attacker could exploit this to cause a loss of yield for lenders if a long period without accrual occurred before pausing.
Source: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/91
Found by
hyh
Summary
Updating pause to false have an option of resetting the accrual timestamp. It can backfire if there was a substantial enough period of not updating the accrual before pausing, as it does not call accrue by itself.
Vulnerability Detail
In other words updatePause(type, false, true) will erase interest accrual for the unpaused period between last accrual and pausing. That period can be arbitrary long.
Impact
Interest accrual is incorrectly erased for the period before pause was initiated. This is protocol-wide break of core logic via loss of yield for that period, so the impact is high. The preconditions are that resetAccrueTimestmap == true must be used on unpausing and that long enough period without accrual call should take place before pausing. The probability on that can be estimated as low.
Likelihood: Low + Impact: High = Severity: Medium.
Code Snippet
If resetAccrueTimestmap == true on unpausing the accrual between accrueInfo.lastAccrued and pausing time is lost:
function updatePause(PauseType _type, bool val, bool resetAccrueTimestmap) external {
if (msg.sender != conservator) revert NotAuthorized();
if (val == pauseOptions[_type]) revert SameState();
emit PausedUpdated(_type, pauseOptions[_type], val);
pauseOptions[_type] = val;
// In case of 'unpause', `lastAccrued` is set to block.timestamp
// Valid for all action types that has an impact on debt or supply
if (!val && (_type != PauseType.AddCollateral && _type != PauseType.RemoveCollateral)) {
>> accrueInfo.lastAccrued = resetAccrueTimestmap ? block.timestamp.toUint64() : accrueInfo.lastAccrued;
}
}
That's incorrect as that was a going concern period for which lenders should have interest accounted for.
Tool used
Manual Review
Recommendation
Consider accruing whenever pause is being triggered, so the state be updated as of pausing time:
function updatePause(PauseType _type, bool val, bool resetAccrueTimestmap) external {
if (msg.sender != conservator) revert NotAuthorized();
if (val == pauseOptions[_type]) revert SameState();
emit PausedUpdated(_type, pauseOptions[_type], val);
pauseOptions[_type] = val;
+ // since the `lastAccrued` can be reset later the state need to be updated as of pausing time
+ if (val) {
+ _accrue();
+ }
// In case of 'unpause', `lastAccrued` is set to block.timestamp
// Valid for all action types that has an impact on debt or supply
if (!val && (_type != PauseType.AddCollateral && _type != PauseType.RemoveCollateral)) {
accrueInfo.lastAccrued = resetAccrueTimestmap ? block.timestamp.toUint64() : accrueInfo.lastAccrued;
}
}
Discussion
sherlock-admin4
The protocol team fixed this issue in PR/commit https://github.com/Tapioca-DAO/Tapioca-bar/pull/358.
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 updatePause function resets the lastAccrued timestamp on unpause without first accruing interest, so any unaccrued period before pausing is skipped.
Impact
Interest accrual is incorrectly erased for the period before pause was initiated, causing a protocol-wide loss of yield for that period; the likelihood is low but impact is high.
What the attacker needed
ResetAccrueTimestmap == true on unpausing; long period without accrual before pausing
The fix
The protocol team fixed this issue by accruing interest whenever pause is triggered, so the state is updated as of pausing time.
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 lending protocol, interest is calculated based on time. The contract records the last time interest was calculated. When pausing certain actions, the contract can optionally reset that timestamp when unpausing. If it resets without first calculating interest for the time since the last calculation, that interest is lost. This means lenders lose the interest they should have earned for that period.
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.