@lodestar/state-transition 1.43.0-dev.ca1fc40294 → 1.43.0-dev.dfb984e779

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 (38) hide show
  1. package/lib/block/index.d.ts +2 -2
  2. package/lib/block/index.d.ts.map +1 -1
  3. package/lib/block/index.js +11 -4
  4. package/lib/block/index.js.map +1 -1
  5. package/lib/block/processParentExecutionPayload.d.ts +20 -0
  6. package/lib/block/processParentExecutionPayload.d.ts.map +1 -0
  7. package/lib/block/processParentExecutionPayload.js +100 -0
  8. package/lib/block/processParentExecutionPayload.js.map +1 -0
  9. package/lib/block/processWithdrawals.d.ts.map +1 -1
  10. package/lib/block/processWithdrawals.js +12 -4
  11. package/lib/block/processWithdrawals.js.map +1 -1
  12. package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
  13. package/lib/slot/upgradeStateToGloas.js +1 -0
  14. package/lib/slot/upgradeStateToGloas.js.map +1 -1
  15. package/lib/stateView/beaconStateView.d.ts +4 -2
  16. package/lib/stateView/beaconStateView.d.ts.map +1 -1
  17. package/lib/stateView/beaconStateView.js +15 -9
  18. package/lib/stateView/beaconStateView.js.map +1 -1
  19. package/lib/stateView/interface.d.ts +6 -2
  20. package/lib/stateView/interface.d.ts.map +1 -1
  21. package/lib/stateView/interface.js.map +1 -1
  22. package/lib/util/computeAnchorCheckpoint.d.ts +1 -1
  23. package/lib/util/computeAnchorCheckpoint.d.ts.map +1 -1
  24. package/lib/util/computeAnchorCheckpoint.js +6 -19
  25. package/lib/util/computeAnchorCheckpoint.js.map +1 -1
  26. package/package.json +7 -7
  27. package/src/block/index.ts +12 -4
  28. package/src/block/processParentExecutionPayload.ts +116 -0
  29. package/src/block/processWithdrawals.ts +12 -4
  30. package/src/slot/upgradeStateToGloas.ts +3 -0
  31. package/src/stateView/beaconStateView.ts +15 -16
  32. package/src/stateView/interface.ts +6 -5
  33. package/src/util/computeAnchorCheckpoint.ts +6 -19
  34. package/lib/block/processExecutionPayloadEnvelope.d.ts +0 -9
  35. package/lib/block/processExecutionPayloadEnvelope.d.ts.map +0 -1
  36. package/lib/block/processExecutionPayloadEnvelope.js +0 -103
  37. package/lib/block/processExecutionPayloadEnvelope.js.map +0 -1
  38. package/src/block/processExecutionPayloadEnvelope.ts +0 -169
@@ -1,169 +0,0 @@
1
- import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
2
- import {gloas, ssz} from "@lodestar/types";
3
- import {byteArrayEquals, toHex, toRootHex} from "@lodestar/utils";
4
- import {getExecutionPayloadEnvelopeSignatureSet} from "../signatureSets/executionPayloadEnvelope.js";
5
- import {BeaconStateView} from "../stateView/beaconStateView.js";
6
- import {CachedBeaconStateGloas} from "../types.js";
7
- import {computeTimeAtSlot} from "../util/index.js";
8
- import {verifySignatureSet} from "../util/signatureSets.js";
9
- import {processConsolidationRequest} from "./processConsolidationRequest.js";
10
- import {getPendingValidatorPubkeys, processDepositRequest} from "./processDepositRequest.js";
11
- import {processWithdrawalRequest} from "./processWithdrawalRequest.js";
12
-
13
- export type ProcessExecutionPayloadEnvelopeOpts = {
14
- verifySignature?: boolean;
15
- verifyStateRoot?: boolean;
16
- dontTransferCache?: boolean;
17
- };
18
-
19
- // Unlike other block processing functions which mutate state in-place, this function
20
- // clones the state and returns the post-state, similar to stateTransition().
21
- // This function does not call execution engine to verify payload. Need to call it from other place.
22
- export function processExecutionPayloadEnvelope(
23
- state: CachedBeaconStateGloas,
24
- signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
25
- opts?: ProcessExecutionPayloadEnvelopeOpts
26
- ): CachedBeaconStateGloas {
27
- const {verifySignature = true} = opts ?? {};
28
- const envelope = signedEnvelope.message;
29
- const payload = envelope.payload;
30
- const fork = state.config.getForkSeq(payload.slotNumber);
31
-
32
- if (verifySignature && !verifyExecutionPayloadEnvelopeSignature(state, signedEnvelope)) {
33
- throw Error(`Execution payload envelope has invalid signature builderIndex=${envelope.builderIndex}`);
34
- }
35
-
36
- // .clone() before mutating state, similar to stateTransition()
37
- const postState = state.clone(opts?.dontTransferCache) as CachedBeaconStateGloas;
38
-
39
- validateExecutionPayloadEnvelope(postState, envelope);
40
-
41
- const requests = envelope.executionRequests;
42
-
43
- if (requests.deposits.length > 0) {
44
- // Build cache of pending validator pubkeys once, shared across all deposit requests
45
- const pendingValidatorPubkeys = getPendingValidatorPubkeys(postState.config, postState);
46
-
47
- for (const deposit of requests.deposits) {
48
- processDepositRequest(fork, postState, deposit, pendingValidatorPubkeys);
49
- }
50
- }
51
-
52
- for (const withdrawal of requests.withdrawals) {
53
- processWithdrawalRequest(fork, postState, withdrawal);
54
- }
55
-
56
- for (const consolidation of requests.consolidations) {
57
- processConsolidationRequest(postState, consolidation);
58
- }
59
-
60
- // Queue the builder payment
61
- const paymentIndex = SLOTS_PER_EPOCH + (postState.slot % SLOTS_PER_EPOCH);
62
- const payment = postState.builderPendingPayments.get(paymentIndex).clone();
63
- const amount = payment.withdrawal.amount;
64
-
65
- if (amount > 0) {
66
- postState.builderPendingWithdrawals.push(payment.withdrawal);
67
- }
68
-
69
- postState.builderPendingPayments.set(paymentIndex, ssz.gloas.BuilderPendingPayment.defaultViewDU());
70
-
71
- // Cache the execution payload hash
72
- postState.executionPayloadAvailability.set(postState.slot % SLOTS_PER_HISTORICAL_ROOT, true);
73
- postState.latestBlockHash = payload.blockHash;
74
-
75
- postState.commit();
76
-
77
- return postState;
78
- }
79
-
80
- function validateExecutionPayloadEnvelope(
81
- state: CachedBeaconStateGloas,
82
- envelope: gloas.ExecutionPayloadEnvelope
83
- ): void {
84
- const payload = envelope.payload;
85
-
86
- // Cache latest block header state root
87
- if (byteArrayEquals(state.latestBlockHeader.stateRoot, ssz.Root.defaultValue())) {
88
- const previousStateRoot = state.hashTreeRoot();
89
- state.latestBlockHeader.stateRoot = previousStateRoot;
90
- }
91
-
92
- // Verify consistency with the beacon block
93
- if (!byteArrayEquals(envelope.beaconBlockRoot, state.latestBlockHeader.hashTreeRoot())) {
94
- throw new Error(
95
- `Envelope's block is not the latest block header envelope=${toRootHex(envelope.beaconBlockRoot)} latestBlockHeader=${toRootHex(state.latestBlockHeader.hashTreeRoot())}`
96
- );
97
- }
98
-
99
- if (payload.slotNumber !== state.slot) {
100
- throw new Error(`Slot mismatch between payload and state payload=${payload.slotNumber} state=${state.slot}`);
101
- }
102
-
103
- // Verify consistency with the committed bid
104
- const committedBid = state.latestExecutionPayloadBid;
105
- if (envelope.builderIndex !== committedBid.builderIndex) {
106
- throw new Error(
107
- `Builder index mismatch between envelope and committed bid envelope=${envelope.builderIndex} committedBid=${committedBid.builderIndex}`
108
- );
109
- }
110
-
111
- if (!byteArrayEquals(committedBid.prevRandao, payload.prevRandao)) {
112
- throw new Error(
113
- `Prev randao mismatch between committed bid and payload committedBid=${toHex(committedBid.prevRandao)} payload=${toHex(payload.prevRandao)}`
114
- );
115
- }
116
-
117
- // Verify consistency with expected withdrawals
118
- const payloadWithdrawalsRoot = ssz.capella.Withdrawals.hashTreeRoot(payload.withdrawals);
119
- const expectedWithdrawalsRoot = state.payloadExpectedWithdrawals.hashTreeRoot();
120
- if (!byteArrayEquals(payloadWithdrawalsRoot, expectedWithdrawalsRoot)) {
121
- throw new Error(
122
- `Withdrawals mismatch between payload and expected withdrawals payload=${toRootHex(payloadWithdrawalsRoot)} expected=${toRootHex(expectedWithdrawalsRoot)}`
123
- );
124
- }
125
-
126
- // Verify the gas_limit
127
- if (Number(committedBid.gasLimit) !== payload.gasLimit) {
128
- throw new Error(
129
- `Gas limit mismatch between envelope's payload and committed bid envelope=${payload.gasLimit} committedBid=${Number(committedBid.gasLimit)}`
130
- );
131
- }
132
-
133
- // Verify the block hash
134
- if (!byteArrayEquals(committedBid.blockHash, payload.blockHash)) {
135
- throw new Error(
136
- `Block hash mismatch between envelope's payload and committed bid envelope=${toRootHex(payload.blockHash)} committedBid=${toRootHex(committedBid.blockHash)}`
137
- );
138
- }
139
-
140
- // Verify consistency of the parent hash with respect to the previous execution payload
141
- if (!byteArrayEquals(payload.parentHash, state.latestBlockHash)) {
142
- throw new Error(
143
- `Parent hash mismatch between envelope's payload and state envelope=${toRootHex(payload.parentHash)} state=${toRootHex(state.latestBlockHash)}`
144
- );
145
- }
146
-
147
- // Verify timestamp
148
- if (payload.timestamp !== computeTimeAtSlot(state.config, state.slot, state.genesisTime)) {
149
- throw new Error(
150
- `Timestamp mismatch between envelope's payload and state envelope=${payload.timestamp} state=${computeTimeAtSlot(state.config, state.slot, state.genesisTime)}`
151
- );
152
- }
153
-
154
- // Skipped: Verify the execution payload is valid
155
- }
156
-
157
- function verifyExecutionPayloadEnvelopeSignature(
158
- state: CachedBeaconStateGloas,
159
- signedEnvelope: gloas.SignedExecutionPayloadEnvelope
160
- ): boolean {
161
- const signatureSet = getExecutionPayloadEnvelopeSignatureSet(
162
- state.config,
163
- state.epochCtx.pubkeyCache,
164
- new BeaconStateView(state),
165
- signedEnvelope,
166
- state.latestBlockHeader.proposerIndex
167
- );
168
- return verifySignatureSet(signatureSet);
169
- }