# Findings

**Review**: Trail of Bits and Uniswap skill review of the Dices launchpad
**Date**: 2026-11-25, commit `bcd45b2` (`main`)
**Scope**: `src/`, and `script/deployment/V001.s.sol` for deployment

Every finding below passed the false-positive check in [`fp-check-verification.md`](fp-check-verification.md).
Tests named as evidence are in [`poc-tests.md`](poc-tests.md) and
[`poc-tests-verify05.md`](poc-tests-verify05.md) with their output.

One finding, DICES-05, lets an unprivileged caller come away with USDC; the amount is bounded by the fee queued
by one large buy. No finding lets anyone remove the locked launch liquidity, take another user's coins, or take
credits from the escrow.

## Summary

| ID | Severity | Difficulty | Title |
| --- | --- | --- | --- |
| [DICES-01](#dices-01) | Medium | Low | A zero creator or buy-and-burn recipient makes USDC-fee swaps revert |
| [DICES-02](#dices-02) | Medium | n/a | Game levels 9 and 10 can never unlock |
| [DICES-03](#dices-03) | Medium | High (owner key) | The owner can change the fee, the split and the level of existing pools without bound or delay |
| [DICES-05](#dices-05) | Medium | Medium | Queued fees are converted at a spot price that any caller can push down first |
| [DICES-04](#dices-04) | Low | n/a | The deployment script leaves a single EOA as owner on mainnet by default |
| [DICES-06](#dices-06) | Low | Low | The launch-block guard does not stop anyone who uses the trusted router |
| [DICES-07](#dices-07) | Low | High (owner error) | A calculator that returns malformed data halts every swap; the level is not bounded |
| [DICES-08](#dices-08) | Low | n/a | The swap pool keeps the fee split it was deployed with |
| [DICES-09](#dices-09) | Undetermined | n/a | The fee model in the code is not the one in the brief as restated in `AGENT.md` |
| [DICES-10](#dices-10) | Informational | | A conversion position is opened on every buy; callback gas is high |
| [DICES-11](#dices-11) | Informational | | Production code uses a settler from v4-core's test utilities |
| [DICES-12](#dices-12) | Informational | | Anyone can initialise the coin implementation |
| [DICES-13](#dices-13) | Informational | | ETH sent to the swap pool is stuck |
| [DICES-14](#dices-14) | Informational | | Levels price the coin on a supply that burning changes |
| [DICES-15](#dices-15) | Informational | | Every holder gives Permit2 an infinite allowance |
| [DICES-16](#dices-16) | Informational | | Code that cannot run or has no effect |
| [DICES-17](#dices-17) | Informational | | Documentation and comments promise things the code does not do |
| [DICES-18](#dices-18) | Informational | | Events leave gaps for indexers and monitoring |
| [DICES-19](#dices-19) | Informational | | Fees are taken from the PoolManager before the swapper pays |
| [DICES-20](#dices-20) | Informational | | Blind spots in the test suite |
| [DICES-21](#dices-21) | Informational | | Design limits the team already documents |
| [DICES-22](#dices-22) | Informational | | Unbounded inputs |

Severity is impact on users and the protocol; difficulty is what an attacker needs. "Undetermined" means the
answer depends on a decision that is not in the repository.

Eight further candidates were checked and rejected; they are listed at the end.

---

## DICES-01

**A zero creator or buy-and-burn recipient makes USDC-fee swaps revert**

Severity: Medium. Difficulty: Low. Type: data validation, denial of service.
Location: `src/DicesHook.sol:574`, `:480`, `:218`; `src/core/InternalSwapPool.sol:274`;
`src/core/FeeEscrow.sol:36-38`.

### Description

`createCoin` stores the caller-supplied creator without checking it:

```solidity
// src/DicesHook.sol:574
poolCreators[poolId] = params.creator;
```

Whenever a fee is in USDC, the hook credits the creator's 30% share through the escrow, and the escrow rejects
a zero beneficiary:

```solidity
// src/DicesHook.sol:480
_creditFee(poolCreators[poolId], Currency.unwrap(fee.currency), creator);

// src/core/FeeEscrow.sol:36
if (_beneficiary == address(0)) {
    revert InvalidBeneficiary();
}
```

The swap pool does the same when it converts queued coin fees (`src/core/InternalSwapPool.sol:274`). The revert
propagates to the PoolManager and fails the swap. `poolCreators` has no setter, so the pool cannot be repaired.

For a pool created with `creator == address(0)`:

| Swap | Fee currency | Result |
| --- | --- | --- |
| Buy, exact USDC in, first one | Coin | Succeeds; the fee is only queued |
| Buy, exact USDC in, once it trades into the conversion range | Coin, plus conversion proceeds in USDC | Reverts |
| Buy, exact coin out | USDC | Reverts |
| Sell, exact coin in | USDC | Reverts |
| Sell, exact USDC out | Coin | Succeeds |

The same failure applies to every pool if the hook is constructed with a zero `_buyAndBurnRecipient`
(`src/DicesHook.sol:218` has no check; the setter at `:771` does). `V001` guards against that
(`script/deployment/V001.s.sol:324`), and the owner can fix it afterwards.

### Impact

Anyone can launch a coin whose buyers cannot sell with an ordinary exact-input swap. Funds are not lost: an
exact-output sell still works. The creator gains nothing from doing this deliberately, so the likelier cause is
an integration that leaves `creator` unset. Either way the pool is permanently broken, the creation fee is
spent, and the first buyers need a non-standard swap to leave.

### Evidence

`testPoC1_zeroCreatorBricksEverySwapThatCreditsTheCreator(bool)` passes for both currency orderings and checks
that each failing swap's revert data contains `FeeEscrow.InvalidBeneficiary`.
`testPoC1_control_nonZeroCreatorTradesNormally(bool)` runs the same swaps with a real creator and all succeed.
`testPoC12_zeroBuyAndBurnRecipientBlocksUsdcFeeSwapsUntilSet` covers the constructor case.

### Recommendation

- Revert in `createCoin` when `params.creator == address(0)`.
- Revert in the constructor when `_buyAndBurnRecipient == address(0)`.
- Add both cases to the test suite, and consider an invariant that a launched pool always accepts an
  exact-input sell.

Reported independently by the token-integration (TI-04), Uniswap (V4SF-02), guidelines (F-05, F-09) and
code-maturity (F1, F10) reviews.

---

## DICES-02

**Game levels 9 and 10 can never unlock**

Severity: Medium. Type: specification, arithmetic.
Location: `src/DicesCoin.sol:32`; `src/DicesHook.sol:71`; `src/calculators/LiveCalculator.sol:252`, `:373-375`.

### Description

A level needs the coin to have at least its floor of qualifying holders, and a qualifying holder is an address
with at least 300,000 coins. The supply is fixed at 1,000,000,000 coins, so no more than
1,000,000,000 ÷ 300,000 = 3,333 addresses can qualify at once, whatever happens.

| Level | Holder floor | Coins that must sit in qualifying wallets | Possible |
| --- | --- | --- | --- |
| 7 | 1,700 | 510M | Yes |
| 8 | 2,500 | 750M | Only if about three quarters of all coins are in qualifying wallets |
| 9 | 3,800 | 1,140M | No: more than the supply |
| 10 | 5,800 | 1,740M | No: more than the supply |

The practical ceiling is lower than 3,333, because the hook, the PoolManager, the swap pool and the bankroll
address are not counted (`src/DicesCoin.sol:247-249`) and the pool always holds some coins. At level 8's
market cap about 982M coins can be outside the pool at most.

`_levelAt` lowers the level until the floor is met (`src/calculators/LiveCalculator.sol:373-375`), so a coin
whose average market cap is above $51M or $102M stays at level 8 or below.

### Impact

Two of the ten games in the client's table (9 November update) cannot be reached by any coin. Level 8 is
reachable only with an unusually flat distribution. No funds are at risk.

The project's tests do not catch this because the tests that reach level 10 use a stand-in coin whose holder
count is set directly (`test/utils/Fixtures.sol:83-99`).

### Evidence

`testPoC9_levelsNineAndTenNeedMoreHoldersThanTheSupplyAllows` passes: it prints the table above from the
deployed constants and asserts that floors 9 and 10 exceed `totalSupply() / HOLDER_THRESHOLD()`.

### Recommendation

This needs a decision from the client, since both the floors and the 300,000-coin threshold came out of
`AGENT.md` open question 5:

- lower the threshold (for 5,800 holders to be possible at all it must be under about 172,000 coins, and much
  lower to be practical), or
- lower the floors for the upper levels, or
- define the floor for upper levels differently, for example as a count of addresses above a smaller balance.

Then add a test that every level's floor × threshold fits within the coins that can be in circulation at that
level's market cap.

Reported independently by the token-integration (TI-01) and guidelines (F-01) reviews and by the calculator
context review.

---

## DICES-03

**The owner can change the fee, the split and the level of existing pools without bound or delay**

Severity: Medium. Difficulty: High (needs the owner key). Type: access control, centralisation.
Location: `src/DicesHook.sol:462`, `:478-481`, `:436-440`, `:752-763`, `:819-838`.

### Description

The hook reads its fee rate and fee split from `feeCalculator` and its level from `liveCalculator` on every
swap. Both are replaced by a single owner call that checks only that the new address has code. The values they
return are used as they come:

```solidity
// src/DicesHook.sol:462
fee.amount = Math.mulDiv(amount, feeCalculator.getSwapFee(poolLive(key.toId())), FEE_DENOMINATOR);

// src/DicesHook.sol:478
(uint platform, uint creator, uint buyAndBurn) = feeCalculator.getFeeDistribution(fee.amount, poolLive(poolId));
```

Nothing in the hook caps the rate, checks that the three shares add up to the fee, or limits the level to ten.
The setting is global and is not snapshotted when a pool launches, so a change applies at once to every pool,
and those pools' liquidity is locked for good.

With a replacement calculator the owner can:

- charge up to 100% of the unspecified side of every swap (a sell then pays out nothing);
- return a rate above 100%, so that a swap costs the trader more than it pays out; a router with a
  minimum-output or maximum-input check reverts instead, which halts trading;
- return a split that sums to more than the fee, which makes the last escrow deposit fail and the swap revert;
- return a split that sums to less than the fee, which strands the difference in the hook with no way out;
- unlock any level for any pool, irreversibly, by pointing `liveCalculator` at a contract that returns it.

A trader is protected only by the slippage limit they set in the router.

### Impact

The brief asks for a treasury Safe behind a 48-hour timelock with "all critical financial operations enforced
on-chain with caps" (`AGENT.md`, Governance). The timelock is deferred and no cap exists. Until both are in
place, one key decides the cost of trading in every pool, including whether holders can exit at all.

### Evidence

`testPoC4_ownerCanChargeTheWholeOutputOfExistingPools` passes: after `setFeeCalculator`, a sell of 1,000,000
coins on a pool that already existed returns 0 USDC and 14.73 USDC is credited as fees.
`testPoC10_hookStoresAnyLevelTheCalculatorReturns` passes: `poolLevel` becomes 255 and stays there.

### Recommendation

- Add a constant maximum fee rate in `DicesHook` and revert, or clamp, above it.
- Require `platform + creator + buyAndBurn == fee.amount` in `_collectSwapFee`.
- Ignore a level above `LEVELS` in `_syncLevel`.
- Put calculator changes behind the timelock the brief describes, so that traders can see a change coming.
- Consider snapshotting the fee rate per pool at launch, as `AGENT.md` still describes, if the client expects
  a launched coin's terms to be fixed.
- Check the bytecode size after these changes: the hook has 1,499 bytes of headroom.

Reported independently by the token-integration (TI-02), Uniswap (V4SF-01), guidelines (F-03) and
code-maturity (F2, F8) reviews.

---

## DICES-04

**The deployment script leaves a single EOA as owner on mainnet by default**

Severity: Low. Type: configuration, access control.
Location: `script/deployment/V001.s.sol:131`, `:306`, `:244-246`, `:323-325`; `src/core/TrustedRouters.sol:13`.

### Description

`V001` refuses a mainnet run until the fee recipient, the buy-and-burn recipient and the bankroll are set. It
does not do the same for the owner:

```solidity
// script/deployment/V001.s.sol:306
protocolOwner = cfg.protocolOwner == address(0) ? deployer : cfg.protocolOwner;
```

`BASE_MAINNET_PROTOCOL_OWNER` is `address(0)` (`:131`), so as committed the deploying wallet stays owner and
`_requireWiring` accepts that (`:512`).

Ownership is OpenZeppelin `Ownable`, reached through `TrustedRouters`. `transferOwnership` takes effect in one
step, and `renounceOwnership` is callable.

### Impact

All the powers in DICES-03 would sit on a hot deployer key. A one-step transfer to a mistyped address, or a
renounce, removes administration permanently, including the ability to replace a faulty calculator
(DICES-07) or set a missing recipient (DICES-01).

### Evidence

The project's own test pins this behaviour: `test_unsetOwnerKeepsTheDeployer`
(`test/scripts/V001.t.sol:259-266`) runs the script with a non-testnet configuration and a zero owner and
asserts that `hook.owner()` is the deploying wallet. `test_mainnetRequiresRecipients` (`:293-310`) shows the
other three constants are refused when unset. Both pass. So the default is deliberate; the finding is that
it should not be available on mainnet.

### Recommendation

- Require a non-zero `protocolOwner` that is a contract when `isTestnet` is false.
- Use `Ownable2Step`.
- Override `renounceOwnership` to revert unless the client wants the option, and say so in the docs if they do.

---

## DICES-05

**Queued fees are converted at a spot price that any caller can push down first**

Severity: Medium. Difficulty: Medium (needs a prior large buy; nothing else). Type: economic, transaction
ordering.
Location: `src/core/InternalSwapPool.sol:155-212`, `:226-279`; `src/DicesHook.sol:474-476`.

### Description

On an exact-input buy the fee is charged in the coin and queued in the swap pool. On the next buy, the swap
pool places the whole queue as liquidity in one tick spacing next to the pool's price at that moment:

```solidity
// src/core/InternalSwapPool.sol:168
(uint160 sqrtPriceX96, int24 tick,,) = poolManager.getSlot0(poolId);
```

There is no reference price, no minimum price and no cap on how much is offered in one swap. Whoever makes
that next buy purchases the queued coins at the current spot price, and the USDC they pay is what the platform,
the creator and the buy-and-burn recipient receive.

A caller can lower that price first. It does not need to own any coins. Inside one `unlock`, Uniswap v4 lets a
contract sell coins it only owes and buy the same number back before settling:

1. Sell `c` coins (exact input). The price falls. The caller is owed USDC and owes `c` coins.
2. Buy exactly `c` coins (exact output). The swap pool has just placed the queue at the lowered price, so
   part of the `c` coins comes from the queue cheaply and the rest from the pool on the way back up.
3. The coin debt is now zero. The USDC left over is taken as profit.

Both swaps pay the 1.25% fee. The manoeuvre pays when the queue is worth more than those fees, which in
practice means directly after one large exact-input buy.

### Impact

Measured after a single 30,000 USDC exact-input buy (market cap about $159k, 8.40M coins queued, worth
1,338 USDC at spot):

| | Ordinary conversion by a 5,000 USDC buyer | Zero-capital caller sells and re-buys 436.7M coins in one unlock |
| --- | --- | --- |
| Caller's profit | none | **470.38 USDC**, with no coins, no USDC and no approvals |
| Credited to recipients for the queue | 1,349.45 USDC | 188.58 USDC |
| Credited to recipients in total | 1,349.45 USDC | 826.41 USDC, of which 637.83 is the fee on the caller's own two swaps |
| Pool's USDC | unchanged | falls from 30,000.00 to 28,703.19 |

Who bears the cost depends on what happens next. If ordinary buying follows, the fee recipients are 523.04
USDC short (39%) and holders are unaffected. If nobody buys, the cost falls on holders instead: the large
buyer could realise 1,175.89 USDC less by selling everything, because the queue was in effect sold into the
pool.

How large the preceding buy has to be, for a pool at launch:

| One exact-input buy from launch | Best result for the zero-capital caller | Share of the queue's spot value |
| --- | --- | --- |
| 1,000 to 12,500 USDC | a loss | |
| 13,500 USDC (price × 4.65) | +1.58 USDC | |
| 20,000 USDC | +107.46 USDC | 16% |
| 30,000 USDC | +470.38 USDC | 35% |
| 34,000 USDC | +674.96 USDC | 41% |
| 50,000 USDC | +2,024.95 USDC | 57% |
| 75,000 USDC | +5,361.49 USDC | 67% |

The threshold is a single buy that multiplies the price by about 4.5, whatever the fee rate. Ordinary flow
does not create it: after one further 5,000 USDC buy has converted the queue, every size of the manoeuvre
loses. An exact-output buy queues nothing, so it cannot be targeted.

Things that limit the severity:

- The amount is bounded by one buy's queued fee. No pool liquidity or escrow balance can be taken, and the
  escrow stays fully funded throughout.
- The state it needs comes from someone else's large buy. An attacker cannot create it at a profit, because
  it would pay the fee it then partly recovers.

Things that raise it:

- Once the state exists, anyone can take the profit in one transaction with no capital, so it will be taken.
- The large buyer can do it to its own queue in the same transaction as its buy, which turns it into a
  standing discount on the buy fee for large buys.
- The launch block is where large single buys are most likely, and the guard meant to restrict that block
  does not (DICES-06).

A holder can run the same manoeuvre with coins it owns and end with the same USDC and more coins (1,783,265
more in the test above). That version is not profitable in money terms: the holder realises 675.31 USDC less
if it then sells everything.

The independent verifier who established the zero-capital form rated it Low, and Medium if large first-block
buys are expected to be routine. It is rated Medium here because that is the expected pattern on a launchpad
and because the profit needs no capital or position.

### Evidence

Two sets of tests, written separately:

- Mine, in [`poc-tests.md`](poc-tests.md): `testPoC8_queuedFeeInventoryIsSoldAtAPriceTheBuyerCanPushDown`,
  `testPoC8_baseline_inventoryValueAtTheUnmanipulatedPrice`,
  `testPoC8b_aDifferentHolderCapturesAnotherBuyersQueuedFee` and `testPoC8c_measuresOfGainAndWhoPays`. These
  cover the holder version.
- The independent verifier's, in [`poc-tests-verify05.md`](poc-tests-verify05.md): eleven tests including
  `test_2_zeroInventoryVariant_paysOutUsdc`, the precondition sweeps (`test_3a`, `test_3b`, `test_5c`), the
  other currency ordering (`test_4`) and a run without extra USDC in the PoolManager that also asserts escrow
  solvency (`test_5b`). I re-ran all eleven; the figures above are from that run.

### Recommendation

Give the conversion a price it cannot be pushed below. In rising order of effort:

- Skip conversion when the spot tick is below the pool's time-weighted average. `LiveCalculator` already
  keeps one per pool, and a price pushed down inside one transaction is by construction below it.
- Record the price at which each fee was charged and do not convert below it.
- Cap the share of the queue offered in a single swap, which shrinks the prize without removing it.
- Charge buy fees in USDC as well, as `AGENT.md` still describes. No queue forms and the swap pool is not
  needed.

Whichever is chosen, add a test that a sell followed by a buy in one unlock cannot leave the caller with
more USDC than it started with.

The guidelines review flagged the same code as "offered at spot with no reference price" (F-15) without
establishing whether it paid.

---

## DICES-06

**The launch-block guard does not stop anyone who uses the trusted router**

Severity: Low. Difficulty: Low. Type: access control, transaction ordering.
Location: `src/DicesHook.sol:326-336`; `src/core/TrustedRouters.sol:17-28`;
`script/deployment/V001.s.sol:238`, `:516`.

### Description

```solidity
// src/DicesHook.sol:328
// Prevent 0-block buys: Prevents bots from buying in the same block as launch, unless token creator.
// src/DicesHook.sol:334
if (launchBlock[poolId] == block.number && !trustedRouters[sender]) {
    revert CannotBuyZeroBlock();
}
```

`sender` is the router. The check passes for any swap that comes through a trusted router, whoever sent it.
There is no check on the creator, although the comment says there is. `V001` trusts the Universal Router so
that its `msgSender()` can attribute buyers (`script/deployment/V001.s.sol:238`), which is the router most
traders and bots use.

The same list therefore does two jobs: "ask this router who its caller is" and "let this router trade in the
launch block". The first job has no effect at present, because the resolved address is passed to the swap
pool and ignored there (`src/core/InternalSwapPool.sol:146`).

### Impact

As deployed, anyone can buy in a coin's launch block. The guard would only ever cover one block, and on its
own this puts no funds at risk. But the protection the comment describes is not there, and a team that
believes it is may not add another. It also feeds DICES-05: a large buy in the launch block is the state that
finding needs, and the buyer can exploit its own queue in the same transaction.

### Evidence

`testPoC2_anyUserOfATrustedRouterBuysInTheLaunchBlock(bool)` passes: in the launch block, a buy through an
untrusted router reverts with `CannotBuyZeroBlock`, and the same buy by the same third party through the
trusted router succeeds and receives 72.7M coins for 1,000 USDC.

### Recommendation

Decide what the launch block should allow, then make the code say it:

- if only the creator may buy, resolve the caller with `_getSender` and compare it with `poolCreators[poolId]`;
- if a dedicated launch router may buy, keep a separate list for that and leave the Universal Router off it;
- if anyone may buy, remove the guard and the comment.

Reported independently by the Uniswap (V4SF-03), guidelines (F-07) and code-maturity (F3) reviews.

---

## DICES-07

**A calculator that returns malformed data halts every swap; the level is not bounded**

Severity: Low. Difficulty: High (owner error). Type: error handling.
Location: `src/DicesHook.sol:433-449`, `:832-838`.

### Description

```solidity
// src/DicesHook.sol:436
try liveCalculator.qualify(_poolKey) returns (uint8 level) {
    uint8 unlocked = poolLevel[_poolId];
    if (level > unlocked) {
        poolLevel[_poolId] = level;
        ...
    }
} catch {}
```

The comment above it says a fault in the calculator "must never block a swap". That holds when the calculator
reverts. It does not hold when the call succeeds but the return data cannot be decoded as a `uint8`: Solidity
decodes in the caller, outside the `catch`, and the hook reverts. Any contract with a fallback that returns
nothing, or a function that returns a wider value, has this effect. `_setLiveCalculator` checks only that the
address has code (`:833`).

Separately, the hook stores any `uint8` the calculator returns, so a level above 10 can be recorded and never
lowered.

### Impact

Setting the wrong address as Live calculator stops all trading in all pools until the owner sets a correct
one. If ownership has been renounced (DICES-04) it cannot be fixed.

`AGENT.md` tells integrators that "a reverting calculator leaves the level as it is and never blocks a swap",
which reads as a stronger promise than the code keeps.

### Evidence

`testPoC3_calculatorReturningMalformedDataBlocksEverySwap` passes: a reverting calculator is tolerated; one
that returns the word 256 and one that returns nothing each make buys, sells and `syncLevel` revert.
`testPoC10_hookStoresAnyLevelTheCalculatorReturns` covers the unbounded level.

### Recommendation

- Call `qualify` with a low-level `call`, and treat a failed call, a return shorter than 32 bytes or a value
  above `LEVELS` as "no change".
- Add `dicesHook()` to `ILiveCalculator` (the contract already exposes it) and have `_setLiveCalculator`
  check that the new calculator reports this hook. That also catches the documented mistake of attaching a
  calculator built for another address.
- A gas note for whoever replaces the calculator: the review checked that a caller cannot starve `qualify` of
  gas and still complete the swap (rejected candidate R-01). That holds for the current calculator, whose
  most expensive call is about 207,000 gas. It should be re-checked for a replacement that costs several times
  more.

Reported independently by the guidelines (F-08) and code-maturity (F8) reviews.

---

## DICES-08

**The swap pool keeps the fee split it was deployed with**

Severity: Low. Type: configuration.
Location: `src/core/InternalSwapPool.sol:75`, `:265`; `src/DicesHook.sol:115`, `:752`.

### Description

`DicesHook.feeCalculator` is replaceable. `InternalSwapPool.feeCalculator` is `immutable` and the hook's
reference to the swap pool has no setter. USDC-denominated fees are split by the first; coin-denominated fees
are split by the second when they are converted. After a replacement the two disagree.

### Impact

A change of split by the owner applies to fees from exact-output buys and exact-input sells and not to fees
from exact-input buys and exact-output sells. Recipients are paid by two rules with no on-chain signal that
this is so. No funds are lost: every unit still reaches one of the three recipients.

### Evidence

`testPoC5_swapPoolKeepsTheOldSplitAfterTheCalculatorIsReplaced` passes: after the owner installs a split that
pays everything to the protocol, the next conversion still credits the creator 0.30 USDC and the buy-and-burn
recipient the same.

### Recommendation

Have the swap pool read `dicesHook.feeCalculator()` at conversion time, or move the split into one place.
`test/CalculatorUpdates.t.sol` currently pins the immutability, so the test will need to change with it.

Reported independently by the token-integration (TI-10), Uniswap (V4SF-04), guidelines (F-06) and
code-maturity (F7) reviews.

---

## DICES-09

**The fee model in the code is not the one in the brief as restated in `AGENT.md`**

Severity: Undetermined. Type: specification.
Location: `src/calculators/FeeCalculator.sol:23-38`, `:85-94`; `src/DicesHook.sol:458-483`; `AGENT.md:43-49`;
`README.md:10-13`.

### Description

| | `AGENT.md` section 2 and `README.md` | Code |
| --- | --- | --- |
| Buy fee before Live | 1.25% base + 0.50% to the coin's reserve | 1.25% |
| Buy fee after Live | 1.00% base + 0.50% to the reserve | 1.00% |
| After the reserve target | base + 0.25% to the race pool | No reserve, target or race pool exists |
| Who receives the base fee | Platform and creator | 40% platform, 30% creator, 30% buy and burn |
| Fee currency | USDC, always | The swap's unspecified currency: the coin on exact-input buys and exact-output sells |
| "Every buy funds the coin's casino reserve" | Required output | Not produced |
| Sealed game registered at launch | Required output (`gameCommitment`) | Not in `CoinParams` |

`AGENT.md` carries a note dated 5 November that its Fees, Ledgers, Contracts and Configuration subsections
"predate the internal-swap-pool rework and no longer match the code". That note covers section 3. The rows
above are from section 2, the restated client brief, and from the README, neither of which is flagged.

### Impact

This cannot be rated from the repository. If the client has agreed to replace the reserve surcharge with a
buy-and-burn share, the code is right and the documents are stale (see DICES-17). If not, a required output of
the brief is missing: nothing funds the per-coin casino bankroll that later phases depend on.

### Recommendation

Get the fee model confirmed in writing, then update `AGENT.md` section 2, its open questions 1 to 3 and the
README to match whichever answer stands.

The spec-compliance review extracted 209 statements from `AGENT.md`, `README.md` and NatSpec. 127 match the
code in full, 41 contradict it and 23 describe things that are not in the code. Most of the last two groups
are this one fee-and-ledger design counted sentence by sentence. It rates the missing reserve HIGH as a
compliance gap (DIV-01) and the three-way split and missing game commitment MEDIUM (DIV-02, DIV-05).

Reported by the code-maturity (F4), guidelines (F-02), Uniswap (V4SF-11) and spec-compliance (DIV-01, 02, 05,
08, 09) reviews.

---

## Informational findings

### DICES-10

**A conversion position is opened on every buy; callback gas is high.**
`MINIMUM_INTERNAL_SWAP_POOL_SIZE` is `1e6` (`src/core/InternalSwapPool.sol:90`) and is compared with an
18-decimal coin balance, so it filters nothing: once any fee is queued, every buy adds and removes a liquidity
position. Rounding makes an untouched position cost one raw unit, so the swap pool also runs `sync`, a coin
transfer and `settle` on every such buy. The position state is kept in ordinary storage
(`:80`, `:212`, `:234`) although it never outlives the swap.

Measured from test traces (test environment, cold storage included):

| Callback | Median | Maximum | Uniswap skill's hard ceiling |
| --- | --- | --- | --- |
| `beforeSwap` | 44,558 | 202,036 | 150,000 |
| `afterSwap` | 210,011 | 397,604 | 100,000 (300,000 with external calls) |

Recommendation: express the minimum in whole coins or in USDC value; use transient storage for the position
state; credit three recipients with one token transfer rather than three. Detail in
[`uniswap-v4-security-foundations.md`](uniswap-v4-security-foundations.md), section 7.

### DICES-11

**Production code uses a settler from v4-core's test utilities.**
`src/core/InternalSwapPool.sol:9` imports `@uniswap/v4-core/test/utils/CurrencySettler.sol`, which calls
`transfer` without checking the returned boolean. The repository has its own `CurrencySettler`
(`src/libraries/CurrencySettler.sol`) that uses `SafeERC20`; the hook uses that one. Not exploitable today,
because the only token transferred this way is `DicesCoin`, which reverts on failure.
Recommendation: use the in-repo library in both places.

### DICES-12

**Anyone can initialise the coin implementation.**
`DicesCoin.initialize` has a one-time flag and no caller check (`src/DicesCoin.sol:123-138`), and the
constructor does not set the flag. Clones are unaffected: each has its own storage and is initialised in the
transaction that creates it. A stranger can turn the published implementation address into a token with any
name and a supply minted to themselves (`testPoC7_anyoneCanInitialiseTheCoinImplementation`).
Recommendation: set `_initialized = true` in the constructor.

### DICES-13

**ETH sent to the swap pool is stuck.**
`InternalSwapPool.receive()` accepts ETH from anyone (`src/core/InternalSwapPool.sol:363-365`). The only code
that could send it on is the native branch of `_creditFee` (`:291-292`), which a USDC pool never reaches
(`testPoC13_ethSentToTheSwapPoolStaysThere`).
Recommendation: remove `receive()` and the native branches, or add a sweep to the fee recipient.

### DICES-14

**Levels price the coin on a supply that burning changes.**
`LiveCalculator` multiplies price by a constant `SUPPLY = 1e27` (`src/calculators/LiveCalculator.sol:94`,
`:208`). `DicesCoin.burn` lowers `totalSupply()` (`src/DicesCoin.sol:182-184`), and a buy-and-burn recipient
exists to do exactly that. After burns, the "market cap" that levels use is price × launch supply.
Recommendation: confirm with the client that level targets are meant as price targets, and say so in
`AGENT.md`, which currently states "supply is fixed".

### DICES-15

**Every holder gives Permit2 an infinite allowance.**
solady's `ERC20` grants the canonical Permit2 contract an unlimited allowance by default
(`_givePermit2InfiniteAllowance`, solady `ERC20.sol:667-669`) and `DicesCoin` does not override it. It cannot
be revoked, and `approve(PERMIT2, x)` with `x` below the maximum reverts
(`testPoC15_permit2AllowanceIsInfiniteAndFixed`). A signed Permit2 message is still needed to move coins. Recommendation: keep it if the gas saving for Universal Router users is wanted, and
document it; otherwise override the function to return `false`.

### DICES-16

**Code that cannot run or has no effect.**

- `_beforeInitialize` after its first check (`src/DicesHook.sol:260-279`): the PoolManager skips callbacks for
  the hook's own calls, so the function is only ever entered by a third party and always reverts at `:257`.
  The fee, spacing and USDC checks and the `launchBlock` write never run on a real launch.
- `_beforeRemoveLiquidity` would not stop the hook itself, for the same reason. The lock on launch liquidity
  holds because the hook contains no removal call, which is a convention rather than a guard.
- `lastSwapBlock` (`:185`, `:339`) is written on every swap and read by no contract or script in the
  repository. Its comment says it is for a buy-and-burn contract, which is not here.
- `_getSender` is called twice per swap (`:350`, `:373`) and both results are discarded by the swap pool.
- `CurrencySettler.settle`'s `payer != address(this)` branch (`src/libraries/CurrencySettler.sol:40-41`).
- `src/interfaces/IFlaunch.sol`; the `PoolSwap`, `PoolLiquidityDelta` and `PoolDonation` events and the
  `emitLiquidityDeltaUpdate` and `emitDonationUpdate` functions (`src/libraries/UniswapEvents.sol`).
- `DicesHook.internalSwapPool` and `feeEscrow` are written only in the constructor and could be `immutable`.

Recommendation: remove what is unused. It costs gas per swap, it counts towards the 100% coverage figure
without being reachable, and it uses bytecode the hook is short of.

### DICES-17

**Documentation and comments promise things the code does not do.**

Security-relevant statements:

| Statement | Where | What the code does |
| --- | --- | --- |
| "`beforeRemoveLiquidity` always reverts" / "rejects everyone" | `AGENT.md:68`, `:118` | Admits the swap pool (`src/DicesHook.sol:303`) |
| Fees are held as ERC-6909 claims and withdrawn with `claimFees()` | `AGENT.md:69`, `:82`, `:146`; `README.md:12-13` | ERC-20 credits in `FeeEscrow` |
| Rates are cached in transient storage | `AGENT.md:140` | Read in `afterSwap` before the level sync; same outcome, different mechanism |
| A per-pool `PoolConfig` snapshot fixes a launched coin's terms | `AGENT.md:76`, `:110`, `:233` | No snapshot; the current calculator applies to every pool |
| "A reverting calculator ... never blocks a swap" | `AGENT.md:218-219`; `src/DicesHook.sol:434-435` | True of reverts only (DICES-07) |
| "0-block buys ... unless token creator" | `src/DicesHook.sol:328` | Router allow-list (DICES-06) |
| No level in the first 24 hours "of trading" / "after its first trade" | `AGENT.md:203-205` | The clock starts at the first `qualify`, which `syncLevel` can trigger before any trade. Harmless (rejected candidate R-08) |
| "Supply is fixed at 1e9" | `AGENT.md:188` | `burn` exists (DICES-14) |
| `PoolSwap` is emitted after every swap | `AGENT.md:168`; `src/libraries/UniswapEvents.sol:41-43` | `HookSwap` and `HookFee` are emitted; `PoolSwap` never is |
| `_afterSwap`: "The hook's own swaps." | `src/DicesHook.sol:361` | It runs for everyone else's swaps and never for the hook's |
| "the hook settles the launched token inside `afterSwap`" | `src/libraries/CurrencySettler.sol:21-22` | The swap pool does, through the test-utility settler |
| An untouched position "owes nothing back" | `src/core/InternalSwapPool.sol:242`, `:256` | Rounding makes it cost one raw unit, so the settle runs |
| A holder that crossed the threshold in this block "is not reported" | `src/DicesCoin.sol:162-164`; `AGENT.md:159` | The function returns the lower of the count before this block's first change and the count now (`:170-174`). A same-block joiner can stand in for a same-block leaver; the count can never exceed what it was before the block, which is the property that matters |
| A coin that cannot report its holders "never blocks an observation" | `AGENT.md:208-209` | True only while the average is short of the first target. After that, a reverting read reverts the whole `qualify` call, the hook's `catch` swallows it, and the observation is lost (`src/calculators/LiveCalculator.sol:163-164`, `:371`). Not reachable with the shipped `DicesCoin` |

The four context files under [`context/`](context/) list further comment-level mismatches, each with a line
reference. Recommendation: rewrite `AGENT.md` section 3 and the README from the code, and fix the comments
above. An accurate "what the hook guarantees" list matters most to the casino-phase contracts that will build
on this one.

### DICES-18

**Events leave gaps for indexers and monitoring.**
No event records a coin's creator, name or symbol: `PoolCreated(poolId, coin, usdc)` is all a launch emits
(`src/DicesHook.sol:604`). Escrow `Deposited` events carry no pool id, so fee income cannot be attributed to a
coin from logs. A conversion emits nothing of its own. `HookFee` repeats the fee already carried by
`HookSwap` (`:376-383`), which invites double counting. Recommendation: emit a launch event with the creator;
add the pool id to fee credits or emit a per-swap distribution event; drop the events that are never emitted.

### DICES-19

**Fees are taken from the PoolManager before the swapper pays.**
The hook's `take` of a USDC fee (`src/DicesHook.sol:473`) and the swap pool's `take` of conversion proceeds
(`src/core/InternalSwapPool.sol:262`) happen inside `afterSwap`, while the router settles the swapper's input
only afterwards. The PoolManager pays from its own balance in the meantime. On a live chain it holds every
pool's USDC, so this works. On a fresh chain or a quiet testnet it can revert
(`testPoC11_conversionProceedsAreTakenBeforeTheBuyerPays`). The swap pool also calls `sync` inside the
swapper's unlock, so a router that syncs its input before swapping fails with `CurrencyNotSettled`; the code
says so (`:219-222`) but no integration document does. Recommendation: document both constraints for
integrators, and seed testnet deployments accordingly.

### DICES-20

**Blind spots in the test suite.**
CI enforces 100% coverage of `src/`, and unit and fuzz tests run against a real PoolManager in both currency
orderings. The gaps are in what the tests explore rather than what they touch:

- the invariant suite runs one ordering, small exact-input buys, a stub level calculator and no time movement,
  at 64 runs × depth 32 (`test/DicesHookInvariant.t.sol:36-51`, `:67`; `foundry.toml`);
- most `testFuzz_` functions fuzz only the ordering flag;
- level 10 is reached only with a stand-in coin, which is how DICES-02 went unnoticed;
- there is no test with a zero creator (DICES-01) or a malformed calculator return (DICES-07);
- the launch-block test asserts a bare revert rather than `CannotBuyZeroBlock`
  (`test/DicesHookTrading.t.sol:148`);
- Slither is not in CI and cannot analyse three functions, among them `closeInternalSwapPool`;
- nothing runs against a fork of the deployed PoolManager and Universal Router.

Recommendation: see Step 4 of [`tob-secure-workflow.md`](tob-secure-workflow.md) for the list of properties
that are not yet asserted.

### DICES-21

**Design limits the team already documents.**
Checked and found to be as described, no worse:

- A patient buyer can hold a $200k average for a day at the cost of fees, and split holdings across wallets to
  meet a holder floor (`AGENT.md`, design decisions).
- The bankroll receives 10% of every coin with no restriction and can sell into buyers' USDC (`AGENT.md` open
  question 10). It is also the only party that normally holds enough coins to push a pool's price below its
  launch range, where no liquidity sits and the price moves for free. That lowers the 24-hour average and can
  only delay a level. Upward movement is never free: the upper position runs to the usable tick limit
  (`src/DicesHook.sol:646`, `:653`).
- The hook, the swap pool and the escrow all receive USDC in the swap path and cannot be replaced. If USDC's
  issuer blocked one of them, the affected class of swaps would revert for good.

### DICES-22

**Unbounded inputs.**
Coin `name` and `symbol` are stored as given (`src/DicesCoin.sol:133-134`): front ends must escape them and
may want a length limit. `setCreateFee` accepts any value (`src/DicesHook.sol:783`). `setTrustedRouter`
accepts the zero address (`src/core/TrustedRouters.sol:25`). None has an on-chain consequence that was found.

---

## Rejected candidates

Each was a plausible concern that the check showed to be unfounded. Full reasoning is in
[`fp-check-verification.md`](fp-check-verification.md).

| ID | Candidate | Why it was rejected |
| --- | --- | --- |
| R-01 | A caller starves `qualify` of gas so a swap completes without recording its price | Measured: no gas limit does this. The hook's remaining work costs more than the 1/64 of gas it would have left |
| R-02 | Slither `arbitrary-send-erc20` in `CurrencySettler.settle` | The `transferFrom` branch is unreachable; the only caller passes `address(this)` |
| R-03 | Slither `reentrancy-eth` in `_afterSwap` | Every callee is fixed or owner-set; the late write only ratchets upward |
| R-04 | Slither `weak-prng` in `LiveCalculator._average` | The modulo is a ring index and a rounding test |
| R-05 | The stored conversion state is left behind, or consumed by another pool's swap | Nothing untrusted runs between `beforeSwap` and `afterSwap`; a failed swap reverts the write |
| R-06 | The swap pool or a third party can remove the hook's launch liquidity | Positions are keyed by owner; the swap pool removes only what it added in the same swap |
| R-07 | A conversion can cost more coins than were queued and revert the swap | Proven from the liquidity formulas: cost ≤ inventory |
| R-08 | Starting the 24-hour clock with `syncLevel` at launch reaches a level early | The average is over a moving window; early low observations cannot raise it |

## Cross-reference to the skill reports

The skill reports use their own numbering. This table maps them.

| Finding | Token integration | Uniswap | Guidelines | Code maturity | Spec compliance |
| --- | --- | --- | --- | --- | --- |
| DICES-01 | TI-04 | V4SF-02, V4SF-08 | F-05, F-09 | F1, F10 | DIV-14 |
| DICES-02 | TI-01 | | F-01 | |  |
| DICES-03 | TI-02 | V4SF-01 | F-03 | F2, F8 | DIV-03 |
| DICES-04 | | V4SF-01, V4SF-08 | F-03 | F2 |  |
| DICES-05 | | | F-15 (suspected) | |  |
| DICES-06 | | V4SF-03 | F-07 | F3 | DIV-06 |
| DICES-07 | | | F-08 | F8 | DIV-13 |
| DICES-08 | TI-10 | V4SF-04 | F-06 | F7 | DIV-04 |
| DICES-09 | | V4SF-11 | F-02 | F4 | DIV-01, 02, 05, 08, 09 |
| DICES-10 | TI-11 | V4SF-05 | F-13 | F9 |  |
| DICES-11 | TI-12 | V4SF-07 | F-11 | F6 |  |
| DICES-12 | TI-07 | | F-10 | |  |
| DICES-13 | TI-13 | | F-12 | F11 |  |
| DICES-14 | TI-06 | | | |  |
| DICES-15 | TI-05 | | | |  |
| DICES-16 | | V4SF-12 | F-12 | | DIV-10 |
| DICES-17 | | V4SF-11 | F-02 | F4 | DIV-07, 11, 12, 15, 17 |
| DICES-18 | | | F-14 | | DIV-10 |
| DICES-19 | | V4SF-09 | | |  |
| DICES-20 | | V4SF-06 | F-18 | |  |
| DICES-21 | TI-03, TI-09 | V4SF-10 | F-04 | F5 |  |
| DICES-22 | TI-08 | V4SF-08 | | |  |
