# PEPE RUN: independent review of RunVerifier (EIP-712 v2) - **Repository:** https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe - **Commit reviewed:** `bddb39f58e88db884565d1c0c6ee9106f536a2f4`. Commit date is 2026-11-28T04:42:32+00:00 and the review was done on 2026-11-28. No chain state was read. This is a source-only review. - **Scope:** [src/RunVerifier.sol](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol), [test/RunVerifier.t.sol](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/test/RunVerifier.t.sol), [docs/verification.md](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md), [docs/protocol.md](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md). - **Toolchain:** forge 1.8.3 (cae51ad), solc 0.8.26 (from repo [foundry.toml](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/foundry.toml): optimizer 200, evm cancun), cast 1.8.3, node v24.21.0. - **Out of scope / absent:** At this commit the repository has no ledger contract (RunArcade) and no IMD payment, jackpot or settlement code. `git ls-files` lists only `src/RunVerifier.sol` under `src/`. So every ledger-side protection below is an **unverified requirement**, not an observed property. ## 1. Summary RunVerifier is a stateless `view` contract. It computes an EIP-712 domain with name `RunVerifier`, version `2`, `chainId = block.chainid` and `verifyingContract = msg.sender`. It checks one admission signature, or two score signatures from distinct addresses, against roles that **the caller supplies**. Within that design the cryptographic checks are sound: - The encoding matches EIP-712. - The five published vectors reproduce independently with `cast`. - Malleable, high-s, wrong-v, wrong-length, zero-r/s and r≥n signatures are rejected. - A zero recovered address can never match, because zero roles are rejected first. - Replay across chains, ledgers, entries (`sessionId`), weeks (`epoch`) and struct types is rejected. **No critical or high finding was found in the verifier itself.** The real risk is the part the verifier leaves to the ledger: roles, single use, the week window, linking a score to its entry, terms and policy, and ranking. That ledger code does not exist at this commit (§6). ## 2. What I ran and what I measured | # | Command (run in a clean clone at the commit) | Result measured | |---|---|---| | R1 | `forge test -vv` (repo suite only, before my tests were added) | 12 passed, 0 failed. Fuzz runs: 256 each | | R2 | `forge test -vv` with my adversarial suite `test/adv/RunVerifierAdversarial.t.sol` (code in §8) | Repo 12/12 pass, adversarial 13/13 pass (A1–A5, A7–A14; fuzz 256 runs). Total: 25 passed, 0 failed | | R3 | Independent vector recomputation with `cast keccak` / `cast abi-encode` / `cast concat-hex` (no Solidity) | Domain `0xac058b1c…5a3b`, admission struct `0x53ae2a43…f3f1`, admission digest `0x915ddd7d…f842`, score struct `0x93baaaf9…1849`, score digest `0x0a15720c…8b75`. All five equal the values in [verification.md L72-78](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L72-L78) | | R4 | `forge inspect RunVerifier methodIdentifiers` | All 11 selectors equal [verification.md L34-45](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L34-L45) | | R5 | `node backend/protocol/check.mjs` | "protocol check: 3/3 steps passed". The node suite showed 18/18 pass and Foundry 12/12 pass | ## 3. Findings (ranked) No **Critical** or **High** findings. ### M-1 (Medium): The Score does not carry `termsHash`, `policyHash`, `nonce`, `action` or `sku`. Its link to the paid entry exists only through ledger state. - **Where:** - [RunVerifier.sol L21-31](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L21-L31): the Score fields are wallet, sessionId, epoch, distanceMeters, royal, seedCommitment, rulesHash, replayHash and expiry. - [verification.md L61](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L61): the ledger "must require `score.sessionId == bytes32(entryId)`…". - **Effect:** The brief asks that the signature bind termsHash and policyHash. That holds only for the Admission ([L7-18](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L7-L18)). A Score signature is valid whatever terms or policy the entry was admitted under. It is valid for any `sessionId` the ledger treats as existing. If a ledger skips the `sessionId`→entry lookup, a score could be credited: - to a session that was never paid for, or - under a policy the wallet never accepted. - **Repro:** adversarial test `testA9ScoreDoesNotCarryTermsOrPolicy`. A Score signed with no terms or policy field verifies (PASS). - **Fix (ledger):** load the entry by `uint256(score.sessionId)`, then require all of the following equal the stored values: - wallet, epoch, royal, seedCommitment and rulesHash; - the entry must be unscored and paid. Optionally add `termsHash` and `policyHash` to the Score type in a v3, so the score signers attest them as well. ### M-2 (Medium): Roles are caller-supplied, and the domain is "whoever calls". The verifier gives no authority of its own. - **Where:** - [RunVerifier.sol L53-55](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L53-L55) puts `msg.sender` in the domain. - [L66-94](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L66-L94) take `authority` and `replayVerifier` as arguments. - [verification.md L59](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L59) documents this. - **Effect:** Any contract can get `true` for any distance by signing with keys it controls. The only defence is that the real ledger passes role addresses from trusted, preferably immutable, configuration. One mistake in the ledger is a complete bypass, for example: - passing a role taken from calldata, or - an owner-settable role without a timelock. - **Repro:** `testA3RogueCallerOwnRolesAccepted`. `RogueLedger` gets `true` for `distanceMeters = type(uint256).max` with its own keys 7 and 8. The same signatures revert `InvalidSignature` for the real ledger domain (PASS). - **Fix:** ledger checklist items C1 and C2. ### L-1 (Low): Stateless, so signatures can be replayed until expiry. - **Where:** - [verification.md L63](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L63): "A valid signature can be submitted repeatedly to the stateless verifier until expiry." - No storage exists in [RunVerifier.sol](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol). - **Repro:** `testA2StatelessRepeatAccepted`. The same admission signature and the same score signature pair each verify 3× (PASS). - **Fix:** ledger items C3 and C4. ### L-2 (Low): No week or epoch time window in the verifier. - **Where:** [RunVerifier.sol L72, L88](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L88) check only `block.timestamp > expiry`. The epoch is opaque. - **Effect:** - A score for epoch 1 with `expiry = 2^256-1` verifies at any time. - An admission whose expiry passes the 19:30 entry cutoff, or the week end, also verifies. - The week rules are in [protocol.md L78-85](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md#L78-L85). - **Repro:** `testA10NoWeekWindowInVerifier` (PASS). - **Fix:** ledger items C5 and C6. ### L-3 (Low): 32-bit engine seed, and the seed block can be withheld. - **Where:** - [RunVerifier.sol L101-106](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L101-L106): `uint32(...)`. - [protocol.md L44-57](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md#L44-L57). - **Effect:** - There are only 2^32 seeds, so by the birthday bound seeds collide after about 77k entries. That makes precomputed course knowledge reusable across entries, if the engine is deterministic per seed. - The proposer of block `entryBlock+2` can choose not to propose and so change the blockhash. If the proposer colludes with a server that knows `seedSecret`, the pair can pick between outcomes. - The commitment does prevent the server alone from grinding after payment. - **Repro:** analytical. `testA14SeedBinding` only confirms chain and caller binding (PASS). I could not measure exploitability, because I did not review the game engine. - **Fix:** widen the seed, or accept the risk and document it. Treat missed or reorged blocks as invalidating the run, as protocol.md already states. ### L-4 (Low / informational): Only EOA-style ECDSA signers are supported. There is no EIP-1271 and no key rotation. - **Where:** [RunVerifier.sol L112-123](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L112-L123). - **Effect:** - A Safe or other contract signer cannot be a role. - Key rotation depends on the ledger's role configuration. - If the ledger makes roles immutable, as [protocol.md L102-103](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md#L102-L103) suggests, a compromised key cannot be rotated without redeploying. - **Repro:** by inspection. - **Fix:** none needed in the verifier. The ledger should document its rotation and incident procedure (C2). ### L-5 (Informational): One key signs both admission and score. - **Where:** [protocol.md L102-103](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md#L102-L103): "one admission/score authority and one distinct replay verifier". - **Effect:** The authority role controls admission alone. A score needs both the authority and the replay verifier, so a leak of a single key cannot forge a score. How independent the two roles really are operationally cannot be checked from source ([verification.md L59](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L59)). - **Repro:** `testA4OneKeyBothRolesRejected` (PASS). ## 4. Claim-by-claim results | # | Claim checked | Evidence | Result | |---|---|---|---| | 1 | Domain type string is the standard `EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)` | [L40-41](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L40-L41) | pass | | 2 | Domain version is `"2"` and name is `"RunVerifier"` | [L42-43](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L42-L43), R3 | pass | | 3 | Domain separator for chain 1 and ledger 0x11…11 = `0xac058b1c…5a3b` | R3, [test L37-42](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/test/RunVerifier.t.sol#L37-L42) | pass | | 4 | v1 domain vector in the docs differs from v2, so v1 signatures are not accepted | `testA12`, [verification.md L82](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L82) | pass | | 5 | Admission and Score type strings match the struct field order and types | [L7-39](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L7-L39), R3 | pass | | 6 | Struct hash = keccak(abi.encode(typehash, fields)) is EIP-712 `encodeData` for all-static fields (bool→0/1, uint8 padded, address uint160) | R3, EIP-712 spec | pass | | 7 | Digest = keccak(0x1901‖domain‖struct) | [L108-110](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L108-L110), R3 | pass | | 8 | Admission and score digests reproduce the published vectors | R3 | pass | | 9 | Dirty ABI words (bool=2, uint8=257, address with high bits set) cannot create alias digests | `testA11` (decoder reverts) | pass | | 10 | The admission check requires authority ≠ 0 and expiry not passed (inclusive) | [L71-72](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L71-L72), repo `testExpiryBoundary`, `testInvalidRoles` | pass | | 11 | The score check requires two non-zero, distinct signer addresses | [L85-87](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L85-L87), `testInvalidRoles`, `testA4` | pass | | 12 | Both score signatures cover the same digest, and role order is enforced (swapped signatures rejected) | [L90-92](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L90-L92), repo `testSwappedDuplicatedAndCrossTypeSignatures` | pass | | 13 | Bound to the calling ledger (msg.sender) | [L54](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L54), `testWrongLedgerAndChain`, `testA8`, `testFuzzA13` (random caller) | pass | | 14 | Bound to chain id (live `block.chainid`, so it also holds after a fork) | `testWrongLedgerAndChain` (8453), `testA8` (11155111) | pass | | 15 | Bound to entry: Score.sessionId is signed | `testScoreBindsEveryField`, `testA8` | pass | | 16 | Bound to entry: sessionId == bytes32(entryId) is enforced | only a comment at [L20](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L20). The ledger is absent | unknown | | 17 | Bound to wallet (Admission and Score) | `test*BindsEveryField` | pass | | 18 | Bound to week (epoch signed in both structs) | `test*BindsEveryField`, `testA8` | pass | | 19 | rulesHash and seedCommitment signed in both structs | `test*BindsEveryField` | pass | | 20 | termsHash and policyHash signed in the Admission | `testAdmissionBindsEveryField` | pass | | 21 | termsHash and policyHash signed in the Score | [L21-31](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L21-L31) (fields absent). See M-1 | fail | | 22 | Malleability: high-s, v∉{27,28}, length≠65 (incl. 64-byte EIP-2098 compact, 66-byte), r=0, s=0, r≥n rejected | [L113-122](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/src/RunVerifier.sol#L113-L122), repo `testNoncanonicalSignatures`, `testA5` | pass | | 23 | `HALF_CURVE_ORDER` == floor(secp256k1n/2) | `testA1` | pass | | 24 | ecrecover returning address(0) can never satisfy a role | `testA7` (zero role is rejected before recovery) | pass | | 25 | Cross-type confusion (admission signature used as a score signature and vice versa) rejected | repo `testSwapped…` | pass | | 26 | Wrong key in either role rejected (fuzz, 256 random keys) | `testFuzzA13WrongKey` | pass | | 27 | Replay of the same signature prevented | stateless by design, `testA2`. Left to the ledger | fail (in verifier, by design); unknown (ledger) | | 28 | Week, cutoff and submission window enforced | `testA10`. Left to the ledger | fail (in verifier, by design); unknown (ledger) | | 29 | Selectors in the docs equal the compiled ABI | R4 | pass | | 30 | `check.mjs` cross-checks JS, JSON and Solidity vectors | R5 | pass | | 31 | Two score signers are *operationally* independent | not checkable from source | unknown | | 32 | Contract deployed or verified on Ethereum mainnet | no address in scope. Not checked | unknown | ## 5. Replay matrix (verifier level) | Replay attempt | Blocked by | Test | |---|---|---| | Another chain | `block.chainid` in the domain | `testWrongLedgerAndChain`, `testA8` | | Another ledger or a rogue caller | `msg.sender` in the domain | `testWrongLedgerAndChain`, `testA3`, `testFuzzA13` | | Another entry (score) | `sessionId` signed | `testA8` | | Another week | `epoch` signed | `testA8` | | Another wallet | `wallet` signed | `testScoreBindsEveryField` | | Same entry or nonce a second time | **nothing in the verifier**. The ledger must consume it | `testA2` | | After expiry | `Expired()` | `testExpiryBoundary` | | v1 signatures | version `"2"` | `testA12` | ## 6. Checklist the calling ledger (RunArcade) must meet None of these can be checked at this commit, because the ledger is absent. Each is **unknown** until ledger source exists. - [ ] **C1** The roles passed to `verifyAdmission` / `verifyScore` come from the ledger's own storage or immutables. They never come from calldata or the user. - [ ] **C2** The roles are non-zero, and the authority differs from the replay verifier. Any change to a role has a public, documented process (or roles are immutable). The ledger has a documented compromise and rotation plan. - [ ] **C3** The admission `nonce` is consumed (used[nonce]=true) **before** any token transfer or entry creation. The consumption is reentrancy-safe. A nonce is never reused across actions or SKUs. - [ ] **C4** Each `sessionId` (entry) can be scored at most once. The record is set before ranking state is updated. - [ ] **C5** `admission.epoch` equals the current week computed on-chain (A = 331200, 604800 s). Entries and Royal purchases revert after the 19:30 UTC cutoff ([protocol.md L78-85](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md#L78-L85)). - [ ] **C6** A score is accepted only if `score.epoch` equals the entry's epoch and `block.timestamp < weekEnd(epoch)`. Settlement reads only scores for that epoch. - [ ] **C7** `admission.wallet == msg.sender` (the payer), unless sponsored entry is an explicit, documented feature. `admission.action` and `sku` match the function called, and the price comes from the ledger (1/5/10 IMD × 10^decimals). Price is **not** signed. - [ ] **C8** The ledger stores rulesHash, termsHash, policyHash, seedCommitment, wallet, epoch and royal immutably per entryId, and emits `AdmissionConsumed`. - [ ] **C9** `uint256(score.sessionId)` is an existing, paid, unscored entry. score.wallet, epoch, royal, seedCommitment and rulesHash equal the stored values (M-1). - [ ] **C10** `distanceMeters` is bounded or sanity-checked (the verifier accepts up to 2^256-1, `testA3`). Ties are broken by lower entryId, as [protocol.md](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/protocol.md#L78-L85) states. - [ ] **C11** The ledger checks `verify*`'s return value **or** relies on the revert, and never wraps the call in `try/catch` that falls through. The verifier address is immutable or controlled the same way as roles. - [ ] **C12** If the ledger is a proxy, the verifier is called from proxy context, so `msg.sender` is the proxy address the signers used ([verification.md L3](https://github.com/identity-md-launches/goal-3502-build-audit-deploy-pepe/blob/bddb39f58e88db884565d1c0c6ee9106f536a2f4/docs/verification.md#L3)). Outstanding authorizations are accounted for across upgrades. - [ ] **C13** Royal: `royal` reflects a Royal purchase valid for that epoch, taken at entry, with no stacking. - [ ] **C14** Settlement is permissionless after the week ends, pays exactly one winner, rolls the jackpot over if there is no verified score, and has no admin withdrawal path. ## 7. What I could not check - The ledger (RunArcade), IMD transfers, the 50/25/25 split, burn semantics, and IMD `decimals()`. None of these exist in scope at this commit. - Any deployment, contract verification or on-chain state. No address was given and no chain was read. **Nothing here implies that RunVerifier is deployed, safe to use with real funds, or legally cleared for paid play.** - Off-chain signer services (`backend/protocol/signer.mjs`), the low-s normalisation of the KMS adapter, and whether the two signers are operationally independent. - Game engine determinism and replay validation, which determine whether a signed distance is honest. - Formal verification. Only fuzzing was done: 256 runs per fuzz test. ## 8. Adversarial tests added (not part of the submission; run in a scratch clone) File `test/adv/RunVerifierAdversarial.t.sol` was placed in the clone and run with `forge test -vv`. Result: 13/13 pass alongside the repo's 12/12 (§2). A tautological `testA6` was removed before the final run. ```solidity // SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {RunVerifier} from "../../src/RunVerifier.sol"; interface Vm { function addr(uint256 privateKey) external returns (address); function sign(uint256 privateKey, bytes32 digest) external returns (uint8 v, bytes32 r, bytes32 s); function chainId(uint256 newChainId) external; function warp(uint256 newTimestamp) external; function prank(address sender) external; function expectRevert(bytes4 selector) external; function assume(bool condition) external; } /// Attacker-controlled "ledger" that calls the verifier with roles of its choosing. contract RogueLedger { function check(RunVerifier v, RunVerifier.Score calldata s, address a, address b, bytes calldata sa, bytes calldata sb) external view returns (bool) { return v.verifyScore(s, a, b, sa, sb); } function digest(RunVerifier v, RunVerifier.Score calldata s) external view returns (bytes32) { return v.scoreDigest(s); } } contract RunVerifierAdversarialTest { Vm private constant VM = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); address private constant LEDGER = 0x1111111111111111111111111111111111111111; address private constant WALLET = 0x2222222222222222222222222222222222222222; uint256 private constant AK = 1; uint256 private constant RK = 2; uint256 private constant EXPIRY = 2_000_000_000; uint256 private constant N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141; uint256 private constant HALF = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0; RunVerifier private v; address private auth; address private rep; function setUp() public { v = new RunVerifier(); auth = VM.addr(AK); rep = VM.addr(RK); VM.chainId(1); VM.warp(EXPIRY - 1); } // A1: HALF_CURVE_ORDER equals floor(n/2) function testA1HalfOrderConstant() public pure { require(HALF == N / 2, "half order"); } // A2: verifier is stateless: the same admission and score signatures verify repeatedly (replay must be stopped by ledger) function testA2StatelessRepeatAccepted() public { RunVerifier.Admission memory a = _adm(); bytes memory sig = _sign(AK, _ad(a)); for (uint256 i; i < 3; i++) { VM.prank(LEDGER); require(v.verifyAdmission(a, auth, sig)); } RunVerifier.Score memory s = _sc(); bytes32 d = _sd(s); bytes memory sa = _sign(AK, d); bytes memory sr = _sign(RK, d); for (uint256 i; i < 3; i++) { VM.prank(LEDGER); require(v.verifyScore(s, auth, rep, sa, sr)); } } // A3: any contract gets `true` for its own domain with roles it controls -> result has no authority unless roles come from trusted config function testA3RogueCallerOwnRolesAccepted() public { RogueLedger rogue = new RogueLedger(); RunVerifier.Score memory s = _sc(); s.distanceMeters = type(uint256).max; bytes32 d = rogue.digest(v, s); require(rogue.check(v, s, VM.addr(7), VM.addr(8), _sign(7, d), _sign(8, d))); // ...but the same signatures fail for the real ledger domain VM.expectRevert(RunVerifier.InvalidSignature.selector); VM.prank(LEDGER); v.verifyScore(s, VM.addr(7), VM.addr(8), _sign(7, d), _sign(8, d)); } // A4: a single key cannot satisfy both roles; signer order matters function testA4OneKeyBothRolesRejected() public { RunVerifier.Score memory s = _sc(); bytes32 d = _sd(s); bytes memory sa = _sign(AK, d); VM.expectRevert(RunVerifier.InvalidRoles.selector); VM.prank(LEDGER); v.verifyScore(s, auth, auth, sa, sa); VM.expectRevert(RunVerifier.InvalidSignature.selector); VM.prank(LEDGER); v.verifyScore(s, auth, rep, sa, sa); } // A5: r >= n, r = n exactly, s = n/2 + 1, EIP-2098 64-byte compact form, 66-byte padded form are rejected function testA5MalformedSignatures() public { RunVerifier.Admission memory a = _adm(); (uint8 vv, bytes32 r, bytes32 s) = VM.sign(AK, _ad(a)); _rejA(a, abi.encodePacked(bytes32(N), s, vv)); _rejA(a, abi.encodePacked(bytes32(N + 1), s, vv)); _rejA(a, abi.encodePacked(r, bytes32(HALF + 1), vv)); bytes32 vs = bytes32(uint256(s) | (uint256(vv - 27) << 255)); _rejA(a, abi.encodePacked(r, vs)); _rejA(a, abi.encodePacked(r, s, vv, uint8(0))); _rejA(a, abi.encodePacked(r, s, uint8(29))); _rejA(a, bytes("")); } // A7: garbage that makes ecrecover return address(0) cannot satisfy a role because zero roles are rejected first function testA7ZeroRecoveryNeverMatches() public { RunVerifier.Admission memory a = _adm(); bytes memory garbage = abi.encodePacked(bytes32(uint256(1)), bytes32(uint256(1)), uint8(27)); VM.expectRevert(RunVerifier.InvalidRoles.selector); VM.prank(LEDGER); v.verifyAdmission(a, address(0), garbage); _rejA(a, garbage); } // A8: cross-entry / cross-week / cross-chain / cross-ledger replay of a score are rejected function testA8CrossContextReplay() public { RunVerifier.Score memory s = _sc(); bytes32 d = _sd(s); bytes memory sa = _sign(AK, d); bytes memory sr = _sign(RK, d); RunVerifier.Score memory t = _sc(); t.sessionId = bytes32(uint256(4)); _rejS(t, sa, sr); t = _sc(); t.epoch = 43; _rejS(t, sa, sr); VM.chainId(11155111); _rejS(s, sa, sr); VM.chainId(1); VM.expectRevert(RunVerifier.InvalidSignature.selector); VM.prank(address(0x4444444444444444444444444444444444444444)); v.verifyScore(s, auth, rep, sa, sr); } // A9: Score has no termsHash/policyHash/nonce/action/sku field; a score signed once verifies whatever // terms/policy the entry was admitted under -> ledger MUST tie sessionId to a stored entry function testA9ScoreDoesNotCarryTermsOrPolicy() public { RunVerifier.Score memory s = _sc(); bytes32 d = _sd(s); VM.prank(LEDGER); require(v.verifyScore(s, auth, rep, _sign(AK, d), _sign(RK, d))); } // A10: verifier has no notion of week end; a score with far-future expiry for an old epoch verifies function testA10NoWeekWindowInVerifier() public { RunVerifier.Score memory s = _sc(); s.epoch = 1; s.expiry = type(uint256).max; VM.warp(4_000_000_000); bytes32 d = _sd(s); VM.prank(LEDGER); require(v.verifyScore(s, auth, rep, _sign(AK, d), _sign(RK, d))); } // A11: dirty ABI words (bool=2, uint8>255, address high bits) are rejected by the ABI decoder (no alias digests) function testA11DirtyCalldataRejected() public { RunVerifier.Score memory s = _sc(); bytes memory good = abi.encodeCall(RunVerifier.scoreDigest, (s)); (bool ok,) = address(v).staticcall(good); require(ok); bytes memory bad = _copy(good); bad[4 + 32 * 4 + 31] = 0x02; // royal = 2 (ok,) = address(v).staticcall(bad); require(!ok, "bool=2 accepted"); bad = _copy(good); bad[4] = 0x01; // wallet high byte dirty (ok,) = address(v).staticcall(bad); require(!ok, "dirty address accepted"); RunVerifier.Admission memory a = _adm(); bytes memory ga = abi.encodeCall(RunVerifier.admissionDigest, (a)); bad = _copy(ga); bad[4 + 32 + 30] = 0x01; // action = 257 (ok,) = address(v).staticcall(bad); require(!ok, "uint8 overflow accepted"); } // A12: v1 domain (version "1") differs from v2 function testA12VersionSeparation() public { bytes32 v1 = keccak256(abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256("RunVerifier"), keccak256("1"), uint256(1), LEDGER)); require(v1 == 0x5554712f258a5cdf4b53d60556d6d01206ac547a67915166199694c6e699cd7b, "doc v1 vector"); VM.prank(LEDGER); require(v.domainSeparator() != v1); } // A13: fuzz - signature by any key other than the configured role is rejected; wrong caller rejected function testFuzzA13WrongKey(uint256 k, address caller) public { k = 3 + (k % (N - 4)); VM.assume(caller != LEDGER); RunVerifier.Score memory s = _sc(); bytes32 d = _sd(s); _rejS(s, _sign(k, d), _sign(RK, d)); _rejS(s, _sign(AK, d), _sign(k, d)); bytes memory sa = _sign(AK, d); bytes memory sr = _sign(RK, d); VM.expectRevert(RunVerifier.InvalidSignature.selector); VM.prank(caller); v.verifyScore(s, auth, rep, sa, sr); } // A14: seed is only 32 bits of entropy; deriveSeed binds caller and chain function testA14SeedBinding() public { VM.prank(LEDGER); uint32 a = v.deriveSeed(3, bytes32(uint256(1)), bytes32(uint256(2))); VM.chainId(5); VM.prank(LEDGER); uint32 b = v.deriveSeed(3, bytes32(uint256(1)), bytes32(uint256(2))); require(a != b); } function _copy(bytes memory x) private pure returns (bytes memory y) { y = new bytes(x.length); for (uint256 i; i < x.length; i++) y[i] = x[i]; } function _adm() private pure returns (RunVerifier.Admission memory) { return RunVerifier.Admission(WALLET, 1, 5, 42, 9, EXPIRY, bytes32(uint256(5)), bytes32(uint256(7)), bytes32(uint256(8)), bytes32(uint256(4))); } function _sc() private pure returns (RunVerifier.Score memory) { return RunVerifier.Score(WALLET, bytes32(uint256(3)), 42, 1234, true, bytes32(uint256(4)), bytes32(uint256(5)), bytes32(uint256(6)), EXPIRY); } function _ad(RunVerifier.Admission memory a) private returns (bytes32) { VM.prank(LEDGER); return v.admissionDigest(a); } function _sd(RunVerifier.Score memory s) private returns (bytes32) { VM.prank(LEDGER); return v.scoreDigest(s); } function _sign(uint256 k, bytes32 d) private returns (bytes memory) { (uint8 vv, bytes32 r, bytes32 s) = VM.sign(k, d); return abi.encodePacked(r, s, vv); } function _rejA(RunVerifier.Admission memory a, bytes memory sig) private { VM.expectRevert(RunVerifier.InvalidSignature.selector); VM.prank(LEDGER); v.verifyAdmission(a, auth, sig); } function _rejS(RunVerifier.Score memory s, bytes memory sa, bytes memory sr) private { VM.expectRevert(RunVerifier.InvalidSignature.selector); VM.prank(LEDGER); v.verifyScore(s, auth, rep, sa, sr); } } ```