@lodestar/state-transition 1.38.0-rc.0 → 1.39.0-dev.0321dbcf04

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 (131) hide show
  1. package/lib/block/index.js +2 -2
  2. package/lib/block/index.js.map +1 -1
  3. package/lib/block/isValidIndexedAttestation.d.ts +6 -5
  4. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  5. package/lib/block/isValidIndexedAttestation.js +9 -10
  6. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  7. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  8. package/lib/block/processAttestationPhase0.js +1 -1
  9. package/lib/block/processAttestationPhase0.js.map +1 -1
  10. package/lib/block/processAttestationsAltair.d.ts.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 +4 -2
  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/processBlsToExecutionChange.d.ts +3 -1
  18. package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
  19. package/lib/block/processBlsToExecutionChange.js +7 -11
  20. package/lib/block/processBlsToExecutionChange.js.map +1 -1
  21. package/lib/block/processProposerSlashing.d.ts +5 -2
  22. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  23. package/lib/block/processProposerSlashing.js +7 -5
  24. package/lib/block/processProposerSlashing.js.map +1 -1
  25. package/lib/block/processRandao.js +2 -2
  26. package/lib/block/processRandao.js.map +1 -1
  27. package/lib/block/processSyncCommittee.d.ts +4 -1
  28. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  29. package/lib/block/processSyncCommittee.js +7 -6
  30. package/lib/block/processSyncCommittee.js.map +1 -1
  31. package/lib/block/processVoluntaryExit.d.ts.map +1 -1
  32. package/lib/block/processVoluntaryExit.js +2 -1
  33. package/lib/block/processVoluntaryExit.js.map +1 -1
  34. package/lib/block/processWithdrawals.d.ts +3 -3
  35. package/lib/block/processWithdrawals.d.ts.map +1 -1
  36. package/lib/block/processWithdrawals.js +152 -105
  37. package/lib/block/processWithdrawals.js.map +1 -1
  38. package/lib/cache/epochCache.d.ts +0 -3
  39. package/lib/cache/epochCache.d.ts.map +1 -1
  40. package/lib/cache/epochCache.js +0 -3
  41. package/lib/cache/epochCache.js.map +1 -1
  42. package/lib/cache/stateCache.d.ts +1 -0
  43. package/lib/cache/stateCache.d.ts.map +1 -1
  44. package/lib/cache/stateCache.js.map +1 -1
  45. package/lib/index.d.ts +2 -1
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js +2 -0
  48. package/lib/index.js.map +1 -1
  49. package/lib/rewards/attestationsRewards.d.ts +6 -0
  50. package/lib/rewards/attestationsRewards.d.ts.map +1 -0
  51. package/lib/rewards/attestationsRewards.js +113 -0
  52. package/lib/rewards/attestationsRewards.js.map +1 -0
  53. package/lib/rewards/blockRewards.d.ts +13 -0
  54. package/lib/rewards/blockRewards.d.ts.map +1 -0
  55. package/lib/rewards/blockRewards.js +95 -0
  56. package/lib/rewards/blockRewards.js.map +1 -0
  57. package/lib/rewards/index.d.ts +4 -0
  58. package/lib/rewards/index.d.ts.map +1 -0
  59. package/lib/rewards/index.js +4 -0
  60. package/lib/rewards/index.js.map +1 -0
  61. package/lib/rewards/syncCommitteeRewards.d.ts +6 -0
  62. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -0
  63. package/lib/rewards/syncCommitteeRewards.js +36 -0
  64. package/lib/rewards/syncCommitteeRewards.js.map +1 -0
  65. package/lib/signatureSets/attesterSlashings.d.ts +6 -5
  66. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  67. package/lib/signatureSets/attesterSlashings.js +11 -8
  68. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  69. package/lib/signatureSets/blsToExecutionChange.d.ts +1 -2
  70. package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
  71. package/lib/signatureSets/blsToExecutionChange.js +2 -2
  72. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  73. package/lib/signatureSets/index.d.ts +5 -3
  74. package/lib/signatureSets/index.d.ts.map +1 -1
  75. package/lib/signatureSets/index.js +10 -10
  76. package/lib/signatureSets/index.js.map +1 -1
  77. package/lib/signatureSets/indexedAttestation.d.ts +7 -6
  78. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  79. package/lib/signatureSets/indexedAttestation.js +12 -9
  80. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  81. package/lib/signatureSets/proposer.d.ts +7 -6
  82. package/lib/signatureSets/proposer.d.ts.map +1 -1
  83. package/lib/signatureSets/proposer.js +14 -13
  84. package/lib/signatureSets/proposer.js.map +1 -1
  85. package/lib/signatureSets/proposerSlashings.d.ts +5 -4
  86. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  87. package/lib/signatureSets/proposerSlashings.js +8 -6
  88. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  89. package/lib/signatureSets/randao.d.ts +4 -3
  90. package/lib/signatureSets/randao.d.ts.map +1 -1
  91. package/lib/signatureSets/randao.js +7 -6
  92. package/lib/signatureSets/randao.js.map +1 -1
  93. package/lib/signatureSets/voluntaryExits.d.ts +6 -5
  94. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  95. package/lib/signatureSets/voluntaryExits.js +11 -9
  96. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  97. package/lib/stateTransition.js +1 -1
  98. package/lib/stateTransition.js.map +1 -1
  99. package/lib/util/execution.d.ts +2 -7
  100. package/lib/util/execution.d.ts.map +1 -1
  101. package/lib/util/execution.js +7 -25
  102. package/lib/util/execution.js.map +1 -1
  103. package/package.json +14 -11
  104. package/src/block/index.ts +1 -1
  105. package/src/block/isValidIndexedAttestation.ts +25 -12
  106. package/src/block/processAttestationPhase0.ts +10 -1
  107. package/src/block/processAttestationsAltair.ts +7 -1
  108. package/src/block/processAttesterSlashing.ts +20 -5
  109. package/src/block/processBlsToExecutionChange.ts +13 -14
  110. package/src/block/processProposerSlashing.ts +21 -6
  111. package/src/block/processRandao.ts +2 -2
  112. package/src/block/processSyncCommittee.ts +18 -6
  113. package/src/block/processVoluntaryExit.ts +4 -1
  114. package/src/block/processWithdrawals.ts +230 -135
  115. package/src/cache/epochCache.ts +0 -3
  116. package/src/cache/stateCache.ts +1 -0
  117. package/src/index.ts +2 -2
  118. package/src/rewards/attestationsRewards.ts +200 -0
  119. package/src/rewards/blockRewards.ts +147 -0
  120. package/src/rewards/index.ts +3 -0
  121. package/src/rewards/syncCommitteeRewards.ts +59 -0
  122. package/src/signatureSets/attesterSlashings.ts +19 -10
  123. package/src/signatureSets/blsToExecutionChange.ts +2 -3
  124. package/src/signatureSets/index.ts +18 -12
  125. package/src/signatureSets/indexedAttestation.ts +30 -12
  126. package/src/signatureSets/proposer.ts +22 -14
  127. package/src/signatureSets/proposerSlashings.ts +14 -12
  128. package/src/signatureSets/randao.ts +17 -7
  129. package/src/signatureSets/voluntaryExits.ts +19 -11
  130. package/src/stateTransition.ts +1 -1
  131. package/src/util/execution.ts +8 -29
@@ -1,38 +1,47 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {ForkSeq, MAX_COMMITTEES_PER_SLOT, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
2
- import {IndexedAttestation, IndexedAttestationBigint} from "@lodestar/types";
3
+ import {IndexedAttestation, IndexedAttestationBigint, Slot} from "@lodestar/types";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
5
  import {getIndexedAttestationBigintSignatureSet, getIndexedAttestationSignatureSet} from "../signatureSets/index.js";
4
- import {CachedBeaconStateAllForks} from "../types.js";
5
6
  import {verifySignatureSet} from "../util/index.js";
6
7
 
7
8
  /**
8
9
  * Check if `indexedAttestation` has sorted and unique indices and a valid aggregate signature.
9
10
  */
10
11
  export function isValidIndexedAttestation(
11
- state: CachedBeaconStateAllForks,
12
+ config: BeaconConfig,
13
+ index2pubkey: Index2PubkeyCache,
14
+ stateSlot: Slot,
15
+ validatorsLen: number,
12
16
  indexedAttestation: IndexedAttestation,
13
17
  verifySignature: boolean
14
18
  ): boolean {
15
- if (!isValidIndexedAttestationIndices(state, indexedAttestation.attestingIndices)) {
19
+ if (!isValidIndexedAttestationIndices(config, stateSlot, validatorsLen, indexedAttestation.attestingIndices)) {
16
20
  return false;
17
21
  }
18
22
 
19
23
  if (verifySignature) {
20
- return verifySignatureSet(getIndexedAttestationSignatureSet(state, indexedAttestation));
24
+ return verifySignatureSet(getIndexedAttestationSignatureSet(config, index2pubkey, stateSlot, indexedAttestation));
21
25
  }
22
26
  return true;
23
27
  }
24
28
 
25
29
  export function isValidIndexedAttestationBigint(
26
- state: CachedBeaconStateAllForks,
30
+ config: BeaconConfig,
31
+ index2pubkey: Index2PubkeyCache,
32
+ stateSlot: Slot,
33
+ validatorsLen: number,
27
34
  indexedAttestation: IndexedAttestationBigint,
28
35
  verifySignature: boolean
29
36
  ): boolean {
30
- if (!isValidIndexedAttestationIndices(state, indexedAttestation.attestingIndices)) {
37
+ if (!isValidIndexedAttestationIndices(config, stateSlot, validatorsLen, indexedAttestation.attestingIndices)) {
31
38
  return false;
32
39
  }
33
40
 
34
41
  if (verifySignature) {
35
- return verifySignatureSet(getIndexedAttestationBigintSignatureSet(state, indexedAttestation));
42
+ return verifySignatureSet(
43
+ getIndexedAttestationBigintSignatureSet(config, index2pubkey, stateSlot, indexedAttestation)
44
+ );
36
45
  }
37
46
  return true;
38
47
  }
@@ -40,10 +49,15 @@ export function isValidIndexedAttestationBigint(
40
49
  /**
41
50
  * Check if `indexedAttestation` has sorted and unique indices and a valid aggregate signature.
42
51
  */
43
- export function isValidIndexedAttestationIndices(state: CachedBeaconStateAllForks, indices: number[]): boolean {
52
+ export function isValidIndexedAttestationIndices(
53
+ config: BeaconConfig,
54
+ stateSlot: Slot,
55
+ validatorsLen: number,
56
+ indices: number[]
57
+ ): boolean {
44
58
  // verify max number of indices
45
59
  const maxIndices =
46
- state.config.getForkSeq(state.slot) >= ForkSeq.electra
60
+ config.getForkSeq(stateSlot) >= ForkSeq.electra
47
61
  ? MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT
48
62
  : MAX_VALIDATORS_PER_COMMITTEE;
49
63
  if (!(indices.length > 0 && indices.length <= maxIndices)) {
@@ -60,9 +74,8 @@ export function isValidIndexedAttestationIndices(state: CachedBeaconStateAllFork
60
74
  }
61
75
 
62
76
  // check if indices are out of bounds, by checking the highest index (since it is sorted)
63
- // TODO - SLOW CODE - Does this .length check the tree and is expensive?
64
77
  const lastIndex = indices.at(-1);
65
- if (lastIndex && lastIndex >= state.validators.length) {
78
+ if (lastIndex && lastIndex >= validatorsLen) {
66
79
  return false;
67
80
  }
68
81
 
@@ -50,7 +50,16 @@ export function processAttestationPhase0(
50
50
  state.previousEpochAttestations.push(pendingAttestation);
51
51
  }
52
52
 
53
- if (!isValidIndexedAttestation(state, epochCtx.getIndexedAttestation(ForkSeq.phase0, attestation), verifySignature)) {
53
+ if (
54
+ !isValidIndexedAttestation(
55
+ state.config,
56
+ epochCtx.index2pubkey,
57
+ state.slot,
58
+ state.validators.length,
59
+ epochCtx.getIndexedAttestation(ForkSeq.phase0, attestation),
60
+ verifySignature
61
+ )
62
+ ) {
54
63
  throw new Error("Attestation is not valid");
55
64
  }
56
65
  }
@@ -64,7 +64,13 @@ export function processAttestationsAltair(
64
64
  // TODO: Why should we verify an indexed attestation that we just created? If it's just for the signature
65
65
  // we can verify only that and nothing else.
66
66
  if (verifySignature) {
67
- const sigSet = getAttestationWithIndicesSignatureSet(state, attestation, attestingIndices);
67
+ const sigSet = getAttestationWithIndicesSignatureSet(
68
+ state.config,
69
+ epochCtx.index2pubkey,
70
+ state.slot,
71
+ attestation,
72
+ attestingIndices
73
+ );
68
74
  if (!verifySignatureSet(sigSet)) {
69
75
  throw new Error("Attestation signature is not valid");
70
76
  }
@@ -1,5 +1,7 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {ForkSeq} from "@lodestar/params";
2
- import {AttesterSlashing} from "@lodestar/types";
3
+ import {AttesterSlashing, Slot} from "@lodestar/types";
4
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
5
  import {CachedBeaconStateAllForks} from "../types.js";
4
6
  import {getAttesterSlashableIndices, isSlashableAttestationData, isSlashableValidator} from "../util/index.js";
5
7
  import {isValidIndexedAttestationBigint} from "./isValidIndexedAttestation.js";
@@ -17,7 +19,15 @@ export function processAttesterSlashing(
17
19
  attesterSlashing: AttesterSlashing,
18
20
  verifySignatures = true
19
21
  ): void {
20
- assertValidAttesterSlashing(state, attesterSlashing, verifySignatures);
22
+ const {epochCtx} = state;
23
+ assertValidAttesterSlashing(
24
+ state.config,
25
+ epochCtx.index2pubkey,
26
+ state.slot,
27
+ state.validators.length,
28
+ attesterSlashing,
29
+ verifySignatures
30
+ );
21
31
 
22
32
  const intersectingIndices = getAttesterSlashableIndices(attesterSlashing);
23
33
 
@@ -25,7 +35,7 @@ export function processAttesterSlashing(
25
35
  const validators = state.validators; // Get the validators sub tree once for all indices
26
36
  // Spec requires to sort indexes beforehand
27
37
  for (const index of intersectingIndices.sort((a, b) => a - b)) {
28
- if (isSlashableValidator(validators.getReadonly(index), state.epochCtx.epoch)) {
38
+ if (isSlashableValidator(validators.getReadonly(index), epochCtx.epoch)) {
29
39
  slashValidator(fork, state, index);
30
40
  slashedAny = true;
31
41
  }
@@ -37,7 +47,10 @@ export function processAttesterSlashing(
37
47
  }
38
48
 
39
49
  export function assertValidAttesterSlashing(
40
- state: CachedBeaconStateAllForks,
50
+ config: BeaconConfig,
51
+ index2pubkey: Index2PubkeyCache,
52
+ stateSlot: Slot,
53
+ validatorsLen: number,
41
54
  attesterSlashing: AttesterSlashing,
42
55
  verifySignatures = true
43
56
  ): void {
@@ -52,7 +65,9 @@ export function assertValidAttesterSlashing(
52
65
  // be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which
53
66
  // can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
54
67
  for (const [i, attestation] of [attestation1, attestation2].entries()) {
55
- if (!isValidIndexedAttestationBigint(state, attestation, verifySignatures)) {
68
+ if (
69
+ !isValidIndexedAttestationBigint(config, index2pubkey, stateSlot, validatorsLen, attestation, verifySignatures)
70
+ ) {
56
71
  throw new Error(`AttesterSlashing attestation${i} is invalid`);
57
72
  }
58
73
  }
@@ -1,7 +1,9 @@
1
1
  import {digest} from "@chainsafe/as-sha256";
2
2
  import {byteArrayEquals} from "@chainsafe/ssz";
3
+ import {BeaconConfig} from "@lodestar/config";
3
4
  import {BLS_WITHDRAWAL_PREFIX, ETH1_ADDRESS_WITHDRAWAL_PREFIX} from "@lodestar/params";
4
5
  import {capella} from "@lodestar/types";
6
+ import {Validator} from "@lodestar/types/phase0";
5
7
  import {toHex} from "@lodestar/utils";
6
8
  import {verifyBlsToExecutionChangeSignature} from "../signatureSets/index.js";
7
9
  import {CachedBeaconStateCapella} from "../types.js";
@@ -12,12 +14,18 @@ export function processBlsToExecutionChange(
12
14
  ): void {
13
15
  const addressChange = signedBlsToExecutionChange.message;
14
16
 
15
- const validation = isValidBlsToExecutionChange(state, signedBlsToExecutionChange, true);
17
+ if (addressChange.validatorIndex >= state.validators.length) {
18
+ throw Error(
19
+ `withdrawalValidatorIndex ${addressChange.validatorIndex} >= state.validators len ${state.validators.length}`
20
+ );
21
+ }
22
+
23
+ const validator = state.validators.get(addressChange.validatorIndex);
24
+ const validation = isValidBlsToExecutionChange(state.config, validator, signedBlsToExecutionChange, true);
16
25
  if (!validation.valid) {
17
26
  throw validation.error;
18
27
  }
19
28
 
20
- const validator = state.validators.get(addressChange.validatorIndex);
21
29
  const newWithdrawalCredentials = new Uint8Array(32);
22
30
  newWithdrawalCredentials[0] = ETH1_ADDRESS_WITHDRAWAL_PREFIX;
23
31
  newWithdrawalCredentials.set(addressChange.toExecutionAddress, 12);
@@ -27,22 +35,13 @@ export function processBlsToExecutionChange(
27
35
  }
28
36
 
29
37
  export function isValidBlsToExecutionChange(
30
- state: CachedBeaconStateCapella,
38
+ config: BeaconConfig,
39
+ validator: Validator,
31
40
  signedBLSToExecutionChange: capella.SignedBLSToExecutionChange,
32
41
  verifySignature = true
33
42
  ): {valid: true} | {valid: false; error: Error} {
34
43
  const addressChange = signedBLSToExecutionChange.message;
35
44
 
36
- if (addressChange.validatorIndex >= state.validators.length) {
37
- return {
38
- valid: false,
39
- error: Error(
40
- `withdrawalValidatorIndex ${addressChange.validatorIndex} > state.validators len ${state.validators.length}`
41
- ),
42
- };
43
- }
44
-
45
- const validator = state.validators.getReadonly(addressChange.validatorIndex);
46
45
  const {withdrawalCredentials} = validator;
47
46
  if (withdrawalCredentials[0] !== BLS_WITHDRAWAL_PREFIX) {
48
47
  return {
@@ -65,7 +64,7 @@ export function isValidBlsToExecutionChange(
65
64
  };
66
65
  }
67
66
 
68
- if (verifySignature && !verifyBlsToExecutionChangeSignature(state, signedBLSToExecutionChange)) {
67
+ if (verifySignature && !verifyBlsToExecutionChangeSignature(config, signedBLSToExecutionChange)) {
69
68
  return {
70
69
  valid: false,
71
70
  error: Error(
@@ -1,5 +1,8 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
2
- import {phase0, ssz} from "@lodestar/types";
3
+ import {Slot, phase0, ssz} from "@lodestar/types";
4
+ import {Validator} from "@lodestar/types/phase0";
5
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
6
  import {getProposerSlashingSignatureSets} from "../signatureSets/index.js";
4
7
  import {CachedBeaconStateAllForks, CachedBeaconStateGloas} from "../types.js";
5
8
  import {computeEpochAtSlot, isSlashableValidator} from "../util/index.js";
@@ -18,7 +21,15 @@ export function processProposerSlashing(
18
21
  proposerSlashing: phase0.ProposerSlashing,
19
22
  verifySignatures = true
20
23
  ): void {
21
- assertValidProposerSlashing(state, proposerSlashing, verifySignatures);
24
+ const proposer = state.validators.getReadonly(proposerSlashing.signedHeader1.message.proposerIndex);
25
+ assertValidProposerSlashing(
26
+ state.config,
27
+ state.epochCtx.index2pubkey,
28
+ state.slot,
29
+ proposerSlashing,
30
+ proposer,
31
+ verifySignatures
32
+ );
22
33
 
23
34
  if (fork >= ForkSeq.gloas) {
24
35
  const slot = Number(proposerSlashing.signedHeader1.message.slot);
@@ -45,8 +56,11 @@ export function processProposerSlashing(
45
56
  }
46
57
 
47
58
  export function assertValidProposerSlashing(
48
- state: CachedBeaconStateAllForks,
59
+ config: BeaconConfig,
60
+ index2pubkey: Index2PubkeyCache,
61
+ stateSlot: Slot,
49
62
  proposerSlashing: phase0.ProposerSlashing,
63
+ proposer: Validator,
50
64
  verifySignatures = true
51
65
  ): void {
52
66
  const header1 = proposerSlashing.signedHeader1.message;
@@ -70,14 +84,15 @@ export function assertValidProposerSlashing(
70
84
  }
71
85
 
72
86
  // verify the proposer is slashable
73
- const proposer = state.validators.getReadonly(header1.proposerIndex);
74
- if (!isSlashableValidator(proposer, state.epochCtx.epoch)) {
87
+ // ideally we would get the proposer from state.validators using proposerIndex but that requires access to state
88
+ // instead of that we pass in the proposer directly from the consumer side
89
+ if (!isSlashableValidator(proposer, computeEpochAtSlot(stateSlot))) {
75
90
  throw new Error("ProposerSlashing proposer is not slashable");
76
91
  }
77
92
 
78
93
  // verify signatures
79
94
  if (verifySignatures) {
80
- const signatureSets = getProposerSlashingSignatureSets(state, proposerSlashing);
95
+ const signatureSets = getProposerSlashingSignatureSets(config, index2pubkey, stateSlot, proposerSlashing);
81
96
  for (let i = 0; i < signatureSets.length; i++) {
82
97
  if (!verifySignatureSet(signatureSets[i])) {
83
98
  throw new Error(`ProposerSlashing header${i + 1} signature invalid`);
@@ -12,12 +12,12 @@ import {getRandaoMix} from "../util/index.js";
12
12
  * PERF: Fixed work independent of block contents.
13
13
  */
14
14
  export function processRandao(state: CachedBeaconStateAllForks, block: BeaconBlock, verifySignature = true): void {
15
- const {epochCtx} = state;
15
+ const {epochCtx, config} = state;
16
16
  const epoch = epochCtx.epoch;
17
17
  const randaoReveal = block.body.randaoReveal;
18
18
 
19
19
  // verify RANDAO reveal
20
- if (verifySignature && !verifyRandaoSignature(state, block)) {
20
+ if (verifySignature && !verifyRandaoSignature(config, epochCtx.index2pubkey, block)) {
21
21
  throw new Error("RANDAO reveal is an invalid signature");
22
22
  }
23
23
 
@@ -1,6 +1,9 @@
1
1
  import {byteArrayEquals} from "@chainsafe/ssz";
2
+ import {BeaconConfig} from "@lodestar/config";
2
3
  import {DOMAIN_SYNC_COMMITTEE, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
3
4
  import {altair, ssz} from "@lodestar/types";
5
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
6
+ import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
4
7
  import {G2_POINT_AT_INFINITY} from "../constants/index.js";
5
8
  import {CachedBeaconStateAllForks} from "../types.js";
6
9
  import {
@@ -23,7 +26,13 @@ export function processSyncAggregate(
23
26
  if (verifySignatures) {
24
27
  // This is to conform to the spec - we want the signature to be verified
25
28
  const participantIndices = block.body.syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
26
- const signatureSet = getSyncCommitteeSignatureSet(state, block, participantIndices);
29
+ const signatureSet = getSyncCommitteeSignatureSet(
30
+ state.config,
31
+ state.epochCtx.index2pubkey,
32
+ state.epochCtx.currentSyncCommitteeIndexed,
33
+ block,
34
+ participantIndices
35
+ );
27
36
  // When there's no participation we consider the signature valid and just ignore i
28
37
  if (signatureSet !== null && !verifySignatureSet(signatureSet)) {
29
38
  throw Error("Sync committee signature invalid");
@@ -63,12 +72,13 @@ export function processSyncAggregate(
63
72
  }
64
73
 
65
74
  export function getSyncCommitteeSignatureSet(
66
- state: CachedBeaconStateAllForks,
75
+ config: BeaconConfig,
76
+ index2pubkey: Index2PubkeyCache,
77
+ currentSyncCommitteeIndexed: SyncCommitteeCache,
67
78
  block: altair.BeaconBlock,
68
79
  /** Optional parameter to prevent computing it twice */
69
80
  participantIndices?: number[]
70
81
  ): ISignatureSet | null {
71
- const {epochCtx} = state;
72
82
  const {syncAggregate} = block.body;
73
83
  const signature = syncAggregate.syncCommitteeSignature;
74
84
 
@@ -92,7 +102,7 @@ export function getSyncCommitteeSignatureSet(
92
102
  const rootSigned = block.parentRoot;
93
103
 
94
104
  if (!participantIndices) {
95
- const committeeIndices = state.epochCtx.currentSyncCommitteeIndexed.validatorIndices;
105
+ const committeeIndices = currentSyncCommitteeIndexed.validatorIndices;
96
106
  participantIndices = syncAggregate.syncCommitteeBits.intersectValues(committeeIndices);
97
107
  }
98
108
 
@@ -106,11 +116,13 @@ export function getSyncCommitteeSignatureSet(
106
116
  throw Error("Empty sync committee signature is not infinity");
107
117
  }
108
118
 
109
- const domain = state.config.getDomain(state.slot, DOMAIN_SYNC_COMMITTEE, previousSlot);
119
+ // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
120
+ // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
121
+ const domain = config.getDomain(block.slot, DOMAIN_SYNC_COMMITTEE, previousSlot);
110
122
 
111
123
  return {
112
124
  type: SignatureSetType.aggregate,
113
- pubkeys: participantIndices.map((i) => epochCtx.index2pubkey[i]),
125
+ pubkeys: participantIndices.map((i) => index2pubkey[i]),
114
126
  signingRoot: computeSigningRoot(ssz.Root, rootSigned, domain),
115
127
  signature,
116
128
  };
@@ -74,7 +74,10 @@ export function getVoluntaryExitValidity(
74
74
  return VoluntaryExitValidity.pendingWithdrawals;
75
75
  }
76
76
 
77
- if (verifySignature && !verifyVoluntaryExitSignature(state, signedVoluntaryExit)) {
77
+ if (
78
+ verifySignature &&
79
+ !verifyVoluntaryExitSignature(state.config, epochCtx.index2pubkey, state.slot, signedVoluntaryExit)
80
+ ) {
78
81
  return VoluntaryExitValidity.invalidSignature;
79
82
  }
80
83