@probecli/cli 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +15 -0
  2. package/dist/probe.mjs +165 -9
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -29,6 +29,13 @@ It also reports whether the hook is upgradeable, owned by a single key, uses SEL
29
29
 
30
30
  `--publish` has the verifier rerun the check at the same block and sign it. The result then appears at [probecli.com/hooks](https://probecli.com/hooks) with a badge you can put in a README. A pass is evidence about one property at one block, not an audit.
31
31
 
32
+ Anyone can check a published result without trusting the website:
33
+
34
+ ```shell
35
+ probe hooks # hooks with a published check
36
+ probe verify hook 0x0af57f62982d03066ef917acad87f771c06528ec # signature, signer, and signer approved on-chain
37
+ ```
38
+
32
39
  ## Run a job
33
40
 
34
41
  ```shell
@@ -51,8 +58,16 @@ probe case check <job> FeeAfterNextBlock.t.sol
51
58
  probe work <job> --case FeeAfterNextBlock.t.sol
52
59
  ```
53
60
 
61
+ Before you work a job, confirm its scope and rules are the ones fixed at funding:
62
+
63
+ ```shell
64
+ probe verify job volume-discount-fee-swaps # recomputes the spec hash and compares it with getJob(id)
65
+ ```
66
+
54
67
  `probe help` lists every command.
55
68
 
69
+ If `npm install -g` fails with EACCES, your Node lives in a folder your user cannot write. Set `npm config set prefix ~/.npm-global`, add `~/.npm-global/bin` to your PATH, and install again, or run `npx @probecli/cli` without installing.
70
+
56
71
  ## Links
57
72
 
58
73
  - Website and docs: [probecli.com](https://probecli.com)
package/dist/probe.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  // src/cli/main.ts
4
4
  import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
5
5
  import { join as join4, resolve as resolve3 } from "node:path";
6
- import { parseArgs as parseArgs2 } from "node:util";
6
+ import { parseArgs as parseArgs3 } from "node:util";
7
7
  import { parseUnits, toHex as toHex5 } from "viem";
8
8
  import { privateKeyToAccount as privateKeyToAccount5 } from "viem/accounts";
9
9
 
@@ -1880,6 +1880,15 @@ function finish(r) {
1880
1880
  }
1881
1881
  };
1882
1882
  }
1883
+ function reportDigest(r) {
1884
+ const { checkedAt: _t, ...rest2 } = r;
1885
+ return keccak2564(toHex4(JSON.stringify(rest2, (_k, v) => typeof v === "bigint" ? v.toString() : v)));
1886
+ }
1887
+ var reportMessage = (r) => `PROBE hook check v${r.version}
1888
+ chain ${r.chainId}
1889
+ hook ${r.hook}
1890
+ block ${r.block}
1891
+ digest ${reportDigest(r)}`;
1883
1892
 
1884
1893
  // src/cli/check.ts
1885
1894
  var SITE = process.env.PROBE_SITE_URL ?? "https://probecli.com";
@@ -1947,8 +1956,147 @@ async function check(args) {
1947
1956
  if (report.summary.failed) process.exitCode = 1;
1948
1957
  }
1949
1958
 
1959
+ // src/cli/verify.ts
1960
+ import { parseArgs as parseArgs2 } from "node:util";
1961
+ import { getAddress as getAddress4, isAddress as isAddress3 } from "viem";
1962
+
1963
+ // src/shared/verify.ts
1964
+ import { getAddress as getAddress3, isAddressEqual, recoverMessageAddress } from "viem";
1965
+ var PROBE_JOBS = {
1966
+ 4663: "0x75a7af44fe0117b1f5ff11eddad11fe1e0d34189",
1967
+ 46630: "0x75a7af44fe0117b1f5ff11eddad11fe1e0d34189"
1968
+ };
1969
+ function registeredSpec(job2) {
1970
+ const { specHash: _h, chain: _c, state: _s, ...spec } = job2;
1971
+ return spec;
1972
+ }
1973
+ function verifyJobSpec(job2, onchainSpecHash) {
1974
+ const computed = specHash(registeredSpec(job2));
1975
+ return {
1976
+ computed,
1977
+ findings: [
1978
+ {
1979
+ ok: computed === job2.specHash,
1980
+ title: "The verifier's spec hashes to the hash it reports",
1981
+ detail: computed === job2.specHash ? computed : `computed ${computed}, verifier reports ${job2.specHash}`
1982
+ },
1983
+ {
1984
+ ok: computed === onchainSpecHash.toLowerCase(),
1985
+ title: "The hash stored on-chain matches",
1986
+ detail: computed === onchainSpecHash.toLowerCase() ? `getJob(${job2.chain.jobId}).specHash` : `on-chain ${onchainSpecHash}, computed ${computed}`
1987
+ }
1988
+ ]
1989
+ };
1990
+ }
1991
+ async function verifyHookCheck(c2, approvedOnChain) {
1992
+ const rebuilt = reportMessage(c2.report);
1993
+ const findings = [
1994
+ {
1995
+ ok: rebuilt === c2.message,
1996
+ title: "The signed message matches the published results",
1997
+ detail: rebuilt === c2.message ? rebuilt.split("\n").find((l) => l.startsWith("digest ")) ?? "" : "the results do not hash to the digest that was signed"
1998
+ }
1999
+ ];
2000
+ let recovered = null;
2001
+ try {
2002
+ recovered = await recoverMessageAddress({ message: c2.message, signature: c2.signature });
2003
+ } catch {
2004
+ recovered = null;
2005
+ }
2006
+ const sameSigner = recovered !== null && isAddressEqual(recovered, getAddress3(c2.signer));
2007
+ findings.push({
2008
+ ok: sameSigner,
2009
+ title: "The signature recovers to the stated signer",
2010
+ detail: recovered ? `${recovered}` : "the signature is malformed"
2011
+ });
2012
+ if (recovered) {
2013
+ const approved = await approvedOnChain(recovered);
2014
+ findings.push({
2015
+ ok: approved,
2016
+ title: "The signer is an approved verifier on ProbeJobs",
2017
+ detail: approved ? `approvedVerifier(${recovered}) is true` : `approvedVerifier(${recovered}) is false`
2018
+ });
2019
+ }
2020
+ return findings;
2021
+ }
2022
+
2023
+ // src/cli/verify.ts
2024
+ var SITE2 = process.env.PROBE_SITE_URL ?? "https://probecli.com";
2025
+ var USAGE = "Usage: probe verify job <job> | probe verify hook <address> [--json]";
2026
+ function printFindings(findings) {
2027
+ console.log("");
2028
+ for (const f of findings) {
2029
+ console.log(`${f.ok ? dim("\u2713") : hot("\xD7")} ${f.ok ? f.title : hot(f.title)}`);
2030
+ console.log(` ${dim(f.detail)}`);
2031
+ }
2032
+ console.log("");
2033
+ const failed = findings.filter((f) => !f.ok).length;
2034
+ console.log(failed ? `${hot("\xD7")} ${bold(`${failed} of ${findings.length} did not hold`)}` : `${dim("\u2713")} ${bold(`All ${findings.length} held`)}`);
2035
+ if (failed) process.exitCode = 1;
2036
+ }
2037
+ async function verifyJob(slug, json) {
2038
+ const job2 = await api(`/jobs/${slug}`);
2039
+ const onchain = await readJob(clientFor(job2), job2.chain.contract, BigInt(job2.chain.jobId));
2040
+ const { computed, findings } = verifyJobSpec(job2, onchain.specHash);
2041
+ if (json) {
2042
+ printJson({ job: slug, jobId: job2.chain.jobId, contract: job2.chain.contract, computed, verifier: job2.specHash, onchain: onchain.specHash, findings });
2043
+ if (findings.some((f) => !f.ok)) process.exitCode = 1;
2044
+ return;
2045
+ }
2046
+ console.log(`${bold("probe verify job")} ${slug} ${dim(`job #${job2.chain.jobId} on chain ${job2.chain.chainId}`)}`);
2047
+ printFindings(findings);
2048
+ console.log(dim(" The scope and rules you work under cannot have changed since the job was funded."));
2049
+ }
2050
+ async function verifyHook(address, json, rpc) {
2051
+ if (!isAddress3(address)) fail(USAGE);
2052
+ const hook = getAddress4(address);
2053
+ const published = await api(`/hooks/${hook}`).catch(
2054
+ (e) => fail(/not found|404|not been checked/i.test(e.message) ? `No published check for ${hook}. Publish one with: probe check ${hook} --publish` : e.message)
2055
+ );
2056
+ const report = published.report;
2057
+ const contract = PROBE_JOBS[report.chainId];
2058
+ if (!contract) fail(`No ProbeJobs deployment known for chain ${report.chainId}.`);
2059
+ const client = publicClient(rpc, report.chainId);
2060
+ const approved = (signer) => client.readContract({ address: contract, abi: probeJobsAbi, functionName: "approvedVerifier", args: [signer] });
2061
+ const findings = json ? await verifyHookCheck(published, approved) : await task("Checking the signature and the signer", () => verifyHookCheck(published, approved), () => "done");
2062
+ if (json) {
2063
+ printJson({ hook, block: report.block, chainId: report.chainId, signer: published.signer, findings });
2064
+ if (findings.some((f) => !f.ok)) process.exitCode = 1;
2065
+ return;
2066
+ }
2067
+ console.log(`${dim(" hook")} ${hook} ${dim(`at block ${Number(report.block).toLocaleString("en-US")}, ${report.summary.passed} of ${report.summary.total} checks passed`)}`);
2068
+ printFindings(findings);
2069
+ console.log(dim(` Rerun the checks yourself: probe check ${hook} --block ${report.block}`));
2070
+ console.log(dim(` ${SITE2}/hooks/${hook}`));
2071
+ }
2072
+ async function verify(args) {
2073
+ const { values, positionals } = parseArgs2({
2074
+ args,
2075
+ allowPositionals: true,
2076
+ options: { json: { type: "boolean", default: false }, rpc: { type: "string" } }
2077
+ });
2078
+ const [kind, target] = positionals;
2079
+ if (!kind || !target) fail(USAGE);
2080
+ if (kind === "job") return verifyJob(target, values.json);
2081
+ if (kind === "hook") return verifyHook(target, values.json, values.rpc ?? process.env.PROBE_RPC_URL ?? DEFAULT_RPC);
2082
+ fail(USAGE);
2083
+ }
2084
+ async function hooks(args) {
2085
+ const { values } = parseArgs2({ args, options: { json: { type: "boolean", default: false } } });
2086
+ const list = await api("/hooks");
2087
+ if (values.json) return printJson(list);
2088
+ if (!list.length) return console.log(dim("No published hook checks yet. Publish one with: probe check <hook> --publish"));
2089
+ for (const h of list) {
2090
+ const s = h.summary;
2091
+ const line = s.failed ? hot(`${s.failed} failed`) : `${s.passed} of ${s.total} passed${s.warnings ? `, ${s.warnings} warning${s.warnings === 1 ? "" : "s"}` : ""}`;
2092
+ console.log(`${s.failed ? hot("\xD7") : dim("\u2713")} ${h.hook} ${line} ${dim(`block ${Number(h.block).toLocaleString("en-US")}`)}`);
2093
+ }
2094
+ console.log(dim(`
2095
+ ${list.length} published. Check one's signature: probe verify hook <address>`));
2096
+ }
2097
+
1950
2098
  // src/cli/version.ts
1951
- var VERSION = true ? "0.4.0" : JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
2099
+ var VERSION = true ? "0.5.0" : JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
1952
2100
 
1953
2101
  // src/cli/main.ts
1954
2102
  var HELP = `${bold("probe")}: test Uniswap v4 hooks, get paid for verified work.
@@ -1978,6 +2126,12 @@ Hooks
1978
2126
  --rpc <url> Chain RPC (default: Robinhood Chain mainnet)
1979
2127
  --publish Have the verifier reproduce, sign and publish the result
1980
2128
  --json Print the report as JSON
2129
+ probe hooks [--json] List hooks with a published, signed check
2130
+
2131
+ Verify
2132
+ probe verify job <job> Recompute a job's spec hash and compare it with the chain
2133
+ probe verify hook <address> Check a published hook check's signature and that its signer
2134
+ is an approved verifier on ProbeJobs
1981
2135
 
1982
2136
  Sponsor
1983
2137
  probe sponsor keygen Create your report-decryption key pair
@@ -1992,7 +2146,7 @@ Environment: PROBE_VERIFIER_URL, PROBE_RPC_URL, PROBE_OPERATOR_KEY, PROBE_SPONSO
1992
2146
  `;
1993
2147
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1994
2148
  async function init(args) {
1995
- const { values } = parseArgs2({ args, options: { verifier: { type: "string" }, force: { type: "boolean" } } });
2149
+ const { values } = parseArgs3({ args, options: { verifier: { type: "string" }, force: { type: "boolean" } } });
1996
2150
  const cfg = loadConfig();
1997
2151
  if (values.verifier) saveConfig({ verifierUrl: values.verifier.replace(/\/$/, "") });
1998
2152
  if (cfg.operatorKey && !values.force) {
@@ -2013,7 +2167,7 @@ async function whoami() {
2013
2167
  console.log(`${dim("agent ")} ${agentAvailable() ? `${AGENT_MODEL} (credentials found)` : "no credentials; seed cases only"}`);
2014
2168
  }
2015
2169
  async function jobs(args) {
2016
- const { values } = parseArgs2({ args, options: { json: { type: "boolean" } } });
2170
+ const { values } = parseArgs3({ args, options: { json: { type: "boolean" } } });
2017
2171
  const list = await api("/jobs");
2018
2172
  if (values.json) return printJson(list);
2019
2173
  if (!list.length) return note("No jobs registered on this verifier yet.");
@@ -2028,7 +2182,7 @@ async function jobs(args) {
2028
2182
  }
2029
2183
  }
2030
2184
  async function work(args) {
2031
- const { values, positionals } = parseArgs2({
2185
+ const { values, positionals } = parseArgs3({
2032
2186
  args,
2033
2187
  allowPositionals: true,
2034
2188
  options: {
@@ -2141,7 +2295,7 @@ async function work(args) {
2141
2295
  }
2142
2296
  }
2143
2297
  async function job(args) {
2144
- const { values, positionals } = parseArgs2({ args, allowPositionals: true, options: { json: { type: "boolean" } } });
2298
+ const { values, positionals } = parseArgs3({ args, allowPositionals: true, options: { json: { type: "boolean" } } });
2145
2299
  const slug = positionals[0];
2146
2300
  if (!slug) fail("Usage: probe job <job> [--json]");
2147
2301
  const [j, subs] = await Promise.all([
@@ -2208,7 +2362,7 @@ function localFailure(local) {
2208
2362
  return failed.map((t) => `${t.name}${t.reason ? ` (${t.reason})` : ""}`).join(", ") || "no tests ran";
2209
2363
  }
2210
2364
  async function caseNew(args) {
2211
- const { values, positionals } = parseArgs2({ args, allowPositionals: true, options: { out: { type: "string", default: "." } } });
2365
+ const { values, positionals } = parseArgs3({ args, allowPositionals: true, options: { out: { type: "string", default: "." } } });
2212
2366
  const [slug, raw] = positionals;
2213
2367
  if (!slug || !raw) fail("Usage: probe case new <job> <Name> [--out <dir>]");
2214
2368
  const name = caseName(raw);
@@ -2252,7 +2406,7 @@ async function caseCheck(args) {
2252
2406
  else process.exitCode = 1;
2253
2407
  }
2254
2408
  async function submissions(args) {
2255
- const { values, positionals } = parseArgs2({ args, allowPositionals: true, options: { all: { type: "boolean" }, json: { type: "boolean" } } });
2409
+ const { values, positionals } = parseArgs3({ args, allowPositionals: true, options: { all: { type: "boolean" }, json: { type: "boolean" } } });
2256
2410
  const key = loadConfig().operatorKey;
2257
2411
  if (!values.all && !key) fail("No operator key, so no submissions of yours. Run probe init, or pass --all to see everyone's.");
2258
2412
  const me = key && !values.all ? privateKeyToAccount5(key).address.toLowerCase() : null;
@@ -2331,7 +2485,7 @@ async function sponsorKeygen() {
2331
2485
  note(` Put it in your job spec as "reportKey". The secret key is in ${configPath}. Only it can open your reports.`);
2332
2486
  }
2333
2487
  async function sponsorCreate(args) {
2334
- const { values } = parseArgs2({
2488
+ const { values } = parseArgs3({
2335
2489
  args,
2336
2490
  options: {
2337
2491
  spec: { type: "string" },
@@ -2416,6 +2570,8 @@ var commands = {
2416
2570
  whoami,
2417
2571
  doctor,
2418
2572
  check,
2573
+ hooks,
2574
+ verify,
2419
2575
  jobs,
2420
2576
  job,
2421
2577
  work,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probecli/cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "description": "probe: run reproducible tests for Uniswap v4 hooks, get paid for verified work, and check any deployed hook.",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "probe": "node bin/probe.mjs",
42
42
  "abi": "node scripts/gen-abi.ts",
43
43
  "typecheck": "tsc --noEmit",
44
- "test": "node --test test/unit.test.ts test/hookcheck.test.ts",
44
+ "test": "node --test test/unit.test.ts test/hookcheck.test.ts test/verify.test.ts",
45
45
  "e2e": "node scripts/e2e.ts",
46
46
  "preflight": "node scripts/preflight.ts",
47
47
  "dev:stack": "node scripts/dev-stack.ts",