Anyone can remove existing term without queueing through setTerms()
Lines of code
Vulnerability details
Impact
In PoolOfferHandler, new terms require a two-step process for setting (setTerms() and confirmTerms()). The setTerm() function is onlyOwner, but the confirmTerms() function can be called by anyone. This function uses the provided input __terms from the caller to execute the logic. This could enable an attacker to remove all existing terms, even if the owner does not intend to do so (without pending through the setTerms() function).
solidityfunction 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]; // @audit Can be used to remove terms without pending through setTerm() 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); }
Proof of Concept
Consider the following scenario
- The pool has 5 existing terms. Now the owner wants to create a new term in the Pool, so they call
setTerms()with the__termsthey want to set up. The new term is pending confirmation after a waiting period. - After
NEW_TERMS_WAITING_TIME, an attacker callsconfirmTerms()with_termKeysset to all 5 existing terms and__terms.aprPremium = 0. - The function executes with the input provided by the attacker. Since the
pendingAprPremiumof these terms is reset to 0 after it is confirmed earlier, the checkif (pendingAprPremium != __terms[i].aprPremium)is bypassed. The attacker could set the_terms[][][][]mapping of existing loans to 0.
Tools Used
Manual Review
Recommended Mitigation Steps
Only allow the owner to call confirmTerms().
Assessed type
Invalid Validation
