@swarm-tips/client 0.4.9 → 0.4.10
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.
- package/SBOM.spdx.json +76 -174
- package/dist/auth/token-manager.d.ts +9 -0
- package/dist/auth/token-manager.js +31 -18
- package/dist/cli/lean-init.d.ts +3 -1
- package/dist/cli/lean-init.js +91 -16
- package/dist/cli/vow-verify.js +14 -9
- package/dist/contracts/generated/shillbot.d.ts +15 -3
- package/dist/contracts/idl/shillbot.json +15 -3
- package/dist/coordination-game/evm/cross-chain.d.ts +6 -0
- package/dist/coordination-game/evm/cross-chain.js +65 -15
- package/dist/inbox/client.js +3 -0
- package/dist/shillbot/api.d.ts +104 -3
- package/dist/shillbot/api.js +326 -6
- package/dist/shillbot/index.js +40 -2
- package/dist/shillbot/verify-tx.js +49 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vow/types.d.ts +1 -1
- package/dist/vow/verify.d.ts +4 -2
- package/dist/vow/verify.js +32 -11
- package/package.json +1 -1
package/dist/shillbot/api.js
CHANGED
|
@@ -270,6 +270,126 @@ export const SHILLBOT_EVM_SELECTORS = {
|
|
|
270
270
|
finalize: "0xcb26e65b", // finalizeTask(uint64)
|
|
271
271
|
expire: "0x5e9f3d19", // expireTask(uint64)
|
|
272
272
|
};
|
|
273
|
+
/** Canonical ABI for `ShillbotEscrow.sol` lifecycle functions (`P2-27`). */
|
|
274
|
+
export const SHILLBOT_ESCROW_ABI = [
|
|
275
|
+
{
|
|
276
|
+
type: "function",
|
|
277
|
+
name: "createTask",
|
|
278
|
+
stateMutability: "payable",
|
|
279
|
+
inputs: [
|
|
280
|
+
{ name: "statementCommitment", type: "bytes32" },
|
|
281
|
+
{ name: "policyId", type: "bytes32" },
|
|
282
|
+
{ name: "verificationKind", type: "uint8" },
|
|
283
|
+
{ name: "deadline", type: "uint64" },
|
|
284
|
+
{ name: "requiresApproval", type: "bool" },
|
|
285
|
+
],
|
|
286
|
+
outputs: [{ name: "taskId", type: "uint64" }],
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
type: "function",
|
|
290
|
+
name: "claimTask",
|
|
291
|
+
stateMutability: "nonpayable",
|
|
292
|
+
inputs: [{ name: "taskId", type: "uint64" }],
|
|
293
|
+
outputs: [],
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
type: "function",
|
|
297
|
+
name: "submitWork",
|
|
298
|
+
stateMutability: "nonpayable",
|
|
299
|
+
inputs: [
|
|
300
|
+
{ name: "taskId", type: "uint64" },
|
|
301
|
+
{ name: "contentIdHash", type: "bytes32" },
|
|
302
|
+
{ name: "artifactHash", type: "bytes32" },
|
|
303
|
+
],
|
|
304
|
+
outputs: [],
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
type: "function",
|
|
308
|
+
name: "approveTask",
|
|
309
|
+
stateMutability: "nonpayable",
|
|
310
|
+
inputs: [{ name: "taskId", type: "uint64" }],
|
|
311
|
+
outputs: [],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
type: "function",
|
|
315
|
+
name: "verifyTaskAttested",
|
|
316
|
+
stateMutability: "nonpayable",
|
|
317
|
+
inputs: [
|
|
318
|
+
{ name: "taskId", type: "uint64" },
|
|
319
|
+
{ name: "score", type: "uint64" },
|
|
320
|
+
{ name: "sig", type: "bytes" },
|
|
321
|
+
],
|
|
322
|
+
outputs: [],
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
type: "function",
|
|
326
|
+
name: "finalizeTask",
|
|
327
|
+
stateMutability: "nonpayable",
|
|
328
|
+
inputs: [{ name: "taskId", type: "uint64" }],
|
|
329
|
+
outputs: [],
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
type: "function",
|
|
333
|
+
name: "expireTask",
|
|
334
|
+
stateMutability: "nonpayable",
|
|
335
|
+
inputs: [{ name: "taskId", type: "uint64" }],
|
|
336
|
+
outputs: [],
|
|
337
|
+
},
|
|
338
|
+
];
|
|
339
|
+
const SHILLBOT_EVM_FUNCTION_NAMES = {
|
|
340
|
+
create: "createTask",
|
|
341
|
+
claim: "claimTask",
|
|
342
|
+
submit: "submitWork",
|
|
343
|
+
approve: "approveTask",
|
|
344
|
+
verify: "verifyTaskAttested",
|
|
345
|
+
finalize: "finalizeTask",
|
|
346
|
+
expire: "expireTask",
|
|
347
|
+
};
|
|
348
|
+
function parseExpectedUintArg(value, field) {
|
|
349
|
+
let parsed;
|
|
350
|
+
if (typeof value === "bigint") {
|
|
351
|
+
parsed = value;
|
|
352
|
+
}
|
|
353
|
+
else if (typeof value === "number") {
|
|
354
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
355
|
+
throw new SwarmClientError({
|
|
356
|
+
code: "INVALID_ARGUMENT",
|
|
357
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
358
|
+
message: `Expected ${field} must be a non-negative safe integer`,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
parsed = BigInt(value);
|
|
362
|
+
}
|
|
363
|
+
else if (typeof value === "string" && /^\d+$/.test(value.trim())) {
|
|
364
|
+
parsed = BigInt(value.trim());
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
throw new SwarmClientError({
|
|
368
|
+
code: "INVALID_ARGUMENT",
|
|
369
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
370
|
+
message: `Expected ${field} must be a non-negative integer`,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (parsed < 0n || parsed > 0xffffffffffffffffn) {
|
|
374
|
+
throw new SwarmClientError({
|
|
375
|
+
code: "INVALID_ARGUMENT",
|
|
376
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
377
|
+
message: `Expected ${field} is out of uint64 range`,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return parsed;
|
|
381
|
+
}
|
|
382
|
+
function normalizeExpectedBytes32(value, field) {
|
|
383
|
+
const trimmed = value.trim();
|
|
384
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(trimmed)) {
|
|
385
|
+
throw new SwarmClientError({
|
|
386
|
+
code: "INVALID_ARGUMENT",
|
|
387
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
388
|
+
message: `Expected ${field} must be a 32-byte 0x-prefixed hex string`,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
return trimmed.toLowerCase();
|
|
392
|
+
}
|
|
273
393
|
export function normalizeEvmChainId(chain) {
|
|
274
394
|
if (typeof chain === "number") {
|
|
275
395
|
if (!Number.isSafeInteger(chain) || chain <= 0) {
|
|
@@ -296,9 +416,9 @@ export function normalizeEvmChainId(chain) {
|
|
|
296
416
|
return trimmed;
|
|
297
417
|
}
|
|
298
418
|
/**
|
|
299
|
-
* C10 fail-closed local validator for server-prepared EVM `ShillbotEscrow` calls.
|
|
300
|
-
* Verifies canonical contract address for `chain`, 4-byte function selector
|
|
301
|
-
* `action`, and `value_wei <= maxValueWei` (strictly `0n` on non-create actions).
|
|
419
|
+
* C10 + P2-27 fail-closed local validator for server-prepared EVM `ShillbotEscrow` calls.
|
|
420
|
+
* Verifies canonical contract address for `chain`, 4-byte function selector and full ABI-decoded
|
|
421
|
+
* calldata arguments for `action`, and `value_wei <= maxValueWei` (strictly `0n` on non-create actions).
|
|
302
422
|
*/
|
|
303
423
|
export function validatePreparedEvmCall(evmCall, expected) {
|
|
304
424
|
if (!evmCall || typeof evmCall !== "object") {
|
|
@@ -355,7 +475,8 @@ export function validatePreparedEvmCall(evmCall, expected) {
|
|
|
355
475
|
});
|
|
356
476
|
}
|
|
357
477
|
const expectedSelector = SHILLBOT_EVM_SELECTORS[expected.action];
|
|
358
|
-
|
|
478
|
+
const expectedFnName = SHILLBOT_EVM_FUNCTION_NAMES[expected.action];
|
|
479
|
+
if (!expectedSelector || !expectedFnName) {
|
|
359
480
|
throw new SwarmClientError({
|
|
360
481
|
code: "INVALID_ARGUMENT",
|
|
361
482
|
operation: "shillbot.validatePreparedEvmCall",
|
|
@@ -370,6 +491,205 @@ export function validatePreparedEvmCall(evmCall, expected) {
|
|
|
370
491
|
message: `Function selector ${actualSelector} does not match expected ${expectedSelector} for ${expected.action}`,
|
|
371
492
|
});
|
|
372
493
|
}
|
|
494
|
+
// Decode calldata via a zero-dependency pure-TS canonical ABI decoder (so CLI and
|
|
495
|
+
// Solana-only consumers never require optional peerDependency `viem` at runtime)
|
|
496
|
+
// and verify exact canonical encoding + arguments (P2-27).
|
|
497
|
+
const argHex = raw.data.slice(10).toLowerCase();
|
|
498
|
+
const decodeFailure = (detail) => {
|
|
499
|
+
throw new SwarmClientError({
|
|
500
|
+
code: "TRANSACTION_MISMATCH",
|
|
501
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
502
|
+
message: `Prepared EVM call data failed ABI decoding for ${expectedFnName}: ${detail}`,
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
const readWordHex = (wordIdx) => argHex.slice(wordIdx * 64, (wordIdx + 1) * 64);
|
|
506
|
+
const readCanonicalUint = (wordIdx, maxBits, label) => {
|
|
507
|
+
const word = readWordHex(wordIdx);
|
|
508
|
+
const zeroPrefixChars = (256 - maxBits) / 4;
|
|
509
|
+
if (!/^0+$/.test(word.slice(0, zeroPrefixChars))) {
|
|
510
|
+
decodeFailure(`has non-canonical high bits for ${label}`);
|
|
511
|
+
}
|
|
512
|
+
return BigInt(`0x${word.slice(zeroPrefixChars)}`);
|
|
513
|
+
};
|
|
514
|
+
const readCanonicalBool = (wordIdx, label) => {
|
|
515
|
+
const word = readWordHex(wordIdx);
|
|
516
|
+
if (word === `${"0".repeat(63)}0`)
|
|
517
|
+
return false;
|
|
518
|
+
if (word === `${"0".repeat(63)}1`)
|
|
519
|
+
return true;
|
|
520
|
+
decodeFailure(`has non-canonical bool encoding for ${label}`);
|
|
521
|
+
return false;
|
|
522
|
+
};
|
|
523
|
+
const readBytes32 = (wordIdx) => `0x${readWordHex(wordIdx)}`;
|
|
524
|
+
if (expectedFnName === "createTask") {
|
|
525
|
+
if (argHex.length !== 5 * 64) {
|
|
526
|
+
decodeFailure("has invalid calldata length or trailing bytes");
|
|
527
|
+
}
|
|
528
|
+
const statementCommitment = readBytes32(0);
|
|
529
|
+
const policyId = readBytes32(1);
|
|
530
|
+
const verificationKind = Number(readCanonicalUint(2, 8, "verificationKind"));
|
|
531
|
+
const deadline = readCanonicalUint(3, 64, "deadline");
|
|
532
|
+
const requiresApproval = readCanonicalBool(4, "requiresApproval");
|
|
533
|
+
if (expected.statementCommitment !== undefined) {
|
|
534
|
+
const want = normalizeExpectedBytes32(expected.statementCommitment, "statementCommitment");
|
|
535
|
+
if (statementCommitment !== want) {
|
|
536
|
+
throw new SwarmClientError({
|
|
537
|
+
code: "TRANSACTION_MISMATCH",
|
|
538
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
539
|
+
message: `createTask statementCommitment ${statementCommitment} differs from expected ${want}`,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (expected.policyId !== undefined) {
|
|
544
|
+
const want = normalizeExpectedBytes32(expected.policyId, "policyId");
|
|
545
|
+
if (policyId !== want) {
|
|
546
|
+
throw new SwarmClientError({
|
|
547
|
+
code: "TRANSACTION_MISMATCH",
|
|
548
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
549
|
+
message: `createTask policyId ${policyId} differs from expected ${want}`,
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (expected.verificationKind !== undefined) {
|
|
554
|
+
if (!Number.isInteger(expected.verificationKind) ||
|
|
555
|
+
expected.verificationKind < 0 ||
|
|
556
|
+
expected.verificationKind > 255) {
|
|
557
|
+
throw new SwarmClientError({
|
|
558
|
+
code: "INVALID_ARGUMENT",
|
|
559
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
560
|
+
message: "Expected verificationKind must be an integer in [0, 255]",
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
if (verificationKind !== expected.verificationKind) {
|
|
564
|
+
throw new SwarmClientError({
|
|
565
|
+
code: "TRANSACTION_MISMATCH",
|
|
566
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
567
|
+
message: `createTask verificationKind ${verificationKind} differs from expected ${expected.verificationKind}`,
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (expected.deadline !== undefined) {
|
|
572
|
+
const want = parseExpectedUintArg(expected.deadline, "deadline");
|
|
573
|
+
if (deadline !== want) {
|
|
574
|
+
throw new SwarmClientError({
|
|
575
|
+
code: "TRANSACTION_MISMATCH",
|
|
576
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
577
|
+
message: `createTask deadline ${deadline} differs from expected ${want}`,
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (expected.requiresApproval !== undefined && requiresApproval !== expected.requiresApproval) {
|
|
582
|
+
throw new SwarmClientError({
|
|
583
|
+
code: "TRANSACTION_MISMATCH",
|
|
584
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
585
|
+
message: `createTask requiresApproval ${requiresApproval} differs from expected ${expected.requiresApproval}`,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
else if (expectedFnName === "claimTask" ||
|
|
590
|
+
expectedFnName === "approveTask" ||
|
|
591
|
+
expectedFnName === "finalizeTask" ||
|
|
592
|
+
expectedFnName === "expireTask") {
|
|
593
|
+
if (argHex.length !== 64) {
|
|
594
|
+
decodeFailure("has invalid calldata length or trailing bytes");
|
|
595
|
+
}
|
|
596
|
+
const taskId = readCanonicalUint(0, 64, "taskId");
|
|
597
|
+
if (expected.taskId !== undefined) {
|
|
598
|
+
const want = parseExpectedUintArg(expected.taskId, "taskId");
|
|
599
|
+
if (taskId !== want) {
|
|
600
|
+
throw new SwarmClientError({
|
|
601
|
+
code: "TRANSACTION_MISMATCH",
|
|
602
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
603
|
+
message: `${expectedFnName} taskId ${taskId} differs from expected ${want}`,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
else if (expectedFnName === "submitWork") {
|
|
609
|
+
if (argHex.length !== 3 * 64) {
|
|
610
|
+
decodeFailure("has invalid calldata length or trailing bytes");
|
|
611
|
+
}
|
|
612
|
+
const taskId = readCanonicalUint(0, 64, "taskId");
|
|
613
|
+
const contentIdHash = readBytes32(1);
|
|
614
|
+
const artifactHash = readBytes32(2);
|
|
615
|
+
if (expected.taskId !== undefined) {
|
|
616
|
+
const want = parseExpectedUintArg(expected.taskId, "taskId");
|
|
617
|
+
if (taskId !== want) {
|
|
618
|
+
throw new SwarmClientError({
|
|
619
|
+
code: "TRANSACTION_MISMATCH",
|
|
620
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
621
|
+
message: `submitWork taskId ${taskId} differs from expected ${want}`,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (expected.contentIdHash !== undefined) {
|
|
626
|
+
const want = normalizeExpectedBytes32(expected.contentIdHash, "contentIdHash");
|
|
627
|
+
if (contentIdHash !== want) {
|
|
628
|
+
throw new SwarmClientError({
|
|
629
|
+
code: "TRANSACTION_MISMATCH",
|
|
630
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
631
|
+
message: `submitWork contentIdHash ${contentIdHash} differs from expected ${want}`,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (expected.artifactHash !== undefined) {
|
|
636
|
+
const want = normalizeExpectedBytes32(expected.artifactHash, "artifactHash");
|
|
637
|
+
if (artifactHash !== want) {
|
|
638
|
+
throw new SwarmClientError({
|
|
639
|
+
code: "TRANSACTION_MISMATCH",
|
|
640
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
641
|
+
message: `submitWork artifactHash ${artifactHash} differs from expected ${want}`,
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
else if (expectedFnName === "verifyTaskAttested") {
|
|
647
|
+
// Head: taskId (uint64), score (uint64), sig offset (0x60 = 96 bytes); Tail: length + padded bytes.
|
|
648
|
+
if (argHex.length < 4 * 64 || argHex.length % 64 !== 0) {
|
|
649
|
+
decodeFailure("has truncated or unaligned dynamic bytes calldata");
|
|
650
|
+
}
|
|
651
|
+
const taskId = readCanonicalUint(0, 64, "taskId");
|
|
652
|
+
const score = readCanonicalUint(1, 64, "score");
|
|
653
|
+
const sigOffset = BigInt(`0x${readWordHex(2)}`);
|
|
654
|
+
if (sigOffset !== 96n) {
|
|
655
|
+
decodeFailure("has non-canonical dynamic bytes offset");
|
|
656
|
+
}
|
|
657
|
+
const sigLenBig = BigInt(`0x${readWordHex(3)}`);
|
|
658
|
+
if (sigLenBig > 65536n) {
|
|
659
|
+
decodeFailure("has oversized sig byte length");
|
|
660
|
+
}
|
|
661
|
+
const sigLen = Number(sigLenBig);
|
|
662
|
+
const paddedBytes = Math.ceil(sigLen / 32) * 32;
|
|
663
|
+
const expectedHexLen = (4 * 32 + paddedBytes) * 2;
|
|
664
|
+
if (argHex.length !== expectedHexLen) {
|
|
665
|
+
decodeFailure("is non-canonical or has trailing bytes");
|
|
666
|
+
}
|
|
667
|
+
const sigHex = argHex.slice(4 * 64);
|
|
668
|
+
const paddingHex = sigHex.slice(sigLen * 2);
|
|
669
|
+
if (paddingHex.length > 0 && !/^0+$/.test(paddingHex)) {
|
|
670
|
+
decodeFailure("has non-zero trailing padding bytes in sig");
|
|
671
|
+
}
|
|
672
|
+
if (expected.taskId !== undefined) {
|
|
673
|
+
const want = parseExpectedUintArg(expected.taskId, "taskId");
|
|
674
|
+
if (taskId !== want) {
|
|
675
|
+
throw new SwarmClientError({
|
|
676
|
+
code: "TRANSACTION_MISMATCH",
|
|
677
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
678
|
+
message: `verifyTaskAttested taskId ${taskId} differs from expected ${want}`,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (expected.score !== undefined) {
|
|
683
|
+
const want = parseExpectedUintArg(expected.score, "score");
|
|
684
|
+
if (score !== want) {
|
|
685
|
+
throw new SwarmClientError({
|
|
686
|
+
code: "TRANSACTION_MISMATCH",
|
|
687
|
+
operation: "shillbot.validatePreparedEvmCall",
|
|
688
|
+
message: `verifyTaskAttested score ${score} differs from expected ${want}`,
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
373
693
|
let valueWei;
|
|
374
694
|
try {
|
|
375
695
|
const rawVal = raw.value_wei ?? raw.value ?? "0";
|
|
@@ -462,8 +782,8 @@ export function estimateSolanaNetworkFeeLamports(inspected, wallet) {
|
|
|
462
782
|
return baseSignatureFeeLamports + priorityFeeLamports + additionalFeeLamports;
|
|
463
783
|
}
|
|
464
784
|
export function permittedPreparedProgramIds(action, network) {
|
|
465
|
-
if (action === "verify") {
|
|
466
|
-
return [SWITCHBOARD_PROGRAM_IDS
|
|
785
|
+
if (action === "verify" && network === "devnet") {
|
|
786
|
+
return [SWITCHBOARD_PROGRAM_IDS.devnet, Secp256k1Program.programId.toBase58()];
|
|
467
787
|
}
|
|
468
788
|
if (action === "finalize") {
|
|
469
789
|
return [EXTENSION_CREDIT_PROGRAM_ID.toBase58()];
|
package/dist/shillbot/index.js
CHANGED
|
@@ -360,8 +360,8 @@ export function verifyIntent(encoded, intent) {
|
|
|
360
360
|
const allowedPrograms = new Set([
|
|
361
361
|
shillbotProgramId,
|
|
362
362
|
COMPUTE_BUDGET_PROGRAM_ID,
|
|
363
|
-
...(intent.action === "verify"
|
|
364
|
-
? [SWITCHBOARD_PROGRAM_IDS
|
|
363
|
+
...(intent.action === "verify" && intent.network === "devnet"
|
|
364
|
+
? [SWITCHBOARD_PROGRAM_IDS.devnet, SECP256K1_PROGRAM_ID]
|
|
365
365
|
: []),
|
|
366
366
|
...(intent.action === "finalize" ? [extensionCreditId] : []),
|
|
367
367
|
]);
|
|
@@ -382,6 +382,44 @@ export function verifyIntent(encoded, intent) {
|
|
|
382
382
|
const payoutDiscriminator = shillbotInstructionDiscriminator("set_payout_to");
|
|
383
383
|
const companions = shillbotInstructions.filter((ix) => ix !== lifecycle[0]);
|
|
384
384
|
const lifecycleIndex = inspected.instructions.indexOf(lifecycle[0]);
|
|
385
|
+
const switchboardPullFeedDiscriminator = Buffer.from(sha256.arrayBuffer("global:pull_feed_submit_response_consensus")).subarray(0, 8);
|
|
386
|
+
const secpEntries = inspected.instructions
|
|
387
|
+
.map((ix, txIndex) => ({ ix, txIndex }))
|
|
388
|
+
.filter((entry) => entry.ix.program_id === SECP256K1_PROGRAM_ID);
|
|
389
|
+
const switchboardEntries = inspected.instructions
|
|
390
|
+
.map((ix, txIndex) => ({ ix, txIndex }))
|
|
391
|
+
.filter((entry) => entry.ix.program_id === SWITCHBOARD_PROGRAM_IDS.mainnet ||
|
|
392
|
+
entry.ix.program_id === SWITCHBOARD_PROGRAM_IDS.devnet);
|
|
393
|
+
if (secpEntries.length > 0 || switchboardEntries.length > 0) {
|
|
394
|
+
if (intent.network !== "devnet" || intent.action !== "verify") {
|
|
395
|
+
throw new Error("Switchboard/Secp256k1 crank instructions are only permitted on devnet verify_task");
|
|
396
|
+
}
|
|
397
|
+
if (secpEntries.length !== 1 || switchboardEntries.length !== 1) {
|
|
398
|
+
throw new Error("devnet verify_task Switchboard crank requires exactly 1 Secp256k1 and 1 Switchboard instruction");
|
|
399
|
+
}
|
|
400
|
+
const secpEntry = secpEntries[0];
|
|
401
|
+
const sbEntry = switchboardEntries[0];
|
|
402
|
+
if (sbEntry.ix.program_id !== SWITCHBOARD_PROGRAM_IDS.devnet) {
|
|
403
|
+
throw new Error(`unexpected Switchboard program ${sbEntry.ix.program_id}`);
|
|
404
|
+
}
|
|
405
|
+
const secpData = Buffer.from(secpEntry.ix.data_base64, "base64");
|
|
406
|
+
if (secpData.length === 0 || secpData[0] === 0) {
|
|
407
|
+
throw new Error("Secp256k1 companion instruction must carry at least 1 signature");
|
|
408
|
+
}
|
|
409
|
+
if (secpEntry.txIndex + 1 !== sbEntry.txIndex ||
|
|
410
|
+
sbEntry.txIndex >= lifecycleIndex) {
|
|
411
|
+
throw new Error("Switchboard crank must follow exact order Secp256k1 -> Switchboard -> verify_task");
|
|
412
|
+
}
|
|
413
|
+
const sbData = Buffer.from(sbEntry.ix.data_base64, "base64");
|
|
414
|
+
if (sbData.length < 8 ||
|
|
415
|
+
!sbData.subarray(0, 8).equals(switchboardPullFeedDiscriminator)) {
|
|
416
|
+
throw new Error("Switchboard companion instruction must be pull_feed_submit_response_consensus");
|
|
417
|
+
}
|
|
418
|
+
const expectedFeed = lifecycle[0].accounts[2];
|
|
419
|
+
if (!expectedFeed || !sbEntry.ix.accounts.includes(expectedFeed)) {
|
|
420
|
+
throw new Error("Switchboard companion instruction does not reference expected feed");
|
|
421
|
+
}
|
|
422
|
+
}
|
|
385
423
|
if (intent.action === "claim" &&
|
|
386
424
|
companions.some((ix) => Buffer.from(ix.data_base64, "base64")
|
|
387
425
|
.subarray(0, 8)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
+
import { sha256 } from "js-sha256";
|
|
2
3
|
import { ComputeBudgetProgram, PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, Secp256k1Program, } from "@solana/web3.js";
|
|
3
4
|
import { SHILLBOT_PROGRAM_ID, shillbotInstructionDiscriminator } from "../contracts/index.js";
|
|
4
5
|
import { SwarmClientError, TransactionMismatchError } from "../errors.js";
|
|
@@ -17,6 +18,7 @@ const SWITCHBOARD_PROGRAM_IDS = {
|
|
|
17
18
|
mainnet: "SBondMDrcV3K4kxZR1HNVT7osZxAHVHgYXL5Ze1oMUv",
|
|
18
19
|
devnet: "Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2",
|
|
19
20
|
};
|
|
21
|
+
const SWITCHBOARD_PULL_FEED_SUBMIT_DISCRIMINATOR = Buffer.from(sha256.arrayBuffer("global:pull_feed_submit_response_consensus")).subarray(0, 8);
|
|
20
22
|
/**
|
|
21
23
|
* Exact Anchor account-index and authority-slot specification for every Shillbot instruction,
|
|
22
24
|
* derived directly from `programs/shillbot/src/instructions/*.rs` and `shillbot.json` IDL.
|
|
@@ -494,17 +496,16 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
494
496
|
if (explicitFeePayer && inspected.fee_payer !== explicitFeePayer) {
|
|
495
497
|
throw txMismatch(operation, "Fee payer differs from expectation");
|
|
496
498
|
}
|
|
497
|
-
const
|
|
498
|
-
expected.instructionName === "verify_task"
|
|
499
|
-
expected.instructionName === "verify_task_attested";
|
|
499
|
+
const allowSwitchboardContext = expected.network === "devnet" &&
|
|
500
|
+
(expected.action === "verify" || expected.instructionName === "verify_task");
|
|
500
501
|
const isFinalizeContext = expected.action === "finalize" || expected.instructionName === "finalize_task";
|
|
501
502
|
const shillbotId = SHILLBOT_PROGRAM_ID.toBase58();
|
|
502
503
|
const extensionCreditId = EXTENSION_CREDIT_PROGRAM_ID.toBase58();
|
|
503
504
|
const alwaysAllowed = new Set([
|
|
504
505
|
shillbotId,
|
|
505
506
|
ComputeBudgetProgram.programId.toBase58(),
|
|
506
|
-
...(
|
|
507
|
-
? [SWITCHBOARD_PROGRAM_IDS
|
|
507
|
+
...(allowSwitchboardContext
|
|
508
|
+
? [SWITCHBOARD_PROGRAM_IDS.devnet, Secp256k1Program.programId.toBase58()]
|
|
508
509
|
: []),
|
|
509
510
|
...(isFinalizeContext ? [extensionCreditId] : []),
|
|
510
511
|
...(expected.allowedProgramIds ?? []),
|
|
@@ -584,6 +585,49 @@ export function verifyBuiltTransaction(encoded, expected, operation = "shillbot.
|
|
|
584
585
|
throw txMismatch(operation, `route_and_recoup advance account (${advanceAcct}) does not match canonical Advance PDA (${derivedAdvance})`);
|
|
585
586
|
}
|
|
586
587
|
}
|
|
588
|
+
// Validate Switchboard / Secp256k1 companions strictly (mirrors Rust `shillbot-chain`, P1-15).
|
|
589
|
+
// Runs BEFORE any `companions.length === 0` or `set_payout_to` early returns so injected
|
|
590
|
+
// Switchboard / Secp256k1 instructions can never slip past `verify_task_attested` or mainnet.
|
|
591
|
+
const switchboardProgramIds = new Set(Object.values(SWITCHBOARD_PROGRAM_IDS));
|
|
592
|
+
const secp256k1ProgramId = Secp256k1Program.programId.toBase58();
|
|
593
|
+
const secpIxs = inspected.instructions
|
|
594
|
+
.map((ix, txIndex) => ({ ix, txIndex }))
|
|
595
|
+
.filter((entry) => entry.ix.program_id === secp256k1ProgramId);
|
|
596
|
+
const switchboardIxs = inspected.instructions
|
|
597
|
+
.map((ix, txIndex) => ({ ix, txIndex }))
|
|
598
|
+
.filter((entry) => switchboardProgramIds.has(entry.ix.program_id));
|
|
599
|
+
if (secpIxs.length > 0 || switchboardIxs.length > 0) {
|
|
600
|
+
if (expected.network !== "devnet") {
|
|
601
|
+
throw txMismatch(operation, "Unexpected program: Switchboard/Secp256k1 crank instructions are forbidden on mainnet");
|
|
602
|
+
}
|
|
603
|
+
if (primary.spec.name !== "verify_task") {
|
|
604
|
+
throw txMismatch(operation, `Unexpected program: Switchboard/Secp256k1 crank instructions are forbidden on ${primary.spec.name}`);
|
|
605
|
+
}
|
|
606
|
+
if (secpIxs.length !== 1 || switchboardIxs.length !== 1) {
|
|
607
|
+
throw txMismatch(operation, `Devnet verify_task Switchboard crank requires exactly 1 Secp256k1 and 1 Switchboard instruction (got ${secpIxs.length} secp256k1, ${switchboardIxs.length} switchboard)`);
|
|
608
|
+
}
|
|
609
|
+
const secpEntry = secpIxs[0];
|
|
610
|
+
const sbEntry = switchboardIxs[0];
|
|
611
|
+
if (sbEntry.ix.program_id !== SWITCHBOARD_PROGRAM_IDS.devnet) {
|
|
612
|
+
throw txMismatch(operation, `Unexpected Switchboard program ${sbEntry.ix.program_id} on devnet`);
|
|
613
|
+
}
|
|
614
|
+
const secpData = Buffer.from(secpEntry.ix.data_base64, "base64");
|
|
615
|
+
if (secpData.length === 0 || secpData[0] === 0) {
|
|
616
|
+
throw txMismatch(operation, "Secp256k1 companion instruction must carry at least 1 signature");
|
|
617
|
+
}
|
|
618
|
+
if (secpEntry.txIndex + 1 !== sbEntry.txIndex || sbEntry.txIndex >= primary.txIndex) {
|
|
619
|
+
throw txMismatch(operation, "Switchboard crank must follow exact order Secp256k1 -> Switchboard -> verify_task");
|
|
620
|
+
}
|
|
621
|
+
const sbData = Buffer.from(sbEntry.ix.data_base64, "base64");
|
|
622
|
+
if (sbData.length < 8 ||
|
|
623
|
+
!sbData.subarray(0, 8).equals(SWITCHBOARD_PULL_FEED_SUBMIT_DISCRIMINATOR)) {
|
|
624
|
+
throw txMismatch(operation, "Switchboard companion instruction must be pull_feed_submit_response_consensus");
|
|
625
|
+
}
|
|
626
|
+
const expectedFeed = expected.oracleAuthority ?? primary.ix.accounts[2];
|
|
627
|
+
if (!sbEntry.ix.accounts.includes(expectedFeed)) {
|
|
628
|
+
throw txMismatch(operation, `Switchboard companion instruction does not reference expected feed ${expectedFeed}`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
587
631
|
// Instruction-specific payload validation
|
|
588
632
|
if (primary.spec.name === "create_task") {
|
|
589
633
|
if (primary.data.length < 24) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLIENT_VERSION = "0.4.
|
|
1
|
+
export declare const CLIENT_VERSION = "0.4.10";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.4.
|
|
1
|
+
export const CLIENT_VERSION = "0.4.10";
|
package/dist/vow/types.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface VowV1Attestation {
|
|
|
31
31
|
* verifier MUST return one of these strings (with the named field
|
|
32
32
|
* substituted into `field_mismatch:<field>` and `schema_invalid:<field>`).
|
|
33
33
|
*/
|
|
34
|
-
export type FailureReason = `schema_invalid:${string}` | "account_closed" | "owner_mismatch" | "discriminator_mismatch" | `field_mismatch:${string}` | "score_above_max" | "state_invalid";
|
|
34
|
+
export type FailureReason = `schema_invalid:${string}` | "network_mismatch" | "account_closed" | "owner_mismatch" | "discriminator_mismatch" | `field_mismatch:${string}` | "score_above_max" | "state_invalid";
|
|
35
35
|
/**
|
|
36
36
|
* @deprecated Renamed to {@link VowV1Attestation} when the standard became VOW
|
|
37
37
|
* (Verifiable On-chain Work) on 2026-07-10. The wire format is `vow/v1`; this
|
package/dist/vow/verify.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export declare function fetchVowAttestationJson(rawUrl: string, opts?: FetchVowO
|
|
|
37
37
|
* Enforces SSRF host/IP validation, `redirect: "error"`, and a 2 MiB streaming body cap.
|
|
38
38
|
*/
|
|
39
39
|
export declare function verifyVow(urlOrJson: string | Record<string, unknown>, opts?: VerifyVowOptions): Promise<Verdict>;
|
|
40
|
+
/** Canonical Solana cluster genesis hashes (full 44-char base58 + 32-char CAIP-2 prefix, P2-26). */
|
|
41
|
+
export declare const SOLANA_GENESIS_HASHES: Readonly<Record<"mainnet" | "devnet", readonly string[]>>;
|
|
40
42
|
/**
|
|
41
43
|
* Step-by-step verifier per `docs/specs/vow-v1.md` §4.
|
|
42
44
|
*
|
|
@@ -47,7 +49,7 @@ export declare function verifyVow(urlOrJson: string | Record<string, unknown>, o
|
|
|
47
49
|
*
|
|
48
50
|
* Splitting lets unit tests cover the pure parts without an RPC.
|
|
49
51
|
*/
|
|
50
|
-
export declare function verifyV1(attestation: unknown, protocol: ProtocolHandler, rpc: Connection, expectedScoreMax?: bigint | number | string): Promise<Verdict>;
|
|
52
|
+
export declare function verifyV1(attestation: unknown, protocol: ProtocolHandler, rpc: Connection, expectedScoreMax?: bigint | number | string, expectedNetwork?: "mainnet" | "devnet"): Promise<Verdict>;
|
|
51
53
|
/**
|
|
52
54
|
* Pure step 1 + step 6 of the protocol. Returns null on success or
|
|
53
55
|
* the first failure reason.
|
|
@@ -57,4 +59,4 @@ export declare function verifyV1Schema(attestation: unknown): FailureReason | nu
|
|
|
57
59
|
* Steps 2-5 + 7 — touches RPC. Returns null on success or the first
|
|
58
60
|
* failure reason.
|
|
59
61
|
*/
|
|
60
|
-
export declare function verifyV1OnChain(a: AasV1Attestation, protocol: ProtocolHandler, rpc: Connection, expectedScoreMax?: bigint | number | string): Promise<FailureReason | null>;
|
|
62
|
+
export declare function verifyV1OnChain(a: AasV1Attestation, protocol: ProtocolHandler, rpc: Connection, expectedScoreMax?: bigint | number | string, expectedNetwork?: "mainnet" | "devnet"): Promise<FailureReason | null>;
|
package/dist/vow/verify.js
CHANGED
|
@@ -449,16 +449,22 @@ export async function verifyVow(urlOrJson, opts) {
|
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
|
-
const
|
|
453
|
-
const net = attestation &&
|
|
454
|
-
typeof attestation === "object" &&
|
|
455
|
-
attestation.network === "devnet"
|
|
456
|
-
? "devnet"
|
|
457
|
-
: defaultNet;
|
|
452
|
+
const expectedNetwork = opts?.network ?? "mainnet";
|
|
458
453
|
const conn = opts?.connection ??
|
|
459
|
-
new Connection(opts?.rpcUrl ?? DEFAULT_VOW_SOLANA_RPC[
|
|
460
|
-
return verifyV1(attestation, opts?.protocol ?? shillbotProtocol, conn, opts?.expectedScoreMax);
|
|
454
|
+
new Connection(opts?.rpcUrl ?? DEFAULT_VOW_SOLANA_RPC[expectedNetwork], "confirmed");
|
|
455
|
+
return verifyV1(attestation, opts?.protocol ?? shillbotProtocol, conn, opts?.expectedScoreMax, expectedNetwork);
|
|
461
456
|
}
|
|
457
|
+
/** Canonical Solana cluster genesis hashes (full 44-char base58 + 32-char CAIP-2 prefix, P2-26). */
|
|
458
|
+
export const SOLANA_GENESIS_HASHES = {
|
|
459
|
+
mainnet: [
|
|
460
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
|
|
461
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
462
|
+
],
|
|
463
|
+
devnet: [
|
|
464
|
+
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG",
|
|
465
|
+
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
466
|
+
],
|
|
467
|
+
};
|
|
462
468
|
/**
|
|
463
469
|
* Step-by-step verifier per `docs/specs/vow-v1.md` §4.
|
|
464
470
|
*
|
|
@@ -469,7 +475,7 @@ export async function verifyVow(urlOrJson, opts) {
|
|
|
469
475
|
*
|
|
470
476
|
* Splitting lets unit tests cover the pure parts without an RPC.
|
|
471
477
|
*/
|
|
472
|
-
export async function verifyV1(attestation, protocol, rpc, expectedScoreMax) {
|
|
478
|
+
export async function verifyV1(attestation, protocol, rpc, expectedScoreMax, expectedNetwork = "mainnet") {
|
|
473
479
|
const checkedAt = nowRfc3339();
|
|
474
480
|
const rpcEndpoint = rpc.rpcEndpoint;
|
|
475
481
|
const schemaFail = verifyV1Schema(attestation);
|
|
@@ -483,7 +489,7 @@ export async function verifyV1(attestation, protocol, rpc, expectedScoreMax) {
|
|
|
483
489
|
};
|
|
484
490
|
}
|
|
485
491
|
const a = asV1(attestation);
|
|
486
|
-
const onChainFail = await verifyV1OnChain(a, protocol, rpc, expectedScoreMax);
|
|
492
|
+
const onChainFail = await verifyV1OnChain(a, protocol, rpc, expectedScoreMax, expectedNetwork);
|
|
487
493
|
if (onChainFail) {
|
|
488
494
|
return {
|
|
489
495
|
valid: false,
|
|
@@ -519,7 +525,22 @@ export function verifyV1Schema(attestation) {
|
|
|
519
525
|
* Steps 2-5 + 7 — touches RPC. Returns null on success or the first
|
|
520
526
|
* failure reason.
|
|
521
527
|
*/
|
|
522
|
-
export async function verifyV1OnChain(a, protocol, rpc, expectedScoreMax) {
|
|
528
|
+
export async function verifyV1OnChain(a, protocol, rpc, expectedScoreMax, expectedNetwork = "mainnet") {
|
|
529
|
+
// P2-26 — network pin check BEFORE any RPC calls so a devnet attestation
|
|
530
|
+
// can never downgrade a mainnet verifier (fail closed with `network_mismatch`).
|
|
531
|
+
const allowedGenesisHashes = SOLANA_GENESIS_HASHES[expectedNetwork];
|
|
532
|
+
if (!allowedGenesisHashes || a.network !== expectedNetwork) {
|
|
533
|
+
return "network_mismatch";
|
|
534
|
+
}
|
|
535
|
+
// Verify the RPC cluster's genesis hash when the connection exposes `getGenesisHash`.
|
|
536
|
+
const maybeGetGenesisHash = rpc.getGenesisHash;
|
|
537
|
+
if (typeof maybeGetGenesisHash === "function") {
|
|
538
|
+
const genesisHash = await maybeGetGenesisHash.call(rpc);
|
|
539
|
+
if (typeof genesisHash !== "string" ||
|
|
540
|
+
!allowedGenesisHashes.includes(genesisHash)) {
|
|
541
|
+
return "network_mismatch";
|
|
542
|
+
}
|
|
543
|
+
}
|
|
523
544
|
const expectedMax = BigInt(expectedScoreMax ?? protocol.scoreMax ?? DEFAULT_SCORE_MAX);
|
|
524
545
|
if (BigInt(a.score_max) !== expectedMax) {
|
|
525
546
|
return "field_mismatch:score_max";
|
package/package.json
CHANGED