Attacker can front-run and pass in empty terms, making it impossible to confirmTerms()
The confirmTerms() function can be called by anyone and accepts an empty terms list, which sets pendingTermsSetTime to max and prevents the owner from confirming new terms. An attacker can front-run the owner's confirmTerms() call with an empty list, blocking the owner from setting up new terms.
minhquanym Follow with zhaojie and bin2chen
Originally disclosed on Code4rena
Submitted by minhquanym, also found by zhaojie and bin2chen
In PoolOfferHandler, setting new terms requires two steps (setTerms() and confirmTerms()). The setTerm() function is onlyOwner, but anyone can call the confirmTerms() function. At the end of the confirmTerms() function, pendingTermsSetTime is set to type(uint256).max, preventing the function from being called again.
Since confirmTerms() uses the caller’s input to execute the setup, an attacker could input empty __terms to prevent the owner from setting up new terms.
Proof of Concept
// @audit Anyone can front-run and pass in empty terms, making it impossible to confirmTerms
function confirmTerms(TermsKey[] calldata _termKeys, Terms[] calldata __terms) external {
if (block.timestamp - pendingTermsSetTime < NEW_TERMS_WAITING_TIME) {
revert TooSoonError();
}
for (uint256 i = 0; i < __terms.length; i++) {
if (_termKeys[i].duration > getMaxDuration) {
revert InvalidDurationError();
}
uint256 pendingAprPremium = _pendingTerms[_termKeys[i].collection][_termKeys[i].duration][_termKeys[i]
.maxSeniorRepayment][__terms[i].principalAmount];
if (pendingAprPremium != __terms[i].aprPremium) {
revert InvalidTermsError();
}
_terms[_termKeys[i].collection][_termKeys[i].duration][_termKeys[i].maxSeniorRepayment][__terms[i]
.principalAmount] = __terms[i].aprPremium;
delete _pendingTerms[_termKeys[i].collection][_termKeys[i].duration][_termKeys[i]
.maxSeniorRepayment][__terms[i].principalAmount];
}
pendingTermsSetTime = type(uint256).max;
emit TermsSet(_termKeys, __terms);
}
In this function, it loops through the input __terms.length list. If an attacker calls confirmTerms() with an empty __terms list, there will be no terms set, and pendingTermsSetTime is still set to type(uint256).max.
As a result, the owner will never be able to set up new terms for the pool because the attacker keeps spamming confirmTerms() when the NEW_TERMS_WAITING_TIME passes after the owner calls setTerms().
Recommended Mitigation Steps
Record the __terms list in the setTerms() function to confirm terms instead of using input from caller.
Assessed type
DoS
Terms must be passed in the confirm as well.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
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 confirmTerms() function does not validate that the provided terms list is non-empty and does not restrict who can call it, allowing an attacker to set the pendingTermsSetTime to max with an empty list.
Impact
The owner is permanently prevented from setting new terms for the pool, causing a denial of service.
What the attacker needed
Attacker can call confirmTerms(); owner has called setTerms(); waiting period has passed
The fix
The terms should be recorded during setTerms() and confirmed using that stored data, rather than accepting terms from the caller in confirmTerms().
How it was found
- Owner calls setTerms() to propose new terms.
- Attacker observes the pending terms and waits for the waiting period to pass.
- Attacker calls confirmTerms() with an empty terms list.
- The function sets pendingTermsSetTime to max, blocking further confirmations.
- Owner cannot confirm the real terms and must repeat setTerms(), but the attacker can repeat the attack.
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.
A smart contract has a two-step process for updating terms: the owner sets them, then anyone can confirm them. The confirm function doesn't check that the terms list is non-empty, so an attacker can call it with an empty list, which locks the process and stops the owner from ever confirming real terms.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.