# PEPE RUN — independent security audit of `RunVerifier.sol` and `RunArcade.sol` Scope: `src/RunVerifier.sol` (124 lines), `src/RunArcade.sol` (316 lines), `src/arcade/IArcadeToken.sol`, plus their tests `test/RunVerifier.t.sol` and `test/arcade/RunArcade.t.sol`. All taken from https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe at commit `6083f1b5db4c14344351876ca9d2d057b768ad85`. Line numbers below refer to that commit. I read the backend only where it decides how the contracts are used (`backend/protocol/hashing.mjs`, `backend/protocol/signer.mjs`). Toolchain: forge 1.8.3 and solc 0.8.26, using the repo's own `foundry.toml` with no changes. Mainnet reads were made at block **26,514,125** through the public endpoint `https://ethereum-rpc.publicnode.com`. Token source was read from Sourcify, which reports an exact match. ## Summary **Build and tests.** `forge build` succeeds and the existing suite passes: **38/38** (12 in `RunVerifier.t.sol`, 25 in `RunArcade.t.sol`, and 1 fork test). That fork test, `testForkImdHasNoBurn`, returns early without checking anything unless `IMD_FORK_RPC` is set (`test/arcade/RunArcade.t.sol:520-523`). **PoC tests.** I wrote 9 proof-of-concept tests in a scratch project: 8 unit tests that use the repo's own `MockIMD` harness, and 1 test on a mainnet fork. All 9 pass. Together with the original tests that makes 60/60, with the fork test run against the RPC above. The scratch folder is not submitted, so the PoC source is in the Appendix. **The core contract logic is sound.** On every axis in the brief that the code itself controls, I found no exploitable bug: - **Signature replay** is blocked across chains (`block.chainid` is read on every call), across ledgers (`verifyingContract = msg.sender`), across wallets, nonces, sessions and record types. - **Signature malleability** is closed: low-s is enforced and `v` must be 27 or 28. - **Reentrancy** is blocked by a lock on every function that changes state. - **Awkward token behaviour** (fee-on-transfer, rebasing, a `false` return) causes a revert, because every transfer is checked against exact balance deltas. - **Accounting** of pot and liabilities is conserved. - **No backdoor**: there is no owner, no upgrade path, no withdrawal and no `delegatecall`. **The material risks are in the trust model, not in code bugs:** 1. **Release blocker.** As committed, every mainnet purchase reverts because IMD has no `burn` (**F-00**). I reproduced this on a fork, and also showed that the requester's sink variant works there. 2. **The two score signers together can pick any winner** with any distance, and nothing on chain bounds the score (**F-01**). 3. **The admission authority is also the first score signer**, and the backend asks both score signers to sign inside one function. So "two independent signers" is not enforced anywhere (**F-09**). 4. **Either signer alone can freeze the jackpot** by withholding signatures, and losing a key locks every future pot permanently (**F-02**). 5. **The seed is checked only by the signers.** Nothing on chain checks how the seed was derived, and a deterministic seed known at play time allows bot play (**F-10**). 6. **The sink change** needs specific disclosures and code renames (**F-11**). Severity scale: Critical = blocks release or loses funds; High = one compromise can steal the jackpot; Medium = funds frozen, fairness or disclosure problems; Low and Info = hardening. ## Findings | id | severity | where (file and line) | what goes wrong | proof | fix | |---|---|---|---|---|---| | F-00 | Critical (release blocker, already known) | `src/RunArcade.sol:221-224`, `src/arcade/IArcadeToken.sol:13`; `docs/arcade.md:6-20` | `_collect` calls `IMD.burn(burned)`. Mainnet IMD `0xD34a…63B7` is the Sourcify-verified `BridgedFP` (a LayerZero OFT). Its ABI has no `burn`, so every `purchase` reverts on mainnet. | Fork PoC `testFork_SinkVariant` (Appendix): at block 26,514,125 the original `RunArcade.purchase` reverts. Sourcify ABI read: there is no `burn` function. | Apply the requester-authorised sink change (patch in the Appendix): `transfer(0x…dEaD, p/4)` with exact balance-delta checks, and assert that `totalSupply` is **unchanged**. Remove `burn` from `IArcadeToken`. See F-11 for what must be disclosed. | | F-01 | High | `src/RunArcade.sol:241-267` (no bound on `distanceMeters`; `:259-265` best-score update); `src/RunVerifier.sol:78-94`; immutable signers `:30-31`, `:103-110` | If the admission authority and the replay verifier collude, or both keys are compromised, they can sign a `Score` with any distance (up to `2^256-1`) for an entry they bought for 1 IMD. They win 100% of the pot, including other players' stakes, every week. There is no challenge window, no plausibility bound and no key rotation. The only response is to abandon the contract, and the current week's pot is lost to them when you do. | `testPoC_F01_ColludingSignersChooseWinner`: Bob funds 10 entries and scores 5,000 m. Mallory pays 1 IMD, gets a `type(uint256).max` score signed by both keys, and receives the full 5.5 IMD pot. | (a) Make the signers truly independent: separate operators, separate infrastructure, HSM-held keys (see F-09). (b) Add a public challenge window between the week's close and payout in which a third key or k-of-n verifier set can veto a provably invalid replay. Publish replays (with `replayHash`) so anyone can re-run them. (c) Consider an immutable k-of-n replay-verifier set instead of a single key. (d) Optionally add a `MAX_METERS` bound derived from the rules. Each of these changes the design and needs requester sign-off. | | F-02 | Medium | `src/RunArcade.sol:254`, `:272-284`; no rescue path anywhere in the contract | Either signer alone can refuse to sign, or censor chosen players, so no score lands and the pot rolls over. If either key is lost, every future pot rolls forever: there is no owner, no rotation and no recovery. Funds are not stolen, but they are frozen permanently. A score signed after the week closes is rejected even with both signatures. | `testPoC_F02_SingleSignerWithholdingFreezesPot`: with only the authority's signature the score reverts with `InvalidSignature`. The pot rolls for 3 weeks, the balance equals the liabilities with no exit, and a late score reverts with `ScoreAfterClose`. | Back up both keys in HSMs with documented recovery. Monitor signing latency and publish an SLA. Disclose to players that a signer outage means the jackpot rolls over and that there is no recovery. A k-of-n verifier set (F-01c) also removes the single point of failure. | | F-03 | Low (not reachable with the current IMD) | `src/RunArcade.sol:272-297` | Settlement is strictly sequential (`nextUnsettledEpoch`), and the payout is pushed to the winner inside `settle`. If one week's payout reverts, that week and **all later weeks** can never settle. The OpenZeppelin v5 `ERC20._update` in IMD only reverts on a zero address or an insufficient balance, and neither can occur here, so the current token cannot trigger this. A future token change or a different token could. | `testPoC_F03_OneFailedPayoutBlocksAllLaterWeeks`, using mock mode 4 (`transfer` returns `false`): repeated `settle()` calls stay stuck at the first week. | Use pull payments: `settle` records `claimable[winner] += amount` and moves on, and the winner calls `claim()`. This keeps the no-admin property and isolates any failure to one winner. | | F-04 | Low | `src/RunArcade.sol:249`, `:256`; `submitScore` is permissionless (`:240`) | Each entry can be scored only once, and whoever relays first decides which score counts. If the signers ever sign two different `Score`s for the same entry (a retry, a re-verification or a bug), a mempool observer or the player can submit the worse or the better one. | `testPoC_F04_FirstSubmittedSignedScoreWins`: Bob relays the 100 m score first, the 900 m score then reverts with `AlreadyScored`, and the recorded best is 100. | Backend invariant: sign at most one `Score` per `sessionId`, enforced by a unique constraint in the signer store and not only in the runtime. Add this to the operations runbook. | | F-05 | Info | `src/RunVerifier.sol:97-106` | `seedCommitment()` and `deriveSeed()` mix in `msg.sender`, but `RunArcade` never calls them. An off-chain `eth_call` that does not set `from = ledger` silently returns a different commitment or seed. The backend computes these itself with an explicit `ledger` (`backend/protocol/hashing.mjs:107-125`), so this is a footgun for integrators, not a live bug. | `testPoC_F05_SeedViewsDependOnCaller`. | Either take `ledger` as an explicit argument, or document that `from` must be set to the RunArcade address. | | F-06 | Info (disclosure) | `src/RunArcade.sol:183`, `:150-152` | Royal status is captured when an entry is bought. Royal bought later in the same week does not apply to entries already bought, and any score carrying the Royal flag for such an entry reverts. | `testPoC_F06_RoyalNotRetroactive`. | State this in the shop UI ("Royal applies to entries bought after it, until Sunday 20:00 UTC"). | | F-07 | Medium (fairness and disclosure) | `src/RunArcade.sol:24-26`, `:174`, `:254`; `backend/protocol/hashing.mjs:113-118` | Entries close at 19:30 UTC Sunday and scores must be mined before 20:00 UTC. The backend refuses to derive a seed until block `entryBlock+2` is finalized. Finality is reached at epoch checkpoints, about 2 epochs, or 64 slots × 12 s = 768 s, by my calculation. So an entry bought at 19:29:59 has at most about 1,033 s for play, two signatures and inclusion. If finality stalls (ethereum.org describes the inactivity leak for chains that "fail to finalize"), no late entry can be scored and the week may roll over. | `testPoC_F07_LateEntryWindow`: the window is 1,801 s, about 1,033 s once finality is subtracted, and a score at 20:00:00 reverts. | Disclose this window before purchase. Alternatively, and only with requester approval since it changes the agreed timing, close entries earlier or add a scoring grace period with settlement delayed by the same amount. The two windows must stay disjoint, as they are now (`:254` against `:274`). | | F-08 | Info (positive) | `src/RunArcade.sol:166-210`, `:212-237` | A compromised admission authority alone **cannot** grant a free skin, a Royal life or an entry. Every action calls `transferFrom` for the full price, and `msg.sender` must equal `a.wallet`. It also cannot choose a winner (that needs the replay signature) or move any funds. What it **can** do: refuse paid play (censorship), or admit wallets that fail legal eligibility checks (see F-12). | `testPoC_F08_AuthorityAloneCannotGrantFreeItems`: a signed skin admission for a wallet with no IMD reverts and no skin is granted. | Keep this as is. | | F-09 | High (integration) | `src/RunArcade.sol:30`, `:176`, `:255`; `backend/protocol/signer.mjs:5`, `:23-31` | On chain, the **admission authority** is also the first score signer (`ADMISSION_AUTHORITY` is passed to `verifyScore`). The admission key is the always-online signer that answers purchase requests, which makes it the easiest key to steal. The backend instead models a separate `score-authority` role. (a) If operators provision a distinct score-authority key, every score reverts on chain and every week rolls over (F-02). (b) `signScore()` asks both the authority and the replay verifier to sign in one function in one process, so whoever runs that process controls both signatures. That collapses F-01 to a single compromise. | Code reading. The constructor stores only `ADMISSION_AUTHORITY` and `REPLAY_VERIFIER` (`RunArcade.sol:103-110`), while `signer.mjs:5` lists three roles and `:27-31` signs with both adapters in one call. | Pick one model and enforce it. Preferred: add an immutable `SCORE_AUTHORITY` that is distinct from both other keys, and run the replay verifier as a separate service, under a separate operator, that re-executes the replay from published evidence before signing. Never call both signers from one process. | | F-10 | Medium (system) | `src/RunVerifier.sol:21-31` (the `Score` struct has no seed, block hash or secret), `:101-106`; `src/RunArcade.sol:189-192`; `backend/protocol/hashing.mjs:113-125` | (1) **The seed protocol is not enforced on chain.** Only `seedCommitment` is stored. The seed reveal, the block hash and the derived seed are never checked by the contract, so seed correctness rests entirely on the two signers. (2) **Bias.** The game server cannot grind the seed alone: the secret is committed in the admission before payment, and `blockhash(entryBlock+2)` comes afterwards. A player cannot predict the seed without the secret. But a block proposer or block builder who controls the contents of block `entryBlock+2` *and* knows `seedSecret` (that is, colludes with the server) can try many block variants and choose the seed. Requiring finality stops reorgs, not grinding of block contents. (3) **Seed blocks older than 256 blocks.** This does not apply: the contract never executes `BLOCKHASH`, and the backend reads the finalized hash over RPC, so blocks far older than 256 are fine. If derivation is ever moved on chain, Solidity's `blockhash` returns zero for blocks outside the most recent 256, and any such move would need EIP-2935 or a header proof. (4) **Bots.** The runner is deterministic for a given seed. If the client knows the seed (or upcoming obstacles) while playing, a bot or TAS can produce a perfectly valid replay, and replay verification cannot tell it apart from a human. | Code reading. There is no on-chain test because nothing on chain consumes the seed. | Keep `seedSecret` in the HSM or a separate service, away from any block-building relationship. Publish `seedSecret` and the evidence after each run so anyone can check the seed. Add server-side anti-bot measures (input-timing statistics, streaming the seed or obstacles just in time) and disclose that a determined bot cannot be fully excluded. | | F-11 | Medium (disclosure and integration) | Proposed change to `src/RunArcade.sol:221-232`; `:9-11`, `:70`, `:88` (naming) | The sink is the requester's decision; these are its consequences. (1) **`totalSupply` does not fall.** Tokens sent to `0x…dEaD` stop circulating but remain counted (the fork PoC asserts `totalSupply` unchanged). (2) **0xdEaD is a convention, not a proof.** No one is known to hold its key, but nothing makes it provably unspendable. LayerZero's own OFT uses `0xdead` as its fallback mint target. (3) **The sink's balance is shared.** At block 26,514,125, `0xdEaD` already held **875.583082017371132001 IMD** that did not come from the arcade. The arcade's contribution must be summed from `Distributed` events, not read from the sink's balance. (4) **Naming.** The event field `burned`, the `BurnFailed` error, the NatSpec "destroyed via IMD.burn" and `docs/arcade.md` must be renamed, for example to `sunk` and "sent to 0x…dEaD", or the UI will misstate what happens. (5) **Token trust.** IMD is a bridged LayerZero OFT whose `owner()` at block 26,514,125 is `0x047F606fD5b2BaA5f5C6c4aB8958E45CB6B054B7`, which has no contract code (so it is an EOA). The owner can call `setPeer` (`onlyOwner`), and a malicious or misconfigured peer can mint IMD on Ethereum through `_credit`→`_mint`. That would inflate supply and dilute the value of the pot and of anything sent to the sink. The owner can also change the name and symbol (`updateName`/`updateSymbol`). | `testFork_SinkVariant` (mainnet fork, real IMD): the original contract reverts; the sink variant splits a 1 IMD entry as 0.5 to the pot, 0.25 to `0xdEaD` and 0.25 to DEV, `totalSupply` is unchanged, and `sink0 > 0`. On-chain reads of `owner()`, `balanceOf(0xdEaD)` and the owner's code size were made with `cast` at that block. | Ship the patch in the Appendix, rename as above, and add the sink tests to the repo suite. Suggested disclosure text: "25% of every purchase is sent to the address 0x000000000000000000000000000000000000dEaD, from which no one is known to be able to move tokens. These tokens leave circulation, but IMD's totalSupply does not decrease. IMD is a LayerZero-bridged token whose owner can configure bridge peers." Identify tokens by contract address, not by symbol. | | F-12 | Low (compliance) | `src/RunVerifier.sol:7-18`; `src/RunArcade.sol:208` | `termsHash` and `policyHash` are signed and emitted, but the contract checks them against nothing. The contract has no pause, so "paid play only after legal eligibility is validated" is enforced **only** by the admission authority refusing to sign. If that key leaks, anyone can buy (they still pay full price, so no funds are lost, but this is a legal exposure). The `Admission` also does not bind an `entryId`; that is fine because `sessionId == entryId` is enforced when scoring (`:246-253`). | Code reading. | Before mainnet: keep the admission key cold until approvals exist, publish the terms and policy documents whose hashes are signed, and document the legal-gating role in the operations runbook. | | F-13 | Info | `src/RunVerifier.sol:112-123` | Only ECDSA signatures from externally owned accounts are accepted (no EIP-1271), so a Safe or multisig cannot be a signer. Malleability is handled correctly: `s ≤ n/2`, `v ∈ {27,28}`, `r,s ≠ 0`, and a signer of `0` is rejected (`:71`, `:85`; the constructor checks at `RunArcade.sol:104-107`). | The existing `testNoncanonicalSignatures` and `testSwappedDuplicatedAndCrossTypeSignatures` tests pass. | Use HSM-backed EOAs and document that choice. | | F-14 | Info | `src/RunArcade.sol:299-308`; no `receive` function | Anyone can absorb unaccounted IMD into the current week's pot, which is harmless. ETH sends revert. Non-IMD tokens sent to the contract are stuck forever. | Code reading; the existing `testDonationAccounting` test passes. | Disclose in the docs: "Tokens other than IMD sent to the contract are unrecoverable." | | F-15 | Low (tests) | `test/arcade/RunArcade.t.sol:22-66`, `:520-523` | The suite tests a mock token that has `burn`, so the sink path that will actually ship has no tests. The fork test passes vacuously without an RPC. There is no stateful invariant test of `balance ≥ liabilities` across random `purchase`, `submitScore`, `settle` and `absorbDonations` sequences. | Code reading. | Port `testFork_SinkVariant` into the repo with a pinned block. Add a Foundry invariant test, and run the fork test in CI with an RPC secret. | ### Checked and found sound (no finding) **Signature replay** - **Across chains and forks:** the domain separator recomputes `block.chainid` on every call (`RunVerifier.sol:53-55`), as EIP-712 intends. - **Across ledgers:** `verifyingContract = msg.sender`, which is the calling RunArcade (`:54`). - **Across wallets:** a purchase requires `msg.sender == a.wallet` (`RunArcade.sol:171`), so a stolen admission is useless to anyone else. - **Nonces:** the nonce is checked before verification and stored before any external call (`:175-177`). - **Sessions:** `sessionId` must equal `entryId`, and the `scored` flag allows one score per entry (`:246-256`). - **Across record types:** admission and score use distinct typehashes (`RunVerifier.sol:33-39`). This is covered by the existing tests. **Signature malleability:** handled in `RunVerifier.sol:112-123`; see F-13. **A score for another wallet's entry:** rejected. `s.wallet` must equal `e.wallet` (`RunArcade.sol:251`), and the payout goes to `_entries[best].wallet` (`:285`), so relaying someone else's score can only pay *them*. Epoch, Royal flag, seed commitment and rules hash are all bound to the stored entry (`:250-253`). **Reentrancy and token behaviour** - All state-changing functions use `nonReentrant` (`:96-101`). - The real IMD has no transfer hooks: Sourcify source, OpenZeppelin v5 `ERC20`. - Fee-on-transfer, rebasing and a `false` return revert through exact balance-delta checks and `_call` (`:217-232`, `:290-295`, `:310-315`). This is covered by the existing tests. **Accounting** - `liabilities` rises by the jackpot share or by absorbed donations, and falls only by a paid amount (`:235`, `:287`, `:306`). - A rollover moves the pot without changing `liabilities` (`:279-283`), and an empty week rolls over 0. - Purchases always credit `currentEpoch()`, which can never be settled yet, since `settle` requires `block.timestamp ≥ epochEnd`. - The existing fuzz test `testFuzzConservation` passes. **Week boundaries:** `EPOCH_ANCHOR = 331,200 s = 3 days + 20 h`, which is Sunday 1970-01-04 20:00 UTC, since 1970-01-01 was a Thursday. The entry cutoff is `start + 604,800 − 1,800`, which is 19:30 UTC Sunday. The scoring window (`< epochEnd`, `:254`) and the settlement window (`≥ epochEnd`, `:274`) are disjoint, so no one can settle early to cut off scores. The calendar is UTC, with no daylight-saving shifts. **Griefing settlement:** `settle` is permissionless and O(1) per week. A week that nobody calls can be settled later in order. Nobody can force a week to stay unsettled with the current token (see F-03 for the general case). **Owner, upgrade and backdoor:** none found. There is no owner variable, no proxy, no `delegatecall`, no `selfdestruct` and no withdrawal function. Prices are constants of 1, 5 and 10 × `UNIT` (`:137-142`), `DEV` is a constant (`:15`), and the signers are immutable. The existing `testNoAdminSurface` test passes. **Free skins and lives:** the colluding signers can choose a winner (F-01), but they cannot mint skins or Royal lives without payment, and they cannot withdraw the pot except by "winning" it. That is still a full drain of each week's pot. ## What to do next | # | action | |---|---| | 1 | Apply the sink patch (Appendix) to `src/RunArcade.sol` and `src/arcade/IArcadeToken.sol`, rename `burned`/`BurnFailed`/NatSpec/docs to "sink", and commit `testFork_SinkVariant` with pinned block 26,514,125 (F-00, F-11). | | 2 | Separate the score signer from the admission signer on chain (`SCORE_AUTHORITY` immutable), and change `backend/protocol/signer.mjs` so the replay verifier signs in its own service after re-executing the replay itself (F-09). | | 3 | Decide and implement the collusion mitigation: a challenge window with a veto key or k-of-n set, published replays, and optionally `MAX_METERS`. This changes the design and needs requester sign-off (F-01). | | 4 | Switch payouts to pull-based `claim()` so one failed payout cannot freeze later weeks (F-03). | | 5 | Name the signer operators, put the keys in HSMs with written backup and recovery procedures, and publish a signing SLA. Disclose that a signer outage means a rollover with no recovery (F-02). | | 6 | Add a sign-once-per-`sessionId` unique constraint in the signer store (F-04). | | 7 | Publish the player disclosures before paid play: sink and `totalSupply` text, the IMD owner/peer trust, the Royal timing, the 19:30–20:00 scoring window and its finality caveat, bot limits, and stuck non-IMD tokens (F-06, F-07, F-10, F-11, F-14). | | 8 | Add a Foundry invariant test (`balance ≥ liabilities`, the sum of unsettled pots equals `liabilities`) and run the fork tests in CI (F-15). | | 9 | Re-run this audit on the patched contracts, then deploy to Sepolia with a plain OpenZeppelin ERC20 (no burn) standing in for IMD and run a full week end to end before any mainnet deploy. | ## Not checked - **Prices against the requester's spec.** The prices of 1, 5 and 10 IMD come only from the contract (`RunArcade.sol:137-142`). The brief I received truncates the price list, so I could not compare them. - **Signer deployment.** I did not see which key or adapter backs which role, which operators run them, or whether they share infrastructure. F-09 is based on code alone. - **Game client and runtime.** I did not check whether the client receives the seed or upcoming obstacles before or while playing, so the bot risk in F-10 is unconfirmed. I also did not check whether skins affect hitboxes, or whether the replay engine is deterministic across platforms. - **Live Sepolia.** I ran only the mainnet fork and local tests. I made no Sepolia deployment and sent no transactions. - **Who controls the IMD token.** I did not check who controls `0x047F606f…` or which LayerZero peers and DVN configuration the token uses. I did not check whether anyone holds the key to `0x…dEaD`, which cannot be checked by construction. - **Finality timing.** The 768 s figure is my arithmetic (64 slots × 12 s), not a measured value. The proposer timestamp rules after the Merge are not separately sourced here. - **Formal verification and gas.** I did no formal verification, symbolic execution or gas profiling. - **The rest of the system.** I audited only the parts of the backend, API, indexer, web app and legal posture that are named above. ## Appendix A — sink patch (as tested on the fork) Add the constant and replace the burn block in `_collect`: ```solidity address public constant SINK = 0x000000000000000000000000000000000000dEaD; ... uint256 supply0 = IMD.totalSupply(); uint256 sink0 = IMD.balanceOf(SINK); _call(abi.encodeCall(IArcadeToken.transfer, (SINK, burned))); if (IMD.balanceOf(SINK) != sink0 + burned) revert TokenTransferFailed(); uint256 dev0 = IMD.balanceOf(DEV); _call(abi.encodeCall(IArcadeToken.transfer, (DEV, developer))); if (IMD.balanceOf(DEV) != dev0 + developer || IMD.balanceOf(address(this)) != bal0 + jackpot) { revert TokenTransferFailed(); } if (IMD.totalSupply() != supply0) revert BurnFailed(); // rename: SupplyChanged ``` ## Appendix B — PoC tests (scratch; `test/PoC.t.sol`, imports the repo test as `Base.t.sol`) Run with `IMD_FORK_RPC= forge test --match-path test/PoC.t.sol`. Result: 33/33 in `PoCTest` (8 PoCs plus the 25 inherited tests) and 1/1 in `SinkForkPoC`. ```solidity contract PoCTest is RunArcadeTest { Vm2 internal constant V = Vm2(address(uint160(uint256(keccak256("hevm cheat code"))))); function _scoreFor(uint256 id, uint256 meters, uint256 salt) internal view returns (RunVerifier.Score memory s) { RunArcade.Entry memory e = arcade.entryOf(id); s = RunVerifier.Score(e.wallet, bytes32(id), e.epoch, meters, e.royal, e.seedCommitment, e.rulesHash, keccak256(abi.encode(salt)), block.timestamp + 600); } function testPoC_F01_ColludingSignersChooseWinner() public { for (uint256 i; i < 10; i++) _buy(bob, 1, 0); _submit(1, 5_000); address mallory = V.addr(0xBAD); token.mint(mallory, 1 * E); uint256 mid = _buy(mallory, 1, 0); RunVerifier.Score memory s = _scoreFor(mid, type(uint256).max, 1); arcade.submitScore(s, _sigScore(s, AUTH_KEY), _sigScore(s, REPLAY_KEY)); _toEnd(EPOCH); uint256 pot = arcade.weekOf(EPOCH).pot; arcade.settle(); require(token.balanceOf(mallory) == pot && pot == 55 * E / 10); } function testPoC_F02_SingleSignerWithholdingFreezesPot() public { uint256 id = _buy(bob, 1, 0); RunVerifier.Score memory s = _scoreFor(id, 9_999, 2); bytes memory a = _sigScore(s, AUTH_KEY); V.expectRevert(RunVerifier.InvalidSignature.selector); arcade.submitScore(s, a, a); for (uint256 w; w < 3; w++) { _toEnd(EPOCH + w); arcade.settle(); } require(arcade.weekOf(EPOCH + 3).pot == E / 2); require(token.balanceOf(address(arcade)) == E / 2 && arcade.liabilities() == E / 2); V.warp(arcade.epochEnd(EPOCH + 3)); RunVerifier.Score memory late = _scoreFor(id, 9_999, 3); bytes memory la = _sigScore(late, AUTH_KEY); bytes memory lr = _sigScore(late, REPLAY_KEY); V.expectRevert(RunArcade.ScoreAfterClose.selector); arcade.submitScore(late, la, lr); } function testPoC_F03_OneFailedPayoutBlocksAllLaterWeeks() public { uint256 id = _buy(alice, 1, 0); _submit(id, 1); _toEnd(EPOCH); uint256 id2 = _buy(bob, 1, 0); _submit(id2, 7); _toEnd(EPOCH + 1); token.setMode(4); V.expectRevert(RunArcade.TokenTransferFailed.selector); arcade.settle(); V.expectRevert(RunArcade.TokenTransferFailed.selector); arcade.settle(); require(arcade.nextUnsettledEpoch() == EPOCH); } function testPoC_F04_FirstSubmittedSignedScoreWins() public { uint256 id = _buy(alice, 1, 0); RunVerifier.Score memory lo = _scoreFor(id, 100, 4); RunVerifier.Score memory hi = _scoreFor(id, 900, 5); bytes memory la = _sigScore(lo, AUTH_KEY); bytes memory lr = _sigScore(lo, REPLAY_KEY); bytes memory ha = _sigScore(hi, AUTH_KEY); bytes memory hr = _sigScore(hi, REPLAY_KEY); V.prank(bob); arcade.submitScore(lo, la, lr); V.expectRevert(RunArcade.AlreadyScored.selector); arcade.submitScore(hi, ha, hr); require(arcade.weekOf(EPOCH).bestMeters == 100); } function testPoC_F05_SeedViewsDependOnCaller() public { bytes32 secret = keccak256("secret"); bytes32 asEoa = verifier.seedCommitment(alice, 1, secret); V.prank(address(arcade)); require(asEoa != verifier.seedCommitment(alice, 1, secret)); uint32 s1 = verifier.deriveSeed(1, secret, bytes32(uint256(7))); V.prank(address(arcade)); require(s1 != verifier.deriveSeed(1, secret, bytes32(uint256(7)))); } function testPoC_F06_RoyalNotRetroactive() public { uint256 id = _buy(alice, 1, 0); _buy(alice, 3, 21); require(arcade.royalActive(alice) && !arcade.entryOf(id).royal); RunVerifier.Score memory s = _scoreFor(id, 10, 6); s.royal = true; bytes memory a = _sigScore(s, AUTH_KEY); bytes memory r = _sigScore(s, REPLAY_KEY); V.expectRevert(RunArcade.ScoreMismatch.selector); arcade.submitScore(s, a, r); } function testPoC_F07_LateEntryWindow() public { V.warp(arcade.entryCutoff(EPOCH) - 1); uint256 id = _buy(alice, 1, 0); uint256 window = arcade.epochEnd(EPOCH) - block.timestamp; require(window == 1801 && window - 64 * 12 == 1033); V.warp(arcade.epochEnd(EPOCH)); RunVerifier.Score memory s = _scoreFor(id, 10, 7); bytes memory a = _sigScore(s, AUTH_KEY); bytes memory r = _sigScore(s, REPLAY_KEY); V.expectRevert(RunArcade.ScoreAfterClose.selector); arcade.submitScore(s, a, r); } function testPoC_F08_AuthorityAloneCannotGrantFreeItems() public { address eve = V.addr(0xE7E); RunVerifier.Admission memory a = _adm(eve, 2, 7); bytes memory sig = _signAdm(a, AUTH_KEY); V.prank(eve); V.expectRevert(); arcade.purchase(a, sig); require(!arcade.ownsSkin(eve, 7)); } } contract SinkForkPoC { // fork at block 26_514_125, real IMD at 0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7 // _fund(): finds IMD's balance mapping slot by matching vm.load(keccak(0xdEaD, slot)) to balanceOf(0xdEaD), then vm.store for the player. function testFork_SinkVariant() public { V.createSelectFork(rpc, BLOCK); _fund(player, 10e18); RunVerifier v = new RunVerifier(); RunArcade orig = new RunArcade(v, V.addr(authKey), V.addr(0xB0B)); /* signed entry admission, approve 1e18 */ V.expectRevert(); orig.purchase(a, sig); // no IMD.burn on mainnet RunArcadeSink sink = new RunArcadeSink(v, V.addr(authKey), V.addr(0xB0B)); /* signed entry admission, approve 1e18 */ sink.purchase(a, sig); require(IERC20x(IMD).totalSupply() == supply0); // totalSupply unchanged require(_bal(SINK) == sink0 + 0.25e18 && _bal(DEV) == dev0 + 0.25e18); require(_bal(address(sink)) == 0.5e18 && sink.liabilities() == 0.5e18); require(sink0 > 0); // 0xdEaD already held third-party IMD } } ```