# Attacker can front-run and pass in empty terms, making it impossible to confirmTerms()

Anyone can call confirmTerms() with an empty terms array, setting pendingTermsSetTime to max and permanently blocking the owner from confirming new pool terms.

- Payout: Audit contest
- Severity: medium
- Program: Gondi
- Found by: minhquanym
- Disclosed: 2024-07-25
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-gondi-findings/issues/58
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AM-07
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:access-control vuln:business-logic vuln:dos

**Target:** PoolOfferHandler.confirmTerms() (Solidity contract)
**Root cause:** confirmTerms() trusts caller-supplied __terms and unconditionally sets pendingTermsSetTime = type(uint256).max even when the loop body never executes, so an empty array consumes the confirmation slot without setting any terms.
**Steps:**
1. Owner calls setTerms() (onlyOwner) to stage pending terms.
2. Wait until block.timestamp - pendingTermsSetTime >= NEW_TERMS_WAITING_TIME.
3. Attacker front-runs owner's confirmTerms() with `confirmTerms([], [])`.
4. Loop over __terms.length (0) does nothing; pendingTermsSetTime = type(uint256).max.
5. Owner's confirmTerms() now reverts TooSoonError forever; repeat each time owner re-calls setTerms().
**How found:** Code reading of confirmTerms(): noticed the loop bound is caller-controlled __terms.length and that pendingTermsSetTime is set to max outside the loop, so an empty input still burns the confirmation.
**Exploitation:** Attacker monitors the mempool for the owner's confirmTerms() transaction after the waiting period and submits confirmTerms([], []) with higher gas to land first, consuming the one-shot confirmation and locking out legitimate term updates.
**Escalation:** Repeated spam after each setTerms() makes the DoS persistent, preventing any new pool terms from being configured.
**Insight:** When a two-step commit/confirm pattern uses caller-supplied data in the confirm step and a one-shot state flag, check whether an empty or mismatched input can consume the flag without performing the intended state change.

## Proof of concept (copied exactly from the original report)

**confirmTerms() callable by anyone with empty terms**

```
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;
```

