@lodestar/state-transition 1.39.1 → 1.40.0-dev.1020f27ca9

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 (218) hide show
  1. package/lib/block/index.d.ts +1 -0
  2. package/lib/block/index.d.ts.map +1 -1
  3. package/lib/block/index.js +1 -0
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/isValidIndexedAttestation.d.ts +4 -5
  6. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  7. package/lib/block/isValidIndexedAttestation.js +9 -10
  8. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  9. package/lib/block/isValidIndexedPayloadAttestation.d.ts.map +1 -1
  10. package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
  11. package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
  12. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  13. package/lib/block/processAttestationPhase0.js +1 -1
  14. package/lib/block/processAttestationPhase0.js.map +1 -1
  15. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  16. package/lib/block/processAttestationsAltair.js +2 -2
  17. package/lib/block/processAttestationsAltair.js.map +1 -1
  18. package/lib/block/processAttesterSlashing.d.ts +3 -2
  19. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  20. package/lib/block/processAttesterSlashing.js +3 -3
  21. package/lib/block/processAttesterSlashing.js.map +1 -1
  22. package/lib/block/processBlsToExecutionChange.d.ts +3 -1
  23. package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
  24. package/lib/block/processBlsToExecutionChange.js +7 -11
  25. package/lib/block/processBlsToExecutionChange.js.map +1 -1
  26. package/lib/block/processConsolidationRequest.d.ts +1 -2
  27. package/lib/block/processConsolidationRequest.d.ts.map +1 -1
  28. package/lib/block/processConsolidationRequest.js +2 -2
  29. package/lib/block/processConsolidationRequest.js.map +1 -1
  30. package/lib/block/processDepositRequest.d.ts +8 -2
  31. package/lib/block/processDepositRequest.d.ts.map +1 -1
  32. package/lib/block/processDepositRequest.js +81 -8
  33. package/lib/block/processDepositRequest.js.map +1 -1
  34. package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
  35. package/lib/block/processExecutionPayloadBid.js +16 -29
  36. package/lib/block/processExecutionPayloadBid.js.map +1 -1
  37. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
  38. package/lib/block/processExecutionPayloadEnvelope.js +26 -25
  39. package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
  40. package/lib/block/processOperations.js +2 -2
  41. package/lib/block/processOperations.js.map +1 -1
  42. package/lib/block/processProposerSlashing.d.ts +5 -2
  43. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  44. package/lib/block/processProposerSlashing.js +8 -6
  45. package/lib/block/processProposerSlashing.js.map +1 -1
  46. package/lib/block/processSyncCommittee.d.ts +1 -2
  47. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  48. package/lib/block/processSyncCommittee.js +5 -5
  49. package/lib/block/processSyncCommittee.js.map +1 -1
  50. package/lib/block/processVoluntaryExit.d.ts +1 -1
  51. package/lib/block/processVoluntaryExit.d.ts.map +1 -1
  52. package/lib/block/processVoluntaryExit.js +45 -3
  53. package/lib/block/processVoluntaryExit.js.map +1 -1
  54. package/lib/block/processWithdrawalRequest.js +1 -1
  55. package/lib/block/processWithdrawalRequest.js.map +1 -1
  56. package/lib/block/processWithdrawals.d.ts +1 -0
  57. package/lib/block/processWithdrawals.d.ts.map +1 -1
  58. package/lib/block/processWithdrawals.js +121 -66
  59. package/lib/block/processWithdrawals.js.map +1 -1
  60. package/lib/cache/epochCache.d.ts +8 -28
  61. package/lib/cache/epochCache.d.ts.map +1 -1
  62. package/lib/cache/epochCache.js +40 -180
  63. package/lib/cache/epochCache.js.map +1 -1
  64. package/lib/cache/epochTransitionCache.d.ts +5 -12
  65. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  66. package/lib/cache/epochTransitionCache.js +4 -14
  67. package/lib/cache/epochTransitionCache.js.map +1 -1
  68. package/lib/cache/stateCache.d.ts.map +1 -1
  69. package/lib/cache/stateCache.js +1 -2
  70. package/lib/cache/stateCache.js.map +1 -1
  71. package/lib/epoch/processBuilderPendingPayments.d.ts.map +1 -1
  72. package/lib/epoch/processBuilderPendingPayments.js +1 -4
  73. package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
  74. package/lib/epoch/processProposerLookahead.d.ts.map +1 -1
  75. package/lib/epoch/processProposerLookahead.js +3 -6
  76. package/lib/epoch/processProposerLookahead.js.map +1 -1
  77. package/lib/index.d.ts +1 -1
  78. package/lib/index.d.ts.map +1 -1
  79. package/lib/index.js +1 -1
  80. package/lib/index.js.map +1 -1
  81. package/lib/rewards/blockRewards.d.ts +2 -1
  82. package/lib/rewards/blockRewards.d.ts.map +1 -1
  83. package/lib/rewards/blockRewards.js +3 -2
  84. package/lib/rewards/blockRewards.js.map +1 -1
  85. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
  86. package/lib/rewards/syncCommitteeRewards.js +10 -11
  87. package/lib/rewards/syncCommitteeRewards.js.map +1 -1
  88. package/lib/signatureSets/attesterSlashings.d.ts +3 -4
  89. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  90. package/lib/signatureSets/attesterSlashings.js +6 -6
  91. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  92. package/lib/signatureSets/blsToExecutionChange.d.ts +4 -5
  93. package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
  94. package/lib/signatureSets/blsToExecutionChange.js +2 -2
  95. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  96. package/lib/signatureSets/executionPayloadBid.d.ts +4 -0
  97. package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -0
  98. package/lib/signatureSets/executionPayloadBid.js +8 -0
  99. package/lib/signatureSets/executionPayloadBid.js.map +1 -0
  100. package/lib/signatureSets/executionPayloadEnvelope.d.ts +4 -0
  101. package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -0
  102. package/lib/signatureSets/executionPayloadEnvelope.js +8 -0
  103. package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -0
  104. package/lib/signatureSets/index.d.ts +3 -2
  105. package/lib/signatureSets/index.d.ts.map +1 -1
  106. package/lib/signatureSets/index.js +10 -8
  107. package/lib/signatureSets/index.js.map +1 -1
  108. package/lib/signatureSets/indexedAttestation.d.ts +3 -4
  109. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  110. package/lib/signatureSets/indexedAttestation.js +6 -6
  111. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  112. package/lib/signatureSets/indexedPayloadAttestation.d.ts +5 -4
  113. package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
  114. package/lib/signatureSets/indexedPayloadAttestation.js +3 -3
  115. package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
  116. package/lib/signatureSets/proposer.d.ts +3 -3
  117. package/lib/signatureSets/proposer.d.ts.map +1 -1
  118. package/lib/signatureSets/proposer.js +12 -12
  119. package/lib/signatureSets/proposer.js.map +1 -1
  120. package/lib/signatureSets/proposerSlashings.d.ts +2 -3
  121. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  122. package/lib/signatureSets/proposerSlashings.js +6 -6
  123. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  124. package/lib/signatureSets/randao.d.ts +1 -1
  125. package/lib/signatureSets/randao.d.ts.map +1 -1
  126. package/lib/signatureSets/randao.js +4 -4
  127. package/lib/signatureSets/randao.js.map +1 -1
  128. package/lib/signatureSets/voluntaryExits.d.ts +2 -2
  129. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  130. package/lib/signatureSets/voluntaryExits.js +6 -6
  131. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  132. package/lib/types.d.ts +1 -1
  133. package/lib/types.d.ts.map +1 -1
  134. package/lib/util/electra.d.ts.map +1 -1
  135. package/lib/util/electra.js +1 -2
  136. package/lib/util/electra.js.map +1 -1
  137. package/lib/util/epochShuffling.d.ts +1 -34
  138. package/lib/util/epochShuffling.d.ts.map +1 -1
  139. package/lib/util/epochShuffling.js +1 -1
  140. package/lib/util/epochShuffling.js.map +1 -1
  141. package/lib/util/gloas.d.ts +46 -5
  142. package/lib/util/gloas.d.ts.map +1 -1
  143. package/lib/util/gloas.js +91 -5
  144. package/lib/util/gloas.js.map +1 -1
  145. package/lib/util/index.d.ts +2 -2
  146. package/lib/util/index.d.ts.map +1 -1
  147. package/lib/util/index.js +2 -2
  148. package/lib/util/index.js.map +1 -1
  149. package/lib/util/interop.js +1 -1
  150. package/lib/util/interop.js.map +1 -1
  151. package/lib/util/shuffling.d.ts +58 -0
  152. package/lib/util/shuffling.d.ts.map +1 -0
  153. package/lib/util/shuffling.js +175 -0
  154. package/lib/util/shuffling.js.map +1 -0
  155. package/lib/util/signatureSets.d.ts +38 -5
  156. package/lib/util/signatureSets.d.ts.map +1 -1
  157. package/lib/util/signatureSets.js +48 -6
  158. package/lib/util/signatureSets.js.map +1 -1
  159. package/lib/util/validator.d.ts +6 -1
  160. package/lib/util/validator.d.ts.map +1 -1
  161. package/lib/util/validator.js +26 -16
  162. package/lib/util/validator.js.map +1 -1
  163. package/package.json +8 -8
  164. package/src/block/index.ts +1 -0
  165. package/src/block/isValidIndexedAttestation.ts +18 -12
  166. package/src/block/isValidIndexedPayloadAttestation.ts +4 -1
  167. package/src/block/processAttestationPhase0.ts +2 -1
  168. package/src/block/processAttestationsAltair.ts +2 -8
  169. package/src/block/processAttesterSlashing.ts +16 -4
  170. package/src/block/processBlsToExecutionChange.ts +13 -14
  171. package/src/block/processConsolidationRequest.ts +2 -3
  172. package/src/block/processDepositRequest.ts +101 -8
  173. package/src/block/processExecutionPayloadBid.ts +20 -42
  174. package/src/block/processExecutionPayloadEnvelope.ts +34 -30
  175. package/src/block/processOperations.ts +2 -2
  176. package/src/block/processProposerSlashing.ts +22 -12
  177. package/src/block/processSyncCommittee.ts +3 -6
  178. package/src/block/processVoluntaryExit.ts +60 -5
  179. package/src/block/processWithdrawalRequest.ts +1 -1
  180. package/src/block/processWithdrawals.ts +168 -70
  181. package/src/cache/epochCache.ts +52 -214
  182. package/src/cache/epochTransitionCache.ts +9 -34
  183. package/src/cache/stateCache.ts +1 -2
  184. package/src/epoch/processBuilderPendingPayments.ts +1 -5
  185. package/src/epoch/processProposerLookahead.ts +3 -7
  186. package/src/index.ts +0 -2
  187. package/src/rewards/blockRewards.ts +6 -3
  188. package/src/rewards/syncCommitteeRewards.ts +10 -13
  189. package/src/signatureSets/attesterSlashings.ts +3 -7
  190. package/src/signatureSets/blsToExecutionChange.ts +5 -6
  191. package/src/signatureSets/executionPayloadBid.ts +14 -0
  192. package/src/signatureSets/executionPayloadEnvelope.ts +13 -0
  193. package/src/signatureSets/index.ts +8 -9
  194. package/src/signatureSets/indexedAttestation.ts +2 -7
  195. package/src/signatureSets/indexedPayloadAttestation.ts +9 -7
  196. package/src/signatureSets/proposer.ts +8 -12
  197. package/src/signatureSets/proposerSlashings.ts +4 -7
  198. package/src/signatureSets/randao.ts +4 -8
  199. package/src/signatureSets/voluntaryExits.ts +5 -10
  200. package/src/types.ts +1 -0
  201. package/src/util/electra.ts +1 -4
  202. package/src/util/epochShuffling.ts +2 -43
  203. package/src/util/gloas.ts +116 -10
  204. package/src/util/index.ts +2 -2
  205. package/src/util/interop.ts +1 -1
  206. package/src/util/shuffling.ts +234 -0
  207. package/src/util/signatureSets.ts +84 -8
  208. package/src/util/validator.ts +31 -16
  209. package/lib/util/calculateCommitteeAssignments.d.ts +0 -12
  210. package/lib/util/calculateCommitteeAssignments.d.ts.map +0 -1
  211. package/lib/util/calculateCommitteeAssignments.js +0 -26
  212. package/lib/util/calculateCommitteeAssignments.js.map +0 -1
  213. package/lib/util/shufflingDecisionRoot.d.ts +0 -20
  214. package/lib/util/shufflingDecisionRoot.d.ts.map +0 -1
  215. package/lib/util/shufflingDecisionRoot.js +0 -76
  216. package/lib/util/shufflingDecisionRoot.js.map +0 -1
  217. package/src/util/calculateCommitteeAssignments.ts +0 -43
  218. package/src/util/shufflingDecisionRoot.ts +0 -81
@@ -4,8 +4,6 @@ import {BeaconBlock, ValidatorIndex, altair, rewards} from "@lodestar/types";
4
4
  import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
5
5
  import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../cache/stateCache.js";
6
6
 
7
- type BalanceRecord = {val: number}; // Use val for convenient way to increment/decrement balance
8
-
9
7
  export async function computeSyncCommitteeRewards(
10
8
  config: BeaconConfig,
11
9
  index2pubkey: Index2PubkeyCache,
@@ -19,7 +17,7 @@ export async function computeSyncCommitteeRewards(
19
17
  }
20
18
 
21
19
  const altairBlock = block as altair.BeaconBlock;
22
- const preStateAltair = preState as CachedBeaconStateAltair;
20
+ const preStateAltair = preState.clone() as CachedBeaconStateAltair;
23
21
 
24
22
  // Bound syncCommitteeValidatorIndices in case it goes beyond SYNC_COMMITTEE_SIZE just to be safe
25
23
  const syncCommitteeValidatorIndices = preStateAltair.epochCtx.currentSyncCommitteeIndexed.validatorIndices.slice(
@@ -29,24 +27,23 @@ export async function computeSyncCommitteeRewards(
29
27
  const {syncParticipantReward} = preStateAltair.epochCtx;
30
28
  const {syncCommitteeBits} = altairBlock.body.syncAggregate;
31
29
 
32
- // Use balance of each committee as starting point such that we cap the penalty to avoid balance dropping below 0
33
- const balances: Map<ValidatorIndex, BalanceRecord> = new Map();
34
- for (const i of syncCommitteeValidatorIndices) {
35
- balances.set(i, {val: preStateAltair.balances.get(i)});
36
- }
30
+ // Track reward deltas per validator (can appear multiple times in sync committee)
31
+ const rewardDeltas: Map<ValidatorIndex, number> = new Map();
37
32
 
38
- for (const i of syncCommitteeValidatorIndices) {
39
- const balanceRecord = balances.get(i) as BalanceRecord;
33
+ // Iterate by position index to correctly access syncCommitteeBits
34
+ for (let i = 0; i < syncCommitteeValidatorIndices.length; i++) {
35
+ const validatorIndex = syncCommitteeValidatorIndices[i];
36
+ const currentDelta = rewardDeltas.get(validatorIndex) ?? 0;
40
37
  if (syncCommitteeBits.get(i)) {
41
38
  // Positive rewards for participants
42
- balanceRecord.val += syncParticipantReward;
39
+ rewardDeltas.set(validatorIndex, currentDelta + syncParticipantReward);
43
40
  } else {
44
41
  // Negative rewards for non participants
45
- balanceRecord.val = Math.max(0, balanceRecord.val - syncParticipantReward);
42
+ rewardDeltas.set(validatorIndex, currentDelta - syncParticipantReward);
46
43
  }
47
44
  }
48
45
 
49
- const rewards = Array.from(balances, ([validatorIndex, v]) => ({validatorIndex, reward: v.val}));
46
+ const rewards = Array.from(rewardDeltas, ([validatorIndex, reward]) => ({validatorIndex, reward}));
50
47
 
51
48
  if (validatorIds.length) {
52
49
  const filtersSet = new Set(validatorIds);
@@ -1,38 +1,34 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
3
3
  import {AttesterSlashing, IndexedAttestationBigint, SignedBeaconBlock, Slot, ssz} from "@lodestar/types";
4
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
5
4
  import {ISignatureSet, SignatureSetType, computeSigningRoot, computeStartSlotAtEpoch} from "../util/index.js";
6
5
 
7
6
  /** Get signature sets from all AttesterSlashing objects in a block */
8
7
  export function getAttesterSlashingsSignatureSets(
9
8
  config: BeaconConfig,
10
- index2pubkey: Index2PubkeyCache,
11
9
  signedBlock: SignedBeaconBlock
12
10
  ): ISignatureSet[] {
13
11
  // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
14
12
  // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
15
13
  const blockSlot = signedBlock.message.slot;
16
14
  return signedBlock.message.body.attesterSlashings.flatMap((attesterSlashing) =>
17
- getAttesterSlashingSignatureSets(config, index2pubkey, blockSlot, attesterSlashing)
15
+ getAttesterSlashingSignatureSets(config, blockSlot, attesterSlashing)
18
16
  );
19
17
  }
20
18
 
21
19
  /** Get signature sets from a single AttesterSlashing object */
22
20
  export function getAttesterSlashingSignatureSets(
23
21
  config: BeaconConfig,
24
- index2pubkey: Index2PubkeyCache,
25
22
  stateSlot: Slot,
26
23
  attesterSlashing: AttesterSlashing
27
24
  ): ISignatureSet[] {
28
25
  return [attesterSlashing.attestation1, attesterSlashing.attestation2].map((attestation) =>
29
- getIndexedAttestationBigintSignatureSet(config, index2pubkey, stateSlot, attestation)
26
+ getIndexedAttestationBigintSignatureSet(config, stateSlot, attestation)
30
27
  );
31
28
  }
32
29
 
33
30
  export function getIndexedAttestationBigintSignatureSet(
34
31
  config: BeaconConfig,
35
- index2pubkey: Index2PubkeyCache,
36
32
  stateSlot: Slot,
37
33
  indexedAttestation: IndexedAttestationBigint
38
34
  ): ISignatureSet {
@@ -41,7 +37,7 @@ export function getIndexedAttestationBigintSignatureSet(
41
37
 
42
38
  return {
43
39
  type: SignatureSetType.aggregate,
44
- pubkeys: indexedAttestation.attestingIndices.map((i) => index2pubkey[i]),
40
+ indices: indexedAttestation.attestingIndices.map((i) => Number(i)),
45
41
  signingRoot: computeSigningRoot(ssz.phase0.AttestationDataBigint, indexedAttestation.data, domain),
46
42
  signature: indexedAttestation.signature,
47
43
  };
@@ -2,14 +2,13 @@ import {PublicKey} from "@chainsafe/blst";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
3
  import {DOMAIN_BLS_TO_EXECUTION_CHANGE, ForkName} from "@lodestar/params";
4
4
  import {capella, ssz} from "@lodestar/types";
5
- import {CachedBeaconStateAllForks} from "../types.js";
6
- import {ISignatureSet, SignatureSetType, computeSigningRoot, verifySignatureSet} from "../util/index.js";
5
+ import {SignatureSetType, SingleSignatureSet, computeSigningRoot, verifySignatureSet} from "../util/index.js";
7
6
 
8
7
  export function verifyBlsToExecutionChangeSignature(
9
- state: CachedBeaconStateAllForks,
8
+ config: BeaconConfig,
10
9
  signedBLSToExecutionChange: capella.SignedBLSToExecutionChange
11
10
  ): boolean {
12
- return verifySignatureSet(getBlsToExecutionChangeSignatureSet(state.config, signedBLSToExecutionChange));
11
+ return verifySignatureSet(getBlsToExecutionChangeSignatureSet(config, signedBLSToExecutionChange));
13
12
  }
14
13
 
15
14
  /**
@@ -18,7 +17,7 @@ export function verifyBlsToExecutionChangeSignature(
18
17
  export function getBlsToExecutionChangeSignatureSet(
19
18
  config: BeaconConfig,
20
19
  signedBLSToExecutionChange: capella.SignedBLSToExecutionChange
21
- ): ISignatureSet {
20
+ ): SingleSignatureSet {
22
21
  // signatureFork for signing domain is fixed
23
22
  const signatureFork = ForkName.phase0;
24
23
  const domain = config.getDomainAtFork(signatureFork, DOMAIN_BLS_TO_EXECUTION_CHANGE);
@@ -36,7 +35,7 @@ export function getBlsToExecutionChangeSignatureSet(
36
35
  export function getBlsToExecutionChangeSignatureSets(
37
36
  config: BeaconConfig,
38
37
  signedBlock: capella.SignedBeaconBlock
39
- ): ISignatureSet[] {
38
+ ): SingleSignatureSet[] {
40
39
  return signedBlock.message.body.blsToExecutionChanges.map((blsToExecutionChange) =>
41
40
  getBlsToExecutionChangeSignatureSet(config, blsToExecutionChange)
42
41
  );
@@ -0,0 +1,14 @@
1
+ import {BeaconConfig} from "@lodestar/config";
2
+ import {DOMAIN_BEACON_BUILDER} from "@lodestar/params";
3
+ import {Slot, gloas, ssz} from "@lodestar/types";
4
+ import {computeSigningRoot} from "../util/index.js";
5
+
6
+ export function getExecutionPayloadBidSigningRoot(
7
+ config: BeaconConfig,
8
+ stateSlot: Slot,
9
+ bid: gloas.ExecutionPayloadBid
10
+ ): Uint8Array {
11
+ const domain = config.getDomain(stateSlot, DOMAIN_BEACON_BUILDER);
12
+
13
+ return computeSigningRoot(ssz.gloas.ExecutionPayloadBid, bid, domain);
14
+ }
@@ -0,0 +1,13 @@
1
+ import {BeaconConfig} from "@lodestar/config";
2
+ import {DOMAIN_BEACON_BUILDER} from "@lodestar/params";
3
+ import {gloas, ssz} from "@lodestar/types";
4
+ import {computeSigningRoot} from "../util/index.js";
5
+
6
+ export function getExecutionPayloadEnvelopeSigningRoot(
7
+ config: BeaconConfig,
8
+ envelope: gloas.ExecutionPayloadEnvelope
9
+ ): Uint8Array {
10
+ const domain = config.getDomain(envelope.slot, DOMAIN_BEACON_BUILDER);
11
+
12
+ return computeSigningRoot(ssz.gloas.ExecutionPayloadEnvelope, envelope, domain);
13
+ }
@@ -2,7 +2,6 @@ import {BeaconConfig} from "@lodestar/config";
2
2
  import {ForkSeq} from "@lodestar/params";
3
3
  import {IndexedAttestation, SignedBeaconBlock, altair, capella} from "@lodestar/types";
4
4
  import {getSyncCommitteeSignatureSet} from "../block/processSyncCommittee.js";
5
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
6
5
  import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
7
6
  import {ISignatureSet} from "../util/index.js";
8
7
  import {getAttesterSlashingsSignatureSets} from "./attesterSlashings.js";
@@ -15,6 +14,8 @@ import {getVoluntaryExitsSignatureSets} from "./voluntaryExits.js";
15
14
 
16
15
  export * from "./attesterSlashings.js";
17
16
  export * from "./blsToExecutionChange.js";
17
+ export * from "./executionPayloadBid.js";
18
+ export * from "./executionPayloadEnvelope.js";
18
19
  export * from "./indexedAttestation.js";
19
20
  export * from "./indexedPayloadAttestation.js";
20
21
  export * from "./proposer.js";
@@ -28,7 +29,6 @@ export * from "./voluntaryExits.js";
28
29
  */
29
30
  export function getBlockSignatureSets(
30
31
  config: BeaconConfig,
31
- index2pubkey: Index2PubkeyCache,
32
32
  currentSyncCommitteeIndexed: SyncCommitteeCache,
33
33
  signedBlock: SignedBeaconBlock,
34
34
  indexedAttestations: IndexedAttestation[],
@@ -41,22 +41,21 @@ export function getBlockSignatureSets(
41
41
  const fork = config.getForkSeq(signedBlock.message.slot);
42
42
 
43
43
  const signatureSets = [
44
- getRandaoRevealSignatureSet(config, index2pubkey, signedBlock.message),
45
- ...getProposerSlashingsSignatureSets(config, index2pubkey, signedBlock),
46
- ...getAttesterSlashingsSignatureSets(config, index2pubkey, signedBlock),
47
- ...getAttestationsSignatureSets(config, index2pubkey, signedBlock, indexedAttestations),
48
- ...getVoluntaryExitsSignatureSets(config, index2pubkey, signedBlock),
44
+ getRandaoRevealSignatureSet(config, signedBlock.message),
45
+ ...getProposerSlashingsSignatureSets(config, signedBlock),
46
+ ...getAttesterSlashingsSignatureSets(config, signedBlock),
47
+ ...getAttestationsSignatureSets(config, signedBlock, indexedAttestations),
48
+ ...getVoluntaryExitsSignatureSets(config, signedBlock),
49
49
  ];
50
50
 
51
51
  if (!opts?.skipProposerSignature) {
52
- signatureSets.push(getBlockProposerSignatureSet(config, index2pubkey, signedBlock));
52
+ signatureSets.push(getBlockProposerSignatureSet(config, signedBlock));
53
53
  }
54
54
 
55
55
  // Only after altair fork, validate tSyncCommitteeSignature
56
56
  if (fork >= ForkSeq.altair) {
57
57
  const syncCommitteeSignatureSet = getSyncCommitteeSignatureSet(
58
58
  config,
59
- index2pubkey,
60
59
  currentSyncCommitteeIndexed,
61
60
  (signedBlock as altair.SignedBeaconBlock).message
62
61
  );
@@ -1,7 +1,6 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params";
3
3
  import {IndexedAttestation, SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
4
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
5
4
  import {
6
5
  ISignatureSet,
7
6
  computeSigningRoot,
@@ -22,13 +21,12 @@ export function getAttestationDataSigningRoot(
22
21
 
23
22
  export function getAttestationWithIndicesSignatureSet(
24
23
  config: BeaconConfig,
25
- index2pubkey: Index2PubkeyCache,
26
24
  stateSlot: Slot,
27
25
  attestation: Pick<phase0.Attestation, "data" | "signature">,
28
26
  attestingIndices: number[]
29
27
  ): ISignatureSet {
30
28
  return createAggregateSignatureSetFromComponents(
31
- attestingIndices.map((i) => index2pubkey[i]),
29
+ attestingIndices,
32
30
  getAttestationDataSigningRoot(config, stateSlot, attestation.data),
33
31
  attestation.signature
34
32
  );
@@ -36,13 +34,11 @@ export function getAttestationWithIndicesSignatureSet(
36
34
 
37
35
  export function getIndexedAttestationSignatureSet(
38
36
  config: BeaconConfig,
39
- index2pubkey: Index2PubkeyCache,
40
37
  stateSlot: Slot,
41
38
  indexedAttestation: IndexedAttestation
42
39
  ): ISignatureSet {
43
40
  return getAttestationWithIndicesSignatureSet(
44
41
  config,
45
- index2pubkey,
46
42
  stateSlot,
47
43
  indexedAttestation,
48
44
  indexedAttestation.attestingIndices
@@ -51,7 +47,6 @@ export function getIndexedAttestationSignatureSet(
51
47
 
52
48
  export function getAttestationsSignatureSets(
53
49
  config: BeaconConfig,
54
- index2pubkey: Index2PubkeyCache,
55
50
  signedBlock: SignedBeaconBlock,
56
51
  indexedAttestations: IndexedAttestation[]
57
52
  ): ISignatureSet[] {
@@ -64,6 +59,6 @@ export function getAttestationsSignatureSets(
64
59
  // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
65
60
  const blockSlot = signedBlock.message.slot;
66
61
  return indexedAttestations.map((indexedAttestation) =>
67
- getIndexedAttestationSignatureSet(config, index2pubkey, blockSlot, indexedAttestation)
62
+ getIndexedAttestationSignatureSet(config, blockSlot, indexedAttestation)
68
63
  );
69
64
  }
@@ -1,24 +1,26 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {DOMAIN_PTC_ATTESTER} from "@lodestar/params";
2
- import {gloas, ssz} from "@lodestar/types";
3
- import {CachedBeaconStateGloas} from "../types.ts";
4
- import {ISignatureSet, computeSigningRoot, createAggregateSignatureSetFromComponents} from "../util/index.ts";
3
+ import {Slot, gloas, ssz} from "@lodestar/types";
4
+ import {CachedBeaconStateGloas} from "../types.js";
5
+ import {ISignatureSet, computeSigningRoot, createAggregateSignatureSetFromComponents} from "../util/index.js";
5
6
 
6
7
  export function getIndexedPayloadAttestationSignatureSet(
7
8
  state: CachedBeaconStateGloas,
8
9
  indexedPayloadAttestation: gloas.IndexedPayloadAttestation
9
10
  ): ISignatureSet {
10
11
  return createAggregateSignatureSetFromComponents(
11
- indexedPayloadAttestation.attestingIndices.map((i) => state.epochCtx.index2pubkey[i]),
12
- getPayloadAttestationDataSigningRoot(state, indexedPayloadAttestation.data),
12
+ indexedPayloadAttestation.attestingIndices,
13
+ getPayloadAttestationDataSigningRoot(state.config, state.slot, indexedPayloadAttestation.data),
13
14
  indexedPayloadAttestation.signature
14
15
  );
15
16
  }
16
17
 
17
18
  export function getPayloadAttestationDataSigningRoot(
18
- state: CachedBeaconStateGloas,
19
+ config: BeaconConfig,
20
+ stateSlot: Slot,
19
21
  data: gloas.PayloadAttestationData
20
22
  ): Uint8Array {
21
- const domain = state.config.getDomain(state.slot, DOMAIN_PTC_ATTESTER);
23
+ const domain = config.getDomain(stateSlot, DOMAIN_PTC_ATTESTER);
22
24
 
23
25
  return computeSigningRoot(ssz.gloas.PayloadAttestationData, data, domain);
24
26
  }
@@ -10,13 +10,12 @@ export function verifyProposerSignature(
10
10
  index2pubkey: Index2PubkeyCache,
11
11
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
12
12
  ): boolean {
13
- const signatureSet = getBlockProposerSignatureSet(config, index2pubkey, signedBlock);
14
- return verifySignatureSet(signatureSet);
13
+ const signatureSet = getBlockProposerSignatureSet(config, signedBlock);
14
+ return verifySignatureSet(signatureSet, index2pubkey);
15
15
  }
16
16
 
17
17
  export function getBlockProposerSignatureSet(
18
18
  config: BeaconConfig,
19
- index2pubkey: Index2PubkeyCache,
20
19
  signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
21
20
  ): ISignatureSet {
22
21
  // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
@@ -29,8 +28,8 @@ export function getBlockProposerSignatureSet(
29
28
  : config.getForkTypes(signedBlock.message.slot).BeaconBlock;
30
29
 
31
30
  return {
32
- type: SignatureSetType.single,
33
- pubkey: index2pubkey[signedBlock.message.proposerIndex],
31
+ type: SignatureSetType.indexed,
32
+ index: signedBlock.message.proposerIndex,
34
33
  signingRoot: computeSigningRoot(blockType, signedBlock.message, domain),
35
34
  signature: signedBlock.signature,
36
35
  };
@@ -38,32 +37,29 @@ export function getBlockProposerSignatureSet(
38
37
 
39
38
  export function getBlockHeaderProposerSignatureSetByParentStateSlot(
40
39
  config: BeaconConfig,
41
- index2pubkey: Index2PubkeyCache,
42
40
  parentStateSlot: Slot,
43
41
  signedBlockHeader: phase0.SignedBeaconBlockHeader
44
42
  ) {
45
- return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, parentStateSlot);
43
+ return getBlockHeaderProposerSignatureSet(config, signedBlockHeader, parentStateSlot);
46
44
  }
47
45
 
48
46
  export function getBlockHeaderProposerSignatureSetByHeaderSlot(
49
47
  config: BeaconConfig,
50
- index2pubkey: Index2PubkeyCache,
51
48
  signedBlockHeader: phase0.SignedBeaconBlockHeader
52
49
  ) {
53
- return getBlockHeaderProposerSignatureSet(config, index2pubkey, signedBlockHeader, signedBlockHeader.message.slot);
50
+ return getBlockHeaderProposerSignatureSet(config, signedBlockHeader, signedBlockHeader.message.slot);
54
51
  }
55
52
 
56
53
  function getBlockHeaderProposerSignatureSet(
57
54
  config: BeaconConfig,
58
- index2pubkey: Index2PubkeyCache,
59
55
  signedBlockHeader: phase0.SignedBeaconBlockHeader,
60
56
  domainSlot: Slot
61
57
  ): ISignatureSet {
62
58
  const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
63
59
 
64
60
  return {
65
- type: SignatureSetType.single,
66
- pubkey: index2pubkey[signedBlockHeader.message.proposerIndex],
61
+ type: SignatureSetType.indexed,
62
+ index: signedBlockHeader.message.proposerIndex,
67
63
  signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeader, signedBlockHeader.message, domain),
68
64
  signature: signedBlockHeader.signature,
69
65
  };
@@ -1,7 +1,6 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
3
3
  import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
4
- import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
5
4
  import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
6
5
 
7
6
  /**
@@ -9,11 +8,10 @@ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index
9
8
  */
10
9
  export function getProposerSlashingSignatureSets(
11
10
  config: BeaconConfig,
12
- index2pubkey: Index2PubkeyCache,
13
11
  stateSlot: Slot,
14
12
  proposerSlashing: phase0.ProposerSlashing
15
13
  ): ISignatureSet[] {
16
- const pubkey = index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
14
+ const proposerIndex = proposerSlashing.signedHeader1.message.proposerIndex;
17
15
 
18
16
  // In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
19
17
  // clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
@@ -21,8 +19,8 @@ export function getProposerSlashingSignatureSets(
21
19
  const domain = config.getDomain(stateSlot, DOMAIN_BEACON_PROPOSER, Number(signedHeader.message.slot as bigint));
22
20
 
23
21
  return {
24
- type: SignatureSetType.single,
25
- pubkey,
22
+ type: SignatureSetType.indexed,
23
+ index: proposerIndex,
26
24
  signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeaderBigint, signedHeader.message, domain),
27
25
  signature: signedHeader.signature,
28
26
  };
@@ -31,13 +29,12 @@ export function getProposerSlashingSignatureSets(
31
29
 
32
30
  export function getProposerSlashingsSignatureSets(
33
31
  config: BeaconConfig,
34
- index2pubkey: Index2PubkeyCache,
35
32
  signedBlock: SignedBeaconBlock
36
33
  ): ISignatureSet[] {
37
34
  // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
38
35
  // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
39
36
  const blockSlot = signedBlock.message.slot;
40
37
  return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
41
- getProposerSlashingSignatureSets(config, index2pubkey, blockSlot, proposerSlashing)
38
+ getProposerSlashingSignatureSets(config, blockSlot, proposerSlashing)
42
39
  );
43
40
  }
@@ -15,17 +15,13 @@ export function verifyRandaoSignature(
15
15
  index2pubkey: Index2PubkeyCache,
16
16
  block: BeaconBlock
17
17
  ): boolean {
18
- return verifySignatureSet(getRandaoRevealSignatureSet(config, index2pubkey, block));
18
+ return verifySignatureSet(getRandaoRevealSignatureSet(config, block), index2pubkey);
19
19
  }
20
20
 
21
21
  /**
22
22
  * Extract signatures to allow validating all block signatures at once
23
23
  */
24
- export function getRandaoRevealSignatureSet(
25
- config: BeaconConfig,
26
- index2pubkey: Index2PubkeyCache,
27
- block: BeaconBlock
28
- ): ISignatureSet {
24
+ export function getRandaoRevealSignatureSet(config: BeaconConfig, block: BeaconBlock): ISignatureSet {
29
25
  // should not get epoch from epochCtx
30
26
  const epoch = computeEpochAtSlot(block.slot);
31
27
  // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
@@ -33,8 +29,8 @@ export function getRandaoRevealSignatureSet(
33
29
  const domain = config.getDomain(block.slot, DOMAIN_RANDAO, block.slot);
34
30
 
35
31
  return {
36
- type: SignatureSetType.single,
37
- pubkey: index2pubkey[block.proposerIndex],
32
+ type: SignatureSetType.indexed,
33
+ index: block.proposerIndex,
38
34
  signingRoot: computeSigningRoot(ssz.Epoch, epoch, domain),
39
35
  signature: block.body.randaoReveal,
40
36
  };
@@ -15,7 +15,7 @@ export function verifyVoluntaryExitSignature(
15
15
  stateSlot: Slot,
16
16
  signedVoluntaryExit: phase0.SignedVoluntaryExit
17
17
  ): boolean {
18
- return verifySignatureSet(getVoluntaryExitSignatureSet(config, index2pubkey, stateSlot, signedVoluntaryExit));
18
+ return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit), index2pubkey);
19
19
  }
20
20
 
21
21
  /**
@@ -23,7 +23,6 @@ export function verifyVoluntaryExitSignature(
23
23
  */
24
24
  export function getVoluntaryExitSignatureSet(
25
25
  config: BeaconConfig,
26
- index2pubkey: Index2PubkeyCache,
27
26
  stateSlot: Slot,
28
27
  signedVoluntaryExit: phase0.SignedVoluntaryExit
29
28
  ): ISignatureSet {
@@ -31,22 +30,18 @@ export function getVoluntaryExitSignatureSet(
31
30
  const domain = config.getDomainForVoluntaryExit(stateSlot, messageSlot);
32
31
 
33
32
  return {
34
- type: SignatureSetType.single,
35
- pubkey: index2pubkey[signedVoluntaryExit.message.validatorIndex],
33
+ type: SignatureSetType.indexed,
34
+ index: signedVoluntaryExit.message.validatorIndex,
36
35
  signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
37
36
  signature: signedVoluntaryExit.signature,
38
37
  };
39
38
  }
40
39
 
41
- export function getVoluntaryExitsSignatureSets(
42
- config: BeaconConfig,
43
- index2pubkey: Index2PubkeyCache,
44
- signedBlock: SignedBeaconBlock
45
- ): ISignatureSet[] {
40
+ export function getVoluntaryExitsSignatureSets(config: BeaconConfig, signedBlock: SignedBeaconBlock): ISignatureSet[] {
46
41
  // the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
47
42
  // and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
48
43
  const blockSlot = signedBlock.message.slot;
49
44
  return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
50
- getVoluntaryExitSignatureSet(config, index2pubkey, blockSlot, voluntaryExit)
45
+ getVoluntaryExitSignatureSet(config, blockSlot, voluntaryExit)
51
46
  );
52
47
  }
package/src/types.ts CHANGED
@@ -23,4 +23,5 @@ export type {
23
23
  BeaconStateFulu,
24
24
  BeaconStateGloas,
25
25
  BeaconStatePhase0,
26
+ ShufflingGetter,
26
27
  } from "./cache/types.js";
@@ -3,12 +3,9 @@ import {ValidatorIndex, ssz} from "@lodestar/types";
3
3
  import {G2_POINT_AT_INFINITY} from "../constants/constants.js";
4
4
  import {CachedBeaconStateElectra, CachedBeaconStateGloas} from "../types.js";
5
5
  import {hasEth1WithdrawalCredential} from "./capella.js";
6
- import {hasBuilderWithdrawalCredential} from "./gloas.ts";
7
6
 
8
7
  export function hasCompoundingWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
9
- return (
10
- withdrawalCredentials[0] === COMPOUNDING_WITHDRAWAL_PREFIX || hasBuilderWithdrawalCredential(withdrawalCredentials)
11
- );
8
+ return withdrawalCredentials[0] === COMPOUNDING_WITHDRAWAL_PREFIX;
12
9
  }
13
10
 
14
11
  export function hasExecutionWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
@@ -9,54 +9,13 @@ import {
9
9
  TARGET_COMMITTEE_SIZE,
10
10
  } from "@lodestar/params";
11
11
  import {Epoch, RootHex, ValidatorIndex, ssz} from "@lodestar/types";
12
- import {GaugeExtra, Logger, NoLabels, intDiv, toRootHex} from "@lodestar/utils";
12
+ import {intDiv, toRootHex} from "@lodestar/utils";
13
13
  import {BeaconStateAllForks} from "../types.js";
14
14
  import {getBlockRootAtSlot} from "./blockRoot.js";
15
15
  import {computeAnchorCheckpoint} from "./computeAnchorCheckpoint.js";
16
16
  import {computeStartSlotAtEpoch} from "./epoch.js";
17
17
  import {getSeed} from "./seed.js";
18
18
 
19
- export interface ShufflingBuildProps {
20
- state: BeaconStateAllForks;
21
- activeIndices: Uint32Array;
22
- }
23
-
24
- export interface PublicShufflingCacheMetrics {
25
- shufflingCache: {
26
- nextShufflingNotOnEpochCache: GaugeExtra<NoLabels>;
27
- };
28
- }
29
- export interface IShufflingCache {
30
- metrics: PublicShufflingCacheMetrics | null;
31
- logger: Logger | null;
32
- /**
33
- * Gets a cached shuffling via the epoch and decision root. If the state and
34
- * activeIndices are passed and a shuffling is not available it will be built
35
- * synchronously. If the state is not passed and the shuffling is not available
36
- * nothing will be returned.
37
- *
38
- * NOTE: If a shuffling is already queued and not calculated it will build and resolve
39
- * the promise but the already queued build will happen at some later time
40
- */
41
- getSync<T extends ShufflingBuildProps | undefined>(
42
- epoch: Epoch,
43
- decisionRoot: RootHex,
44
- buildProps?: T
45
- ): T extends ShufflingBuildProps ? EpochShuffling : EpochShuffling | null;
46
-
47
- /**
48
- * Gets a cached shuffling via the epoch and decision root. Returns a promise
49
- * for the shuffling if it hs not calculated yet. Returns null if a build has
50
- * not been queued nor a shuffling was calculated.
51
- */
52
- get(epoch: Epoch, decisionRoot: RootHex): Promise<EpochShuffling | null>;
53
-
54
- /**
55
- * Queue asynchronous build for an EpochShuffling
56
- */
57
- build(epoch: Epoch, decisionRoot: RootHex, state: BeaconStateAllForks, activeIndices: Uint32Array): void;
58
- }
59
-
60
19
  /**
61
20
  * Readonly interface for EpochShuffling.
62
21
  */
@@ -164,7 +123,7 @@ export async function computeEpochShufflingAsync(
164
123
  };
165
124
  }
166
125
 
167
- function calculateDecisionRoot(state: BeaconStateAllForks, epoch: Epoch): RootHex {
126
+ export function calculateDecisionRoot(state: BeaconStateAllForks, epoch: Epoch): RootHex {
168
127
  const pivotSlot = computeStartSlotAtEpoch(epoch - 1) - 1;
169
128
  return toRootHex(getBlockRootAtSlot(state, pivotSlot));
170
129
  }