@lodestar/state-transition 1.38.0-dev.bc1fed4d3d → 1.38.0-dev.ebc352f211

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 (191) hide show
  1. package/lib/block/index.d.ts +4 -1
  2. package/lib/block/index.d.ts.map +1 -1
  3. package/lib/block/index.js +18 -9
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/isValidIndexedAttestation.d.ts +3 -2
  6. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  7. package/lib/block/isValidIndexedAttestation.js +4 -4
  8. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  9. package/lib/block/isValidIndexedPayloadAttestation.d.ts +4 -0
  10. package/lib/block/isValidIndexedPayloadAttestation.d.ts.map +1 -0
  11. package/lib/block/isValidIndexedPayloadAttestation.js +14 -0
  12. package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -0
  13. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  14. package/lib/block/processAttestationPhase0.js +7 -2
  15. package/lib/block/processAttestationPhase0.js.map +1 -1
  16. package/lib/block/processAttestationsAltair.d.ts +3 -3
  17. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  18. package/lib/block/processAttestationsAltair.js +47 -5
  19. package/lib/block/processAttestationsAltair.js.map +1 -1
  20. package/lib/block/processAttesterSlashing.d.ts +2 -1
  21. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  22. package/lib/block/processAttesterSlashing.js +5 -4
  23. package/lib/block/processAttesterSlashing.js.map +1 -1
  24. package/lib/block/processConsolidationRequest.d.ts +3 -2
  25. package/lib/block/processConsolidationRequest.d.ts.map +1 -1
  26. package/lib/block/processConsolidationRequest.js +2 -2
  27. package/lib/block/processConsolidationRequest.js.map +1 -1
  28. package/lib/block/processDepositRequest.d.ts +2 -2
  29. package/lib/block/processDepositRequest.d.ts.map +1 -1
  30. package/lib/block/processDepositRequest.js.map +1 -1
  31. package/lib/block/processExecutionPayload.d.ts.map +1 -1
  32. package/lib/block/processExecutionPayload.js +4 -6
  33. package/lib/block/processExecutionPayload.js.map +1 -1
  34. package/lib/block/processExecutionPayloadBid.d.ts +5 -0
  35. package/lib/block/processExecutionPayloadBid.d.ts.map +1 -0
  36. package/lib/block/processExecutionPayloadBid.js +89 -0
  37. package/lib/block/processExecutionPayloadBid.js.map +1 -0
  38. package/lib/block/processExecutionPayloadEnvelope.d.ts +4 -0
  39. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -0
  40. package/lib/block/processExecutionPayloadEnvelope.js +118 -0
  41. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -0
  42. package/lib/block/processOperations.d.ts.map +1 -1
  43. package/lib/block/processOperations.js +8 -2
  44. package/lib/block/processOperations.js.map +1 -1
  45. package/lib/block/processPayloadAttestation.d.ts +4 -0
  46. package/lib/block/processPayloadAttestation.d.ts.map +1 -0
  47. package/lib/block/processPayloadAttestation.js +16 -0
  48. package/lib/block/processPayloadAttestation.js.map +1 -0
  49. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  50. package/lib/block/processProposerSlashing.js +17 -2
  51. package/lib/block/processProposerSlashing.js.map +1 -1
  52. package/lib/block/processRandao.js +1 -1
  53. package/lib/block/processRandao.js.map +1 -1
  54. package/lib/block/processSyncCommittee.d.ts +2 -1
  55. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  56. package/lib/block/processSyncCommittee.js +3 -4
  57. package/lib/block/processSyncCommittee.js.map +1 -1
  58. package/lib/block/processVoluntaryExit.js +2 -2
  59. package/lib/block/processVoluntaryExit.js.map +1 -1
  60. package/lib/block/processWithdrawalRequest.d.ts +2 -2
  61. package/lib/block/processWithdrawalRequest.d.ts.map +1 -1
  62. package/lib/block/processWithdrawalRequest.js +1 -1
  63. package/lib/block/processWithdrawalRequest.js.map +1 -1
  64. package/lib/block/processWithdrawals.d.ts +4 -3
  65. package/lib/block/processWithdrawals.d.ts.map +1 -1
  66. package/lib/block/processWithdrawals.js +89 -19
  67. package/lib/block/processWithdrawals.js.map +1 -1
  68. package/lib/cache/epochCache.d.ts +5 -1
  69. package/lib/cache/epochCache.d.ts.map +1 -1
  70. package/lib/cache/epochCache.js +34 -1
  71. package/lib/cache/epochCache.js.map +1 -1
  72. package/lib/epoch/index.d.ts +4 -2
  73. package/lib/epoch/index.d.ts.map +1 -1
  74. package/lib/epoch/index.js +10 -1
  75. package/lib/epoch/index.js.map +1 -1
  76. package/lib/epoch/processBuilderPendingPayments.d.ts +6 -0
  77. package/lib/epoch/processBuilderPendingPayments.d.ts.map +1 -0
  78. package/lib/epoch/processBuilderPendingPayments.js +28 -0
  79. package/lib/epoch/processBuilderPendingPayments.js.map +1 -0
  80. package/lib/index.d.ts +1 -1
  81. package/lib/index.d.ts.map +1 -1
  82. package/lib/index.js.map +1 -1
  83. package/lib/signatureSets/attesterSlashings.d.ts +4 -3
  84. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  85. package/lib/signatureSets/attesterSlashings.js +6 -6
  86. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  87. package/lib/signatureSets/index.d.ts +3 -1
  88. package/lib/signatureSets/index.d.ts.map +1 -1
  89. package/lib/signatureSets/index.js +9 -8
  90. package/lib/signatureSets/index.js.map +1 -1
  91. package/lib/signatureSets/indexedAttestation.d.ts +4 -3
  92. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  93. package/lib/signatureSets/indexedAttestation.js +6 -6
  94. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  95. package/lib/signatureSets/indexedPayloadAttestation.d.ts +6 -0
  96. package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -0
  97. package/lib/signatureSets/indexedPayloadAttestation.js +11 -0
  98. package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -0
  99. package/lib/signatureSets/proposer.d.ts +5 -4
  100. package/lib/signatureSets/proposer.d.ts.map +1 -1
  101. package/lib/signatureSets/proposer.js +12 -12
  102. package/lib/signatureSets/proposer.js.map +1 -1
  103. package/lib/signatureSets/proposerSlashings.d.ts +3 -2
  104. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  105. package/lib/signatureSets/proposerSlashings.js +4 -5
  106. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  107. package/lib/signatureSets/randao.d.ts +3 -2
  108. package/lib/signatureSets/randao.d.ts.map +1 -1
  109. package/lib/signatureSets/randao.js +4 -5
  110. package/lib/signatureSets/randao.js.map +1 -1
  111. package/lib/signatureSets/voluntaryExits.d.ts +4 -3
  112. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  113. package/lib/signatureSets/voluntaryExits.js +6 -7
  114. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  115. package/lib/slot/index.d.ts +2 -1
  116. package/lib/slot/index.d.ts.map +1 -1
  117. package/lib/slot/index.js +6 -2
  118. package/lib/slot/index.js.map +1 -1
  119. package/lib/slot/upgradeStateToAltair.js +1 -1
  120. package/lib/slot/upgradeStateToAltair.js.map +1 -1
  121. package/lib/slot/upgradeStateToGloas.d.ts +0 -1
  122. package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
  123. package/lib/slot/upgradeStateToGloas.js +47 -5
  124. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  125. package/lib/stateTransition.js +5 -4
  126. package/lib/stateTransition.js.map +1 -1
  127. package/lib/util/electra.d.ts +5 -5
  128. package/lib/util/electra.d.ts.map +1 -1
  129. package/lib/util/electra.js +2 -1
  130. package/lib/util/electra.js.map +1 -1
  131. package/lib/util/epoch.d.ts +3 -3
  132. package/lib/util/epoch.d.ts.map +1 -1
  133. package/lib/util/epoch.js.map +1 -1
  134. package/lib/util/execution.d.ts +1 -16
  135. package/lib/util/execution.d.ts.map +1 -1
  136. package/lib/util/execution.js +1 -44
  137. package/lib/util/execution.js.map +1 -1
  138. package/lib/util/gloas.d.ts +11 -0
  139. package/lib/util/gloas.d.ts.map +1 -0
  140. package/lib/util/gloas.js +35 -0
  141. package/lib/util/gloas.js.map +1 -0
  142. package/lib/util/seed.d.ts +5 -1
  143. package/lib/util/seed.d.ts.map +1 -1
  144. package/lib/util/seed.js +33 -1
  145. package/lib/util/seed.js.map +1 -1
  146. package/lib/util/validator.d.ts +2 -2
  147. package/lib/util/validator.d.ts.map +1 -1
  148. package/lib/util/validator.js +14 -1
  149. package/lib/util/validator.js.map +1 -1
  150. package/package.json +6 -6
  151. package/src/block/index.ts +32 -15
  152. package/src/block/isValidIndexedAttestation.ts +5 -2
  153. package/src/block/isValidIndexedPayloadAttestation.ts +23 -0
  154. package/src/block/processAttestationPhase0.ts +13 -2
  155. package/src/block/processAttestationsAltair.ts +63 -6
  156. package/src/block/processAttesterSlashing.ts +6 -3
  157. package/src/block/processConsolidationRequest.ts +6 -5
  158. package/src/block/processDepositRequest.ts +5 -2
  159. package/src/block/processExecutionPayload.ts +8 -14
  160. package/src/block/processExecutionPayloadBid.ts +120 -0
  161. package/src/block/processExecutionPayloadEnvelope.ts +181 -0
  162. package/src/block/processOperations.ts +16 -4
  163. package/src/block/processPayloadAttestation.ts +25 -0
  164. package/src/block/processProposerSlashing.ts +25 -4
  165. package/src/block/processRandao.ts +1 -1
  166. package/src/block/processSyncCommittee.ts +4 -3
  167. package/src/block/processVoluntaryExit.ts +2 -2
  168. package/src/block/processWithdrawalRequest.ts +4 -4
  169. package/src/block/processWithdrawals.ts +118 -27
  170. package/src/cache/epochCache.ts +58 -1
  171. package/src/epoch/index.ts +12 -0
  172. package/src/epoch/processBuilderPendingPayments.ts +31 -0
  173. package/src/index.ts +2 -0
  174. package/src/signatureSets/attesterSlashings.ts +7 -3
  175. package/src/signatureSets/index.ts +10 -6
  176. package/src/signatureSets/indexedAttestation.ts +14 -3
  177. package/src/signatureSets/indexedPayloadAttestation.ts +24 -0
  178. package/src/signatureSets/proposer.ts +13 -7
  179. package/src/signatureSets/proposerSlashings.ts +5 -3
  180. package/src/signatureSets/randao.ts +13 -5
  181. package/src/signatureSets/voluntaryExits.ts +7 -4
  182. package/src/slot/index.ts +11 -3
  183. package/src/slot/upgradeStateToAltair.ts +2 -1
  184. package/src/slot/upgradeStateToGloas.ts +49 -5
  185. package/src/stateTransition.ts +5 -5
  186. package/src/util/electra.ts +15 -6
  187. package/src/util/epoch.ts +6 -3
  188. package/src/util/execution.ts +0 -60
  189. package/src/util/gloas.ts +58 -0
  190. package/src/util/seed.ts +57 -1
  191. package/src/util/validator.ts +21 -2
@@ -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
  }
package/src/slot/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {byteArrayEquals} from "@chainsafe/ssz";
2
- import {SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
2
+ import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
3
3
  import {ZERO_HASH} from "../constants/index.js";
4
- import {CachedBeaconStateAllForks} from "../types.js";
4
+ import {CachedBeaconStateAllForks, CachedBeaconStateGloas} from "../types.js";
5
5
 
6
6
  export {upgradeStateToAltair} from "./upgradeStateToAltair.js";
7
7
  export {upgradeStateToBellatrix} from "./upgradeStateToBellatrix.js";
@@ -14,7 +14,7 @@ export {upgradeStateToGloas} from "./upgradeStateToGloas.js";
14
14
  /**
15
15
  * Dial state to next slot. Common for all forks
16
16
  */
17
- export function processSlot(state: CachedBeaconStateAllForks): void {
17
+ export function processSlot(fork: ForkSeq, state: CachedBeaconStateAllForks): void {
18
18
  // Cache state root
19
19
  // Note: .hashTreeRoot() automatically commits() pending changes
20
20
  const previousStateRoot = state.hashTreeRoot();
@@ -29,4 +29,12 @@ export function processSlot(state: CachedBeaconStateAllForks): void {
29
29
  // Note: .hashTreeRoot() automatically commits() pending changes
30
30
  const previousBlockRoot = state.latestBlockHeader.hashTreeRoot();
31
31
  state.blockRoots.set(state.slot % SLOTS_PER_HISTORICAL_ROOT, previousBlockRoot);
32
+
33
+ if (fork >= ForkSeq.gloas) {
34
+ // Unset the next payload availability
35
+ (state as CachedBeaconStateGloas).executionPayloadAvailability.set(
36
+ (state.slot + 1) % SLOTS_PER_HISTORICAL_ROOT,
37
+ false
38
+ );
39
+ }
32
40
  }
@@ -135,7 +135,8 @@ function translateParticipation(
135
135
  data,
136
136
  attestation.inclusionDelay,
137
137
  epochCtx.epoch,
138
- rootCache
138
+ rootCache,
139
+ null
139
140
  );
140
141
 
141
142
  const committeeIndices = epochCtx.getBeaconCommittee(data.slot, data.index);
@@ -1,24 +1,68 @@
1
+ import {SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
1
2
  import {ssz} from "@lodestar/types";
2
3
  import {getCachedBeaconState} from "../cache/stateCache.js";
3
4
  import {CachedBeaconStateFulu, CachedBeaconStateGloas} from "../types.js";
4
5
 
5
6
  /**
6
7
  * Upgrade a state from Fulu to Gloas.
7
- * TODO GLOAS: Implement this
8
8
  */
9
9
  export function upgradeStateToGloas(stateFulu: CachedBeaconStateFulu): CachedBeaconStateGloas {
10
10
  const {config} = stateFulu;
11
11
 
12
- const stateFuluNode = ssz.fulu.BeaconState.commitViewDU(stateFulu);
13
- const stateGloasView = ssz.gloas.BeaconState.getViewDU(stateFuluNode);
12
+ ssz.fulu.BeaconState.commitViewDU(stateFulu);
13
+ const stateGloasCloned = stateFulu;
14
14
 
15
- const stateGloas = getCachedBeaconState(stateGloasView, stateFulu);
15
+ const stateGloasView = ssz.gloas.BeaconState.defaultViewDU();
16
16
 
17
- stateGloas.fork = ssz.phase0.Fork.toViewDU({
17
+ stateGloasView.genesisTime = stateGloasCloned.genesisTime;
18
+ stateGloasView.genesisValidatorsRoot = stateGloasCloned.genesisValidatorsRoot;
19
+ stateGloasView.slot = stateGloasCloned.slot;
20
+ stateGloasView.fork = ssz.phase0.Fork.toViewDU({
18
21
  previousVersion: stateFulu.fork.currentVersion,
19
22
  currentVersion: config.GLOAS_FORK_VERSION,
20
23
  epoch: stateFulu.epochCtx.epoch,
21
24
  });
25
+ stateGloasView.latestBlockHeader = stateGloasCloned.latestBlockHeader;
26
+ stateGloasView.blockRoots = stateGloasCloned.blockRoots;
27
+ stateGloasView.stateRoots = stateGloasCloned.stateRoots;
28
+ stateGloasView.historicalRoots = stateGloasCloned.historicalRoots;
29
+ stateGloasView.eth1Data = stateGloasCloned.eth1Data;
30
+ stateGloasView.eth1DataVotes = stateGloasCloned.eth1DataVotes;
31
+ stateGloasView.eth1DepositIndex = stateGloasCloned.eth1DepositIndex;
32
+ stateGloasView.validators = stateGloasCloned.validators;
33
+ stateGloasView.balances = stateGloasCloned.balances;
34
+ stateGloasView.randaoMixes = stateGloasCloned.randaoMixes;
35
+ stateGloasView.slashings = stateGloasCloned.slashings;
36
+ stateGloasView.previousEpochParticipation = stateGloasCloned.previousEpochParticipation;
37
+ stateGloasView.currentEpochParticipation = stateGloasCloned.currentEpochParticipation;
38
+ stateGloasView.justificationBits = stateGloasCloned.justificationBits;
39
+ stateGloasView.previousJustifiedCheckpoint = stateGloasCloned.previousJustifiedCheckpoint;
40
+ stateGloasView.currentJustifiedCheckpoint = stateGloasCloned.currentJustifiedCheckpoint;
41
+ stateGloasView.finalizedCheckpoint = stateGloasCloned.finalizedCheckpoint;
42
+ stateGloasView.inactivityScores = stateGloasCloned.inactivityScores;
43
+ stateGloasView.currentSyncCommittee = stateGloasCloned.currentSyncCommittee;
44
+ stateGloasView.nextSyncCommittee = stateGloasCloned.nextSyncCommittee;
45
+ stateGloasView.latestExecutionPayloadBid.blockHash = stateFulu.latestExecutionPayloadHeader.blockHash;
46
+ stateGloasView.nextWithdrawalIndex = stateGloasCloned.nextWithdrawalIndex;
47
+ stateGloasView.nextWithdrawalValidatorIndex = stateGloasCloned.nextWithdrawalValidatorIndex;
48
+ stateGloasView.historicalSummaries = stateGloasCloned.historicalSummaries;
49
+ stateGloasView.depositRequestsStartIndex = stateGloasCloned.depositRequestsStartIndex;
50
+ stateGloasView.depositBalanceToConsume = stateGloasCloned.depositBalanceToConsume;
51
+ stateGloasView.exitBalanceToConsume = stateGloasCloned.exitBalanceToConsume;
52
+ stateGloasView.earliestExitEpoch = stateGloasCloned.earliestExitEpoch;
53
+ stateGloasView.consolidationBalanceToConsume = stateGloasCloned.consolidationBalanceToConsume;
54
+ stateGloasView.earliestConsolidationEpoch = stateGloasCloned.earliestConsolidationEpoch;
55
+ stateGloasView.pendingDeposits = stateGloasCloned.pendingDeposits;
56
+ stateGloasView.pendingPartialWithdrawals = stateGloasCloned.pendingPartialWithdrawals;
57
+ stateGloasView.pendingConsolidations = stateGloasCloned.pendingConsolidations;
58
+ stateGloasView.proposerLookahead = stateGloasCloned.proposerLookahead;
59
+
60
+ for (let i = 0; i < SLOTS_PER_HISTORICAL_ROOT; i++) {
61
+ stateGloasView.executionPayloadAvailability.set(i, true);
62
+ }
63
+ stateGloasView.latestBlockHash = stateFulu.latestExecutionPayloadHeader.blockHash;
64
+
65
+ const stateGloas = getCachedBeaconState(stateGloasView, stateFulu);
22
66
 
23
67
  stateGloas.commit();
24
68
  // Clear cache to ensure the cache of fulu fields is not used by new gloas fields
@@ -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
 
@@ -217,13 +217,13 @@ function processSlotsWithTransientCache(
217
217
  }
218
218
 
219
219
  while (postState.slot < slot) {
220
- processSlot(postState);
220
+ const fork = postState.config.getForkSeq(postState.slot);
221
+ processSlot(fork, postState);
221
222
 
222
223
  // Process epoch on the first slot of the next epoch
224
+ // We use `fork` because at fork boundary we don't want to process
225
+ // "next fork" epoch before upgrading state
223
226
  if ((postState.slot + 1) % SLOTS_PER_EPOCH === 0) {
224
- // At fork boundary we don't want to process "next fork" epoch before upgrading state
225
- const fork = postState.config.getForkSeq(postState.slot);
226
-
227
227
  const epochTransitionTimer = metrics?.epochTransitionTime.startTimer();
228
228
 
229
229
  let epochTransitionCache: EpochTransitionCache;
@@ -1,11 +1,14 @@
1
1
  import {COMPOUNDING_WITHDRAWAL_PREFIX, GENESIS_SLOT, MIN_ACTIVATION_BALANCE} from "@lodestar/params";
2
2
  import {ValidatorIndex, ssz} from "@lodestar/types";
3
3
  import {G2_POINT_AT_INFINITY} from "../constants/constants.js";
4
- import {CachedBeaconStateElectra} from "../types.js";
4
+ import {CachedBeaconStateElectra, CachedBeaconStateGloas} from "../types.js";
5
5
  import {hasEth1WithdrawalCredential} from "./capella.js";
6
+ import {hasBuilderWithdrawalCredential} from "./gloas.ts";
6
7
 
7
8
  export function hasCompoundingWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
8
- return withdrawalCredentials[0] === COMPOUNDING_WITHDRAWAL_PREFIX;
9
+ return (
10
+ withdrawalCredentials[0] === COMPOUNDING_WITHDRAWAL_PREFIX || hasBuilderWithdrawalCredential(withdrawalCredentials)
11
+ );
9
12
  }
10
13
 
11
14
  export function hasExecutionWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
@@ -14,7 +17,10 @@ export function hasExecutionWithdrawalCredential(withdrawalCredentials: Uint8Arr
14
17
  );
15
18
  }
16
19
 
17
- export function switchToCompoundingValidator(state: CachedBeaconStateElectra, index: ValidatorIndex): void {
20
+ export function switchToCompoundingValidator(
21
+ state: CachedBeaconStateElectra | CachedBeaconStateGloas,
22
+ index: ValidatorIndex
23
+ ): void {
18
24
  const validator = state.validators.get(index);
19
25
 
20
26
  // directly modifying the byte leads to ssz missing the modification resulting into
@@ -30,7 +36,10 @@ export function switchToCompoundingValidator(state: CachedBeaconStateElectra, in
30
36
  queueExcessActiveBalance(state, index);
31
37
  }
32
38
 
33
- export function queueExcessActiveBalance(state: CachedBeaconStateElectra, index: ValidatorIndex): void {
39
+ export function queueExcessActiveBalance(
40
+ state: CachedBeaconStateElectra | CachedBeaconStateGloas,
41
+ index: ValidatorIndex
42
+ ): void {
34
43
  const balance = state.balances.get(index);
35
44
  if (balance > MIN_ACTIVATION_BALANCE) {
36
45
  const validator = state.validators.getReadonly(index);
@@ -53,7 +62,7 @@ export function queueExcessActiveBalance(state: CachedBeaconStateElectra, index:
53
62
  /**
54
63
  * Since we share pubkey2index, pubkey maybe added by other epoch transition but we don't have that validator in this state
55
64
  */
56
- export function isPubkeyKnown(state: CachedBeaconStateElectra, pubkey: Uint8Array): boolean {
65
+ export function isPubkeyKnown(state: CachedBeaconStateElectra | CachedBeaconStateGloas, pubkey: Uint8Array): boolean {
57
66
  return isValidatorKnown(state, state.epochCtx.getValidatorIndex(pubkey));
58
67
  }
59
68
 
@@ -61,7 +70,7 @@ export function isPubkeyKnown(state: CachedBeaconStateElectra, pubkey: Uint8Arra
61
70
  * Since we share pubkey2index, validatorIndex maybe not null but we don't have that validator in this state
62
71
  */
63
72
  export function isValidatorKnown(
64
- state: CachedBeaconStateElectra,
73
+ state: CachedBeaconStateElectra | CachedBeaconStateGloas,
65
74
  index: ValidatorIndex | null
66
75
  ): index is ValidatorIndex {
67
76
  return index !== null && index < state.validators.length;
package/src/util/epoch.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {EPOCHS_PER_SYNC_COMMITTEE_PERIOD, GENESIS_EPOCH, MAX_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
2
2
  import {BeaconState, Epoch, Gwei, Slot, SyncPeriod} from "@lodestar/types";
3
- import {CachedBeaconStateElectra} from "../types.js";
3
+ import {CachedBeaconStateElectra, CachedBeaconStateGloas} from "../types.js";
4
4
  import {getActivationExitChurnLimit, getConsolidationChurnLimit} from "./validator.js";
5
5
 
6
6
  /**
@@ -41,7 +41,10 @@ export function computeActivationExitEpoch(epoch: Epoch): Epoch {
41
41
  return epoch + 1 + MAX_SEED_LOOKAHEAD;
42
42
  }
43
43
 
44
- export function computeExitEpochAndUpdateChurn(state: CachedBeaconStateElectra, exitBalance: Gwei): number {
44
+ export function computeExitEpochAndUpdateChurn(
45
+ state: CachedBeaconStateElectra | CachedBeaconStateGloas,
46
+ exitBalance: Gwei
47
+ ): number {
45
48
  let earliestExitEpoch = Math.max(state.earliestExitEpoch, computeActivationExitEpoch(state.epochCtx.epoch));
46
49
  const perEpochChurn = getActivationExitChurnLimit(state.epochCtx);
47
50
 
@@ -65,7 +68,7 @@ export function computeExitEpochAndUpdateChurn(state: CachedBeaconStateElectra,
65
68
  }
66
69
 
67
70
  export function computeConsolidationEpochAndUpdateChurn(
68
- state: CachedBeaconStateElectra,
71
+ state: CachedBeaconStateElectra | CachedBeaconStateGloas,
69
72
  consolidationBalance: Gwei
70
73
  ): number {
71
74
  let earliestConsolidationEpoch = Math.max(
@@ -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;
@@ -0,0 +1,58 @@
1
+ import {byteArrayEquals} from "@chainsafe/ssz";
2
+ import {
3
+ BUILDER_PAYMENT_THRESHOLD_DENOMINATOR,
4
+ BUILDER_PAYMENT_THRESHOLD_NUMERATOR,
5
+ BUILDER_WITHDRAWAL_PREFIX,
6
+ EFFECTIVE_BALANCE_INCREMENT,
7
+ SLOTS_PER_EPOCH,
8
+ } from "@lodestar/params";
9
+ import {gloas} from "@lodestar/types";
10
+ import {AttestationData} from "@lodestar/types/phase0";
11
+ import {CachedBeaconStateGloas} from "../types.ts";
12
+ import {getBlockRootAtSlot} from "./blockRoot.ts";
13
+ import {computeEpochAtSlot} from "./epoch.ts";
14
+ import {RootCache} from "./rootCache.ts";
15
+
16
+ export function hasBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
17
+ return withdrawalCredentials[0] === BUILDER_WITHDRAWAL_PREFIX;
18
+ }
19
+
20
+ export function getBuilderPaymentQuorumThreshold(state: CachedBeaconStateGloas): number {
21
+ const quorum =
22
+ Math.floor((state.epochCtx.totalActiveBalanceIncrements * EFFECTIVE_BALANCE_INCREMENT) / SLOTS_PER_EPOCH) *
23
+ BUILDER_PAYMENT_THRESHOLD_NUMERATOR;
24
+
25
+ return Math.floor(quorum / BUILDER_PAYMENT_THRESHOLD_DENOMINATOR);
26
+ }
27
+
28
+ export function isBuilderPaymentWithdrawable(
29
+ state: CachedBeaconStateGloas,
30
+ withdrawal: gloas.BuilderPendingWithdrawal
31
+ ): boolean {
32
+ const builder = state.validators.getReadonly(withdrawal.builderIndex);
33
+ const currentEpoch = computeEpochAtSlot(state.slot);
34
+
35
+ return builder.withdrawableEpoch >= currentEpoch || !builder.slashed;
36
+ }
37
+
38
+ export function isAttestationSameSlot(state: CachedBeaconStateGloas, data: AttestationData): boolean {
39
+ if (data.slot === 0) return true;
40
+
41
+ const isMatchingBlockRoot = byteArrayEquals(data.beaconBlockRoot, getBlockRootAtSlot(state, data.slot));
42
+ const isCurrentBlockRoot = !byteArrayEquals(data.beaconBlockRoot, getBlockRootAtSlot(state, data.slot - 1));
43
+
44
+ return isMatchingBlockRoot && isCurrentBlockRoot;
45
+ }
46
+
47
+ export function isAttestationSameSlotRootCache(rootCache: RootCache, data: AttestationData): boolean {
48
+ if (data.slot === 0) return true;
49
+
50
+ const isMatchingBlockRoot = byteArrayEquals(data.beaconBlockRoot, rootCache.getBlockRootAtSlot(data.slot));
51
+ const isCurrentBlockRoot = !byteArrayEquals(data.beaconBlockRoot, rootCache.getBlockRootAtSlot(data.slot - 1));
52
+
53
+ return isMatchingBlockRoot && isCurrentBlockRoot;
54
+ }
55
+
56
+ export function isParentBlockFull(state: CachedBeaconStateGloas): boolean {
57
+ return byteArrayEquals(state.latestExecutionPayloadBid.blockHash, state.latestBlockHash);
58
+ }
package/src/util/seed.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  } from "@chainsafe/swap-or-not-shuffle";
6
6
  import {
7
7
  DOMAIN_BEACON_PROPOSER,
8
+ DOMAIN_PTC_ATTESTER,
8
9
  DOMAIN_SYNC_COMMITTEE,
9
10
  EFFECTIVE_BALANCE_INCREMENT,
10
11
  EPOCHS_PER_HISTORICAL_VECTOR,
@@ -12,6 +13,7 @@ import {
12
13
  MAX_EFFECTIVE_BALANCE,
13
14
  MAX_EFFECTIVE_BALANCE_ELECTRA,
14
15
  MIN_SEED_LOOKAHEAD,
16
+ PTC_SIZE,
15
17
  SHUFFLE_ROUND_COUNT,
16
18
  SLOTS_PER_EPOCH,
17
19
  SYNC_COMMITTEE_SIZE,
@@ -19,7 +21,7 @@ import {
19
21
  import {Bytes32, DomainType, Epoch, ValidatorIndex} from "@lodestar/types";
20
22
  import {assert, bytesToBigInt, bytesToInt, intToBytes} from "@lodestar/utils";
21
23
  import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
22
- import {BeaconStateAllForks, CachedBeaconStateAllForks} from "../types.js";
24
+ import {BeaconStateAllForks, BeaconStateGloas, CachedBeaconStateAllForks} from "../types.js";
23
25
  import {computeEpochAtSlot, computeStartSlotAtEpoch} from "./epoch.js";
24
26
 
25
27
  /**
@@ -266,6 +268,60 @@ export function getNextSyncCommitteeIndices(
266
268
  );
267
269
  }
268
270
 
271
+ export function naiveGetPayloadTimlinessCommitteeIndices(
272
+ state: BeaconStateGloas,
273
+ shuffling: {committees: Uint32Array[][]},
274
+ effectiveBalanceIncrements: EffectiveBalanceIncrements,
275
+ epoch: Epoch
276
+ ): ValidatorIndex[][] {
277
+ const epochSeed = getSeed(state, epoch, DOMAIN_PTC_ATTESTER);
278
+ const startSlot = computeStartSlotAtEpoch(epoch);
279
+ const committeeIndices = [];
280
+
281
+ for (let slot = startSlot; slot < startSlot + SLOTS_PER_EPOCH; slot++) {
282
+ const slotCommittees = shuffling.committees[slot % SLOTS_PER_EPOCH];
283
+ const indices = naiveComputePayloadTimelinessCommitteeIndices(
284
+ effectiveBalanceIncrements,
285
+ slotCommittees.flatMap((c) => Array.from(c)),
286
+ digest(Buffer.concat([epochSeed, intToBytes(slot, 8)]))
287
+ );
288
+ committeeIndices.push(indices);
289
+ }
290
+
291
+ return committeeIndices;
292
+ }
293
+
294
+ export function naiveComputePayloadTimelinessCommitteeIndices(
295
+ effectiveBalanceIncrements: EffectiveBalanceIncrements,
296
+ indices: ArrayLike<ValidatorIndex>,
297
+ seed: Uint8Array
298
+ ): ValidatorIndex[] {
299
+ if (indices.length === 0) {
300
+ throw Error("Validator indices must not be empty");
301
+ }
302
+
303
+ const result = [];
304
+
305
+ const MAX_RANDOM_VALUE = 2 ** 16 - 1;
306
+ const MAX_EFFECTIVE_BALANCE_INCREMENT = MAX_EFFECTIVE_BALANCE_ELECTRA / EFFECTIVE_BALANCE_INCREMENT;
307
+
308
+ let i = 0;
309
+ while (result.length < PTC_SIZE) {
310
+ const candidateIndex = indices[i % indices.length];
311
+ const randomBytes = digest(Buffer.concat([seed, intToBytes(Math.floor(i / 16), 8, "le")]));
312
+ const offset = (i % 16) * 2;
313
+ const randomValue = bytesToInt(randomBytes.subarray(offset, offset + 2));
314
+
315
+ const effectiveBalanceIncrement = effectiveBalanceIncrements[candidateIndex];
316
+ if (effectiveBalanceIncrement * MAX_RANDOM_VALUE >= MAX_EFFECTIVE_BALANCE_INCREMENT * randomValue) {
317
+ result.push(candidateIndex);
318
+ }
319
+ i += 1;
320
+ }
321
+
322
+ return result;
323
+ }
324
+
269
325
  /**
270
326
  * Return the shuffled validator index corresponding to ``seed`` (and ``index_count``).
271
327
  *