Hooks.wtf

Core contracts

DicesHook.sol

DicesHook creates coins, locks launch liquidity, validates hook callbacks, collects swap fees and synchronises game levels. Its findings cover launch validation, owner controls, calculator failures, trading restrictions and integration assumptions.

Reviewed source: src/DicesHook.sol at commit bcd45b2.

Findings

IDSeverityFinding
DICES-01MediumA zero creator or buy-and-burn recipient makes USDC-fee swaps revert
DICES-03MediumThe owner can change the fee, the split and the level of existing pools without bound or delay
DICES-06LowThe launch-block guard does not stop anyone who uses the trusted router
DICES-07LowA calculator that returns malformed data halts every swap; the level is not bounded
DICES-16InformationalCode that cannot run or has no effect
DICES-17InformationalDocumentation and comments promise things the code does not do
DICES-18InformationalEvents leave gaps for indexers and monitoring
DICES-19InformationalFees are taken from the PoolManager before the swapper pays
DICES-20InformationalBlind spots in the test suite
DICES-21InformationalDesign limits the team already documents

[MEDIUM] DICES-01 · A zero creator or buy-and-burn recipient makes USDC-fee swaps revert

Affected modules: DicesHook.sol, InternalSwapPool.sol, FeeEscrow.sol, V001.s.sol.

Severity: Medium. Difficulty: Low. Type: data validation, denial of service.

Affected code: 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:

// 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:

// 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):

SwapFee currencyResult
Buy, exact USDC in, first oneCoinSucceeds; the fee is only queued
Buy, exact USDC in, once it trades into the conversion rangeCoin, plus conversion proceeds in USDCReverts
Buy, exact coin outUSDCReverts
Sell, exact coin inUSDCReverts
Sell, exact USDC outCoinSucceeds

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.

Recorded test source and output: poc-tests.md.

Source finding: findings.md, DICES-01.

[MEDIUM] DICES-03 · The owner can change the fee, the split and the level of existing pools without bound or delay

Affected modules: DicesHook.sol, FeeCalculator.sol, LiveCalculator.sol.

Severity: Medium. Difficulty: High (needs the owner key). Type: access control, centralisation.

Affected code: 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:

// 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.

Recorded test source and output: poc-tests.md.

Source finding: findings.md, DICES-03.

[LOW] DICES-06 · The launch-block guard does not stop anyone who uses the trusted router

Affected modules: DicesHook.sol, InternalSwapPool.sol, TrustedRouters.sol, V001.s.sol.

Severity: Low. Difficulty: Low. Type: access control, transaction ordering.

Affected code: src/DicesHook.sol:326-336; src/core/TrustedRouters.sol:17-28; script/deployment/V001.s.sol:238, :516.

Description

// 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.

Recorded test source and output: poc-tests.md.

Source finding: findings.md, DICES-06.

[LOW] DICES-07 · A calculator that returns malformed data halts every swap; the level is not bounded

Affected modules: DicesHook.sol, LiveCalculator.sol.

Severity: Low. Difficulty: High (owner error). Type: error handling.

Affected code: src/DicesHook.sol:433-449, :832-838.

Description

// 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.

Recorded test source and output: poc-tests.md.

Source finding: findings.md, DICES-07.

[INFORMATIONAL] DICES-16 · Code that cannot run or has no effect

Affected modules: DicesHook.sol, InternalSwapPool.sol, TrustedRouters.sol, CurrencySettler.sol, UniswapEvents.sol.

Severity: Informational.

  • _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.

Source finding: findings.md, DICES-16.

[INFORMATIONAL] DICES-17 · Documentation and comments promise things the code does not do

Affected modules: DicesHook.sol, DicesCoin.sol, InternalSwapPool.sol, FeeEscrow.sol, FeeCalculator.sol, LiveCalculator.sol, CurrencySettler.sol, UniswapEvents.sol.

Severity: Informational.

Security-relevant statements:

StatementWhereWhat the code does
"beforeRemoveLiquidity always reverts" / "rejects everyone"AGENT.md:68, :118Admits 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-13ERC-20 credits in FeeEscrow
Rates are cached in transient storageAGENT.md:140Read in afterSwap before the level sync; same outcome, different mechanism
A per-pool PoolConfig snapshot fixes a launched coin's termsAGENT.md:76, :110, :233No snapshot; the current calculator applies to every pool
"A reverting calculator ... never blocks a swap"AGENT.md:218-219; src/DicesHook.sol:434-435True of reverts only (DICES-07)
"0-block buys ... unless token creator"src/DicesHook.sol:328Router allow-list (DICES-06)
No level in the first 24 hours "of trading" / "after its first trade"AGENT.md:203-205The 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:188burn exists (DICES-14)
PoolSwap is emitted after every swapAGENT.md:168; src/libraries/UniswapEvents.sol:41-43HookSwap and HookFee are emitted; PoolSwap never is
_afterSwap: "The hook's own swaps."src/DicesHook.sol:361It 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-22The swap pool does, through the test-utility settler
An untouched position "owes nothing back"src/core/InternalSwapPool.sol:242, :256Rounding 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:159The 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-209True 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/ 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.

Source finding: findings.md, DICES-17.

[INFORMATIONAL] DICES-18 · Events leave gaps for indexers and monitoring

Affected modules: DicesHook.sol, InternalSwapPool.sol, FeeEscrow.sol, UniswapEvents.sol.

Severity: Informational.

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.

Source finding: findings.md, DICES-18.

[INFORMATIONAL] DICES-19 · Fees are taken from the PoolManager before the swapper pays

Affected modules: DicesHook.sol, InternalSwapPool.sol.

Severity: Informational.

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.

Recorded test source and output: poc-tests.md.

Source finding: findings.md, DICES-19.

[INFORMATIONAL] DICES-20 · Blind spots in the test suite

Affected modules: DicesHook.sol, DicesCoin.sol, InternalSwapPool.sol, LiveCalculator.sol.

Severity: Informational.

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 for the list of properties that are not yet asserted.

Source finding: findings.md, DICES-20.

[INFORMATIONAL] DICES-21 · Design limits the team already documents

Affected modules: DicesHook.sol, DicesCoin.sol, InternalSwapPool.sol, FeeEscrow.sol, LiveCalculator.sol, V001.s.sol.

Severity: Informational.

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.

Source finding: findings.md, DICES-21.

Shared findings

Previous
Review notes and evidence