solana-privacy-scanner-core 0.1.4 → 0.2.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.
- package/dist/index.cjs +1048 -84
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +1044 -84
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,8 +40,12 @@ __export(index_exports, {
|
|
|
40
40
|
detectAmountReuse: () => detectAmountReuse,
|
|
41
41
|
detectBalanceTraceability: () => detectBalanceTraceability,
|
|
42
42
|
detectCounterpartyReuse: () => detectCounterpartyReuse,
|
|
43
|
+
detectFeePayerReuse: () => detectFeePayerReuse,
|
|
44
|
+
detectInstructionFingerprinting: () => detectInstructionFingerprinting,
|
|
43
45
|
detectKnownEntityInteraction: () => detectKnownEntityInteraction,
|
|
46
|
+
detectSignerOverlap: () => detectSignerOverlap,
|
|
44
47
|
detectTimingPatterns: () => detectTimingPatterns,
|
|
48
|
+
detectTokenAccountLifecycle: () => detectTokenAccountLifecycle,
|
|
45
49
|
evaluateHeuristics: () => evaluateHeuristics,
|
|
46
50
|
generateReport: () => generateReport,
|
|
47
51
|
normalizeProgramData: () => normalizeProgramData,
|
|
@@ -397,6 +401,162 @@ var PROGRAM_IDS = {
|
|
|
397
401
|
MEMO: "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
|
|
398
402
|
MEMO_V1: "Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"
|
|
399
403
|
};
|
|
404
|
+
function extractTransactionMetadata(tx, signature) {
|
|
405
|
+
if (!tx || !tx.transaction || !tx.transaction.message || !tx.transaction.message.accountKeys) {
|
|
406
|
+
return {
|
|
407
|
+
signature,
|
|
408
|
+
blockTime: tx?.blockTime || null,
|
|
409
|
+
feePayer: "unknown",
|
|
410
|
+
signers: []
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
const feePayer = tx.transaction.message.accountKeys[0];
|
|
414
|
+
const feePayerAddress = typeof feePayer === "string" ? feePayer : feePayer.pubkey.toString();
|
|
415
|
+
const signers = [];
|
|
416
|
+
const accountKeys = tx.transaction.message.accountKeys;
|
|
417
|
+
signers.push(feePayerAddress);
|
|
418
|
+
if (accountKeys && Array.isArray(accountKeys)) {
|
|
419
|
+
for (let i = 1; i < accountKeys.length; i++) {
|
|
420
|
+
const key = accountKeys[i];
|
|
421
|
+
const address = typeof key === "string" ? key : key.pubkey?.toString();
|
|
422
|
+
if (typeof key !== "string" && key.signer) {
|
|
423
|
+
if (address && !signers.includes(address)) {
|
|
424
|
+
signers.push(address);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
let memo;
|
|
430
|
+
const instructions = tx.transaction.message.instructions;
|
|
431
|
+
if (instructions && Array.isArray(instructions)) {
|
|
432
|
+
for (const instruction of instructions) {
|
|
433
|
+
if (!instruction || !instruction.programId) continue;
|
|
434
|
+
const programId = instruction.programId.toString();
|
|
435
|
+
if (programId === PROGRAM_IDS.MEMO || programId === PROGRAM_IDS.MEMO_V1) {
|
|
436
|
+
if ("parsed" in instruction && instruction.parsed) {
|
|
437
|
+
const parsed = instruction.parsed;
|
|
438
|
+
if (parsed.type === "memo" && typeof parsed.info === "string") {
|
|
439
|
+
memo = parsed.info;
|
|
440
|
+
}
|
|
441
|
+
} else if ("data" in instruction && typeof instruction.data === "string") {
|
|
442
|
+
try {
|
|
443
|
+
memo = Buffer.from(instruction.data, "base64").toString("utf8");
|
|
444
|
+
} catch {
|
|
445
|
+
memo = instruction.data;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
let computeUnitsUsed;
|
|
453
|
+
let priorityFee;
|
|
454
|
+
if (tx.meta) {
|
|
455
|
+
computeUnitsUsed = tx.meta.computeUnitsConsumed;
|
|
456
|
+
if (tx.meta.fee !== void 0 && tx.meta.fee > 5e3) {
|
|
457
|
+
priorityFee = tx.meta.fee - 5e3;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
signature,
|
|
462
|
+
blockTime: tx.blockTime,
|
|
463
|
+
feePayer: feePayerAddress,
|
|
464
|
+
signers,
|
|
465
|
+
computeUnitsUsed,
|
|
466
|
+
priorityFee,
|
|
467
|
+
memo
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function extractTokenAccountEvents(tx, signature) {
|
|
471
|
+
const events = [];
|
|
472
|
+
if (!tx.transaction?.message?.instructions) {
|
|
473
|
+
return events;
|
|
474
|
+
}
|
|
475
|
+
for (const instruction of tx.transaction.message.instructions) {
|
|
476
|
+
if (!instruction || !instruction.programId) continue;
|
|
477
|
+
const programId = instruction.programId.toString();
|
|
478
|
+
if (programId === PROGRAM_IDS.TOKEN || programId === PROGRAM_IDS.ASSOCIATED_TOKEN) {
|
|
479
|
+
if ("parsed" in instruction && instruction.parsed) {
|
|
480
|
+
const parsed = instruction.parsed;
|
|
481
|
+
if (parsed.type === "initializeAccount" || parsed.type === "create") {
|
|
482
|
+
const info = parsed.info;
|
|
483
|
+
events.push({
|
|
484
|
+
type: "create",
|
|
485
|
+
tokenAccount: info.account || info.newAccount,
|
|
486
|
+
owner: info.owner,
|
|
487
|
+
mint: info.mint,
|
|
488
|
+
signature,
|
|
489
|
+
blockTime: tx.blockTime
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (parsed.type === "closeAccount") {
|
|
493
|
+
const info = parsed.info;
|
|
494
|
+
let rentRefund;
|
|
495
|
+
if (tx.meta?.postBalances && tx.meta?.preBalances) {
|
|
496
|
+
const accountKeys = tx.transaction.message.accountKeys;
|
|
497
|
+
for (let i = 0; i < accountKeys.length; i++) {
|
|
498
|
+
const key = accountKeys[i];
|
|
499
|
+
const address = typeof key === "string" ? key : key.pubkey.toString();
|
|
500
|
+
if (address === info.destination) {
|
|
501
|
+
const diff = tx.meta.postBalances[i] - tx.meta.preBalances[i];
|
|
502
|
+
if (diff > 0) {
|
|
503
|
+
rentRefund = diff / 1e9;
|
|
504
|
+
}
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
events.push({
|
|
510
|
+
type: "close",
|
|
511
|
+
tokenAccount: info.account,
|
|
512
|
+
owner: info.owner || info.destination,
|
|
513
|
+
signature,
|
|
514
|
+
blockTime: tx.blockTime,
|
|
515
|
+
rentRefund
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return events;
|
|
522
|
+
}
|
|
523
|
+
function extractPDAInteractions(tx, signature) {
|
|
524
|
+
const interactions = [];
|
|
525
|
+
if (!tx.transaction?.message?.accountKeys) {
|
|
526
|
+
return interactions;
|
|
527
|
+
}
|
|
528
|
+
const accountProgramMap = /* @__PURE__ */ new Map();
|
|
529
|
+
for (const instruction of tx.transaction.message.instructions) {
|
|
530
|
+
if (!instruction || !instruction.programId) continue;
|
|
531
|
+
const programId = instruction.programId.toString();
|
|
532
|
+
const accounts = [];
|
|
533
|
+
if ("accounts" in instruction && Array.isArray(instruction.accounts)) {
|
|
534
|
+
for (const acc of instruction.accounts) {
|
|
535
|
+
const address = typeof acc === "string" ? acc : acc.toString();
|
|
536
|
+
accounts.push(address);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
for (const account of accounts) {
|
|
540
|
+
if (!accountProgramMap.has(account)) {
|
|
541
|
+
accountProgramMap.set(account, /* @__PURE__ */ new Set());
|
|
542
|
+
}
|
|
543
|
+
accountProgramMap.get(account).add(programId);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
for (const [address, programs] of accountProgramMap) {
|
|
547
|
+
for (const programId of programs) {
|
|
548
|
+
if (programId === PROGRAM_IDS.SYSTEM || programId === PROGRAM_IDS.MEMO || programId === PROGRAM_IDS.MEMO_V1) {
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
interactions.push({
|
|
552
|
+
pda: address,
|
|
553
|
+
programId,
|
|
554
|
+
signature
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return interactions;
|
|
559
|
+
}
|
|
400
560
|
function extractSOLTransfers(tx, signature) {
|
|
401
561
|
const transfers = [];
|
|
402
562
|
if (!tx.meta || !tx.transaction) {
|
|
@@ -560,12 +720,20 @@ function extractInstructions(tx, signature) {
|
|
|
560
720
|
if ("parsed" in instruction) {
|
|
561
721
|
data = instruction.parsed;
|
|
562
722
|
}
|
|
723
|
+
const accounts = [];
|
|
724
|
+
if ("accounts" in instruction && Array.isArray(instruction.accounts)) {
|
|
725
|
+
for (const acc of instruction.accounts) {
|
|
726
|
+
const address = typeof acc === "string" ? acc : acc.toString();
|
|
727
|
+
accounts.push(address);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
563
730
|
instructions.push({
|
|
564
731
|
programId,
|
|
565
732
|
category,
|
|
566
733
|
signature,
|
|
567
734
|
blockTime: tx.blockTime,
|
|
568
|
-
data
|
|
735
|
+
data,
|
|
736
|
+
accounts: accounts.length > 0 ? accounts : void 0
|
|
569
737
|
});
|
|
570
738
|
}
|
|
571
739
|
return instructions;
|
|
@@ -599,6 +767,9 @@ function calculateTimeRange(transactions) {
|
|
|
599
767
|
function normalizeWalletData(rawData, labelProvider) {
|
|
600
768
|
const allTransfers = [];
|
|
601
769
|
const allInstructions = [];
|
|
770
|
+
const allTransactionMetadata = [];
|
|
771
|
+
const allTokenAccountEvents = [];
|
|
772
|
+
const allPDAInteractions = [];
|
|
602
773
|
const transactions = rawData.transactions || [];
|
|
603
774
|
for (const rawTx of transactions) {
|
|
604
775
|
if (!rawTx.transaction) continue;
|
|
@@ -608,6 +779,12 @@ function normalizeWalletData(rawData, labelProvider) {
|
|
|
608
779
|
allTransfers.push(...solTransfers, ...splTransfers);
|
|
609
780
|
const instructions = extractInstructions(rawTx.transaction, rawTx.signature);
|
|
610
781
|
allInstructions.push(...instructions);
|
|
782
|
+
const metadata = extractTransactionMetadata(rawTx.transaction, rawTx.signature);
|
|
783
|
+
allTransactionMetadata.push(metadata);
|
|
784
|
+
const tokenEvents = extractTokenAccountEvents(rawTx.transaction, rawTx.signature);
|
|
785
|
+
allTokenAccountEvents.push(...tokenEvents);
|
|
786
|
+
const pdaInteractions = extractPDAInteractions(rawTx.transaction, rawTx.signature);
|
|
787
|
+
allPDAInteractions.push(...pdaInteractions);
|
|
611
788
|
} catch (error) {
|
|
612
789
|
console.warn(`Failed to normalize transaction ${rawTx.signature}:`, error);
|
|
613
790
|
continue;
|
|
@@ -627,22 +804,47 @@ function normalizeWalletData(rawData, labelProvider) {
|
|
|
627
804
|
return null;
|
|
628
805
|
}
|
|
629
806
|
}).filter((ta) => ta !== null);
|
|
807
|
+
const feePayers = /* @__PURE__ */ new Set();
|
|
808
|
+
const signers = /* @__PURE__ */ new Set();
|
|
809
|
+
const programs = /* @__PURE__ */ new Set();
|
|
810
|
+
for (const metadata of allTransactionMetadata) {
|
|
811
|
+
feePayers.add(metadata.feePayer);
|
|
812
|
+
for (const signer of metadata.signers) {
|
|
813
|
+
signers.add(signer);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
for (const instruction of allInstructions) {
|
|
817
|
+
programs.add(instruction.programId);
|
|
818
|
+
}
|
|
630
819
|
return {
|
|
631
820
|
target: rawData.address,
|
|
632
821
|
targetType: "wallet",
|
|
633
822
|
transfers: allTransfers,
|
|
634
823
|
instructions: allInstructions,
|
|
635
824
|
counterparties,
|
|
636
|
-
labels
|
|
825
|
+
labels,
|
|
637
826
|
tokenAccounts,
|
|
638
827
|
timeRange,
|
|
639
|
-
transactionCount: transactions.length
|
|
828
|
+
transactionCount: transactions.length,
|
|
829
|
+
// Solana-specific fields
|
|
830
|
+
transactions: allTransactionMetadata,
|
|
831
|
+
tokenAccountEvents: allTokenAccountEvents,
|
|
832
|
+
pdaInteractions: allPDAInteractions,
|
|
833
|
+
feePayers,
|
|
834
|
+
signers,
|
|
835
|
+
programs
|
|
640
836
|
};
|
|
641
837
|
}
|
|
642
838
|
function normalizeTransactionData(rawData, labelProvider) {
|
|
643
839
|
const allTransfers = [];
|
|
644
840
|
const allInstructions = [];
|
|
645
841
|
const counterparties = /* @__PURE__ */ new Set();
|
|
842
|
+
const allTransactionMetadata = [];
|
|
843
|
+
const allTokenAccountEvents = [];
|
|
844
|
+
const allPDAInteractions = [];
|
|
845
|
+
const feePayers = /* @__PURE__ */ new Set();
|
|
846
|
+
const signers = /* @__PURE__ */ new Set();
|
|
847
|
+
const programs = /* @__PURE__ */ new Set();
|
|
646
848
|
if (rawData.transaction) {
|
|
647
849
|
try {
|
|
648
850
|
const solTransfers = extractSOLTransfers(rawData.transaction, rawData.signature);
|
|
@@ -650,6 +852,16 @@ function normalizeTransactionData(rawData, labelProvider) {
|
|
|
650
852
|
allTransfers.push(...solTransfers, ...splTransfers);
|
|
651
853
|
const instructions = extractInstructions(rawData.transaction, rawData.signature);
|
|
652
854
|
allInstructions.push(...instructions);
|
|
855
|
+
const metadata = extractTransactionMetadata(rawData.transaction, rawData.signature);
|
|
856
|
+
allTransactionMetadata.push(metadata);
|
|
857
|
+
feePayers.add(metadata.feePayer);
|
|
858
|
+
for (const signer of metadata.signers) {
|
|
859
|
+
signers.add(signer);
|
|
860
|
+
}
|
|
861
|
+
const tokenEvents = extractTokenAccountEvents(rawData.transaction, rawData.signature);
|
|
862
|
+
allTokenAccountEvents.push(...tokenEvents);
|
|
863
|
+
const pdaInteractions = extractPDAInteractions(rawData.transaction, rawData.signature);
|
|
864
|
+
allPDAInteractions.push(...pdaInteractions);
|
|
653
865
|
const accountKeys = rawData.transaction.transaction.message.accountKeys;
|
|
654
866
|
if (accountKeys && Array.isArray(accountKeys)) {
|
|
655
867
|
for (const key of accountKeys) {
|
|
@@ -657,29 +869,46 @@ function normalizeTransactionData(rawData, labelProvider) {
|
|
|
657
869
|
counterparties.add(address);
|
|
658
870
|
}
|
|
659
871
|
}
|
|
872
|
+
for (const instruction of instructions) {
|
|
873
|
+
programs.add(instruction.programId);
|
|
874
|
+
}
|
|
660
875
|
} catch (error) {
|
|
661
876
|
console.warn(`Failed to normalize transaction ${rawData.signature}:`, error);
|
|
662
877
|
}
|
|
663
878
|
}
|
|
879
|
+
const labels = labelProvider ? labelProvider.lookupMany(Array.from(counterparties)) : /* @__PURE__ */ new Map();
|
|
664
880
|
return {
|
|
665
881
|
target: rawData.signature,
|
|
666
882
|
targetType: "transaction",
|
|
667
883
|
transfers: allTransfers,
|
|
668
884
|
instructions: allInstructions,
|
|
669
885
|
counterparties,
|
|
670
|
-
labels
|
|
886
|
+
labels,
|
|
671
887
|
tokenAccounts: [],
|
|
672
888
|
timeRange: {
|
|
673
889
|
earliest: rawData.transaction ? rawData.blockTime : null,
|
|
674
890
|
latest: rawData.transaction ? rawData.blockTime : null
|
|
675
891
|
},
|
|
676
|
-
transactionCount: rawData.transaction ? 1 : 0
|
|
892
|
+
transactionCount: rawData.transaction ? 1 : 0,
|
|
893
|
+
// Solana-specific fields
|
|
894
|
+
transactions: allTransactionMetadata,
|
|
895
|
+
tokenAccountEvents: allTokenAccountEvents,
|
|
896
|
+
pdaInteractions: allPDAInteractions,
|
|
897
|
+
feePayers,
|
|
898
|
+
signers,
|
|
899
|
+
programs
|
|
677
900
|
};
|
|
678
901
|
}
|
|
679
902
|
function normalizeProgramData(rawData, labelProvider) {
|
|
680
903
|
const allTransfers = [];
|
|
681
904
|
const allInstructions = [];
|
|
682
905
|
const counterparties = /* @__PURE__ */ new Set();
|
|
906
|
+
const allTransactionMetadata = [];
|
|
907
|
+
const allTokenAccountEvents = [];
|
|
908
|
+
const allPDAInteractions = [];
|
|
909
|
+
const feePayers = /* @__PURE__ */ new Set();
|
|
910
|
+
const signers = /* @__PURE__ */ new Set();
|
|
911
|
+
const programs = /* @__PURE__ */ new Set();
|
|
683
912
|
const transactions = rawData.relatedTransactions || [];
|
|
684
913
|
for (const rawTx of transactions) {
|
|
685
914
|
if (!rawTx.transaction) continue;
|
|
@@ -689,6 +918,16 @@ function normalizeProgramData(rawData, labelProvider) {
|
|
|
689
918
|
allTransfers.push(...solTransfers, ...splTransfers);
|
|
690
919
|
const instructions = extractInstructions(rawTx.transaction, rawTx.signature);
|
|
691
920
|
allInstructions.push(...instructions);
|
|
921
|
+
const metadata = extractTransactionMetadata(rawTx.transaction, rawTx.signature);
|
|
922
|
+
allTransactionMetadata.push(metadata);
|
|
923
|
+
feePayers.add(metadata.feePayer);
|
|
924
|
+
for (const signer of metadata.signers) {
|
|
925
|
+
signers.add(signer);
|
|
926
|
+
}
|
|
927
|
+
const tokenEvents = extractTokenAccountEvents(rawTx.transaction, rawTx.signature);
|
|
928
|
+
allTokenAccountEvents.push(...tokenEvents);
|
|
929
|
+
const pdaInteractions = extractPDAInteractions(rawTx.transaction, rawTx.signature);
|
|
930
|
+
allPDAInteractions.push(...pdaInteractions);
|
|
692
931
|
const accountKeys = rawTx.transaction.transaction.message.accountKeys;
|
|
693
932
|
if (accountKeys && Array.isArray(accountKeys)) {
|
|
694
933
|
for (const key of accountKeys) {
|
|
@@ -696,6 +935,9 @@ function normalizeProgramData(rawData, labelProvider) {
|
|
|
696
935
|
counterparties.add(address);
|
|
697
936
|
}
|
|
698
937
|
}
|
|
938
|
+
for (const instruction of instructions) {
|
|
939
|
+
programs.add(instruction.programId);
|
|
940
|
+
}
|
|
699
941
|
} catch (error) {
|
|
700
942
|
console.warn(`Failed to normalize program transaction ${rawTx.signature}:`, error);
|
|
701
943
|
continue;
|
|
@@ -709,61 +951,168 @@ function normalizeProgramData(rawData, labelProvider) {
|
|
|
709
951
|
transfers: allTransfers,
|
|
710
952
|
instructions: allInstructions,
|
|
711
953
|
counterparties,
|
|
712
|
-
labels
|
|
954
|
+
labels,
|
|
713
955
|
tokenAccounts: [],
|
|
714
956
|
timeRange,
|
|
715
|
-
transactionCount: transactions.length
|
|
957
|
+
transactionCount: transactions.length,
|
|
958
|
+
// Solana-specific fields
|
|
959
|
+
transactions: allTransactionMetadata,
|
|
960
|
+
tokenAccountEvents: allTokenAccountEvents,
|
|
961
|
+
pdaInteractions: allPDAInteractions,
|
|
962
|
+
feePayers,
|
|
963
|
+
signers,
|
|
964
|
+
programs
|
|
716
965
|
};
|
|
717
966
|
}
|
|
718
967
|
|
|
719
968
|
// src/heuristics/counterparty-reuse.ts
|
|
720
969
|
function detectCounterpartyReuse(context) {
|
|
721
|
-
|
|
722
|
-
|
|
970
|
+
const signals = [];
|
|
971
|
+
if (context.targetType !== "wallet" || context.transactionCount < 2) {
|
|
972
|
+
return signals;
|
|
723
973
|
}
|
|
724
|
-
if (context.
|
|
725
|
-
|
|
974
|
+
if (context.transfers.length > 0) {
|
|
975
|
+
const interactionCounts = /* @__PURE__ */ new Map();
|
|
976
|
+
for (const transfer of context.transfers) {
|
|
977
|
+
const counterparty = transfer.from === context.target ? transfer.to : transfer.from;
|
|
978
|
+
if (counterparty === context.target) continue;
|
|
979
|
+
interactionCounts.set(counterparty, (interactionCounts.get(counterparty) || 0) + 1);
|
|
980
|
+
}
|
|
981
|
+
const reusedCounterparties = Array.from(interactionCounts.entries()).filter(([_, count]) => count >= 3).sort((a, b) => b[1] - a[1]);
|
|
982
|
+
if (reusedCounterparties.length > 0) {
|
|
983
|
+
const totalInteractions = context.transfers.length;
|
|
984
|
+
const topCounterpartyInteractions = reusedCounterparties[0][1];
|
|
985
|
+
const concentration = topCounterpartyInteractions / totalInteractions;
|
|
986
|
+
let severity = "LOW";
|
|
987
|
+
if (concentration > 0.5 || reusedCounterparties.length >= 5) {
|
|
988
|
+
severity = "HIGH";
|
|
989
|
+
} else if (concentration > 0.3 || reusedCounterparties.length >= 3) {
|
|
990
|
+
severity = "MEDIUM";
|
|
991
|
+
}
|
|
992
|
+
const evidence = reusedCounterparties.slice(0, 5).map(([addr, count]) => {
|
|
993
|
+
const label = context.labels.get(addr);
|
|
994
|
+
return {
|
|
995
|
+
description: `${count} transfers with ${addr.slice(0, 8)}...${addr.slice(-8)}${label ? ` (${label.name})` : ""}`,
|
|
996
|
+
severity: count > totalInteractions * 0.3 ? "HIGH" : count > totalInteractions * 0.15 ? "MEDIUM" : "LOW",
|
|
997
|
+
type: "address",
|
|
998
|
+
data: { address: addr, interactionCount: count }
|
|
999
|
+
};
|
|
1000
|
+
});
|
|
1001
|
+
signals.push({
|
|
1002
|
+
id: "counterparty-reuse",
|
|
1003
|
+
name: "Repeated Transfer Counterparties",
|
|
1004
|
+
severity,
|
|
1005
|
+
category: "linkability",
|
|
1006
|
+
reason: `Wallet repeatedly transfers with ${reusedCounterparties.length} address(es). Top counterparty: ${topCounterpartyInteractions}/${totalInteractions} transfers.`,
|
|
1007
|
+
impact: "Repeated interactions with the same addresses can be used to cluster wallets and build transaction graphs.",
|
|
1008
|
+
evidence,
|
|
1009
|
+
mitigation: "Use different wallets for different counterparties, or use privacy-preserving protocols."
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
726
1012
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
1013
|
+
if (context.programs && context.programs.size > 0) {
|
|
1014
|
+
const programUsage = /* @__PURE__ */ new Map();
|
|
1015
|
+
for (const instruction of context.instructions) {
|
|
1016
|
+
programUsage.set(instruction.programId, (programUsage.get(instruction.programId) || 0) + 1);
|
|
1017
|
+
}
|
|
1018
|
+
const SYSTEM_PROGRAMS = [
|
|
1019
|
+
"11111111111111111111111111111111",
|
|
1020
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
1021
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
1022
|
+
"ComputeBudget111111111111111111111111111111"
|
|
1023
|
+
];
|
|
1024
|
+
const significantPrograms = Array.from(programUsage.entries()).filter(([programId]) => !SYSTEM_PROGRAMS.includes(programId)).filter(([_, count]) => count >= Math.min(3, Math.ceil(context.instructions.length * 0.1))).sort((a, b) => b[1] - a[1]);
|
|
1025
|
+
if (significantPrograms.length >= 2) {
|
|
1026
|
+
const evidence = significantPrograms.slice(0, 5).map(([programId, count]) => {
|
|
1027
|
+
const label = context.labels.get(programId);
|
|
1028
|
+
return {
|
|
1029
|
+
description: `${programId.slice(0, 8)}...${label ? ` (${label.name})` : ""} used in ${count} instruction(s)`,
|
|
1030
|
+
severity: "LOW",
|
|
1031
|
+
reference: `https://solscan.io/account/${programId}`
|
|
1032
|
+
};
|
|
1033
|
+
});
|
|
1034
|
+
signals.push({
|
|
1035
|
+
id: "program-reuse",
|
|
1036
|
+
name: "Repeated Program Interactions",
|
|
1037
|
+
severity: "LOW",
|
|
1038
|
+
category: "behavioral",
|
|
1039
|
+
reason: `Wallet interacts with ${significantPrograms.length} non-system program(s) repeatedly.`,
|
|
1040
|
+
impact: "Program usage patterns create a behavioral fingerprint. Addresses with similar patterns are likely related.",
|
|
1041
|
+
mitigation: "This is generally unavoidable when using DeFi. Diversifying protocols can reduce fingerprinting.",
|
|
1042
|
+
evidence
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
732
1045
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
1046
|
+
if (context.pdaInteractions && context.pdaInteractions.length > 0) {
|
|
1047
|
+
const pdaUsage = /* @__PURE__ */ new Map();
|
|
1048
|
+
for (const pda of context.pdaInteractions) {
|
|
1049
|
+
if (!pdaUsage.has(pda.pda)) {
|
|
1050
|
+
pdaUsage.set(pda.pda, { count: 0, programId: pda.programId });
|
|
1051
|
+
}
|
|
1052
|
+
pdaUsage.get(pda.pda).count++;
|
|
1053
|
+
}
|
|
1054
|
+
const repeatedPDAs = Array.from(pdaUsage.entries()).filter(([_, { count }]) => count >= 2).sort((a, b) => b[1].count - a[1].count);
|
|
1055
|
+
if (repeatedPDAs.length > 0) {
|
|
1056
|
+
const evidence = repeatedPDAs.slice(0, 5).map(([pda, { count, programId }]) => ({
|
|
1057
|
+
description: `PDA ${pda.slice(0, 8)}... (program: ${programId.slice(0, 8)}...) used ${count} times`,
|
|
1058
|
+
severity: count > 3 ? "MEDIUM" : "LOW",
|
|
1059
|
+
reference: `https://solscan.io/account/${pda}`
|
|
1060
|
+
}));
|
|
1061
|
+
const maxCount = repeatedPDAs[0][1].count;
|
|
1062
|
+
const severity = maxCount > 5 ? "MEDIUM" : "LOW";
|
|
1063
|
+
signals.push({
|
|
1064
|
+
id: "pda-reuse",
|
|
1065
|
+
name: "Repeated PDA Interactions",
|
|
1066
|
+
severity,
|
|
1067
|
+
category: "linkability",
|
|
1068
|
+
reason: `${repeatedPDAs.length} Program-Derived Address(es) are used repeatedly. Max usage: ${maxCount} times.`,
|
|
1069
|
+
impact: "PDAs often represent user-specific accounts (e.g., your position in a protocol). Repeated usage links all interactions.",
|
|
1070
|
+
mitigation: "Some PDA reuse is inherent to Solana protocols. For sensitive operations, use fresh wallets.",
|
|
1071
|
+
evidence
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
736
1074
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
1075
|
+
if (context.transfers.length > 0 && context.instructions.length > 0) {
|
|
1076
|
+
const combos = /* @__PURE__ */ new Map();
|
|
1077
|
+
for (const transfer of context.transfers) {
|
|
1078
|
+
const counterparty = transfer.from === context.target ? transfer.to : transfer.from;
|
|
1079
|
+
if (counterparty === context.target) continue;
|
|
1080
|
+
const txInstructions = context.instructions.filter((inst) => inst.signature === transfer.signature);
|
|
1081
|
+
for (const inst of txInstructions) {
|
|
1082
|
+
const combo = `${counterparty}:${inst.programId}`;
|
|
1083
|
+
combos.set(combo, (combos.get(combo) || 0) + 1);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
const repeatedCombos = Array.from(combos.entries()).filter(([_, count]) => count >= 2).sort((a, b) => b[1] - a[1]);
|
|
1087
|
+
if (repeatedCombos.length > 0) {
|
|
1088
|
+
const evidence = repeatedCombos.slice(0, 3).map(([combo, count]) => {
|
|
1089
|
+
const [counterparty, programId] = combo.split(":");
|
|
1090
|
+
const label = context.labels.get(counterparty);
|
|
1091
|
+
return {
|
|
1092
|
+
description: `${counterparty.slice(0, 8)}...${label ? ` (${label.name})` : ""} + program ${programId.slice(0, 8)}... used ${count} times`,
|
|
1093
|
+
severity: "MEDIUM"
|
|
1094
|
+
};
|
|
1095
|
+
});
|
|
1096
|
+
signals.push({
|
|
1097
|
+
id: "counterparty-program-combo",
|
|
1098
|
+
name: "Repeated Counterparty-Program Combination",
|
|
1099
|
+
severity: "MEDIUM",
|
|
1100
|
+
category: "linkability",
|
|
1101
|
+
reason: `${repeatedCombos.length} specific counterparty-program combination(s) are reused.`,
|
|
1102
|
+
impact: "This creates a very specific fingerprint. The combination of WHO you interact with and WHAT program is highly identifying.",
|
|
1103
|
+
mitigation: "Rotate both counterparties and programs if privacy is critical.",
|
|
1104
|
+
evidence
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
745
1107
|
}
|
|
746
|
-
|
|
747
|
-
type: "address",
|
|
748
|
-
description: `${count} interactions with ${addr.slice(0, 8)}...${addr.slice(-8)}`,
|
|
749
|
-
data: { address: addr, interactionCount: count }
|
|
750
|
-
}));
|
|
751
|
-
return {
|
|
752
|
-
id: "counterparty-reuse",
|
|
753
|
-
name: "Counterparty Reuse",
|
|
754
|
-
severity,
|
|
755
|
-
reason: `Wallet repeatedly interacts with ${reusedCounterparties.length} address(es)`,
|
|
756
|
-
impact: "Repeated interactions with the same addresses can be used to cluster wallets and build transaction graphs, enabling surveillance of your activity patterns.",
|
|
757
|
-
evidence,
|
|
758
|
-
mitigation: "Use different wallets for different counterparties, or use privacy-preserving protocols that obscure transaction graphs.",
|
|
759
|
-
confidence: 0.9
|
|
760
|
-
};
|
|
1108
|
+
return signals;
|
|
761
1109
|
}
|
|
762
1110
|
|
|
763
1111
|
// src/heuristics/amount-reuse.ts
|
|
764
1112
|
function detectAmountReuse(context) {
|
|
765
|
-
|
|
766
|
-
|
|
1113
|
+
const signals = [];
|
|
1114
|
+
if (context.transfers.length < 5) {
|
|
1115
|
+
return signals;
|
|
767
1116
|
}
|
|
768
1117
|
const amountCounts = /* @__PURE__ */ new Map();
|
|
769
1118
|
const roundNumbers = [];
|
|
@@ -772,49 +1121,114 @@ function detectAmountReuse(context) {
|
|
|
772
1121
|
roundNumbers.push(transfer.amount);
|
|
773
1122
|
}
|
|
774
1123
|
const amountKey = `${transfer.amount.toFixed(9)}-${transfer.token || "SOL"}`;
|
|
775
|
-
|
|
1124
|
+
if (!amountCounts.has(amountKey)) {
|
|
1125
|
+
amountCounts.set(amountKey, { count: 0, counterparties: /* @__PURE__ */ new Set(), signers: /* @__PURE__ */ new Set() });
|
|
1126
|
+
}
|
|
1127
|
+
const data = amountCounts.get(amountKey);
|
|
1128
|
+
data.count++;
|
|
1129
|
+
const counterparty = transfer.from === context.target ? transfer.to : transfer.from;
|
|
1130
|
+
if (counterparty !== context.target) {
|
|
1131
|
+
data.counterparties.add(counterparty);
|
|
1132
|
+
}
|
|
1133
|
+
const tx = context.transactions ? context.transactions.find((t) => t.signature === transfer.signature) : null;
|
|
1134
|
+
if (tx) {
|
|
1135
|
+
tx.signers.forEach((s) => data.signers.add(s));
|
|
1136
|
+
}
|
|
776
1137
|
}
|
|
777
|
-
const reusedAmounts = Array.from(amountCounts.entries()).filter(([_,
|
|
778
|
-
const hasRoundNumbers = roundNumbers.length >=
|
|
1138
|
+
const reusedAmounts = Array.from(amountCounts.entries()).filter(([_, data]) => data.count >= 3).sort((a, b) => b[1].count - a[1].count);
|
|
1139
|
+
const hasRoundNumbers = roundNumbers.length >= 3;
|
|
779
1140
|
const hasReusedAmounts = reusedAmounts.length >= 2;
|
|
780
|
-
if (
|
|
781
|
-
|
|
1141
|
+
if (hasRoundNumbers && roundNumbers.length >= 5) {
|
|
1142
|
+
signals.push({
|
|
1143
|
+
id: "amount-round-numbers",
|
|
1144
|
+
name: "Frequent Round Number Transfers",
|
|
1145
|
+
severity: "LOW",
|
|
1146
|
+
category: "behavioral",
|
|
1147
|
+
reason: `${roundNumbers.length} round-number transfers detected (e.g., 1 SOL, 10 SOL).`,
|
|
1148
|
+
impact: "Round numbers are common on Solana and relatively benign alone. Combined with other patterns, they can contribute to fingerprinting.",
|
|
1149
|
+
mitigation: "Vary amounts slightly if possible, but this is low priority on Solana.",
|
|
1150
|
+
evidence: [{
|
|
1151
|
+
description: `${roundNumbers.length} round-number transfers: ${roundNumbers.slice(0, 5).join(", ")}...`,
|
|
1152
|
+
severity: "LOW",
|
|
1153
|
+
type: "amount",
|
|
1154
|
+
data: { roundNumbers: roundNumbers.slice(0, 5) }
|
|
1155
|
+
}]
|
|
1156
|
+
});
|
|
782
1157
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
1158
|
+
const suspiciousReuse = reusedAmounts.filter(([_, data]) => {
|
|
1159
|
+
return data.counterparties.size === 1 && data.count >= 3;
|
|
1160
|
+
});
|
|
1161
|
+
if (suspiciousReuse.length > 0) {
|
|
1162
|
+
const evidence = suspiciousReuse.slice(0, 3).map(([amountKey, data]) => {
|
|
1163
|
+
const [amount, token] = amountKey.split("-");
|
|
1164
|
+
const counterparty = Array.from(data.counterparties)[0];
|
|
1165
|
+
return {
|
|
1166
|
+
description: `${amount} ${token} sent to ${counterparty.slice(0, 8)}... ${data.count} times`,
|
|
1167
|
+
severity: "MEDIUM",
|
|
1168
|
+
type: "amount",
|
|
1169
|
+
data: { amount: parseFloat(amount), token, count: data.count, counterparty }
|
|
1170
|
+
};
|
|
1171
|
+
});
|
|
1172
|
+
signals.push({
|
|
1173
|
+
id: "amount-reuse-counterparty",
|
|
1174
|
+
name: "Same Amount to Same Counterparty",
|
|
1175
|
+
severity: "MEDIUM",
|
|
1176
|
+
category: "behavioral",
|
|
1177
|
+
reason: `${suspiciousReuse.length} amount(s) repeatedly sent to the same counterparty.`,
|
|
1178
|
+
impact: "Sending the same amount to the same address multiple times creates a strong pattern. This is likely automated or habitual behavior.",
|
|
1179
|
+
mitigation: "Vary amounts when sending to the same address, or use privacy protocols.",
|
|
1180
|
+
evidence
|
|
1181
|
+
});
|
|
788
1182
|
}
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
1183
|
+
const signerReuse = reusedAmounts.filter(([_, data]) => {
|
|
1184
|
+
return data.signers.size <= 2 && data.count >= 3;
|
|
1185
|
+
});
|
|
1186
|
+
if (signerReuse.length > 0 && suspiciousReuse.length === 0) {
|
|
1187
|
+
const evidence = signerReuse.slice(0, 3).map(([amountKey, data]) => {
|
|
1188
|
+
const [amount, token] = amountKey.split("-");
|
|
1189
|
+
return {
|
|
1190
|
+
description: `${amount} ${token} used ${data.count} times with ${data.signers.size} signer(s)`,
|
|
1191
|
+
severity: "LOW",
|
|
1192
|
+
type: "amount",
|
|
1193
|
+
data: { amount: parseFloat(amount), token, count: data.count }
|
|
1194
|
+
};
|
|
1195
|
+
});
|
|
1196
|
+
signals.push({
|
|
1197
|
+
id: "amount-reuse-pattern",
|
|
1198
|
+
name: "Repeated Amount Pattern",
|
|
1199
|
+
severity: "LOW",
|
|
1200
|
+
category: "behavioral",
|
|
1201
|
+
reason: `${signerReuse.length} amount(s) are reused multiple times with consistent signers.`,
|
|
1202
|
+
impact: "Amount reuse alone is relatively weak on Solana, but combined with other signals it contributes to behavioral fingerprinting.",
|
|
1203
|
+
mitigation: "Vary transaction amounts to reduce pattern visibility.",
|
|
1204
|
+
evidence
|
|
795
1205
|
});
|
|
796
1206
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1207
|
+
const veryReused = reusedAmounts.filter(([_, data]) => data.count >= 5);
|
|
1208
|
+
if (veryReused.length > 0 && suspiciousReuse.length === 0 && signerReuse.length === 0) {
|
|
1209
|
+
const evidence = veryReused.slice(0, 3).map(([amountKey, data]) => {
|
|
800
1210
|
const [amount, token] = amountKey.split("-");
|
|
801
|
-
|
|
1211
|
+
return {
|
|
1212
|
+
description: `${amount} ${token} used ${data.count} times across ${data.counterparties.size} counterparties`,
|
|
1213
|
+
severity: data.count > 10 ? "MEDIUM" : "LOW",
|
|
802
1214
|
type: "amount",
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
1215
|
+
data: { amount: parseFloat(amount), token, count: data.count }
|
|
1216
|
+
};
|
|
1217
|
+
});
|
|
1218
|
+
const maxCount = veryReused[0][1].count;
|
|
1219
|
+
const severity = maxCount > 10 ? "MEDIUM" : "LOW";
|
|
1220
|
+
signals.push({
|
|
1221
|
+
id: "amount-reuse-frequency",
|
|
1222
|
+
name: "High-Frequency Amount Reuse",
|
|
1223
|
+
severity,
|
|
1224
|
+
category: "behavioral",
|
|
1225
|
+
reason: `${veryReused.length} amount(s) are used very frequently (${maxCount} times for top amount).`,
|
|
1226
|
+
impact: "Extremely frequent reuse of specific amounts suggests automation or habitual behavior, creating a detectable pattern.",
|
|
1227
|
+
mitigation: "If running automated systems, add randomization to amounts.",
|
|
1228
|
+
evidence
|
|
1229
|
+
});
|
|
807
1230
|
}
|
|
808
|
-
return
|
|
809
|
-
id: "amount-reuse",
|
|
810
|
-
name: "Deterministic Amount Patterns",
|
|
811
|
-
severity,
|
|
812
|
-
reason: `Wallet uses ${hasRoundNumbers ? "round numbers" : "repeated amounts"} in transactions`,
|
|
813
|
-
impact: "Using the same amounts repeatedly or sending round numbers creates fingerprints that can be used to link transactions and identify patterns in your activity.",
|
|
814
|
-
evidence,
|
|
815
|
-
mitigation: "Vary transaction amounts slightly, avoid round numbers, and consider using privacy protocols that obscure amounts.",
|
|
816
|
-
confidence: hasRoundNumbers ? 0.85 : 0.75
|
|
817
|
-
};
|
|
1231
|
+
return signals;
|
|
818
1232
|
}
|
|
819
1233
|
|
|
820
1234
|
// src/heuristics/timing-patterns.ts
|
|
@@ -984,13 +1398,545 @@ function detectBalanceTraceability(context) {
|
|
|
984
1398
|
};
|
|
985
1399
|
}
|
|
986
1400
|
|
|
1401
|
+
// src/heuristics/fee-payer-reuse.ts
|
|
1402
|
+
function detectFeePayerReuse(context) {
|
|
1403
|
+
const signals = [];
|
|
1404
|
+
if (context.targetType === "transaction") {
|
|
1405
|
+
return signals;
|
|
1406
|
+
}
|
|
1407
|
+
if (!context.feePayers || !context.transactions || context.transactions.length === 0) {
|
|
1408
|
+
return signals;
|
|
1409
|
+
}
|
|
1410
|
+
const feePayers = context.feePayers;
|
|
1411
|
+
const target = context.target;
|
|
1412
|
+
const targetIsFeePayer = feePayers.has(target);
|
|
1413
|
+
const onlyTargetPays = feePayers.size === 1 && targetIsFeePayer;
|
|
1414
|
+
if (onlyTargetPays) {
|
|
1415
|
+
return signals;
|
|
1416
|
+
}
|
|
1417
|
+
if (feePayers.size > 1 && targetIsFeePayer) {
|
|
1418
|
+
const externalFeePayers = Array.from(feePayers).filter((fp) => fp !== target);
|
|
1419
|
+
const feePayerCounts = /* @__PURE__ */ new Map();
|
|
1420
|
+
for (const tx of context.transactions) {
|
|
1421
|
+
if (tx.feePayer !== target) {
|
|
1422
|
+
feePayerCounts.set(tx.feePayer, (feePayerCounts.get(tx.feePayer) || 0) + 1);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
const evidence = [];
|
|
1426
|
+
for (const [feePayer, count] of feePayerCounts) {
|
|
1427
|
+
evidence.push({
|
|
1428
|
+
description: `${feePayer} paid fees for ${count} transaction(s)`,
|
|
1429
|
+
severity: count > 1 ? "HIGH" : "MEDIUM",
|
|
1430
|
+
reference: void 0
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
const knownFeePayerLabel = externalFeePayers.find((fp) => context.labels.has(fp));
|
|
1434
|
+
const knownLabel = knownFeePayerLabel ? context.labels.get(knownFeePayerLabel) : null;
|
|
1435
|
+
signals.push({
|
|
1436
|
+
id: "fee-payer-external",
|
|
1437
|
+
name: "External Fee Payer Detected",
|
|
1438
|
+
severity: knownLabel ? "HIGH" : "MEDIUM",
|
|
1439
|
+
category: "linkability",
|
|
1440
|
+
reason: `${externalFeePayers.length} external wallet(s) paid fees for transactions involving this address${knownLabel ? `, including known entity: ${knownLabel.name}` : ""}.`,
|
|
1441
|
+
impact: "This address is linked to the fee payer(s). Anyone observing the blockchain can see this relationship. If the fee payer is identified, this address is also compromised.",
|
|
1442
|
+
mitigation: "Always pay your own transaction fees. Never allow third parties to pay fees for your transactions unless absolutely necessary. If using a relayer, understand that this creates a permanent on-chain link.",
|
|
1443
|
+
evidence
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
if (!targetIsFeePayer && feePayers.size > 0) {
|
|
1447
|
+
const allFeePayers = Array.from(feePayers);
|
|
1448
|
+
const feePayerCounts = /* @__PURE__ */ new Map();
|
|
1449
|
+
for (const tx of context.transactions) {
|
|
1450
|
+
feePayerCounts.set(tx.feePayer, (feePayerCounts.get(tx.feePayer) || 0) + 1);
|
|
1451
|
+
}
|
|
1452
|
+
const evidence = [];
|
|
1453
|
+
for (const [feePayer, count] of feePayerCounts) {
|
|
1454
|
+
const label = context.labels.get(feePayer);
|
|
1455
|
+
evidence.push({
|
|
1456
|
+
description: `${feePayer}${label ? ` (${label.name})` : ""} paid fees for ${count} transaction(s)`,
|
|
1457
|
+
severity: "HIGH",
|
|
1458
|
+
reference: void 0
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
const maxCount = Math.max(...Array.from(feePayerCounts.values()));
|
|
1462
|
+
const repeatedFeePayer = maxCount > 1;
|
|
1463
|
+
signals.push({
|
|
1464
|
+
id: "fee-payer-never-self",
|
|
1465
|
+
name: "Never Self-Pays Transaction Fees",
|
|
1466
|
+
severity: repeatedFeePayer ? "HIGH" : "HIGH",
|
|
1467
|
+
// Always HIGH - this is critical
|
|
1468
|
+
category: "linkability",
|
|
1469
|
+
reason: `This address has NEVER paid its own transaction fees. All ${context.transactionCount} transaction(s) were paid by ${allFeePayers.length} external wallet(s).`,
|
|
1470
|
+
impact: "This is a CRITICAL privacy leak. This address is trivially linked to all fee payer(s). This pattern suggests a managed account, hot wallet, or program-controlled address. The controlling entity is fully exposed.",
|
|
1471
|
+
mitigation: "This account model fundamentally compromises privacy. To improve: (1) Fund this address with SOL and pay your own fees, or (2) Use a fresh address for each operation, or (3) Accept that this address is permanently linked to its fee payer(s).",
|
|
1472
|
+
evidence
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
if (context.targetType === "program") {
|
|
1476
|
+
const feePayerCounts = /* @__PURE__ */ new Map();
|
|
1477
|
+
for (const tx of context.transactions) {
|
|
1478
|
+
if (!feePayerCounts.has(tx.feePayer)) {
|
|
1479
|
+
feePayerCounts.set(tx.feePayer, /* @__PURE__ */ new Set());
|
|
1480
|
+
}
|
|
1481
|
+
for (const signer of tx.signers) {
|
|
1482
|
+
feePayerCounts.get(tx.feePayer).add(signer);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
const multiFeePayerOperators = [];
|
|
1486
|
+
for (const [feePayer, signers] of feePayerCounts) {
|
|
1487
|
+
if (signers.size > 1) {
|
|
1488
|
+
const txCount = context.transactions.filter((tx) => tx.feePayer === feePayer).length;
|
|
1489
|
+
multiFeePayerOperators.push({
|
|
1490
|
+
feePayer,
|
|
1491
|
+
signerCount: signers.size,
|
|
1492
|
+
txCount
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
if (multiFeePayerOperators.length > 0) {
|
|
1497
|
+
const evidence = multiFeePayerOperators.map((op) => ({
|
|
1498
|
+
description: `${op.feePayer} paid fees for ${op.txCount} transaction(s) involving ${op.signerCount} different signer(s)`,
|
|
1499
|
+
severity: "HIGH",
|
|
1500
|
+
reference: void 0
|
|
1501
|
+
}));
|
|
1502
|
+
signals.push({
|
|
1503
|
+
id: "fee-payer-multi-signer",
|
|
1504
|
+
name: "Fee Payer Controls Multiple Signers",
|
|
1505
|
+
severity: "HIGH",
|
|
1506
|
+
category: "linkability",
|
|
1507
|
+
reason: `${multiFeePayerOperators.length} fee payer(s) are paying fees for multiple different signers, suggesting centralized control or bot operation.`,
|
|
1508
|
+
impact: "All addresses funded by the same fee payer are linkable. This pattern exposes operational infrastructure.",
|
|
1509
|
+
mitigation: "If running bots or managing multiple accounts, use a unique fee payer for each to avoid linking them on-chain.",
|
|
1510
|
+
evidence
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return signals;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
// src/heuristics/signer-overlap.ts
|
|
1518
|
+
function detectSignerOverlap(context) {
|
|
1519
|
+
const signals = [];
|
|
1520
|
+
if (context.transactionCount < 2) {
|
|
1521
|
+
return signals;
|
|
1522
|
+
}
|
|
1523
|
+
if (!context.transactions || context.transactions.length === 0) {
|
|
1524
|
+
return signals;
|
|
1525
|
+
}
|
|
1526
|
+
const signerFrequency = /* @__PURE__ */ new Map();
|
|
1527
|
+
const signerTransactions = /* @__PURE__ */ new Map();
|
|
1528
|
+
for (const tx of context.transactions) {
|
|
1529
|
+
for (const signer of tx.signers) {
|
|
1530
|
+
signerFrequency.set(signer, (signerFrequency.get(signer) || 0) + 1);
|
|
1531
|
+
if (!signerTransactions.has(signer)) {
|
|
1532
|
+
signerTransactions.set(signer, []);
|
|
1533
|
+
}
|
|
1534
|
+
signerTransactions.get(signer).push(tx.signature);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
const target = context.target;
|
|
1538
|
+
const frequentSigners = Array.from(signerFrequency.entries()).filter(([signer]) => signer !== target).filter(([_, count]) => count >= Math.min(3, Math.ceil(context.transactionCount * 0.3))).sort((a, b) => b[1] - a[1]);
|
|
1539
|
+
if (frequentSigners.length > 0) {
|
|
1540
|
+
const evidence = frequentSigners.map(([signer, count]) => {
|
|
1541
|
+
const label = context.labels.get(signer);
|
|
1542
|
+
return {
|
|
1543
|
+
description: `${signer}${label ? ` (${label.name})` : ""} signed ${count}/${context.transactionCount} transactions`,
|
|
1544
|
+
severity: count > context.transactionCount * 0.7 ? "HIGH" : "MEDIUM",
|
|
1545
|
+
reference: void 0
|
|
1546
|
+
};
|
|
1547
|
+
});
|
|
1548
|
+
const topSignerCount = frequentSigners[0][1];
|
|
1549
|
+
const severity = topSignerCount > context.transactionCount * 0.7 ? "HIGH" : "MEDIUM";
|
|
1550
|
+
signals.push({
|
|
1551
|
+
id: "signer-repeated",
|
|
1552
|
+
name: "Repeated Signer Across Transactions",
|
|
1553
|
+
severity,
|
|
1554
|
+
category: "linkability",
|
|
1555
|
+
reason: `${frequentSigners.length} address(es) repeatedly sign transactions involving the target. The most frequent signer appears in ${topSignerCount}/${context.transactionCount} transactions.`,
|
|
1556
|
+
impact: "Repeated signers create hard links between transactions. All transactions signed by the same address are trivially linkable.",
|
|
1557
|
+
mitigation: "If you control multiple addresses that sign together, they are permanently linked. Use separate signing keys for unrelated activities.",
|
|
1558
|
+
evidence
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
const signerSets = /* @__PURE__ */ new Map();
|
|
1562
|
+
const signerSetExamples = /* @__PURE__ */ new Map();
|
|
1563
|
+
for (const tx of context.transactions) {
|
|
1564
|
+
const sortedSigners = [...tx.signers].sort();
|
|
1565
|
+
const setKey = JSON.stringify(sortedSigners);
|
|
1566
|
+
signerSets.set(setKey, (signerSets.get(setKey) || 0) + 1);
|
|
1567
|
+
if (!signerSetExamples.has(setKey)) {
|
|
1568
|
+
signerSetExamples.set(setKey, tx.signature);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
const repeatedSets = Array.from(signerSets.entries()).filter(([_, count]) => count > 1).sort((a, b) => b[1] - a[1]);
|
|
1572
|
+
if (repeatedSets.length > 0) {
|
|
1573
|
+
const evidence = repeatedSets.map(([setKey, count]) => {
|
|
1574
|
+
const signers = JSON.parse(setKey);
|
|
1575
|
+
const exampleSig = signerSetExamples.get(setKey);
|
|
1576
|
+
return {
|
|
1577
|
+
description: `${count} transactions with identical signer set: [${signers.map((s) => s.slice(0, 8)).join(", ")}...]`,
|
|
1578
|
+
severity: count > 2 ? "MEDIUM" : "LOW",
|
|
1579
|
+
reference: `https://solscan.io/tx/${exampleSig}`
|
|
1580
|
+
};
|
|
1581
|
+
});
|
|
1582
|
+
signals.push({
|
|
1583
|
+
id: "signer-set-reuse",
|
|
1584
|
+
name: "Repeated Multi-Signature Pattern",
|
|
1585
|
+
severity: "MEDIUM",
|
|
1586
|
+
category: "linkability",
|
|
1587
|
+
reason: `${repeatedSets.length} distinct signer set(s) are reused multiple times. This creates a unique fingerprint.`,
|
|
1588
|
+
impact: "Reused multi-sig patterns are highly unique and easily linkable. Even if addresses differ, the signer set pattern can identify related activity.",
|
|
1589
|
+
mitigation: "If using multi-sig for multiple transactions, rotate signing keys or use threshold signatures to vary the signer set.",
|
|
1590
|
+
evidence
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
if (context.targetType === "program" || context.transactionCount > 10) {
|
|
1594
|
+
const signerCoSigners = /* @__PURE__ */ new Map();
|
|
1595
|
+
for (const tx of context.transactions) {
|
|
1596
|
+
for (const signer of tx.signers) {
|
|
1597
|
+
if (!signerCoSigners.has(signer)) {
|
|
1598
|
+
signerCoSigners.set(signer, /* @__PURE__ */ new Set());
|
|
1599
|
+
}
|
|
1600
|
+
for (const otherSigner of tx.signers) {
|
|
1601
|
+
if (otherSigner !== signer) {
|
|
1602
|
+
signerCoSigners.get(signer).add(otherSigner);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
const authorityCandidates = Array.from(signerCoSigners.entries()).filter(([_, coSigners]) => coSigners.size >= 3).sort((a, b) => b[1].size - a[1].size);
|
|
1608
|
+
if (authorityCandidates.length > 0) {
|
|
1609
|
+
const evidence = authorityCandidates.slice(0, 3).map(([signer, coSigners]) => {
|
|
1610
|
+
const label = context.labels.get(signer);
|
|
1611
|
+
const txCount = signerFrequency.get(signer) || 0;
|
|
1612
|
+
return {
|
|
1613
|
+
description: `${signer}${label ? ` (${label.name})` : ""} co-signed with ${coSigners.size} different addresses across ${txCount} transactions`,
|
|
1614
|
+
severity: "HIGH",
|
|
1615
|
+
reference: void 0
|
|
1616
|
+
};
|
|
1617
|
+
});
|
|
1618
|
+
signals.push({
|
|
1619
|
+
id: "signer-authority-hub",
|
|
1620
|
+
name: "Authority Signer Detected",
|
|
1621
|
+
severity: "HIGH",
|
|
1622
|
+
category: "linkability",
|
|
1623
|
+
reason: `${authorityCandidates.length} address(es) act as an authority, co-signing with multiple different wallets. This exposes a control hub.`,
|
|
1624
|
+
impact: "An authority signer links all accounts it co-signs with. This reveals organizational structure or bot infrastructure.",
|
|
1625
|
+
mitigation: 'Use unique authority keys for each logical group of accounts. Avoid having a single "master" signer.',
|
|
1626
|
+
evidence
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
return signals;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// src/heuristics/instruction-fingerprinting.ts
|
|
1634
|
+
function detectInstructionFingerprinting(context) {
|
|
1635
|
+
const signals = [];
|
|
1636
|
+
if (context.transactionCount < 3) {
|
|
1637
|
+
return signals;
|
|
1638
|
+
}
|
|
1639
|
+
if (!context.transactions || context.transactions.length === 0) {
|
|
1640
|
+
return signals;
|
|
1641
|
+
}
|
|
1642
|
+
const sequenceFingerprints = /* @__PURE__ */ new Map();
|
|
1643
|
+
const sequenceExamples = /* @__PURE__ */ new Map();
|
|
1644
|
+
for (const tx of context.transactions) {
|
|
1645
|
+
const txInstructions = context.instructions.filter((inst) => inst.signature === tx.signature).map((inst) => inst.programId);
|
|
1646
|
+
if (txInstructions.length === 0) continue;
|
|
1647
|
+
const sequence = txInstructions.join("->");
|
|
1648
|
+
sequenceFingerprints.set(sequence, (sequenceFingerprints.get(sequence) || 0) + 1);
|
|
1649
|
+
if (!sequenceExamples.has(sequence)) {
|
|
1650
|
+
sequenceExamples.set(sequence, []);
|
|
1651
|
+
}
|
|
1652
|
+
sequenceExamples.get(sequence).push(tx.signature);
|
|
1653
|
+
}
|
|
1654
|
+
const repeatedSequences = Array.from(sequenceFingerprints.entries()).filter(([_, count]) => count >= Math.min(3, Math.ceil(context.transactionCount * 0.2))).sort((a, b) => b[1] - a[1]);
|
|
1655
|
+
if (repeatedSequences.length > 0) {
|
|
1656
|
+
const evidence = repeatedSequences.slice(0, 5).map(([sequence, count]) => {
|
|
1657
|
+
const exampleSigs = sequenceExamples.get(sequence).slice(0, 2);
|
|
1658
|
+
const programs = sequence.split("->").map((p) => p.slice(0, 8) + "...").join(" \u2192 ");
|
|
1659
|
+
return {
|
|
1660
|
+
description: `Instruction sequence repeated ${count} times: ${programs}`,
|
|
1661
|
+
severity: count > context.transactionCount * 0.5 ? "MEDIUM" : "LOW",
|
|
1662
|
+
reference: `https://solscan.io/tx/${exampleSigs[0]}`
|
|
1663
|
+
};
|
|
1664
|
+
});
|
|
1665
|
+
const topSequenceCount = repeatedSequences[0][1];
|
|
1666
|
+
const severity = topSequenceCount > context.transactionCount * 0.5 ? "MEDIUM" : "LOW";
|
|
1667
|
+
signals.push({
|
|
1668
|
+
id: "instruction-sequence-pattern",
|
|
1669
|
+
name: "Repeated Instruction Sequence Pattern",
|
|
1670
|
+
severity,
|
|
1671
|
+
category: "behavioral",
|
|
1672
|
+
reason: `${repeatedSequences.length} distinct instruction sequence(s) are repeated multiple times. The most common pattern appears in ${topSequenceCount}/${context.transactionCount} transactions.`,
|
|
1673
|
+
impact: "Repeated instruction patterns create a behavioral fingerprint. Even with different addresses, these patterns can link related activity.",
|
|
1674
|
+
mitigation: "Vary the order or combination of operations. Add dummy instructions or randomize transaction structure where possible.",
|
|
1675
|
+
evidence
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
const programUsage = /* @__PURE__ */ new Map();
|
|
1679
|
+
for (const inst of context.instructions) {
|
|
1680
|
+
programUsage.set(inst.programId, (programUsage.get(inst.programId) || 0) + 1);
|
|
1681
|
+
}
|
|
1682
|
+
const COMMON_PROGRAMS = [
|
|
1683
|
+
"11111111111111111111111111111111",
|
|
1684
|
+
// System
|
|
1685
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
1686
|
+
// SPL Token
|
|
1687
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
1688
|
+
// Associated Token
|
|
1689
|
+
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
|
|
1690
|
+
// Memo
|
|
1691
|
+
"ComputeBudget111111111111111111111111111111"
|
|
1692
|
+
// Compute Budget
|
|
1693
|
+
];
|
|
1694
|
+
const uniquePrograms = Array.from(programUsage.entries()).filter(([programId]) => !COMMON_PROGRAMS.includes(programId)).filter(([_, count]) => count >= Math.min(2, Math.ceil(context.transactionCount * 0.15))).sort((a, b) => b[1] - a[1]);
|
|
1695
|
+
if (uniquePrograms.length >= 2) {
|
|
1696
|
+
const evidence = uniquePrograms.slice(0, 5).map(([programId, count]) => {
|
|
1697
|
+
const label = context.labels.get(programId);
|
|
1698
|
+
return {
|
|
1699
|
+
description: `${programId.slice(0, 8)}...${label ? ` (${label.name})` : ""} used in ${count} transactions`,
|
|
1700
|
+
severity: "LOW",
|
|
1701
|
+
reference: `https://solscan.io/account/${programId}`
|
|
1702
|
+
};
|
|
1703
|
+
});
|
|
1704
|
+
signals.push({
|
|
1705
|
+
id: "program-usage-profile",
|
|
1706
|
+
name: "Distinctive Program Usage Profile",
|
|
1707
|
+
severity: "LOW",
|
|
1708
|
+
category: "behavioral",
|
|
1709
|
+
reason: `This address uses ${uniquePrograms.length} less-common programs repeatedly. This creates a unique usage profile.`,
|
|
1710
|
+
impact: "Program usage patterns can fingerprint wallet behavior. Addresses with similar program usage profiles are likely related.",
|
|
1711
|
+
mitigation: "Using niche protocols creates a fingerprint. This is difficult to mitigate without changing your DeFi strategy.",
|
|
1712
|
+
evidence
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
if (context.pdaInteractions.length > 0) {
|
|
1716
|
+
const pdaUsage = /* @__PURE__ */ new Map();
|
|
1717
|
+
for (const pda of context.pdaInteractions) {
|
|
1718
|
+
if (!pdaUsage.has(pda.pda)) {
|
|
1719
|
+
pdaUsage.set(pda.pda, { count: 0, programId: pda.programId });
|
|
1720
|
+
}
|
|
1721
|
+
pdaUsage.get(pda.pda).count++;
|
|
1722
|
+
}
|
|
1723
|
+
const repeatedPDAs = Array.from(pdaUsage.entries()).filter(([_, { count }]) => count > 1).sort((a, b) => b[1].count - a[1].count);
|
|
1724
|
+
if (repeatedPDAs.length > 0) {
|
|
1725
|
+
const evidence = repeatedPDAs.slice(0, 5).map(([pda, { count, programId }]) => ({
|
|
1726
|
+
description: `PDA ${pda.slice(0, 8)}... used ${count} times (program: ${programId.slice(0, 8)}...)`,
|
|
1727
|
+
severity: count > 3 ? "MEDIUM" : "LOW",
|
|
1728
|
+
reference: `https://solscan.io/account/${pda}`
|
|
1729
|
+
}));
|
|
1730
|
+
const maxPDAUsage = repeatedPDAs[0][1].count;
|
|
1731
|
+
const severity = maxPDAUsage > 3 ? "MEDIUM" : "LOW";
|
|
1732
|
+
signals.push({
|
|
1733
|
+
id: "pda-reuse-pattern",
|
|
1734
|
+
name: "Repeated PDA Interaction",
|
|
1735
|
+
severity,
|
|
1736
|
+
category: "behavioral",
|
|
1737
|
+
reason: `${repeatedPDAs.length} Program-Derived Address(es) are used repeatedly. The most common PDA appears in ${maxPDAUsage} transactions.`,
|
|
1738
|
+
impact: "Repeated PDA usage links transactions. If the PDA is specific to you (e.g., a user account), all interactions with it are linked.",
|
|
1739
|
+
mitigation: "Some PDA reuse is unavoidable (e.g., your DEX pool position). For sensitive operations, consider using fresh accounts or different protocols.",
|
|
1740
|
+
evidence
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
const programInstructions = /* @__PURE__ */ new Map();
|
|
1745
|
+
for (const inst of context.instructions) {
|
|
1746
|
+
if (!programInstructions.has(inst.programId)) {
|
|
1747
|
+
programInstructions.set(inst.programId, []);
|
|
1748
|
+
}
|
|
1749
|
+
if (inst.data) {
|
|
1750
|
+
programInstructions.get(inst.programId).push(inst.data);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
for (const [programId, dataList] of programInstructions) {
|
|
1754
|
+
if (dataList.length < 2) continue;
|
|
1755
|
+
const typeMap = /* @__PURE__ */ new Map();
|
|
1756
|
+
for (const data of dataList) {
|
|
1757
|
+
if (data && typeof data === "object" && "type" in data) {
|
|
1758
|
+
const type = String(data.type);
|
|
1759
|
+
typeMap.set(type, (typeMap.get(type) || 0) + 1);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
const repeatedTypes = Array.from(typeMap.entries()).filter(([_, count]) => count >= 2).sort((a, b) => b[1] - a[1]);
|
|
1763
|
+
if (repeatedTypes.length > 0 && repeatedTypes[0][1] >= 3) {
|
|
1764
|
+
const [instructionType, count] = repeatedTypes[0];
|
|
1765
|
+
const label = context.labels.get(programId);
|
|
1766
|
+
signals.push({
|
|
1767
|
+
id: `instruction-type-${programId.slice(0, 8)}`,
|
|
1768
|
+
name: "Repeated Instruction Type",
|
|
1769
|
+
severity: "LOW",
|
|
1770
|
+
category: "behavioral",
|
|
1771
|
+
reason: `The instruction type "${instructionType}" on program ${programId.slice(0, 8)}...${label ? ` (${label.name})` : ""} is used ${count} times.`,
|
|
1772
|
+
impact: "Repeated instruction types on the same program suggest automated behavior or specific strategy execution.",
|
|
1773
|
+
mitigation: "This is generally low-risk but contributes to behavioral fingerprinting. Diversify your transaction types if possible.",
|
|
1774
|
+
evidence: [{
|
|
1775
|
+
description: `"${instructionType}" instruction used ${count} times`,
|
|
1776
|
+
severity: "LOW",
|
|
1777
|
+
reference: void 0
|
|
1778
|
+
}]
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
return signals;
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
// src/heuristics/token-account-lifecycle.ts
|
|
1786
|
+
function detectTokenAccountLifecycle(context) {
|
|
1787
|
+
const signals = [];
|
|
1788
|
+
if (!context.tokenAccountEvents || context.tokenAccountEvents.length === 0) {
|
|
1789
|
+
return signals;
|
|
1790
|
+
}
|
|
1791
|
+
const accountEvents = /* @__PURE__ */ new Map();
|
|
1792
|
+
for (const event of context.tokenAccountEvents) {
|
|
1793
|
+
if (!accountEvents.has(event.tokenAccount)) {
|
|
1794
|
+
accountEvents.set(event.tokenAccount, []);
|
|
1795
|
+
}
|
|
1796
|
+
accountEvents.get(event.tokenAccount).push(event);
|
|
1797
|
+
}
|
|
1798
|
+
const createEvents = context.tokenAccountEvents.filter((e) => e.type === "create");
|
|
1799
|
+
const closeEvents = context.tokenAccountEvents.filter((e) => e.type === "close");
|
|
1800
|
+
if (createEvents.length >= 2 && closeEvents.length >= 2) {
|
|
1801
|
+
const refundDestinations = /* @__PURE__ */ new Map();
|
|
1802
|
+
const totalRefunded = closeEvents.reduce((sum, event) => {
|
|
1803
|
+
if (event.rentRefund) {
|
|
1804
|
+
refundDestinations.set(event.owner, (refundDestinations.get(event.owner) || 0) + event.rentRefund);
|
|
1805
|
+
return sum + event.rentRefund;
|
|
1806
|
+
}
|
|
1807
|
+
return sum;
|
|
1808
|
+
}, 0);
|
|
1809
|
+
if (refundDestinations.size > 0) {
|
|
1810
|
+
const evidence = Array.from(refundDestinations.entries()).map(([owner, amount]) => ({
|
|
1811
|
+
description: `${amount.toFixed(4)} SOL refunded to ${owner.slice(0, 8)}... from ${closeEvents.filter((e) => e.owner === owner).length} closed account(s)`,
|
|
1812
|
+
severity: "MEDIUM",
|
|
1813
|
+
reference: void 0
|
|
1814
|
+
}));
|
|
1815
|
+
signals.push({
|
|
1816
|
+
id: "token-account-churn",
|
|
1817
|
+
name: "Frequent Token Account Creation/Closure",
|
|
1818
|
+
severity: "MEDIUM",
|
|
1819
|
+
category: "behavioral",
|
|
1820
|
+
reason: `${createEvents.length} token account(s) created and ${closeEvents.length} closed. Rent refunds totaling ${totalRefunded.toFixed(4)} SOL expose ownership.`,
|
|
1821
|
+
impact: 'Rent refunds link temporary token accounts back to the owner wallet. This pattern defeats the purpose of using "burner" accounts.',
|
|
1822
|
+
mitigation: "If using temporary token accounts for privacy, leave them open (accept the small rent cost) rather than closing and refunding to your main wallet.",
|
|
1823
|
+
evidence
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
const completeLifecycles = [];
|
|
1828
|
+
for (const [tokenAccount, events] of accountEvents) {
|
|
1829
|
+
const creates = events.filter((e) => e.type === "create");
|
|
1830
|
+
const closes = events.filter((e) => e.type === "close");
|
|
1831
|
+
if (creates.length > 0 && closes.length > 0) {
|
|
1832
|
+
const createTime = creates[0].blockTime;
|
|
1833
|
+
const closeTime = closes[closes.length - 1].blockTime;
|
|
1834
|
+
if (createTime && closeTime) {
|
|
1835
|
+
const duration = closeTime - createTime;
|
|
1836
|
+
completeLifecycles.push({ tokenAccount, events, duration });
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
const shortLived = completeLifecycles.filter((lc) => lc.duration < 3600);
|
|
1841
|
+
if (shortLived.length >= 2) {
|
|
1842
|
+
const evidence = shortLived.slice(0, 5).map((lc) => {
|
|
1843
|
+
const durationMin = Math.floor(lc.duration / 60);
|
|
1844
|
+
const closeEvent = lc.events.find((e) => e.type === "close");
|
|
1845
|
+
return {
|
|
1846
|
+
description: `${lc.tokenAccount.slice(0, 8)}... lived for ${durationMin} minute(s)${closeEvent?.rentRefund ? `, refunded ${closeEvent.rentRefund.toFixed(4)} SOL` : ""}`,
|
|
1847
|
+
severity: "LOW",
|
|
1848
|
+
reference: void 0
|
|
1849
|
+
};
|
|
1850
|
+
});
|
|
1851
|
+
signals.push({
|
|
1852
|
+
id: "token-account-short-lived",
|
|
1853
|
+
name: "Short-Lived Token Accounts",
|
|
1854
|
+
severity: "LOW",
|
|
1855
|
+
category: "behavioral",
|
|
1856
|
+
reason: `${shortLived.length} token account(s) were created and closed within an hour, suggesting burner account usage.`,
|
|
1857
|
+
impact: "Short-lived accounts suggest privacy-conscious behavior, but rent refunds still create linkage.",
|
|
1858
|
+
mitigation: "For true privacy, do not close accounts immediately. The rent refund links the burner back to you.",
|
|
1859
|
+
evidence
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
const ownerAccounts = /* @__PURE__ */ new Map();
|
|
1863
|
+
for (const event of context.tokenAccountEvents) {
|
|
1864
|
+
if (event.type === "create") {
|
|
1865
|
+
if (!ownerAccounts.has(event.owner)) {
|
|
1866
|
+
ownerAccounts.set(event.owner, /* @__PURE__ */ new Set());
|
|
1867
|
+
}
|
|
1868
|
+
ownerAccounts.get(event.owner).add(event.tokenAccount);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
const multiAccountOwners = Array.from(ownerAccounts.entries()).filter(([_, accounts]) => accounts.size >= 2).sort((a, b) => b[1].size - a[1].size);
|
|
1872
|
+
if (multiAccountOwners.length > 0) {
|
|
1873
|
+
const [owner, accounts] = multiAccountOwners[0];
|
|
1874
|
+
const isTarget = owner === context.target;
|
|
1875
|
+
if (!isTarget || multiAccountOwners.length > 1) {
|
|
1876
|
+
const evidence = multiAccountOwners.slice(0, 3).map(([own, accs]) => {
|
|
1877
|
+
const label = context.labels.get(own);
|
|
1878
|
+
return {
|
|
1879
|
+
description: `${own.slice(0, 8)}...${label ? ` (${label.name})` : ""} owns ${accs.size} token account(s)`,
|
|
1880
|
+
severity: "LOW",
|
|
1881
|
+
reference: void 0
|
|
1882
|
+
};
|
|
1883
|
+
});
|
|
1884
|
+
signals.push({
|
|
1885
|
+
id: "token-account-common-owner",
|
|
1886
|
+
name: "Common Owner Across Token Accounts",
|
|
1887
|
+
severity: "LOW",
|
|
1888
|
+
category: "linkability",
|
|
1889
|
+
reason: `${multiAccountOwners.length} wallet(s) control multiple token accounts. The top owner controls ${accounts.size} accounts.`,
|
|
1890
|
+
impact: "All token accounts with the same owner are trivially linked.",
|
|
1891
|
+
mitigation: "This is inherent to Solana's token account model and cannot be avoided.",
|
|
1892
|
+
evidence
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
const rentRefundReceivers = /* @__PURE__ */ new Map();
|
|
1897
|
+
for (const event of context.tokenAccountEvents) {
|
|
1898
|
+
if (event.type === "close" && event.rentRefund) {
|
|
1899
|
+
const current = rentRefundReceivers.get(event.owner) || { count: 0, total: 0 };
|
|
1900
|
+
current.count++;
|
|
1901
|
+
current.total += event.rentRefund;
|
|
1902
|
+
rentRefundReceivers.set(event.owner, current);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
const significantRefunds = Array.from(rentRefundReceivers.entries()).filter(([_, { count }]) => count >= 3).sort((a, b) => b[1].count - a[1].count);
|
|
1906
|
+
if (significantRefunds.length > 0) {
|
|
1907
|
+
const evidence = significantRefunds.slice(0, 3).map(([owner, { count, total }]) => ({
|
|
1908
|
+
description: `${owner.slice(0, 8)}... received ${count} rent refunds totaling ${total.toFixed(4)} SOL`,
|
|
1909
|
+
severity: "MEDIUM",
|
|
1910
|
+
reference: void 0
|
|
1911
|
+
}));
|
|
1912
|
+
const [topOwner, topData] = significantRefunds[0];
|
|
1913
|
+
signals.push({
|
|
1914
|
+
id: "rent-refund-clustering",
|
|
1915
|
+
name: "Rent Refund Clustering",
|
|
1916
|
+
severity: "MEDIUM",
|
|
1917
|
+
category: "linkability",
|
|
1918
|
+
reason: `${significantRefunds.length} address(es) receive multiple rent refunds. ${topOwner.slice(0, 8)}... received ${topData.count} refunds.`,
|
|
1919
|
+
impact: "Rent refunds link closed token accounts back to a central wallet. This exposes the control structure.",
|
|
1920
|
+
mitigation: "Do not close token accounts if privacy is important. The small rent cost (~0.002 SOL) is cheaper than the privacy loss.",
|
|
1921
|
+
evidence
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
return signals;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
987
1927
|
// src/scanner/index.ts
|
|
988
1928
|
var REPORT_VERSION = "1.0.0";
|
|
989
1929
|
var HEURISTICS = [
|
|
1930
|
+
// Solana-specific (highest priority)
|
|
1931
|
+
detectFeePayerReuse,
|
|
1932
|
+
detectSignerOverlap,
|
|
1933
|
+
detectKnownEntityInteraction,
|
|
990
1934
|
detectCounterpartyReuse,
|
|
991
|
-
|
|
1935
|
+
detectInstructionFingerprinting,
|
|
1936
|
+
detectTokenAccountLifecycle,
|
|
1937
|
+
// Traditional heuristics
|
|
992
1938
|
detectTimingPatterns,
|
|
993
|
-
|
|
1939
|
+
detectAmountReuse,
|
|
994
1940
|
detectBalanceTraceability
|
|
995
1941
|
];
|
|
996
1942
|
function calculateOverallRisk(signals) {
|
|
@@ -1015,10 +1961,22 @@ function generateMitigations(signals) {
|
|
|
1015
1961
|
}
|
|
1016
1962
|
mitigations.add("Consider using multiple wallets to compartmentalize different activities.");
|
|
1017
1963
|
const signalIds = new Set(signals.map((s) => s.id));
|
|
1964
|
+
if (signalIds.has("fee-payer-never-self") || signalIds.has("fee-payer-external")) {
|
|
1965
|
+
mitigations.add("Always pay your own transaction fees to avoid linkage.");
|
|
1966
|
+
}
|
|
1967
|
+
if (signalIds.has("signer-repeated") || signalIds.has("signer-set-reuse")) {
|
|
1968
|
+
mitigations.add("Use separate signing keys for unrelated activities.");
|
|
1969
|
+
}
|
|
1970
|
+
if (signalIds.has("instruction-sequence-pattern") || signalIds.has("program-usage-profile")) {
|
|
1971
|
+
mitigations.add("Diversify transaction patterns and protocols to reduce behavioral fingerprinting.");
|
|
1972
|
+
}
|
|
1973
|
+
if (signalIds.has("token-account-churn") || signalIds.has("rent-refund-clustering")) {
|
|
1974
|
+
mitigations.add("Avoid closing token accounts if privacy is important - the rent refund creates linkage.");
|
|
1975
|
+
}
|
|
1018
1976
|
if (signalIds.has("known-entity-interaction")) {
|
|
1019
1977
|
mitigations.add("Avoid direct interactions between privacy-sensitive wallets and KYC services.");
|
|
1020
1978
|
}
|
|
1021
|
-
if (signalIds.has("counterparty-reuse")) {
|
|
1979
|
+
if (signalIds.has("counterparty-reuse") || signalIds.has("pda-reuse")) {
|
|
1022
1980
|
mitigations.add("Use different addresses for different counterparties or contexts.");
|
|
1023
1981
|
}
|
|
1024
1982
|
if (signalIds.has("timing-correlation") || signalIds.has("balance-traceability")) {
|
|
@@ -1034,9 +1992,11 @@ function evaluateHeuristics(context) {
|
|
|
1034
1992
|
const signals = [];
|
|
1035
1993
|
for (const heuristic of HEURISTICS) {
|
|
1036
1994
|
try {
|
|
1037
|
-
const
|
|
1038
|
-
if (
|
|
1039
|
-
signals.push(
|
|
1995
|
+
const result = heuristic(context);
|
|
1996
|
+
if (Array.isArray(result)) {
|
|
1997
|
+
signals.push(...result);
|
|
1998
|
+
} else if (result) {
|
|
1999
|
+
signals.push(result);
|
|
1040
2000
|
}
|
|
1041
2001
|
} catch (error) {
|
|
1042
2002
|
console.warn(`Heuristic evaluation failed:`, error);
|
|
@@ -1166,8 +2126,12 @@ var VERSION = "0.1.0";
|
|
|
1166
2126
|
detectAmountReuse,
|
|
1167
2127
|
detectBalanceTraceability,
|
|
1168
2128
|
detectCounterpartyReuse,
|
|
2129
|
+
detectFeePayerReuse,
|
|
2130
|
+
detectInstructionFingerprinting,
|
|
1169
2131
|
detectKnownEntityInteraction,
|
|
2132
|
+
detectSignerOverlap,
|
|
1170
2133
|
detectTimingPatterns,
|
|
2134
|
+
detectTokenAccountLifecycle,
|
|
1171
2135
|
evaluateHeuristics,
|
|
1172
2136
|
generateReport,
|
|
1173
2137
|
normalizeProgramData,
|