@lodestar/state-transition 1.39.0-dev.882891d89c → 1.39.0-dev.90334173dc

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 (172) hide show
  1. package/lib/block/index.d.ts.map +1 -1
  2. package/lib/block/index.js +4 -2
  3. package/lib/block/index.js.map +1 -1
  4. package/lib/block/isValidIndexedAttestation.d.ts +4 -5
  5. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  6. package/lib/block/isValidIndexedAttestation.js +9 -10
  7. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  8. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  9. package/lib/block/processAttestationPhase0.js +1 -1
  10. package/lib/block/processAttestationPhase0.js.map +1 -1
  11. package/lib/block/processAttestationsAltair.js +1 -1
  12. package/lib/block/processAttestationsAltair.js.map +1 -1
  13. package/lib/block/processAttesterSlashing.d.ts +3 -2
  14. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  15. package/lib/block/processAttesterSlashing.js +3 -3
  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/processExecutionPayload.d.ts.map +1 -1
  22. package/lib/block/processExecutionPayload.js +6 -4
  23. package/lib/block/processExecutionPayload.js.map +1 -1
  24. package/lib/block/processProposerSlashing.d.ts +5 -2
  25. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  26. package/lib/block/processProposerSlashing.js +7 -5
  27. package/lib/block/processProposerSlashing.js.map +1 -1
  28. package/lib/block/processRandao.js +2 -2
  29. package/lib/block/processRandao.js.map +1 -1
  30. package/lib/block/processSyncCommittee.d.ts +2 -1
  31. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  32. package/lib/block/processSyncCommittee.js +6 -4
  33. package/lib/block/processSyncCommittee.js.map +1 -1
  34. package/lib/block/processVoluntaryExit.js +1 -1
  35. package/lib/block/processVoluntaryExit.js.map +1 -1
  36. package/lib/block/processWithdrawals.d.ts +3 -3
  37. package/lib/block/processWithdrawals.d.ts.map +1 -1
  38. package/lib/block/processWithdrawals.js +152 -105
  39. package/lib/block/processWithdrawals.js.map +1 -1
  40. package/lib/cache/epochCache.d.ts +8 -28
  41. package/lib/cache/epochCache.d.ts.map +1 -1
  42. package/lib/cache/epochCache.js +40 -180
  43. package/lib/cache/epochCache.js.map +1 -1
  44. package/lib/cache/epochTransitionCache.d.ts +5 -12
  45. package/lib/cache/epochTransitionCache.d.ts.map +1 -1
  46. package/lib/cache/epochTransitionCache.js +4 -14
  47. package/lib/cache/epochTransitionCache.js.map +1 -1
  48. package/lib/cache/stateCache.d.ts.map +1 -1
  49. package/lib/cache/stateCache.js +1 -2
  50. package/lib/cache/stateCache.js.map +1 -1
  51. package/lib/epoch/processProposerLookahead.d.ts.map +1 -1
  52. package/lib/epoch/processProposerLookahead.js +3 -6
  53. package/lib/epoch/processProposerLookahead.js.map +1 -1
  54. package/lib/index.d.ts +3 -2
  55. package/lib/index.d.ts.map +1 -1
  56. package/lib/index.js +3 -1
  57. package/lib/index.js.map +1 -1
  58. package/lib/rewards/attestationsRewards.d.ts +6 -0
  59. package/lib/rewards/attestationsRewards.d.ts.map +1 -0
  60. package/lib/rewards/attestationsRewards.js +113 -0
  61. package/lib/rewards/attestationsRewards.js.map +1 -0
  62. package/lib/rewards/blockRewards.d.ts +14 -0
  63. package/lib/rewards/blockRewards.d.ts.map +1 -0
  64. package/lib/rewards/blockRewards.js +96 -0
  65. package/lib/rewards/blockRewards.js.map +1 -0
  66. package/lib/rewards/index.d.ts +4 -0
  67. package/lib/rewards/index.d.ts.map +1 -0
  68. package/lib/rewards/index.js +4 -0
  69. package/lib/rewards/index.js.map +1 -0
  70. package/lib/rewards/syncCommitteeRewards.d.ts +6 -0
  71. package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -0
  72. package/lib/rewards/syncCommitteeRewards.js +35 -0
  73. package/lib/rewards/syncCommitteeRewards.js.map +1 -0
  74. package/lib/signatureSets/attesterSlashings.d.ts +4 -5
  75. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  76. package/lib/signatureSets/attesterSlashings.js +10 -7
  77. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  78. package/lib/signatureSets/blsToExecutionChange.d.ts +1 -2
  79. package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
  80. package/lib/signatureSets/blsToExecutionChange.js +2 -2
  81. package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
  82. package/lib/signatureSets/index.d.ts +2 -2
  83. package/lib/signatureSets/index.d.ts.map +1 -1
  84. package/lib/signatureSets/index.js +10 -10
  85. package/lib/signatureSets/index.js.map +1 -1
  86. package/lib/signatureSets/indexedAttestation.d.ts +5 -6
  87. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  88. package/lib/signatureSets/indexedAttestation.js +12 -9
  89. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  90. package/lib/signatureSets/proposer.d.ts +5 -6
  91. package/lib/signatureSets/proposer.d.ts.map +1 -1
  92. package/lib/signatureSets/proposer.js +12 -10
  93. package/lib/signatureSets/proposer.js.map +1 -1
  94. package/lib/signatureSets/proposerSlashings.d.ts +3 -4
  95. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  96. package/lib/signatureSets/proposerSlashings.js +7 -4
  97. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  98. package/lib/signatureSets/randao.d.ts +2 -3
  99. package/lib/signatureSets/randao.d.ts.map +1 -1
  100. package/lib/signatureSets/randao.js +6 -4
  101. package/lib/signatureSets/randao.js.map +1 -1
  102. package/lib/signatureSets/voluntaryExits.d.ts +4 -5
  103. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  104. package/lib/signatureSets/voluntaryExits.js +10 -7
  105. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  106. package/lib/stateTransition.d.ts.map +1 -1
  107. package/lib/stateTransition.js +1 -2
  108. package/lib/stateTransition.js.map +1 -1
  109. package/lib/types.d.ts +1 -1
  110. package/lib/types.d.ts.map +1 -1
  111. package/lib/util/epochShuffling.d.ts +1 -34
  112. package/lib/util/epochShuffling.d.ts.map +1 -1
  113. package/lib/util/epochShuffling.js +1 -1
  114. package/lib/util/epochShuffling.js.map +1 -1
  115. package/lib/util/execution.d.ts +11 -1
  116. package/lib/util/execution.d.ts.map +1 -1
  117. package/lib/util/execution.js +26 -1
  118. package/lib/util/execution.js.map +1 -1
  119. package/lib/util/index.d.ts +1 -2
  120. package/lib/util/index.d.ts.map +1 -1
  121. package/lib/util/index.js +1 -2
  122. package/lib/util/index.js.map +1 -1
  123. package/lib/util/shuffling.d.ts +58 -0
  124. package/lib/util/shuffling.d.ts.map +1 -0
  125. package/lib/util/shuffling.js +175 -0
  126. package/lib/util/shuffling.js.map +1 -0
  127. package/package.json +14 -11
  128. package/src/block/index.ts +6 -2
  129. package/src/block/isValidIndexedAttestation.ts +19 -12
  130. package/src/block/processAttestationPhase0.ts +2 -1
  131. package/src/block/processAttestationsAltair.ts +1 -1
  132. package/src/block/processAttesterSlashing.ts +16 -4
  133. package/src/block/processBlsToExecutionChange.ts +13 -14
  134. package/src/block/processExecutionPayload.ts +14 -8
  135. package/src/block/processProposerSlashing.ts +21 -11
  136. package/src/block/processRandao.ts +2 -2
  137. package/src/block/processSyncCommittee.ts +7 -4
  138. package/src/block/processVoluntaryExit.ts +1 -1
  139. package/src/block/processWithdrawals.ts +230 -135
  140. package/src/cache/epochCache.ts +52 -214
  141. package/src/cache/epochTransitionCache.ts +9 -34
  142. package/src/cache/stateCache.ts +1 -2
  143. package/src/epoch/processProposerLookahead.ts +3 -7
  144. package/src/index.ts +2 -4
  145. package/src/rewards/attestationsRewards.ts +200 -0
  146. package/src/rewards/blockRewards.ts +150 -0
  147. package/src/rewards/index.ts +3 -0
  148. package/src/rewards/syncCommitteeRewards.ts +56 -0
  149. package/src/signatureSets/attesterSlashings.ts +10 -9
  150. package/src/signatureSets/blsToExecutionChange.ts +2 -3
  151. package/src/signatureSets/index.ts +11 -11
  152. package/src/signatureSets/indexedAttestation.ts +12 -11
  153. package/src/signatureSets/proposer.ts +11 -11
  154. package/src/signatureSets/proposerSlashings.ts +7 -6
  155. package/src/signatureSets/randao.ts +4 -5
  156. package/src/signatureSets/voluntaryExits.ts +10 -9
  157. package/src/stateTransition.ts +1 -4
  158. package/src/types.ts +1 -0
  159. package/src/util/epochShuffling.ts +2 -43
  160. package/src/util/execution.ts +39 -0
  161. package/src/util/index.ts +1 -2
  162. package/src/util/shuffling.ts +234 -0
  163. package/lib/util/calculateCommitteeAssignments.d.ts +0 -12
  164. package/lib/util/calculateCommitteeAssignments.d.ts.map +0 -1
  165. package/lib/util/calculateCommitteeAssignments.js +0 -26
  166. package/lib/util/calculateCommitteeAssignments.js.map +0 -1
  167. package/lib/util/shufflingDecisionRoot.d.ts +0 -20
  168. package/lib/util/shufflingDecisionRoot.d.ts.map +0 -1
  169. package/lib/util/shufflingDecisionRoot.js +0 -76
  170. package/lib/util/shufflingDecisionRoot.js.map +0 -1
  171. package/src/util/calculateCommitteeAssignments.ts +0 -43
  172. package/src/util/shufflingDecisionRoot.ts +0 -81
@@ -1,5 +1,30 @@
1
1
  import { ForkSeq } from "@lodestar/params";
2
- import { isBlindedBeaconBlockBody, ssz, } from "@lodestar/types";
2
+ import { isBlindedBeaconBlockBody, isExecutionPayload, ssz, } from "@lodestar/types";
3
+ /**
4
+ * Execution enabled = merge is done.
5
+ * When (A) state has execution data OR (B) block has execution data
6
+ */
7
+ export function isExecutionEnabled(state, block) {
8
+ if (isMergeTransitionComplete(state)) {
9
+ return true;
10
+ }
11
+ // Throws if not post-bellatrix block. A fork-guard before isExecutionEnabled() prevents this from happening
12
+ const payload = getFullOrBlindedPayload(block);
13
+ return isExecutionPayload(payload)
14
+ ? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
15
+ : !ssz.bellatrix.ExecutionPayloadHeader.equals(state.latestExecutionPayloadHeader, ssz.bellatrix.ExecutionPayloadHeader.defaultValue());
16
+ }
17
+ /**
18
+ * Merge is complete when the state includes execution layer data:
19
+ * state.latestExecutionPayloadHeader NOT EMPTY or state is post-capella
20
+ */
21
+ export function isMergeTransitionComplete(state) {
22
+ if (isCapellaStateType(state)) {
23
+ // All networks have completed the merge transition before capella
24
+ return true;
25
+ }
26
+ return !ssz.bellatrix.ExecutionPayloadHeader.equals(state.latestExecutionPayloadHeader, ssz.bellatrix.ExecutionPayloadHeader.defaultValue());
27
+ }
3
28
  /** Type guard for bellatrix.BeaconState */
4
29
  export function isExecutionStateType(state) {
5
30
  return state.latestExecutionPayloadHeader !== undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/util/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACpF,OAAO,EASL,wBAAwB,EACxB,GAAG,GACJ,MAAM,iBAAiB,CAAC;AASzB,2CAA2C;AAC3C,MAAM,UAAU,oBAAoB,CAAC,KAA0B;IAC7D,OAAQ,KAA+B,CAAC,4BAA4B,KAAK,SAAS,CAAC;AACrF,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,kBAAkB,CAAC,KAA0B;IAC3D,OAAO,CACJ,KAA4B,CAAC,4BAA4B,KAAK,SAAS;QACvE,KAA4B,CAAC,4BAA4B,CAAC,eAAe,KAAK,SAAS,CACzF,CAAC;AACJ,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,0BAA0B,CAAC,KAAgC;IACzE,OAAQ,KAAqC,CAAC,4BAA4B,KAAK,SAAS,CAAC;AAC3F,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,wBAAwB,CACtC,SAA0B;IAE1B,OAAQ,SAA+D,CAAC,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,OAAO,CAAC,WAAW,CAAC,YAAY,CAC9G,OAAoC,CAAC,WAAW,CAClD,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAC1B,+GAA+G;QAC9G,sBAAuD,CAAC,WAAW,GAClE,OACD,CAAC,WAAW,CAAC;QACb,sBAAuD,CAAC,aAAa,GACpE,OACD,CAAC,aAAa,CAAC;IAClB,CAAC;IAED,uBAAuB;IAEvB,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
@@ -5,7 +5,6 @@ export * from "./attesterStatus.js";
5
5
  export * from "./balance.js";
6
6
  export * from "./blindedBlock.js";
7
7
  export * from "./blockRoot.js";
8
- export * from "./calculateCommitteeAssignments.js";
9
8
  export * from "./capella.js";
10
9
  export * from "./computeAnchorCheckpoint.js";
11
10
  export * from "./deposit.js";
@@ -20,7 +19,7 @@ export * from "./interop.js";
20
19
  export * from "./loadState/index.js";
21
20
  export * from "./rootCache.js";
22
21
  export * from "./seed.js";
23
- export * from "./shufflingDecisionRoot.js";
22
+ export * from "./shuffling.js";
24
23
  export * from "./signatureSets.js";
25
24
  export * from "./signingRoot.js";
26
25
  export * from "./slot.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oCAAoC,CAAC;AACnD,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
package/lib/util/index.js CHANGED
@@ -5,7 +5,6 @@ export * from "./attesterStatus.js";
5
5
  export * from "./balance.js";
6
6
  export * from "./blindedBlock.js";
7
7
  export * from "./blockRoot.js";
8
- export * from "./calculateCommitteeAssignments.js";
9
8
  export * from "./capella.js";
10
9
  export * from "./computeAnchorCheckpoint.js";
11
10
  export * from "./deposit.js";
@@ -20,7 +19,7 @@ export * from "./interop.js";
20
19
  export * from "./loadState/index.js";
21
20
  export * from "./rootCache.js";
22
21
  export * from "./seed.js";
23
- export * from "./shufflingDecisionRoot.js";
22
+ export * from "./shuffling.js";
24
23
  export * from "./signatureSets.js";
25
24
  export * from "./signingRoot.js";
26
25
  export * from "./slot.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oCAAoC,CAAC;AACnD,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { ForkName, ForkSeq } from "@lodestar/params";
2
+ import { Attestation, CommitteeIndex, Epoch, IndexedAttestation, Root, Slot, ValidatorIndex } from "@lodestar/types";
3
+ import { LodestarError } from "@lodestar/utils";
4
+ import { CachedBeaconStateAllForks } from "../cache/stateCache.js";
5
+ import { EpochShuffling } from "./epochShuffling.js";
6
+ /**
7
+ * Returns the block root which decided the proposer shuffling for the current epoch. This root
8
+ * can be used to key this proposer shuffling.
9
+ *
10
+ * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
11
+ * It should be set to the latest block applied to this `state` or the genesis block root.
12
+ */
13
+ export declare function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null;
14
+ /**
15
+ * Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
16
+ * This root can be used to key that attester shuffling.
17
+ *
18
+ * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
19
+ * It should be set to the latest block applied to this `state` or the genesis block root.
20
+ */
21
+ export declare function attesterShufflingDecisionRoot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Root | null;
22
+ export interface AttesterDuty {
23
+ validatorIndex: ValidatorIndex;
24
+ committeeIndex: CommitteeIndex;
25
+ committeeLength: number;
26
+ committeesAtSlot: number;
27
+ validatorCommitteeIndex: number;
28
+ slot: Slot;
29
+ }
30
+ export declare function calculateCommitteeAssignments(epochShuffling: EpochShuffling, requestedValidatorIndices: ValidatorIndex[]): Map<ValidatorIndex, AttesterDuty>;
31
+ /**
32
+ * Return the indexed attestation corresponding to ``attestation``.
33
+ */
34
+ export declare function getIndexedAttestation(epochShuffling: EpochShuffling, fork: ForkSeq, attestation: Attestation): IndexedAttestation;
35
+ /**
36
+ * Return indices of validators who attestested in `attestation`
37
+ */
38
+ export declare function getAttestingIndices(epochShuffling: EpochShuffling, fork: ForkSeq, attestation: Attestation): number[];
39
+ /**
40
+ * Return the beacon committee at slot for index.
41
+ */
42
+ export declare function getBeaconCommittee(epochShuffling: EpochShuffling, slot: Slot, index: CommitteeIndex): Uint32Array;
43
+ /**
44
+ * Return a Uint32Array[] representing committees validator indices
45
+ */
46
+ export declare function getBeaconCommittees(epochShuffling: EpochShuffling, slot: Slot, indices: CommitteeIndex[]): Uint32Array[];
47
+ export declare enum ShufflingErrorCode {
48
+ COMMITTEE_INDEX_OUT_OF_RANGE = "SHUFFLING_ERROR_COMMITTEE_INDEX_OUT_OF_RANGE"
49
+ }
50
+ type ShufflingErrorType = {
51
+ code: ShufflingErrorCode.COMMITTEE_INDEX_OUT_OF_RANGE;
52
+ index: number;
53
+ maxIndex: number;
54
+ };
55
+ export declare class ShufflingError extends LodestarError<ShufflingErrorType> {
56
+ }
57
+ export {};
58
+ //# source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,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,EAAE,CA6BrH;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,GAAG,WAAW,CAEjH;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,cAAc,EAC9B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,EAAE,GACxB,WAAW,EAAE,CAoBf;AAED,oBAAY,kBAAkB;IAC5B,4BAA4B,iDAAiD;CAC9E;AAED,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,kBAAkB,CAAC,4BAA4B,CAAC;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,qBAAa,cAAe,SAAQ,aAAa,CAAC,kBAAkB,CAAC;CAAG"}
@@ -0,0 +1,175 @@
1
+ import { ForkSeq, SLOTS_PER_EPOCH, isForkPostFulu } from "@lodestar/params";
2
+ import { LodestarError } from "@lodestar/utils";
3
+ import { getBlockRootAtSlot } from "./blockRoot.js";
4
+ import { computeStartSlotAtEpoch } from "./epoch.js";
5
+ /**
6
+ * Returns the block root which decided the proposer shuffling for the current epoch. This root
7
+ * can be used to key this proposer shuffling.
8
+ *
9
+ * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
10
+ * It should be set to the latest block applied to this `state` or the genesis block root.
11
+ */
12
+ export function proposerShufflingDecisionRoot(fork, state) {
13
+ const decisionSlot = proposerShufflingDecisionSlot(fork, state);
14
+ if (state.slot === decisionSlot) {
15
+ return null;
16
+ }
17
+ return getBlockRootAtSlot(state, decisionSlot);
18
+ }
19
+ /**
20
+ * Returns the slot at which the proposer shuffling was decided. The block root at this slot
21
+ * can be used to key the proposer shuffling for the current epoch.
22
+ */
23
+ function proposerShufflingDecisionSlot(fork, state) {
24
+ // After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
25
+ const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
26
+ const startSlot = computeStartSlotAtEpoch(epoch);
27
+ return Math.max(startSlot - 1, 0);
28
+ }
29
+ /**
30
+ * Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
31
+ * This root can be used to key that attester shuffling.
32
+ *
33
+ * Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
34
+ * It should be set to the latest block applied to this `state` or the genesis block root.
35
+ */
36
+ export function attesterShufflingDecisionRoot(state, requestedEpoch) {
37
+ const decisionSlot = attesterShufflingDecisionSlot(state, requestedEpoch);
38
+ if (state.slot === decisionSlot) {
39
+ return null;
40
+ }
41
+ return getBlockRootAtSlot(state, decisionSlot);
42
+ }
43
+ /**
44
+ * Returns the slot at which the proposer shuffling was decided. The block root at this slot
45
+ * can be used to key the proposer shuffling for the current epoch.
46
+ */
47
+ function attesterShufflingDecisionSlot(state, requestedEpoch) {
48
+ const epoch = attesterShufflingDecisionEpoch(state, requestedEpoch);
49
+ const slot = computeStartSlotAtEpoch(epoch);
50
+ return Math.max(slot - 1, 0);
51
+ }
52
+ /**
53
+ * Returns the epoch at which the attester shuffling was decided.
54
+ *
55
+ * Spec ref: https://github.com/ethereum/beacon-APIs/blob/v2.1.0/apis/validator/duties/attester.yaml#L15
56
+ *
57
+ * Throws an error when:
58
+ * - `EpochTooLow` when `requestedEpoch` is more than 1 prior to `currentEpoch`.
59
+ * - `EpochTooHigh` when `requestedEpoch` is more than 1 after `currentEpoch`.
60
+ */
61
+ function attesterShufflingDecisionEpoch(state, requestedEpoch) {
62
+ const currentEpoch = state.epochCtx.epoch;
63
+ // Next
64
+ if (requestedEpoch === currentEpoch + 1)
65
+ return currentEpoch;
66
+ // Current
67
+ if (requestedEpoch === currentEpoch)
68
+ return Math.max(currentEpoch - 1, 0);
69
+ // Previous
70
+ if (requestedEpoch === currentEpoch - 1)
71
+ return Math.max(currentEpoch - 2, 0);
72
+ if (requestedEpoch < currentEpoch) {
73
+ throw Error(`EpochTooLow: current ${currentEpoch} requested ${requestedEpoch}`);
74
+ }
75
+ throw Error(`EpochTooHigh: current ${currentEpoch} requested ${requestedEpoch}`);
76
+ }
77
+ export function calculateCommitteeAssignments(epochShuffling, requestedValidatorIndices) {
78
+ const requestedValidatorIndicesSet = new Set(requestedValidatorIndices);
79
+ const duties = new Map();
80
+ const epochCommittees = epochShuffling.committees;
81
+ for (let epochSlot = 0; epochSlot < SLOTS_PER_EPOCH; epochSlot++) {
82
+ const slotCommittees = epochCommittees[epochSlot];
83
+ for (let i = 0, committeesAtSlot = slotCommittees.length; i < committeesAtSlot; i++) {
84
+ for (let j = 0, committeeLength = slotCommittees[i].length; j < committeeLength; j++) {
85
+ const validatorIndex = slotCommittees[i][j];
86
+ if (requestedValidatorIndicesSet.has(validatorIndex)) {
87
+ duties.set(validatorIndex, {
88
+ validatorIndex,
89
+ committeeLength,
90
+ committeesAtSlot,
91
+ validatorCommitteeIndex: j,
92
+ committeeIndex: i,
93
+ slot: epochShuffling.epoch * SLOTS_PER_EPOCH + epochSlot,
94
+ });
95
+ }
96
+ }
97
+ }
98
+ }
99
+ return duties;
100
+ }
101
+ /**
102
+ * Return the indexed attestation corresponding to ``attestation``.
103
+ */
104
+ export function getIndexedAttestation(epochShuffling, fork, attestation) {
105
+ const { data } = attestation;
106
+ const attestingIndices = getAttestingIndices(epochShuffling, fork, attestation);
107
+ // sort in-place
108
+ attestingIndices.sort((a, b) => a - b);
109
+ return {
110
+ attestingIndices: attestingIndices,
111
+ data: data,
112
+ signature: attestation.signature,
113
+ };
114
+ }
115
+ /**
116
+ * Return indices of validators who attestested in `attestation`
117
+ */
118
+ export function getAttestingIndices(epochShuffling, fork, attestation) {
119
+ if (fork < ForkSeq.electra) {
120
+ const { aggregationBits, data } = attestation;
121
+ const validatorIndices = getBeaconCommittee(epochShuffling, data.slot, data.index);
122
+ return aggregationBits.intersectValues(validatorIndices);
123
+ }
124
+ const { aggregationBits, committeeBits, data } = attestation;
125
+ // There is a naming conflict on the term `committeeIndices`
126
+ // In Lodestar it usually means a list of validator indices of participants in a committee
127
+ // In the spec it means a list of committee indices according to committeeBits
128
+ // This `committeeIndices` refers to the latter
129
+ // TODO Electra: resolve the naming conflicts
130
+ const committeeIndices = committeeBits.getTrueBitIndexes();
131
+ const validatorsByCommittee = getBeaconCommittees(epochShuffling, data.slot, committeeIndices);
132
+ // Create a new Uint32Array to flatten `validatorsByCommittee`
133
+ const totalLength = validatorsByCommittee.reduce((acc, curr) => acc + curr.length, 0);
134
+ const committeeValidators = new Uint32Array(totalLength);
135
+ let offset = 0;
136
+ for (const committee of validatorsByCommittee) {
137
+ committeeValidators.set(committee, offset);
138
+ offset += committee.length;
139
+ }
140
+ return aggregationBits.intersectValues(committeeValidators);
141
+ }
142
+ /**
143
+ * Return the beacon committee at slot for index.
144
+ */
145
+ export function getBeaconCommittee(epochShuffling, slot, index) {
146
+ return getBeaconCommittees(epochShuffling, slot, [index])[0];
147
+ }
148
+ /**
149
+ * Return a Uint32Array[] representing committees validator indices
150
+ */
151
+ export function getBeaconCommittees(epochShuffling, slot, indices) {
152
+ if (indices.length === 0) {
153
+ throw new Error("Attempt to get committees without providing CommitteeIndex");
154
+ }
155
+ const slotCommittees = epochShuffling.committees[slot % SLOTS_PER_EPOCH];
156
+ const committees = [];
157
+ for (const index of indices) {
158
+ if (index >= slotCommittees.length) {
159
+ throw new ShufflingError({
160
+ code: ShufflingErrorCode.COMMITTEE_INDEX_OUT_OF_RANGE,
161
+ index,
162
+ maxIndex: slotCommittees.length,
163
+ });
164
+ }
165
+ committees.push(slotCommittees[index]);
166
+ }
167
+ return committees;
168
+ }
169
+ export var ShufflingErrorCode;
170
+ (function (ShufflingErrorCode) {
171
+ ShufflingErrorCode["COMMITTEE_INDEX_OUT_OF_RANGE"] = "SHUFFLING_ERROR_COMMITTEE_INDEX_OUT_OF_RANGE";
172
+ })(ShufflingErrorCode || (ShufflingErrorCode = {}));
173
+ export class ShufflingError extends LodestarError {
174
+ }
175
+ //# sourceMappingURL=shuffling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shuffling.js","sourceRoot":"","sources":["../../src/util/shuffling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,OAAO,EAAE,eAAe,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAWpF,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,uBAAuB,EAAC,MAAM,YAAY,CAAC;AAGnD;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,IAAc,EAAE,KAAgC;IAC5F,MAAM,YAAY,GAAG,6BAA6B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChE,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAS,6BAA6B,CAAC,IAAc,EAAE,KAAgC;IACrF,6FAA6F;IAC7F,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrF,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAgC,EAAE,cAAqB;IACnG,MAAM,YAAY,GAAG,6BAA6B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAC1E,IAAI,KAAK,CA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882891d89c",
14
+ "version": "1.39.0-dev.90334173dc",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -43,15 +43,15 @@
43
43
  "scripts": {
44
44
  "clean": "rm -rf lib && rm -f *.tsbuildinfo",
45
45
  "build": "tsc -p tsconfig.build.json",
46
- "build:watch": "yarn run build --watch",
47
- "build:release": "yarn clean && yarn build",
46
+ "build:watch": "pnpm run build --watch",
47
+ "build:release": "pnpm clean && pnpm build",
48
48
  "check-build": "node -e \"(async function() { await import('./lib/index.js') })()\"",
49
49
  "check-types": "tsc",
50
50
  "lint": "biome check src/ test/",
51
- "lint:fix": "yarn run lint --write",
52
- "test": "yarn test:unit",
51
+ "lint:fix": "pnpm run lint --write",
52
+ "test": "pnpm test:unit",
53
53
  "test:unit": "vitest run --project unit --project unit-minimal",
54
- "check-readme": "typescript-docs-verifier"
54
+ "check-readme": "pnpm exec ts-node ../../scripts/check_readme.ts"
55
55
  },
56
56
  "types": "lib/index.d.ts",
57
57
  "dependencies": {
@@ -62,17 +62,20 @@
62
62
  "@chainsafe/pubkey-index-map": "^3.0.0",
63
63
  "@chainsafe/ssz": "^1.2.2",
64
64
  "@chainsafe/swap-or-not-shuffle": "^1.2.1",
65
- "@lodestar/config": "1.39.0-dev.882891d89c",
66
- "@lodestar/params": "1.39.0-dev.882891d89c",
67
- "@lodestar/types": "1.39.0-dev.882891d89c",
68
- "@lodestar/utils": "1.39.0-dev.882891d89c",
65
+ "@lodestar/config": "^1.39.0-dev.90334173dc",
66
+ "@lodestar/params": "^1.39.0-dev.90334173dc",
67
+ "@lodestar/types": "^1.39.0-dev.90334173dc",
68
+ "@lodestar/utils": "^1.39.0-dev.90334173dc",
69
69
  "bigint-buffer": "^1.1.5"
70
70
  },
71
+ "devDependencies": {
72
+ "@lodestar/api": "^1.39.0-dev.90334173dc"
73
+ },
71
74
  "keywords": [
72
75
  "ethereum",
73
76
  "eth-consensus",
74
77
  "beacon",
75
78
  "blockchain"
76
79
  ],
77
- "gitHead": "d61f386f2dfd87549476c464c05867b0d740c366"
80
+ "gitHead": "70ad2460adbb8c8ebd26f4575a7b5ee86c70759e"
78
81
  }
@@ -7,7 +7,7 @@ import {
7
7
  CachedBeaconStateCapella,
8
8
  CachedBeaconStateGloas,
9
9
  } from "../types.js";
10
- import {getFullOrBlindedPayload} from "../util/execution.js";
10
+ import {getFullOrBlindedPayload, isExecutionEnabled} from "../util/execution.js";
11
11
  import {BlockExternalData, DataAvailabilityStatus} from "./externalData.js";
12
12
  import {processBlobKzgCommitments} from "./processBlobKzgCommitments.js";
13
13
  import {processBlockHeader} from "./processBlockHeader.js";
@@ -67,7 +67,11 @@ export function processBlock(
67
67
  // The call to the process_execution_payload must happen before the call to the process_randao as the former depends
68
68
  // on the randao_mix computed with the reveal of the previous block.
69
69
  // TODO GLOAS: We call processExecutionPayload somewhere else post-gloas
70
- if (fork >= ForkSeq.bellatrix && fork < ForkSeq.gloas) {
70
+ if (
71
+ fork < ForkSeq.gloas &&
72
+ fork >= ForkSeq.bellatrix &&
73
+ isExecutionEnabled(state as CachedBeaconStateBellatrix, block)
74
+ ) {
71
75
  processExecutionPayload(fork, state as CachedBeaconStateBellatrix, block.body, externalData);
72
76
  }
73
77
 
@@ -1,9 +1,8 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {ForkSeq, MAX_COMMITTEES_PER_SLOT, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
3
- import {IndexedAttestation, IndexedAttestationBigint} from "@lodestar/types";
3
+ import {IndexedAttestation, IndexedAttestationBigint, Slot} from "@lodestar/types";
4
4
  import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
5
5
  import {getIndexedAttestationBigintSignatureSet, getIndexedAttestationSignatureSet} from "../signatureSets/index.js";
6
- import {CachedBeaconStateAllForks} from "../types.js";
7
6
  import {verifySignatureSet} from "../util/index.js";
8
7
 
9
8
  /**
@@ -12,16 +11,17 @@ import {verifySignatureSet} from "../util/index.js";
12
11
  export function isValidIndexedAttestation(
13
12
  config: BeaconConfig,
14
13
  index2pubkey: Index2PubkeyCache,
15
- state: CachedBeaconStateAllForks,
14
+ stateSlot: Slot,
15
+ validatorsLen: number,
16
16
  indexedAttestation: IndexedAttestation,
17
17
  verifySignature: boolean
18
18
  ): boolean {
19
- if (!isValidIndexedAttestationIndices(state, indexedAttestation.attestingIndices)) {
19
+ if (!isValidIndexedAttestationIndices(config, stateSlot, validatorsLen, indexedAttestation.attestingIndices)) {
20
20
  return false;
21
21
  }
22
22
 
23
23
  if (verifySignature) {
24
- return verifySignatureSet(getIndexedAttestationSignatureSet(config, index2pubkey, state, indexedAttestation));
24
+ return verifySignatureSet(getIndexedAttestationSignatureSet(config, index2pubkey, stateSlot, indexedAttestation));
25
25
  }
26
26
  return true;
27
27
  }
@@ -29,16 +29,19 @@ export function isValidIndexedAttestation(
29
29
  export function isValidIndexedAttestationBigint(
30
30
  config: BeaconConfig,
31
31
  index2pubkey: Index2PubkeyCache,
32
- state: CachedBeaconStateAllForks,
32
+ stateSlot: Slot,
33
+ validatorsLen: number,
33
34
  indexedAttestation: IndexedAttestationBigint,
34
35
  verifySignature: boolean
35
36
  ): boolean {
36
- if (!isValidIndexedAttestationIndices(state, indexedAttestation.attestingIndices)) {
37
+ if (!isValidIndexedAttestationIndices(config, stateSlot, validatorsLen, indexedAttestation.attestingIndices)) {
37
38
  return false;
38
39
  }
39
40
 
40
41
  if (verifySignature) {
41
- return verifySignatureSet(getIndexedAttestationBigintSignatureSet(config, index2pubkey, state, indexedAttestation));
42
+ return verifySignatureSet(
43
+ getIndexedAttestationBigintSignatureSet(config, index2pubkey, stateSlot, indexedAttestation)
44
+ );
42
45
  }
43
46
  return true;
44
47
  }
@@ -46,10 +49,15 @@ export function isValidIndexedAttestationBigint(
46
49
  /**
47
50
  * Check if `indexedAttestation` has sorted and unique indices and a valid aggregate signature.
48
51
  */
49
- 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 {
50
58
  // verify max number of indices
51
59
  const maxIndices =
52
- state.config.getForkSeq(state.slot) >= ForkSeq.electra
60
+ config.getForkSeq(stateSlot) >= ForkSeq.electra
53
61
  ? MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT
54
62
  : MAX_VALIDATORS_PER_COMMITTEE;
55
63
  if (!(indices.length > 0 && indices.length <= maxIndices)) {
@@ -66,9 +74,8 @@ export function isValidIndexedAttestationIndices(state: CachedBeaconStateAllFork
66
74
  }
67
75
 
68
76
  // check if indices are out of bounds, by checking the highest index (since it is sorted)
69
- // TODO - SLOW CODE - Does this .length check the tree and is expensive?
70
77
  const lastIndex = indices.at(-1);
71
- if (lastIndex && lastIndex >= state.validators.length) {
78
+ if (lastIndex && lastIndex >= validatorsLen) {
72
79
  return false;
73
80
  }
74
81
 
@@ -54,7 +54,8 @@ export function processAttestationPhase0(
54
54
  !isValidIndexedAttestation(
55
55
  state.config,
56
56
  epochCtx.index2pubkey,
57
- state,
57
+ state.slot,
58
+ state.validators.length,
58
59
  epochCtx.getIndexedAttestation(ForkSeq.phase0, attestation),
59
60
  verifySignature
60
61
  )
@@ -67,7 +67,7 @@ export function processAttestationsAltair(
67
67
  const sigSet = getAttestationWithIndicesSignatureSet(
68
68
  state.config,
69
69
  epochCtx.index2pubkey,
70
- state,
70
+ state.slot,
71
71
  attestation,
72
72
  attestingIndices
73
73
  );
@@ -1,5 +1,6 @@
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";
3
4
  import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
4
5
  import {CachedBeaconStateAllForks} from "../types.js";
5
6
  import {getAttesterSlashableIndices, isSlashableAttestationData, isSlashableValidator} from "../util/index.js";
@@ -19,7 +20,14 @@ export function processAttesterSlashing(
19
20
  verifySignatures = true
20
21
  ): void {
21
22
  const {epochCtx} = state;
22
- assertValidAttesterSlashing(epochCtx.index2pubkey, state, attesterSlashing, verifySignatures);
23
+ assertValidAttesterSlashing(
24
+ state.config,
25
+ epochCtx.index2pubkey,
26
+ state.slot,
27
+ state.validators.length,
28
+ attesterSlashing,
29
+ verifySignatures
30
+ );
23
31
 
24
32
  const intersectingIndices = getAttesterSlashableIndices(attesterSlashing);
25
33
 
@@ -39,8 +47,10 @@ export function processAttesterSlashing(
39
47
  }
40
48
 
41
49
  export function assertValidAttesterSlashing(
50
+ config: BeaconConfig,
42
51
  index2pubkey: Index2PubkeyCache,
43
- state: CachedBeaconStateAllForks,
52
+ stateSlot: Slot,
53
+ validatorsLen: number,
44
54
  attesterSlashing: AttesterSlashing,
45
55
  verifySignatures = true
46
56
  ): void {
@@ -55,7 +65,9 @@ export function assertValidAttesterSlashing(
55
65
  // be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which
56
66
  // can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
57
67
  for (const [i, attestation] of [attestation1, attestation2].entries()) {
58
- if (!isValidIndexedAttestationBigint(state.config, index2pubkey, state, attestation, verifySignatures)) {
68
+ if (
69
+ !isValidIndexedAttestationBigint(config, index2pubkey, stateSlot, validatorsLen, attestation, verifySignatures)
70
+ ) {
59
71
  throw new Error(`AttesterSlashing attestation${i} is invalid`);
60
72
  }
61
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(