@lodestar/state-transition 1.39.0-dev.3bf4734ba9 → 1.39.0-dev.493cc12d2f

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 (94) 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 +3 -2
  5. package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
  6. package/lib/block/isValidIndexedAttestation.js +4 -4
  7. package/lib/block/isValidIndexedAttestation.js.map +1 -1
  8. package/lib/block/processAttestationPhase0.d.ts.map +1 -1
  9. package/lib/block/processAttestationPhase0.js +1 -1
  10. package/lib/block/processAttestationPhase0.js.map +1 -1
  11. package/lib/block/processAttestationsAltair.d.ts.map +1 -1
  12. package/lib/block/processAttestationsAltair.js +1 -1
  13. package/lib/block/processAttestationsAltair.js.map +1 -1
  14. package/lib/block/processAttesterSlashing.js +1 -1
  15. package/lib/block/processAttesterSlashing.js.map +1 -1
  16. package/lib/block/processExecutionPayload.d.ts.map +1 -1
  17. package/lib/block/processExecutionPayload.js +6 -4
  18. package/lib/block/processExecutionPayload.js.map +1 -1
  19. package/lib/block/processProposerSlashing.d.ts.map +1 -1
  20. package/lib/block/processProposerSlashing.js +1 -1
  21. package/lib/block/processProposerSlashing.js.map +1 -1
  22. package/lib/block/processRandao.js +1 -1
  23. package/lib/block/processRandao.js.map +1 -1
  24. package/lib/block/processSyncCommittee.d.ts +2 -1
  25. package/lib/block/processSyncCommittee.d.ts.map +1 -1
  26. package/lib/block/processSyncCommittee.js +3 -3
  27. package/lib/block/processSyncCommittee.js.map +1 -1
  28. package/lib/block/processVoluntaryExit.d.ts.map +1 -1
  29. package/lib/block/processVoluntaryExit.js +2 -1
  30. package/lib/block/processVoluntaryExit.js.map +1 -1
  31. package/lib/cache/epochCache.d.ts +0 -3
  32. package/lib/cache/epochCache.d.ts.map +1 -1
  33. package/lib/cache/epochCache.js +0 -3
  34. package/lib/cache/epochCache.js.map +1 -1
  35. package/lib/cache/stateCache.d.ts +1 -0
  36. package/lib/cache/stateCache.d.ts.map +1 -1
  37. package/lib/cache/stateCache.js.map +1 -1
  38. package/lib/signatureSets/attesterSlashings.d.ts +4 -3
  39. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  40. package/lib/signatureSets/attesterSlashings.js +6 -6
  41. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  42. package/lib/signatureSets/index.d.ts +2 -1
  43. package/lib/signatureSets/index.d.ts.map +1 -1
  44. package/lib/signatureSets/index.js +8 -8
  45. package/lib/signatureSets/index.js.map +1 -1
  46. package/lib/signatureSets/indexedAttestation.d.ts +5 -4
  47. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  48. package/lib/signatureSets/indexedAttestation.js +8 -8
  49. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  50. package/lib/signatureSets/proposer.d.ts +3 -2
  51. package/lib/signatureSets/proposer.d.ts.map +1 -1
  52. package/lib/signatureSets/proposer.js +3 -4
  53. package/lib/signatureSets/proposer.js.map +1 -1
  54. package/lib/signatureSets/proposerSlashings.d.ts +3 -2
  55. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  56. package/lib/signatureSets/proposerSlashings.js +4 -4
  57. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  58. package/lib/signatureSets/randao.d.ts +3 -2
  59. package/lib/signatureSets/randao.d.ts.map +1 -1
  60. package/lib/signatureSets/randao.js +4 -4
  61. package/lib/signatureSets/randao.js.map +1 -1
  62. package/lib/signatureSets/voluntaryExits.d.ts +4 -3
  63. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  64. package/lib/signatureSets/voluntaryExits.js +6 -6
  65. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  66. package/lib/stateTransition.d.ts.map +1 -1
  67. package/lib/stateTransition.js +2 -1
  68. package/lib/stateTransition.js.map +1 -1
  69. package/lib/util/execution.d.ts +11 -1
  70. package/lib/util/execution.d.ts.map +1 -1
  71. package/lib/util/execution.js +26 -1
  72. package/lib/util/execution.js.map +1 -1
  73. package/package.json +6 -6
  74. package/src/block/index.ts +6 -2
  75. package/src/block/isValidIndexedAttestation.ts +5 -2
  76. package/src/block/processAttestationPhase0.ts +1 -0
  77. package/src/block/processAttestationsAltair.ts +7 -1
  78. package/src/block/processAttesterSlashing.ts +1 -1
  79. package/src/block/processExecutionPayload.ts +14 -8
  80. package/src/block/processProposerSlashing.ts +6 -1
  81. package/src/block/processRandao.ts +1 -1
  82. package/src/block/processSyncCommittee.ts +10 -2
  83. package/src/block/processVoluntaryExit.ts +4 -1
  84. package/src/cache/epochCache.ts +0 -3
  85. package/src/cache/stateCache.ts +1 -0
  86. package/src/signatureSets/attesterSlashings.ts +7 -3
  87. package/src/signatureSets/index.ts +9 -6
  88. package/src/signatureSets/indexedAttestation.ts +9 -3
  89. package/src/signatureSets/proposer.ts +4 -2
  90. package/src/signatureSets/proposerSlashings.ts +5 -6
  91. package/src/signatureSets/randao.ts +5 -2
  92. package/src/signatureSets/voluntaryExits.ts +7 -3
  93. package/src/stateTransition.ts +4 -1
  94. package/src/util/execution.ts +39 -0
@@ -1,3 +1,4 @@
1
+ import {BeaconConfig} from "@lodestar/config";
1
2
  import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
2
3
  import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
@@ -10,23 +11,25 @@ import {
10
11
  } from "../util/index.js";
11
12
 
12
13
  export function verifyVoluntaryExitSignature(
14
+ config: BeaconConfig,
13
15
  index2pubkey: Index2PubkeyCache,
14
16
  state: CachedBeaconStateAllForks,
15
17
  signedVoluntaryExit: phase0.SignedVoluntaryExit
16
18
  ): boolean {
17
- return verifySignatureSet(getVoluntaryExitSignatureSet(index2pubkey, state, signedVoluntaryExit));
19
+ return verifySignatureSet(getVoluntaryExitSignatureSet(config, index2pubkey, state, signedVoluntaryExit));
18
20
  }
19
21
 
20
22
  /**
21
23
  * Extract signatures to allow validating all block signatures at once
22
24
  */
23
25
  export function getVoluntaryExitSignatureSet(
26
+ config: BeaconConfig,
24
27
  index2pubkey: Index2PubkeyCache,
25
28
  state: CachedBeaconStateAllForks,
26
29
  signedVoluntaryExit: phase0.SignedVoluntaryExit
27
30
  ): ISignatureSet {
28
31
  const slot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
29
- const domain = state.config.getDomainForVoluntaryExit(state.slot, slot);
32
+ const domain = config.getDomainForVoluntaryExit(state.slot, slot);
30
33
 
31
34
  return {
32
35
  type: SignatureSetType.single,
@@ -37,11 +40,12 @@ export function getVoluntaryExitSignatureSet(
37
40
  }
38
41
 
39
42
  export function getVoluntaryExitsSignatureSets(
43
+ config: BeaconConfig,
40
44
  index2pubkey: Index2PubkeyCache,
41
45
  state: CachedBeaconStateAllForks,
42
46
  signedBlock: SignedBeaconBlock
43
47
  ): ISignatureSet[] {
44
48
  return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
45
- getVoluntaryExitSignatureSet(index2pubkey, state, voluntaryExit)
49
+ getVoluntaryExitSignatureSet(config, index2pubkey, state, voluntaryExit)
46
50
  );
47
51
  }
@@ -111,7 +111,10 @@ 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.epochCtx.index2pubkey, postState, signedBlock)) {
114
+ if (
115
+ verifyProposer &&
116
+ !verifyProposerSignature(postState.config, postState.epochCtx.index2pubkey, postState, signedBlock)
117
+ ) {
115
118
  throw new Error("Invalid block signature");
116
119
  }
117
120
 
@@ -2,6 +2,7 @@ import {ForkName, ForkPostBellatrix, ForkPreGloas, ForkSeq} from "@lodestar/para
2
2
  import {
3
3
  BeaconBlock,
4
4
  BeaconBlockBody,
5
+ BlindedBeaconBlock,
5
6
  BlindedBeaconBlockBody,
6
7
  ExecutionPayload,
7
8
  ExecutionPayloadHeader,
@@ -9,16 +10,54 @@ import {
9
10
  capella,
10
11
  deneb,
11
12
  isBlindedBeaconBlockBody,
13
+ isExecutionPayload,
12
14
  ssz,
13
15
  } from "@lodestar/types";
14
16
  import {
15
17
  BeaconStateAllForks,
18
+ BeaconStateBellatrix,
16
19
  BeaconStateCapella,
17
20
  BeaconStateExecutions,
18
21
  CachedBeaconStateAllForks,
19
22
  CachedBeaconStateExecutions,
20
23
  } from "../types.js";
21
24
 
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 before isExecutionEnabled() prevents this from happening
35
+ const payload = getFullOrBlindedPayload(block);
36
+
37
+ return isExecutionPayload(payload)
38
+ ? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
39
+ : !ssz.bellatrix.ExecutionPayloadHeader.equals(
40
+ state.latestExecutionPayloadHeader,
41
+ ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
42
+ );
43
+ }
44
+
45
+ /**
46
+ * Merge is complete when the state includes execution layer data:
47
+ * state.latestExecutionPayloadHeader NOT EMPTY or state is post-capella
48
+ */
49
+ export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
50
+ if (isCapellaStateType(state)) {
51
+ // All networks have completed the merge transition before capella
52
+ return true;
53
+ }
54
+
55
+ return !ssz.bellatrix.ExecutionPayloadHeader.equals(
56
+ (state as BeaconStateBellatrix).latestExecutionPayloadHeader,
57
+ ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
58
+ );
59
+ }
60
+
22
61
  /** Type guard for bellatrix.BeaconState */
23
62
  export function isExecutionStateType(state: BeaconStateAllForks): state is BeaconStateExecutions {
24
63
  return (state as BeaconStateExecutions).latestExecutionPayloadHeader !== undefined;