@lodestar/state-transition 1.38.0 → 1.39.0-dev.d4a47659a5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/lib/block/index.d.ts.map +1 -1
  2. package/lib/block/index.js +2 -4
  3. package/lib/block/index.js.map +1 -1
  4. package/lib/block/isValidIndexedAttestation.d.ts +3 -2
  5. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  6. package/lib/block/isValidIndexedAttestation.js +4 -4
  7. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  8. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  9. package/lib/block/processAttestationPhase0.js +1 -1
  10. package/lib/block/processAttestationPhase0.js.map +1 -1
  11. package/lib/block/processAttestationsAltair.js +1 -1
  12. package/lib/block/processAttestationsAltair.js.map +1 -1
  13. package/lib/block/processAttesterSlashing.d.ts +2 -1
  14. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  15. package/lib/block/processAttesterSlashing.js +5 -4
  16. package/lib/block/processAttesterSlashing.js.map +1 -1
  17. package/lib/block/processExecutionPayload.d.ts.map +1 -1
  18. package/lib/block/processExecutionPayload.js +4 -6
  19. package/lib/block/processExecutionPayload.js.map +1 -1
  20. package/lib/block/processProposerSlashing.js +1 -1
  21. package/lib/block/processProposerSlashing.js.map +1 -1
  22. package/lib/block/processRandao.js +1 -1
  23. package/lib/block/processRandao.js.map +1 -1
  24. package/lib/block/processSyncCommittee.d.ts +2 -1
  25. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  26. package/lib/block/processSyncCommittee.js +3 -4
  27. package/lib/block/processSyncCommittee.js.map +1 -1
  28. package/lib/block/processVoluntaryExit.js +1 -1
  29. package/lib/block/processVoluntaryExit.js.map +1 -1
  30. package/lib/signatureSets/attesterSlashings.d.ts +4 -3
  31. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  32. package/lib/signatureSets/attesterSlashings.js +6 -6
  33. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  34. package/lib/signatureSets/index.d.ts +3 -2
  35. package/lib/signatureSets/index.d.ts.map +1 -1
  36. package/lib/signatureSets/index.js +8 -8
  37. package/lib/signatureSets/index.js.map +1 -1
  38. package/lib/signatureSets/indexedAttestation.d.ts +4 -3
  39. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  40. package/lib/signatureSets/indexedAttestation.js +6 -6
  41. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  42. package/lib/signatureSets/proposer.d.ts +5 -4
  43. package/lib/signatureSets/proposer.d.ts.map +1 -1
  44. package/lib/signatureSets/proposer.js +12 -12
  45. package/lib/signatureSets/proposer.js.map +1 -1
  46. package/lib/signatureSets/proposerSlashings.d.ts +3 -2
  47. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  48. package/lib/signatureSets/proposerSlashings.js +4 -5
  49. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  50. package/lib/signatureSets/randao.d.ts +3 -2
  51. package/lib/signatureSets/randao.d.ts.map +1 -1
  52. package/lib/signatureSets/randao.js +4 -5
  53. package/lib/signatureSets/randao.js.map +1 -1
  54. package/lib/signatureSets/voluntaryExits.d.ts +4 -3
  55. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  56. package/lib/signatureSets/voluntaryExits.js +6 -7
  57. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  58. package/lib/stateTransition.js +1 -1
  59. package/lib/stateTransition.js.map +1 -1
  60. package/lib/util/execution.d.ts +1 -16
  61. package/lib/util/execution.d.ts.map +1 -1
  62. package/lib/util/execution.js +1 -44
  63. package/lib/util/execution.js.map +1 -1
  64. package/package.json +6 -6
  65. package/src/block/index.ts +2 -6
  66. package/src/block/isValidIndexedAttestation.ts +5 -2
  67. package/src/block/processAttestationPhase0.ts +8 -1
  68. package/src/block/processAttestationsAltair.ts +1 -1
  69. package/src/block/processAttesterSlashing.ts +6 -3
  70. package/src/block/processExecutionPayload.ts +8 -14
  71. package/src/block/processProposerSlashing.ts +1 -1
  72. package/src/block/processRandao.ts +1 -1
  73. package/src/block/processSyncCommittee.ts +4 -3
  74. package/src/block/processVoluntaryExit.ts +1 -1
  75. package/src/signatureSets/attesterSlashings.ts +7 -3
  76. package/src/signatureSets/index.ts +10 -7
  77. package/src/signatureSets/indexedAttestation.ts +14 -3
  78. package/src/signatureSets/proposer.ts +13 -7
  79. package/src/signatureSets/proposerSlashings.ts +5 -3
  80. package/src/signatureSets/randao.ts +13 -5
  81. package/src/signatureSets/voluntaryExits.ts +7 -4
  82. package/src/stateTransition.ts +1 -1
  83. package/src/util/execution.ts +0 -60
@@ -1,5 +1,6 @@
1
1
  import {ForkSeq} from "@lodestar/params";
2
2
  import {AttesterSlashing} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {getAttesterSlashableIndices, isSlashableAttestationData, isSlashableValidator} from "../util/index.js";
5
6
  import {isValidIndexedAttestationBigint} from "./isValidIndexedAttestation.js";
@@ -17,7 +18,8 @@ export function processAttesterSlashing(
17
18
  attesterSlashing: AttesterSlashing,
18
19
  verifySignatures = true
19
20
  ): void {
20
- assertValidAttesterSlashing(state, attesterSlashing, verifySignatures);
21
+ const {epochCtx} = state;
22
+ assertValidAttesterSlashing(epochCtx.index2pubkey, state, attesterSlashing, verifySignatures);
21
23
 
22
24
  const intersectingIndices = getAttesterSlashableIndices(attesterSlashing);
23
25
 
@@ -25,7 +27,7 @@ export function processAttesterSlashing(
25
27
  const validators = state.validators; // Get the validators sub tree once for all indices
26
28
  // Spec requires to sort indexes beforehand
27
29
  for (const index of intersectingIndices.sort((a, b) => a - b)) {
28
- if (isSlashableValidator(validators.getReadonly(index), state.epochCtx.epoch)) {
30
+ if (isSlashableValidator(validators.getReadonly(index), epochCtx.epoch)) {
29
31
  slashValidator(fork, state, index);
30
32
  slashedAny = true;
31
33
  }
@@ -37,6 +39,7 @@ export function processAttesterSlashing(
37
39
  }
38
40
 
39
41
  export function assertValidAttesterSlashing(
42
+ index2pubkey: Index2PubkeyCache,
40
43
  state: CachedBeaconStateAllForks,
41
44
  attesterSlashing: AttesterSlashing,
42
45
  verifySignatures = true
@@ -52,7 +55,7 @@ export function assertValidAttesterSlashing(
52
55
  // be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which
53
56
  // can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
54
57
  for (const [i, attestation] of [attestation1, attestation2].entries()) {
55
- if (!isValidIndexedAttestationBigint(state, attestation, verifySignatures)) {
58
+ if (!isValidIndexedAttestationBigint(index2pubkey, state, attestation, verifySignatures)) {
56
59
  throw new Error(`AttesterSlashing attestation${i} is invalid`);
57
60
  }
58
61
  }
@@ -3,11 +3,7 @@ import {ForkName, ForkSeq, isForkPostDeneb} from "@lodestar/params";
3
3
  import {BeaconBlockBody, BlindedBeaconBlockBody, deneb, isExecutionPayload} from "@lodestar/types";
4
4
  import {toHex, toRootHex} from "@lodestar/utils";
5
5
  import {CachedBeaconStateBellatrix, CachedBeaconStateCapella} from "../types.js";
6
- import {
7
- executionPayloadToPayloadHeader,
8
- getFullOrBlindedPayloadFromBody,
9
- isMergeTransitionComplete,
10
- } from "../util/execution.js";
6
+ import {executionPayloadToPayloadHeader, getFullOrBlindedPayloadFromBody} from "../util/execution.js";
11
7
  import {computeEpochAtSlot, computeTimeAtSlot, getRandaoMix} from "../util/index.js";
12
8
  import {BlockExternalData, ExecutionPayloadStatus} from "./externalData.js";
13
9
 
@@ -21,15 +17,13 @@ export function processExecutionPayload(
21
17
  const forkName = ForkName[ForkSeq[fork] as ForkName];
22
18
  // Verify consistency of the parent hash, block number, base fee per gas and gas limit
23
19
  // with respect to the previous execution payload header
24
- if (isMergeTransitionComplete(state)) {
25
- const {latestExecutionPayloadHeader} = state;
26
- if (!byteArrayEquals(payload.parentHash, latestExecutionPayloadHeader.blockHash)) {
27
- throw Error(
28
- `Invalid execution payload parentHash ${toRootHex(payload.parentHash)} latest blockHash ${toRootHex(
29
- latestExecutionPayloadHeader.blockHash
30
- )}`
31
- );
32
- }
20
+ const {latestExecutionPayloadHeader} = state;
21
+ if (!byteArrayEquals(payload.parentHash, latestExecutionPayloadHeader.blockHash)) {
22
+ throw Error(
23
+ `Invalid execution payload parentHash ${toRootHex(payload.parentHash)} latest blockHash ${toRootHex(
24
+ latestExecutionPayloadHeader.blockHash
25
+ )}`
26
+ );
33
27
  }
34
28
 
35
29
  // Verify random
@@ -77,7 +77,7 @@ export function assertValidProposerSlashing(
77
77
 
78
78
  // verify signatures
79
79
  if (verifySignatures) {
80
- const signatureSets = getProposerSlashingSignatureSets(state, proposerSlashing);
80
+ const signatureSets = getProposerSlashingSignatureSets(state.epochCtx.index2pubkey, state, proposerSlashing);
81
81
  for (let i = 0; i < signatureSets.length; i++) {
82
82
  if (!verifySignatureSet(signatureSets[i])) {
83
83
  throw new Error(`ProposerSlashing header${i + 1} signature invalid`);
@@ -17,7 +17,7 @@ export function processRandao(state: CachedBeaconStateAllForks, block: BeaconBlo
17
17
  const randaoReveal = block.body.randaoReveal;
18
18
 
19
19
  // verify RANDAO reveal
20
- if (verifySignature && !verifyRandaoSignature(state, block)) {
20
+ if (verifySignature && !verifyRandaoSignature(epochCtx.index2pubkey, state, block)) {
21
21
  throw new Error("RANDAO reveal is an invalid signature");
22
22
  }
23
23
 
@@ -1,6 +1,7 @@
1
1
  import {byteArrayEquals} from "@chainsafe/ssz";
2
2
  import {DOMAIN_SYNC_COMMITTEE, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
3
3
  import {altair, ssz} from "@lodestar/types";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
5
  import {G2_POINT_AT_INFINITY} from "../constants/index.js";
5
6
  import {CachedBeaconStateAllForks} from "../types.js";
6
7
  import {
@@ -23,7 +24,7 @@ export function processSyncAggregate(
23
24
  if (verifySignatures) {
24
25
  // This is to conform to the spec - we want the signature to be verified
25
26
  const participantIndices = block.body.syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
26
- const signatureSet = getSyncCommitteeSignatureSet(state, block, participantIndices);
27
+ const signatureSet = getSyncCommitteeSignatureSet(state.epochCtx.index2pubkey, state, block, participantIndices);
27
28
  // When there's no participation we consider the signature valid and just ignore i
28
29
  if (signatureSet !== null && !verifySignatureSet(signatureSet)) {
29
30
  throw Error("Sync committee signature invalid");
@@ -63,12 +64,12 @@ export function processSyncAggregate(
63
64
  }
64
65
 
65
66
  export function getSyncCommitteeSignatureSet(
67
+ index2pubkey: Index2PubkeyCache,
66
68
  state: CachedBeaconStateAllForks,
67
69
  block: altair.BeaconBlock,
68
70
  /** Optional parameter to prevent computing it twice */
69
71
  participantIndices?: number[]
70
72
  ): ISignatureSet | null {
71
- const {epochCtx} = state;
72
73
  const {syncAggregate} = block.body;
73
74
  const signature = syncAggregate.syncCommitteeSignature;
74
75
 
@@ -110,7 +111,7 @@ export function getSyncCommitteeSignatureSet(
110
111
 
111
112
  return {
112
113
  type: SignatureSetType.aggregate,
113
- pubkeys: participantIndices.map((i) => epochCtx.index2pubkey[i]),
114
+ pubkeys: participantIndices.map((i) => index2pubkey[i]),
114
115
  signingRoot: computeSigningRoot(ssz.Root, rootSigned, domain),
115
116
  signature,
116
117
  };
@@ -74,7 +74,7 @@ export function getVoluntaryExitValidity(
74
74
  return VoluntaryExitValidity.pendingWithdrawals;
75
75
  }
76
76
 
77
- if (verifySignature && !verifyVoluntaryExitSignature(state, signedVoluntaryExit)) {
77
+ if (verifySignature && !verifyVoluntaryExitSignature(epochCtx.index2pubkey, state, signedVoluntaryExit)) {
78
78
  return VoluntaryExitValidity.invalidSignature;
79
79
  }
80
80
 
@@ -1,29 +1,33 @@
1
1
  import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
2
2
  import {AttesterSlashing, IndexedAttestationBigint, SignedBeaconBlock, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {ISignatureSet, SignatureSetType, computeSigningRoot, computeStartSlotAtEpoch} from "../util/index.js";
5
6
 
6
7
  /** Get signature sets from all AttesterSlashing objects in a block */
7
8
  export function getAttesterSlashingsSignatureSets(
9
+ index2pubkey: Index2PubkeyCache,
8
10
  state: CachedBeaconStateAllForks,
9
11
  signedBlock: SignedBeaconBlock
10
12
  ): ISignatureSet[] {
11
13
  return signedBlock.message.body.attesterSlashings.flatMap((attesterSlashing) =>
12
- getAttesterSlashingSignatureSets(state, attesterSlashing)
14
+ getAttesterSlashingSignatureSets(index2pubkey, state, attesterSlashing)
13
15
  );
14
16
  }
15
17
 
16
18
  /** Get signature sets from a single AttesterSlashing object */
17
19
  export function getAttesterSlashingSignatureSets(
20
+ index2pubkey: Index2PubkeyCache,
18
21
  state: CachedBeaconStateAllForks,
19
22
  attesterSlashing: AttesterSlashing
20
23
  ): ISignatureSet[] {
21
24
  return [attesterSlashing.attestation1, attesterSlashing.attestation2].map((attestation) =>
22
- getIndexedAttestationBigintSignatureSet(state, attestation)
25
+ getIndexedAttestationBigintSignatureSet(index2pubkey, state, attestation)
23
26
  );
24
27
  }
25
28
 
26
29
  export function getIndexedAttestationBigintSignatureSet(
30
+ index2pubkey: Index2PubkeyCache,
27
31
  state: CachedBeaconStateAllForks,
28
32
  indexedAttestation: IndexedAttestationBigint
29
33
  ): ISignatureSet {
@@ -32,7 +36,7 @@ export function getIndexedAttestationBigintSignatureSet(
32
36
 
33
37
  return {
34
38
  type: SignatureSetType.aggregate,
35
- pubkeys: indexedAttestation.attestingIndices.map((i) => state.epochCtx.index2pubkey[i]),
39
+ pubkeys: indexedAttestation.attestingIndices.map((i) => index2pubkey[i]),
36
40
  signingRoot: computeSigningRoot(ssz.phase0.AttestationDataBigint, indexedAttestation.data, domain),
37
41
  signature: indexedAttestation.signature,
38
42
  };
@@ -1,6 +1,7 @@
1
1
  import {ForkSeq} from "@lodestar/params";
2
2
  import {IndexedAttestation, SignedBeaconBlock, altair, capella} from "@lodestar/types";
3
3
  import {getSyncCommitteeSignatureSet} from "../block/processSyncCommittee.js";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
5
  import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
5
6
  import {ISignatureSet} from "../util/index.js";
6
7
  import {getAttesterSlashingsSignatureSets} from "./attesterSlashings.js";
@@ -14,7 +15,7 @@ import {getVoluntaryExitsSignatureSets} from "./voluntaryExits.js";
14
15
  export * from "./attesterSlashings.js";
15
16
  export * from "./blsToExecutionChange.js";
16
17
  export * from "./indexedAttestation.js";
17
- export * from "./indexedPayloadAttestation.ts";
18
+ export * from "./indexedPayloadAttestation.js";
18
19
  export * from "./proposer.js";
19
20
  export * from "./proposerSlashings.js";
20
21
  export * from "./randao.js";
@@ -25,6 +26,7 @@ export * from "./voluntaryExits.js";
25
26
  * Deposits are not included because they can legally have invalid signatures.
26
27
  */
27
28
  export function getBlockSignatureSets(
29
+ index2pubkey: Index2PubkeyCache,
28
30
  state: CachedBeaconStateAllForks,
29
31
  signedBlock: SignedBeaconBlock,
30
32
  indexedAttestations: IndexedAttestation[],
@@ -37,20 +39,21 @@ export function getBlockSignatureSets(
37
39
  const fork = state.config.getForkSeq(signedBlock.message.slot);
38
40
 
39
41
  const signatureSets = [
40
- getRandaoRevealSignatureSet(state, signedBlock.message),
41
- ...getProposerSlashingsSignatureSets(state, signedBlock),
42
- ...getAttesterSlashingsSignatureSets(state, signedBlock),
43
- ...getAttestationsSignatureSets(state, signedBlock, indexedAttestations),
44
- ...getVoluntaryExitsSignatureSets(state, signedBlock),
42
+ getRandaoRevealSignatureSet(index2pubkey, state, signedBlock.message),
43
+ ...getProposerSlashingsSignatureSets(index2pubkey, state, signedBlock),
44
+ ...getAttesterSlashingsSignatureSets(index2pubkey, state, signedBlock),
45
+ ...getAttestationsSignatureSets(index2pubkey, state, signedBlock, indexedAttestations),
46
+ ...getVoluntaryExitsSignatureSets(index2pubkey, state, signedBlock),
45
47
  ];
46
48
 
47
49
  if (!opts?.skipProposerSignature) {
48
- signatureSets.push(getBlockProposerSignatureSet(state, signedBlock));
50
+ signatureSets.push(getBlockProposerSignatureSet(index2pubkey, state, signedBlock));
49
51
  }
50
52
 
51
53
  // Only after altair fork, validate tSyncCommitteeSignature
52
54
  if (fork >= ForkSeq.altair) {
53
55
  const syncCommitteeSignatureSet = getSyncCommitteeSignatureSet(
56
+ index2pubkey,
54
57
  state as CachedBeaconStateAltair,
55
58
  (signedBlock as altair.SignedBeaconBlock).message
56
59
  );
@@ -1,5 +1,6 @@
1
1
  import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
2
2
  import {IndexedAttestation, SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {
5
6
  ISignatureSet,
@@ -19,25 +20,33 @@ export function getAttestationDataSigningRoot(
19
20
  }
20
21
 
21
22
  export function getAttestationWithIndicesSignatureSet(
23
+ index2pubkey: Index2PubkeyCache,
22
24
  state: CachedBeaconStateAllForks,
23
25
  attestation: Pick<phase0.Attestation, "data" | "signature">,
24
26
  attestingIndices: number[]
25
27
  ): ISignatureSet {
26
28
  return createAggregateSignatureSetFromComponents(
27
- attestingIndices.map((i) => state.epochCtx.index2pubkey[i]),
29
+ attestingIndices.map((i) => index2pubkey[i]),
28
30
  getAttestationDataSigningRoot(state, attestation.data),
29
31
  attestation.signature
30
32
  );
31
33
  }
32
34
 
33
35
  export function getIndexedAttestationSignatureSet(
36
+ index2pubkey: Index2PubkeyCache,
34
37
  state: CachedBeaconStateAllForks,
35
38
  indexedAttestation: IndexedAttestation
36
39
  ): ISignatureSet {
37
- return getAttestationWithIndicesSignatureSet(state, indexedAttestation, indexedAttestation.attestingIndices);
40
+ return getAttestationWithIndicesSignatureSet(
41
+ index2pubkey,
42
+ state,
43
+ indexedAttestation,
44
+ indexedAttestation.attestingIndices
45
+ );
38
46
  }
39
47
 
40
48
  export function getAttestationsSignatureSets(
49
+ index2pubkey: Index2PubkeyCache,
41
50
  state: CachedBeaconStateAllForks,
42
51
  signedBlock: SignedBeaconBlock,
43
52
  indexedAttestations: IndexedAttestation[]
@@ -47,5 +56,7 @@ export function getAttestationsSignatureSets(
47
56
  `Indexed attestations length mismatch: got ${indexedAttestations.length}, expected ${signedBlock.message.body.attestations.length}`
48
57
  );
49
58
  }
50
- return indexedAttestations.map((indexedAttestation) => getIndexedAttestationSignatureSet(state, indexedAttestation));
59
+ return indexedAttestations.map((indexedAttestation) =>
60
+ getIndexedAttestationSignatureSet(index2pubkey, state, indexedAttestation)
61
+ );
51
62
  }
@@ -1,22 +1,25 @@
1
1
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
2
2
  import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {computeSigningRoot} from "../util/index.js";
5
6
  import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
6
7
 
7
8
  export function verifyProposerSignature(
9
+ index2pubkey: Index2PubkeyCache,
8
10
  state: CachedBeaconStateAllForks,
9
11
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
10
12
  ): boolean {
11
- const signatureSet = getBlockProposerSignatureSet(state, signedBlock);
13
+ const signatureSet = getBlockProposerSignatureSet(index2pubkey, state, signedBlock);
12
14
  return verifySignatureSet(signatureSet);
13
15
  }
14
16
 
15
17
  export function getBlockProposerSignatureSet(
18
+ index2pubkey: Index2PubkeyCache,
16
19
  state: CachedBeaconStateAllForks,
17
20
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
18
21
  ): ISignatureSet {
19
- const {config, epochCtx} = state;
22
+ const {config} = state;
20
23
  const domain = config.getDomain(state.slot, DOMAIN_BEACON_PROPOSER, signedBlock.message.slot);
21
24
 
22
25
  const blockType = isBlindedBeaconBlock(signedBlock.message)
@@ -25,37 +28,40 @@ export function getBlockProposerSignatureSet(
25
28
 
26
29
  return {
27
30
  type: SignatureSetType.single,
28
- pubkey: epochCtx.index2pubkey[signedBlock.message.proposerIndex],
31
+ pubkey: index2pubkey[signedBlock.message.proposerIndex],
29
32
  signingRoot: computeSigningRoot(blockType, signedBlock.message, domain),
30
33
  signature: signedBlock.signature,
31
34
  };
32
35
  }
33
36
 
34
37
  export function getBlockHeaderProposerSignatureSetByParentStateSlot(
38
+ index2pubkey: Index2PubkeyCache,
35
39
  parentState: CachedBeaconStateAllForks,
36
40
  signedBlockHeader: phase0.SignedBeaconBlockHeader
37
41
  ) {
38
- return getBlockHeaderProposerSignatureSet(parentState, signedBlockHeader, parentState.slot);
42
+ return getBlockHeaderProposerSignatureSet(index2pubkey, parentState, signedBlockHeader, parentState.slot);
39
43
  }
40
44
 
41
45
  export function getBlockHeaderProposerSignatureSetByHeaderSlot(
46
+ index2pubkey: Index2PubkeyCache,
42
47
  headState: CachedBeaconStateAllForks,
43
48
  signedBlockHeader: phase0.SignedBeaconBlockHeader
44
49
  ) {
45
- return getBlockHeaderProposerSignatureSet(headState, signedBlockHeader, signedBlockHeader.message.slot);
50
+ return getBlockHeaderProposerSignatureSet(index2pubkey, headState, signedBlockHeader, signedBlockHeader.message.slot);
46
51
  }
47
52
 
48
53
  function getBlockHeaderProposerSignatureSet(
54
+ index2pubkey: Index2PubkeyCache,
49
55
  state: CachedBeaconStateAllForks,
50
56
  signedBlockHeader: phase0.SignedBeaconBlockHeader,
51
57
  domainSlot: Slot
52
58
  ): ISignatureSet {
53
- const {config, epochCtx} = state;
59
+ const {config} = state;
54
60
  const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
55
61
 
56
62
  return {
57
63
  type: SignatureSetType.single,
58
- pubkey: epochCtx.index2pubkey[signedBlockHeader.message.proposerIndex],
64
+ pubkey: index2pubkey[signedBlockHeader.message.proposerIndex],
59
65
  signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeader, signedBlockHeader.message, domain),
60
66
  signature: signedBlockHeader.signature,
61
67
  };
@@ -1,5 +1,6 @@
1
1
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
2
2
  import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
5
6
 
@@ -7,11 +8,11 @@ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index
7
8
  * Extract signatures to allow validating all block signatures at once
8
9
  */
9
10
  export function getProposerSlashingSignatureSets(
11
+ index2pubkey: Index2PubkeyCache,
10
12
  state: CachedBeaconStateAllForks,
11
13
  proposerSlashing: phase0.ProposerSlashing
12
14
  ): ISignatureSet[] {
13
- const {epochCtx} = state;
14
- const pubkey = epochCtx.index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
15
+ const pubkey = index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
15
16
 
16
17
  // In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
17
18
  // clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
@@ -32,10 +33,11 @@ export function getProposerSlashingSignatureSets(
32
33
  }
33
34
 
34
35
  export function getProposerSlashingsSignatureSets(
36
+ index2pubkey: Index2PubkeyCache,
35
37
  state: CachedBeaconStateAllForks,
36
38
  signedBlock: SignedBeaconBlock
37
39
  ): ISignatureSet[] {
38
40
  return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
39
- getProposerSlashingSignatureSets(state, proposerSlashing)
41
+ getProposerSlashingSignatureSets(index2pubkey, state, proposerSlashing)
40
42
  );
41
43
  }
@@ -1,5 +1,6 @@
1
1
  import {DOMAIN_RANDAO} from "@lodestar/params";
2
2
  import {BeaconBlock, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {
5
6
  ISignatureSet,
@@ -9,22 +10,29 @@ import {
9
10
  verifySignatureSet,
10
11
  } from "../util/index.js";
11
12
 
12
- export function verifyRandaoSignature(state: CachedBeaconStateAllForks, block: BeaconBlock): boolean {
13
- return verifySignatureSet(getRandaoRevealSignatureSet(state, block));
13
+ export function verifyRandaoSignature(
14
+ index2pubkey: Index2PubkeyCache,
15
+ state: CachedBeaconStateAllForks,
16
+ block: BeaconBlock
17
+ ): boolean {
18
+ return verifySignatureSet(getRandaoRevealSignatureSet(index2pubkey, state, block));
14
19
  }
15
20
 
16
21
  /**
17
22
  * Extract signatures to allow validating all block signatures at once
18
23
  */
19
- export function getRandaoRevealSignatureSet(state: CachedBeaconStateAllForks, block: BeaconBlock): ISignatureSet {
20
- const {epochCtx} = state;
24
+ export function getRandaoRevealSignatureSet(
25
+ index2pubkey: Index2PubkeyCache,
26
+ state: CachedBeaconStateAllForks,
27
+ block: BeaconBlock
28
+ ): ISignatureSet {
21
29
  // should not get epoch from epochCtx
22
30
  const epoch = computeEpochAtSlot(block.slot);
23
31
  const domain = state.config.getDomain(state.slot, DOMAIN_RANDAO, block.slot);
24
32
 
25
33
  return {
26
34
  type: SignatureSetType.single,
27
- pubkey: epochCtx.index2pubkey[block.proposerIndex],
35
+ pubkey: index2pubkey[block.proposerIndex],
28
36
  signingRoot: computeSigningRoot(ssz.Epoch, epoch, domain),
29
37
  signature: block.body.randaoReveal,
30
38
  };
@@ -1,4 +1,5 @@
1
1
  import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
2
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
2
3
  import {CachedBeaconStateAllForks} from "../types.js";
3
4
  import {
4
5
  ISignatureSet,
@@ -9,36 +10,38 @@ import {
9
10
  } from "../util/index.js";
10
11
 
11
12
  export function verifyVoluntaryExitSignature(
13
+ index2pubkey: Index2PubkeyCache,
12
14
  state: CachedBeaconStateAllForks,
13
15
  signedVoluntaryExit: phase0.SignedVoluntaryExit
14
16
  ): boolean {
15
- return verifySignatureSet(getVoluntaryExitSignatureSet(state, signedVoluntaryExit));
17
+ return verifySignatureSet(getVoluntaryExitSignatureSet(index2pubkey, state, signedVoluntaryExit));
16
18
  }
17
19
 
18
20
  /**
19
21
  * Extract signatures to allow validating all block signatures at once
20
22
  */
21
23
  export function getVoluntaryExitSignatureSet(
24
+ index2pubkey: Index2PubkeyCache,
22
25
  state: CachedBeaconStateAllForks,
23
26
  signedVoluntaryExit: phase0.SignedVoluntaryExit
24
27
  ): ISignatureSet {
25
- const {epochCtx} = state;
26
28
  const slot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
27
29
  const domain = state.config.getDomainForVoluntaryExit(state.slot, slot);
28
30
 
29
31
  return {
30
32
  type: SignatureSetType.single,
31
- pubkey: epochCtx.index2pubkey[signedVoluntaryExit.message.validatorIndex],
33
+ pubkey: index2pubkey[signedVoluntaryExit.message.validatorIndex],
32
34
  signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
33
35
  signature: signedVoluntaryExit.signature,
34
36
  };
35
37
  }
36
38
 
37
39
  export function getVoluntaryExitsSignatureSets(
40
+ index2pubkey: Index2PubkeyCache,
38
41
  state: CachedBeaconStateAllForks,
39
42
  signedBlock: SignedBeaconBlock
40
43
  ): ISignatureSet[] {
41
44
  return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
42
- getVoluntaryExitSignatureSet(state, voluntaryExit)
45
+ getVoluntaryExitSignatureSet(index2pubkey, state, voluntaryExit)
43
46
  );
44
47
  }
@@ -111,7 +111,7 @@ export function stateTransition(
111
111
  postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
112
112
 
113
113
  // Verify proposer signature only
114
- if (verifyProposer && !verifyProposerSignature(postState, signedBlock)) {
114
+ if (verifyProposer && !verifyProposerSignature(postState.epochCtx.index2pubkey, postState, signedBlock)) {
115
115
  throw new Error("Invalid block signature");
116
116
  }
117
117
 
@@ -2,7 +2,6 @@ import {ForkName, ForkPostBellatrix, ForkPreGloas, ForkSeq} from "@lodestar/para
2
2
  import {
3
3
  BeaconBlock,
4
4
  BeaconBlockBody,
5
- BlindedBeaconBlock,
6
5
  BlindedBeaconBlockBody,
7
6
  ExecutionPayload,
8
7
  ExecutionPayloadHeader,
@@ -10,75 +9,16 @@ import {
10
9
  capella,
11
10
  deneb,
12
11
  isBlindedBeaconBlockBody,
13
- isExecutionPayload,
14
12
  ssz,
15
13
  } from "@lodestar/types";
16
14
  import {
17
15
  BeaconStateAllForks,
18
- BeaconStateBellatrix,
19
16
  BeaconStateCapella,
20
17
  BeaconStateExecutions,
21
18
  CachedBeaconStateAllForks,
22
19
  CachedBeaconStateExecutions,
23
20
  } from "../types.js";
24
21
 
25
- /**
26
- * Execution enabled = merge is done.
27
- * When (A) state has execution data OR (B) block has execution data
28
- */
29
- export function isExecutionEnabled(state: BeaconStateExecutions, block: BeaconBlock | BlindedBeaconBlock): boolean {
30
- if (isMergeTransitionComplete(state)) {
31
- return true;
32
- }
33
-
34
- // Throws if not post-bellatrix block. A fork-guard in isExecutionEnabled() prevents this from happening
35
- const payload = getFullOrBlindedPayload(block);
36
- // Note: spec says to check all payload is zero-ed. However a state-root cannot be zero for any non-empty payload
37
- // TODO: Consider comparing with the payload root if this assumption is not correct.
38
- // return !byteArrayEquals(payload.stateRoot, ZERO_HASH);
39
-
40
- // UPDATE: stateRoot comparision should have been enough with zero hash, but spec tests were failing
41
- // Revisit this later to fix specs and make this efficient
42
- return isExecutionPayload(payload)
43
- ? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
44
- : !ssz.bellatrix.ExecutionPayloadHeader.equals(
45
- state.latestExecutionPayloadHeader,
46
- // TODO: Performance
47
- ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
48
- );
49
- }
50
-
51
- /**
52
- * Merge block is the SINGLE block that transitions from POW to POS.
53
- * state has no execution data AND this block has execution data
54
- */
55
- export function isMergeTransitionBlock(state: BeaconStateExecutions, body: bellatrix.BeaconBlockBody): boolean {
56
- return (
57
- !isMergeTransitionComplete(state) &&
58
- !ssz.bellatrix.ExecutionPayload.equals(body.executionPayload, ssz.bellatrix.ExecutionPayload.defaultValue())
59
- );
60
- }
61
-
62
- /**
63
- * Merge is complete when the state includes execution layer data:
64
- * state.latestExecutionPayloadHeader NOT EMPTY
65
- */
66
- export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
67
- if (!isCapellaStateType(state)) {
68
- return !ssz.bellatrix.ExecutionPayloadHeader.equals(
69
- (state as BeaconStateBellatrix).latestExecutionPayloadHeader,
70
- // TODO: Performance
71
- ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
72
- );
73
- }
74
-
75
- return !ssz.capella.ExecutionPayloadHeader.equals(
76
- state.latestExecutionPayloadHeader,
77
- // TODO: Performance
78
- ssz.capella.ExecutionPayloadHeader.defaultValue()
79
- );
80
- }
81
-
82
22
  /** Type guard for bellatrix.BeaconState */
83
23
  export function isExecutionStateType(state: BeaconStateAllForks): state is BeaconStateExecutions {
84
24
  return (state as BeaconStateExecutions).latestExecutionPayloadHeader !== undefined;