@lodestar/state-transition 1.38.0 → 1.39.0-dev.2fe8de2346

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 (88) hide show
  1. package/lib/block/index.d.ts.map +1 -1
  2. package/lib/block/index.js +2 -4
  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.js +1 -1
  12. package/lib/block/processAttestationsAltair.js.map +1 -1
  13. package/lib/block/processAttesterSlashing.d.ts +2 -1
  14. package/lib/block/processAttesterSlashing.d.ts.map +1 -1
  15. package/lib/block/processAttesterSlashing.js +5 -4
  16. package/lib/block/processAttesterSlashing.js.map +1 -1
  17. package/lib/block/processExecutionPayload.d.ts.map +1 -1
  18. package/lib/block/processExecutionPayload.js +4 -6
  19. package/lib/block/processExecutionPayload.js.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 -4
  27. package/lib/block/processSyncCommittee.js.map +1 -1
  28. package/lib/block/processVoluntaryExit.js +1 -1
  29. package/lib/block/processVoluntaryExit.js.map +1 -1
  30. package/lib/cache/epochCache.d.ts +0 -3
  31. package/lib/cache/epochCache.d.ts.map +1 -1
  32. package/lib/cache/epochCache.js +0 -3
  33. package/lib/cache/epochCache.js.map +1 -1
  34. package/lib/signatureSets/attesterSlashings.d.ts +4 -3
  35. package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
  36. package/lib/signatureSets/attesterSlashings.js +6 -6
  37. package/lib/signatureSets/attesterSlashings.js.map +1 -1
  38. package/lib/signatureSets/index.d.ts +3 -2
  39. package/lib/signatureSets/index.d.ts.map +1 -1
  40. package/lib/signatureSets/index.js +8 -8
  41. package/lib/signatureSets/index.js.map +1 -1
  42. package/lib/signatureSets/indexedAttestation.d.ts +4 -3
  43. package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
  44. package/lib/signatureSets/indexedAttestation.js +6 -6
  45. package/lib/signatureSets/indexedAttestation.js.map +1 -1
  46. package/lib/signatureSets/proposer.d.ts +5 -4
  47. package/lib/signatureSets/proposer.d.ts.map +1 -1
  48. package/lib/signatureSets/proposer.js +12 -12
  49. package/lib/signatureSets/proposer.js.map +1 -1
  50. package/lib/signatureSets/proposerSlashings.d.ts +3 -2
  51. package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
  52. package/lib/signatureSets/proposerSlashings.js +4 -5
  53. package/lib/signatureSets/proposerSlashings.js.map +1 -1
  54. package/lib/signatureSets/randao.d.ts +3 -2
  55. package/lib/signatureSets/randao.d.ts.map +1 -1
  56. package/lib/signatureSets/randao.js +4 -5
  57. package/lib/signatureSets/randao.js.map +1 -1
  58. package/lib/signatureSets/voluntaryExits.d.ts +4 -3
  59. package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
  60. package/lib/signatureSets/voluntaryExits.js +6 -7
  61. package/lib/signatureSets/voluntaryExits.js.map +1 -1
  62. package/lib/stateTransition.js +1 -1
  63. package/lib/stateTransition.js.map +1 -1
  64. package/lib/util/execution.d.ts +1 -16
  65. package/lib/util/execution.d.ts.map +1 -1
  66. package/lib/util/execution.js +1 -44
  67. package/lib/util/execution.js.map +1 -1
  68. package/package.json +6 -6
  69. package/src/block/index.ts +2 -6
  70. package/src/block/isValidIndexedAttestation.ts +5 -2
  71. package/src/block/processAttestationPhase0.ts +8 -1
  72. package/src/block/processAttestationsAltair.ts +1 -1
  73. package/src/block/processAttesterSlashing.ts +6 -3
  74. package/src/block/processExecutionPayload.ts +8 -14
  75. package/src/block/processProposerSlashing.ts +1 -1
  76. package/src/block/processRandao.ts +1 -1
  77. package/src/block/processSyncCommittee.ts +4 -3
  78. package/src/block/processVoluntaryExit.ts +1 -1
  79. package/src/cache/epochCache.ts +0 -3
  80. package/src/signatureSets/attesterSlashings.ts +7 -3
  81. package/src/signatureSets/index.ts +10 -7
  82. package/src/signatureSets/indexedAttestation.ts +14 -3
  83. package/src/signatureSets/proposer.ts +13 -7
  84. package/src/signatureSets/proposerSlashings.ts +5 -3
  85. package/src/signatureSets/randao.ts +13 -5
  86. package/src/signatureSets/voluntaryExits.ts +7 -4
  87. package/src/stateTransition.ts +1 -1
  88. package/src/util/execution.ts +0 -60
@@ -1,5 +1,6 @@
1
1
  import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
2
2
  import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
5
6
 
@@ -7,11 +8,11 @@ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index
7
8
  * Extract signatures to allow validating all block signatures at once
8
9
  */
9
10
  export function getProposerSlashingSignatureSets(
11
+ index2pubkey: Index2PubkeyCache,
10
12
  state: CachedBeaconStateAllForks,
11
13
  proposerSlashing: phase0.ProposerSlashing
12
14
  ): ISignatureSet[] {
13
- const {epochCtx} = state;
14
- const pubkey = epochCtx.index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
15
+ const pubkey = index2pubkey[proposerSlashing.signedHeader1.message.proposerIndex];
15
16
 
16
17
  // In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
17
18
  // clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
@@ -32,10 +33,11 @@ export function getProposerSlashingSignatureSets(
32
33
  }
33
34
 
34
35
  export function getProposerSlashingsSignatureSets(
36
+ index2pubkey: Index2PubkeyCache,
35
37
  state: CachedBeaconStateAllForks,
36
38
  signedBlock: SignedBeaconBlock
37
39
  ): ISignatureSet[] {
38
40
  return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
39
- getProposerSlashingSignatureSets(state, proposerSlashing)
41
+ getProposerSlashingSignatureSets(index2pubkey, state, proposerSlashing)
40
42
  );
41
43
  }
@@ -1,5 +1,6 @@
1
1
  import {DOMAIN_RANDAO} from "@lodestar/params";
2
2
  import {BeaconBlock, ssz} from "@lodestar/types";
3
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
3
4
  import {CachedBeaconStateAllForks} from "../types.js";
4
5
  import {
5
6
  ISignatureSet,
@@ -9,22 +10,29 @@ import {
9
10
  verifySignatureSet,
10
11
  } from "../util/index.js";
11
12
 
12
- export function verifyRandaoSignature(state: CachedBeaconStateAllForks, block: BeaconBlock): boolean {
13
- return verifySignatureSet(getRandaoRevealSignatureSet(state, block));
13
+ export function verifyRandaoSignature(
14
+ index2pubkey: Index2PubkeyCache,
15
+ state: CachedBeaconStateAllForks,
16
+ block: BeaconBlock
17
+ ): boolean {
18
+ return verifySignatureSet(getRandaoRevealSignatureSet(index2pubkey, state, block));
14
19
  }
15
20
 
16
21
  /**
17
22
  * Extract signatures to allow validating all block signatures at once
18
23
  */
19
- export function getRandaoRevealSignatureSet(state: CachedBeaconStateAllForks, block: BeaconBlock): ISignatureSet {
20
- const {epochCtx} = state;
24
+ export function getRandaoRevealSignatureSet(
25
+ index2pubkey: Index2PubkeyCache,
26
+ state: CachedBeaconStateAllForks,
27
+ block: BeaconBlock
28
+ ): ISignatureSet {
21
29
  // should not get epoch from epochCtx
22
30
  const epoch = computeEpochAtSlot(block.slot);
23
31
  const domain = state.config.getDomain(state.slot, DOMAIN_RANDAO, block.slot);
24
32
 
25
33
  return {
26
34
  type: SignatureSetType.single,
27
- pubkey: epochCtx.index2pubkey[block.proposerIndex],
35
+ pubkey: index2pubkey[block.proposerIndex],
28
36
  signingRoot: computeSigningRoot(ssz.Epoch, epoch, domain),
29
37
  signature: block.body.randaoReveal,
30
38
  };
@@ -1,4 +1,5 @@
1
1
  import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types";
2
+ import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
2
3
  import {CachedBeaconStateAllForks} from "../types.js";
3
4
  import {
4
5
  ISignatureSet,
@@ -9,36 +10,38 @@ import {
9
10
  } from "../util/index.js";
10
11
 
11
12
  export function verifyVoluntaryExitSignature(
13
+ index2pubkey: Index2PubkeyCache,
12
14
  state: CachedBeaconStateAllForks,
13
15
  signedVoluntaryExit: phase0.SignedVoluntaryExit
14
16
  ): boolean {
15
- return verifySignatureSet(getVoluntaryExitSignatureSet(state, signedVoluntaryExit));
17
+ return verifySignatureSet(getVoluntaryExitSignatureSet(index2pubkey, state, signedVoluntaryExit));
16
18
  }
17
19
 
18
20
  /**
19
21
  * Extract signatures to allow validating all block signatures at once
20
22
  */
21
23
  export function getVoluntaryExitSignatureSet(
24
+ index2pubkey: Index2PubkeyCache,
22
25
  state: CachedBeaconStateAllForks,
23
26
  signedVoluntaryExit: phase0.SignedVoluntaryExit
24
27
  ): ISignatureSet {
25
- const {epochCtx} = state;
26
28
  const slot = computeStartSlotAtEpoch(signedVoluntaryExit.message.epoch);
27
29
  const domain = state.config.getDomainForVoluntaryExit(state.slot, slot);
28
30
 
29
31
  return {
30
32
  type: SignatureSetType.single,
31
- pubkey: epochCtx.index2pubkey[signedVoluntaryExit.message.validatorIndex],
33
+ pubkey: index2pubkey[signedVoluntaryExit.message.validatorIndex],
32
34
  signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
33
35
  signature: signedVoluntaryExit.signature,
34
36
  };
35
37
  }
36
38
 
37
39
  export function getVoluntaryExitsSignatureSets(
40
+ index2pubkey: Index2PubkeyCache,
38
41
  state: CachedBeaconStateAllForks,
39
42
  signedBlock: SignedBeaconBlock
40
43
  ): ISignatureSet[] {
41
44
  return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
42
- getVoluntaryExitSignatureSet(state, voluntaryExit)
45
+ getVoluntaryExitSignatureSet(index2pubkey, state, voluntaryExit)
43
46
  );
44
47
  }
@@ -111,7 +111,7 @@ export function stateTransition(
111
111
  postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
112
112
 
113
113
  // Verify proposer signature only
114
- if (verifyProposer && !verifyProposerSignature(postState, signedBlock)) {
114
+ if (verifyProposer && !verifyProposerSignature(postState.epochCtx.index2pubkey, postState, signedBlock)) {
115
115
  throw new Error("Invalid block signature");
116
116
  }
117
117
 
@@ -2,7 +2,6 @@ import {ForkName, ForkPostBellatrix, ForkPreGloas, ForkSeq} from "@lodestar/para
2
2
  import {
3
3
  BeaconBlock,
4
4
  BeaconBlockBody,
5
- BlindedBeaconBlock,
6
5
  BlindedBeaconBlockBody,
7
6
  ExecutionPayload,
8
7
  ExecutionPayloadHeader,
@@ -10,75 +9,16 @@ import {
10
9
  capella,
11
10
  deneb,
12
11
  isBlindedBeaconBlockBody,
13
- isExecutionPayload,
14
12
  ssz,
15
13
  } from "@lodestar/types";
16
14
  import {
17
15
  BeaconStateAllForks,
18
- BeaconStateBellatrix,
19
16
  BeaconStateCapella,
20
17
  BeaconStateExecutions,
21
18
  CachedBeaconStateAllForks,
22
19
  CachedBeaconStateExecutions,
23
20
  } from "../types.js";
24
21
 
25
- /**
26
- * Execution enabled = merge is done.
27
- * When (A) state has execution data OR (B) block has execution data
28
- */
29
- export function isExecutionEnabled(state: BeaconStateExecutions, block: BeaconBlock | BlindedBeaconBlock): boolean {
30
- if (isMergeTransitionComplete(state)) {
31
- return true;
32
- }
33
-
34
- // Throws if not post-bellatrix block. A fork-guard in isExecutionEnabled() prevents this from happening
35
- const payload = getFullOrBlindedPayload(block);
36
- // Note: spec says to check all payload is zero-ed. However a state-root cannot be zero for any non-empty payload
37
- // TODO: Consider comparing with the payload root if this assumption is not correct.
38
- // return !byteArrayEquals(payload.stateRoot, ZERO_HASH);
39
-
40
- // UPDATE: stateRoot comparision should have been enough with zero hash, but spec tests were failing
41
- // Revisit this later to fix specs and make this efficient
42
- return isExecutionPayload(payload)
43
- ? !ssz.bellatrix.ExecutionPayload.equals(payload, ssz.bellatrix.ExecutionPayload.defaultValue())
44
- : !ssz.bellatrix.ExecutionPayloadHeader.equals(
45
- state.latestExecutionPayloadHeader,
46
- // TODO: Performance
47
- ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
48
- );
49
- }
50
-
51
- /**
52
- * Merge block is the SINGLE block that transitions from POW to POS.
53
- * state has no execution data AND this block has execution data
54
- */
55
- export function isMergeTransitionBlock(state: BeaconStateExecutions, body: bellatrix.BeaconBlockBody): boolean {
56
- return (
57
- !isMergeTransitionComplete(state) &&
58
- !ssz.bellatrix.ExecutionPayload.equals(body.executionPayload, ssz.bellatrix.ExecutionPayload.defaultValue())
59
- );
60
- }
61
-
62
- /**
63
- * Merge is complete when the state includes execution layer data:
64
- * state.latestExecutionPayloadHeader NOT EMPTY
65
- */
66
- export function isMergeTransitionComplete(state: BeaconStateExecutions): boolean {
67
- if (!isCapellaStateType(state)) {
68
- return !ssz.bellatrix.ExecutionPayloadHeader.equals(
69
- (state as BeaconStateBellatrix).latestExecutionPayloadHeader,
70
- // TODO: Performance
71
- ssz.bellatrix.ExecutionPayloadHeader.defaultValue()
72
- );
73
- }
74
-
75
- return !ssz.capella.ExecutionPayloadHeader.equals(
76
- state.latestExecutionPayloadHeader,
77
- // TODO: Performance
78
- ssz.capella.ExecutionPayloadHeader.defaultValue()
79
- );
80
- }
81
-
82
22
  /** Type guard for bellatrix.BeaconState */
83
23
  export function isExecutionStateType(state: BeaconStateAllForks): state is BeaconStateExecutions {
84
24
  return (state as BeaconStateExecutions).latestExecutionPayloadHeader !== undefined;