@lodestar/state-transition 1.43.0-dev.6641fd750e → 1.43.0-dev.aef3645690

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.
@@ -1,8 +1,19 @@
1
- import { AttesterSlashing, Slot, ValidatorIndex, phase0 } from "@lodestar/types";
1
+ import { ForkSeq } from "@lodestar/params";
2
+ import { AttesterSlashing, IndexedAttestation, IndexedAttestationBigint, Slot, ValidatorIndex, phase0 } from "@lodestar/types";
2
3
  /**
3
4
  * Check if [[data1]] and [[data2]] are slashable according to Casper FFG rules.
4
5
  */
5
6
  export declare function isSlashableAttestationData(data1: phase0.AttestationDataBigint, data2: phase0.AttestationDataBigint): boolean;
6
7
  export declare function isValidAttestationSlot(attestationSlot: Slot, currentSlot: Slot): boolean;
8
+ /**
9
+ * Compute the intersection of two sorted validator index lists.
10
+ * Both inputs must be sorted in ascending order (per spec).
11
+ */
12
+ export declare function getIntersectingIndices(indices1: ValidatorIndex[], indices2: ValidatorIndex[]): ValidatorIndex[];
7
13
  export declare function getAttesterSlashableIndices(attesterSlashing: AttesterSlashing): ValidatorIndex[];
14
+ /**
15
+ * Convert IndexedAttestation to IndexedAttestationBigint via SSZ roundtrip.
16
+ * Both types share the same binary layout — only the JS numeric representation differs.
17
+ */
18
+ export declare function toIndexedAttestationBigint(att: IndexedAttestation, fork: ForkSeq): IndexedAttestationBigint;
8
19
  //# sourceMappingURL=attestation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"attestation.d.ts","sourceRoot":"","sources":["../../src/util/attestation.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAM,MAAM,iBAAiB,CAAC;AAEpF;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,CAAC,qBAAqB,EACnC,KAAK,EAAE,MAAM,CAAC,qBAAqB,GAClC,OAAO,CAOT;AAED,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,GAAG,OAAO,CAIxF;AAED,wBAAgB,2BAA2B,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,cAAc,EAAE,CAWhG"}
1
+ {"version":3,"file":"attestation.d.ts","sourceRoot":"","sources":["../../src/util/attestation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAmD,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,IAAI,EACJ,cAAc,EACd,MAAM,EAEP,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,CAAC,qBAAqB,EACnC,KAAK,EAAE,MAAM,CAAC,qBAAqB,GAClC,OAAO,CAOT;AAED,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,GAAG,OAAO,CAIxF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAU/G;AAED,wBAAgB,2BAA2B,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,cAAc,EAAE,CAKhG;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,GAAG,wBAAwB,CAK3G"}
@@ -1,5 +1,5 @@
1
- import { MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH } from "@lodestar/params";
2
- import { ssz } from "@lodestar/types";
1
+ import { ForkSeq, MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH } from "@lodestar/params";
2
+ import { ssz, } from "@lodestar/types";
3
3
  /**
4
4
  * Check if [[data1]] and [[data2]] are slashable according to Casper FFG rules.
5
5
  */
@@ -13,16 +13,31 @@ export function isSlashableAttestationData(data1, data2) {
13
13
  export function isValidAttestationSlot(attestationSlot, currentSlot) {
14
14
  return (attestationSlot + MIN_ATTESTATION_INCLUSION_DELAY <= currentSlot && currentSlot <= attestationSlot + SLOTS_PER_EPOCH);
15
15
  }
16
- export function getAttesterSlashableIndices(attesterSlashing) {
16
+ /**
17
+ * Compute the intersection of two sorted validator index lists.
18
+ * Both inputs must be sorted in ascending order (per spec).
19
+ */
20
+ export function getIntersectingIndices(indices1, indices2) {
17
21
  const indices = [];
18
- const attSet1 = new Set(attesterSlashing.attestation1.attestingIndices);
19
- const attArr2 = attesterSlashing.attestation2.attestingIndices;
20
- for (let i = 0, len = attArr2.length; i < len; i++) {
21
- const index = attArr2[i];
22
- if (attSet1.has(index)) {
22
+ const alreadyPresent = new Set(indices1);
23
+ for (let i = 0, len = indices2.length; i < len; i++) {
24
+ const index = indices2[i];
25
+ if (alreadyPresent.has(index)) {
23
26
  indices.push(index);
24
27
  }
25
28
  }
26
29
  return indices;
27
30
  }
31
+ export function getAttesterSlashableIndices(attesterSlashing) {
32
+ return getIntersectingIndices(attesterSlashing.attestation1.attestingIndices, attesterSlashing.attestation2.attestingIndices);
33
+ }
34
+ /**
35
+ * Convert IndexedAttestation to IndexedAttestationBigint via SSZ roundtrip.
36
+ * Both types share the same binary layout — only the JS numeric representation differs.
37
+ */
38
+ export function toIndexedAttestationBigint(att, fork) {
39
+ const sszType = fork >= ForkSeq.electra ? ssz.electra.IndexedAttestation : ssz.phase0.IndexedAttestation;
40
+ const sszTypeBigint = fork >= ForkSeq.electra ? ssz.electra.IndexedAttestationBigint : ssz.phase0.IndexedAttestationBigint;
41
+ return sszTypeBigint.deserialize(sszType.serialize(att));
42
+ }
28
43
  //# sourceMappingURL=attestation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attestation.js","sourceRoot":"","sources":["../../src/util/attestation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,+BAA+B,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAClF,OAAO,E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C,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AAAA,CAChB;AAED,MAAM,UAAU,2BAA2B,CAAC,gBAAkC,EAAoB;IAChG,OAAO,sBAAsB,CAC3B,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,EAC9C,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAC/C,CAAC;AAAA,CACH;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAuB,EAAE,IAAa,EAA4B;IAC3G,MAAM,OAAO,GAAG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC;IACzG,MAAM,aAAa,GACjB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,wBAAwB,CAAC;IACvG,OAAO,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AAAA,CAC1D"}
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.43.0-dev.6641fd750e",
14
+ "version": "1.43.0-dev.aef3645690",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -67,14 +67,14 @@
67
67
  "@chainsafe/pubkey-index-map": "^3.0.0",
68
68
  "@chainsafe/ssz": "^1.2.2",
69
69
  "@chainsafe/swap-or-not-shuffle": "^1.2.1",
70
- "@lodestar/config": "^1.43.0-dev.6641fd750e",
71
- "@lodestar/params": "^1.43.0-dev.6641fd750e",
72
- "@lodestar/types": "^1.43.0-dev.6641fd750e",
73
- "@lodestar/utils": "^1.43.0-dev.6641fd750e",
70
+ "@lodestar/config": "^1.43.0-dev.aef3645690",
71
+ "@lodestar/params": "^1.43.0-dev.aef3645690",
72
+ "@lodestar/types": "^1.43.0-dev.aef3645690",
73
+ "@lodestar/utils": "^1.43.0-dev.aef3645690",
74
74
  "@vekexasia/bigint-buffer2": "^1.1.1"
75
75
  },
76
76
  "devDependencies": {
77
- "@lodestar/api": "^1.43.0-dev.6641fd750e"
77
+ "@lodestar/api": "^1.43.0-dev.aef3645690"
78
78
  },
79
79
  "keywords": [
80
80
  "ethereum",
@@ -82,5 +82,5 @@
82
82
  "beacon",
83
83
  "blockchain"
84
84
  ],
85
- "gitHead": "9791abe98717579326dbf4c9b55e8dd637a6f778"
85
+ "gitHead": "ffc9f7818d18273a196890cbaf9814f62d9d04db"
86
86
  }
@@ -1,5 +1,13 @@
1
- import {MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH} from "@lodestar/params";
2
- import {AttesterSlashing, Slot, ValidatorIndex, phase0, ssz} from "@lodestar/types";
1
+ import {ForkSeq, MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH} from "@lodestar/params";
2
+ import {
3
+ AttesterSlashing,
4
+ IndexedAttestation,
5
+ IndexedAttestationBigint,
6
+ Slot,
7
+ ValidatorIndex,
8
+ phase0,
9
+ ssz,
10
+ } from "@lodestar/types";
3
11
 
4
12
  /**
5
13
  * Check if [[data1]] and [[data2]] are slashable according to Casper FFG rules.
@@ -22,15 +30,36 @@ export function isValidAttestationSlot(attestationSlot: Slot, currentSlot: Slot)
22
30
  );
23
31
  }
24
32
 
25
- export function getAttesterSlashableIndices(attesterSlashing: AttesterSlashing): ValidatorIndex[] {
33
+ /**
34
+ * Compute the intersection of two sorted validator index lists.
35
+ * Both inputs must be sorted in ascending order (per spec).
36
+ */
37
+ export function getIntersectingIndices(indices1: ValidatorIndex[], indices2: ValidatorIndex[]): ValidatorIndex[] {
26
38
  const indices: ValidatorIndex[] = [];
27
- const attSet1 = new Set(attesterSlashing.attestation1.attestingIndices);
28
- const attArr2 = attesterSlashing.attestation2.attestingIndices;
29
- for (let i = 0, len = attArr2.length; i < len; i++) {
30
- const index = attArr2[i];
31
- if (attSet1.has(index)) {
39
+ const alreadyPresent = new Set(indices1);
40
+ for (let i = 0, len = indices2.length; i < len; i++) {
41
+ const index = indices2[i];
42
+ if (alreadyPresent.has(index)) {
32
43
  indices.push(index);
33
44
  }
34
45
  }
35
46
  return indices;
36
47
  }
48
+
49
+ export function getAttesterSlashableIndices(attesterSlashing: AttesterSlashing): ValidatorIndex[] {
50
+ return getIntersectingIndices(
51
+ attesterSlashing.attestation1.attestingIndices,
52
+ attesterSlashing.attestation2.attestingIndices
53
+ );
54
+ }
55
+
56
+ /**
57
+ * Convert IndexedAttestation to IndexedAttestationBigint via SSZ roundtrip.
58
+ * Both types share the same binary layout — only the JS numeric representation differs.
59
+ */
60
+ export function toIndexedAttestationBigint(att: IndexedAttestation, fork: ForkSeq): IndexedAttestationBigint {
61
+ const sszType = fork >= ForkSeq.electra ? ssz.electra.IndexedAttestation : ssz.phase0.IndexedAttestation;
62
+ const sszTypeBigint =
63
+ fork >= ForkSeq.electra ? ssz.electra.IndexedAttestationBigint : ssz.phase0.IndexedAttestationBigint;
64
+ return sszTypeBigint.deserialize(sszType.serialize(att));
65
+ }