# Forced endTime extension in updateArtSettings() allows attacker to mint more tokens

PhiFactory.updateArtSettings forces artists to extend endTime to now, letting a past merkle-eligible user backrun and mint remaining supply post-event.

- Payout: Audit contest
- Severity: high
- Program: Phi
- Found by: MrPotatoMagic
- Disclosed: 2024-10-07
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-08-phi-findings/issues/54
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-phi%3AH-04
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** PhiFactory.updateArtSettings / merkleClaim (Solidity NFT minting)
**Root cause:** updateArtSettings reverts if endTime_ < block.timestamp, so any post-event settings update (uri, soulBounded, royalties) forces endTime to be pushed to now, reopening the mint window. merkleClaim only checks block.timestamp > endTime and maxSupply, not that the event legitimately ended.
**Steps:**
1. Artist's event ran t=0..100; 500 of 1000 maxSupply minted.
2. Artist calls `updateArtSettings(artId_, url_, receiver_, maxSupply_, mintFee_, startTime_, endTime_=block.timestamp, soulBounded_, config)` to change uri/soulBounded/royalties; passes check `endTime_ < block.timestamp` revert.
3. Attacker who held a valid merkle leaf backruns with `merkleClaim(proof_, encodeData_=(minter,ref,artId), mintArgs_={quantity:upToRemainingSupply,...}, leafPart_)`.
4. `_validateAndUpdateClaimState` passes: `block.timestamp > art.endTime` false (equal), `numberMinted+quantity <= maxSupply` true.
5. `_processClaim` mints attacker the remaining tokens for mintFee.
**How found:** Code reading of updateArtSettings' endTime >= block.timestamp constraint combined with merkleClaim's endTime-only gating; recognized that any post-event settings update necessarily reopens minting.
**Exploitation:** Attacker monitors mempool for updateArtSettings calls, backruns with a previously valid merkle proof and arbitrary quantity up to maxSupply, minting tokens at mintFee that then trade on external marketplaces, diluting existing holders and artist royalties.
**Insight:** When a settings-update function shares a time-window field with the mint gate, check whether updating unrelated fields forces the window open; merkle proofs that don't bind quantity let any past-eligible leaf mint up to maxSupply during the reopened window.

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

**Claim state validation allowing mint**

```
function _validateAndUpdateClaimState(uint256 artId_, address minter_, uint256 quantity_) private {
719:         PhiArt storage art = arts[artId_];
720: 
721:         // Common validations
722:         if (tx.origin != _msgSender() && msg.sender != art.artAddress && msg.sender != address(this)) {
723:             revert TxOriginMismatch();
724:         }
725:         if (msg.value < getArtMintFee(artId_, quantity_)) revert InvalidMintFee();
726:         if (block.timestamp < art.startTime) revert ArtNotStarted();
727:         if (block.timestamp > art.endTime) revert ArtEnded(); 
728:         if (quantity_ == 0) revert InvalidQuantity();
729:         if (art.numberMinted + quantity_ > art.maxSupply) revert OverMaxAllowedToMint();
730: 
731:         // Common state updates
732:         if (!credMinted[art.credChainId][art.credId][minter_]) {
733:             credMinted[art.credChainId][art.credId][minter_] = true;
734:         }
735:         artMinted[artId_][minter_] = true;
736:         art.numberMinted += quantity_;
```

