@lodestar/state-transition 1.43.0-dev.aef3645690 → 1.43.0-dev.b741495bdc
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.
- package/lib/block/index.d.ts +2 -2
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +11 -4
- package/lib/block/index.js.map +1 -1
- package/lib/block/processParentExecutionPayload.d.ts +20 -0
- package/lib/block/processParentExecutionPayload.d.ts.map +1 -0
- package/lib/block/processParentExecutionPayload.js +100 -0
- package/lib/block/processParentExecutionPayload.js.map +1 -0
- package/lib/block/processWithdrawals.d.ts.map +1 -1
- package/lib/block/processWithdrawals.js +12 -4
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/cache/epochCache.d.ts +3 -1
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +31 -13
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/epochTransitionCache.d.ts +5 -0
- package/lib/cache/epochTransitionCache.d.ts.map +1 -1
- package/lib/cache/epochTransitionCache.js +1 -0
- package/lib/cache/epochTransitionCache.js.map +1 -1
- package/lib/epoch/index.d.ts +3 -1
- package/lib/epoch/index.d.ts.map +1 -1
- package/lib/epoch/index.js +8 -1
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processPtcWindow.d.ts +11 -0
- package/lib/epoch/processPtcWindow.d.ts.map +1 -0
- package/lib/epoch/processPtcWindow.js +28 -0
- package/lib/epoch/processPtcWindow.js.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.js +1 -1
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +3 -1
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/stateTransition.d.ts +1 -2
- package/lib/stateTransition.d.ts.map +1 -1
- package/lib/stateTransition.js +1 -2
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +8 -10
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +34 -38
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +19 -11
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/util/computeAnchorCheckpoint.d.ts +1 -1
- package/lib/util/computeAnchorCheckpoint.d.ts.map +1 -1
- package/lib/util/computeAnchorCheckpoint.js +6 -19
- package/lib/util/computeAnchorCheckpoint.js.map +1 -1
- package/lib/util/execution.d.ts +4 -2
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +7 -0
- package/lib/util/execution.js.map +1 -1
- package/lib/util/gloas.d.ts +8 -3
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +27 -1
- package/lib/util/gloas.js.map +1 -1
- package/package.json +8 -8
- package/src/block/index.ts +12 -4
- package/src/block/processParentExecutionPayload.ts +116 -0
- package/src/block/processWithdrawals.ts +12 -4
- package/src/cache/epochCache.ts +32 -30
- package/src/cache/epochTransitionCache.ts +7 -0
- package/src/epoch/index.ts +9 -0
- package/src/epoch/processPtcWindow.ts +38 -0
- package/src/signatureSets/executionPayloadEnvelope.ts +1 -1
- package/src/slot/upgradeStateToGloas.ts +5 -1
- package/src/stateTransition.ts +1 -2
- package/src/stateView/beaconStateView.ts +46 -49
- package/src/stateView/interface.ts +26 -14
- package/src/util/computeAnchorCheckpoint.ts +6 -19
- package/src/util/execution.ts +11 -1
- package/src/util/gloas.ts +50 -3
- package/lib/block/processExecutionPayloadEnvelope.d.ts +0 -9
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +0 -1
- package/lib/block/processExecutionPayloadEnvelope.js +0 -106
- package/lib/block/processExecutionPayloadEnvelope.js.map +0 -1
- package/src/block/processExecutionPayloadEnvelope.ts +0 -175
|
@@ -1,175 +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, verifyStateRoot = true} = opts ?? {};
|
|
28
|
-
const envelope = signedEnvelope.message;
|
|
29
|
-
const payload = envelope.payload;
|
|
30
|
-
const fork = state.config.getForkSeq(envelope.slot);
|
|
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
|
-
if (verifyStateRoot && !byteArrayEquals(envelope.stateRoot, postState.hashTreeRoot())) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Envelope's state root does not match state envelope=${toRootHex(envelope.stateRoot)} state=${toRootHex(postState.hashTreeRoot())}`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return postState;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function validateExecutionPayloadEnvelope(
|
|
87
|
-
state: CachedBeaconStateGloas,
|
|
88
|
-
envelope: gloas.ExecutionPayloadEnvelope
|
|
89
|
-
): void {
|
|
90
|
-
const payload = envelope.payload;
|
|
91
|
-
|
|
92
|
-
// Cache latest block header state root
|
|
93
|
-
if (byteArrayEquals(state.latestBlockHeader.stateRoot, ssz.Root.defaultValue())) {
|
|
94
|
-
const previousStateRoot = state.hashTreeRoot();
|
|
95
|
-
state.latestBlockHeader.stateRoot = previousStateRoot;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Verify consistency with the beacon block
|
|
99
|
-
if (!byteArrayEquals(envelope.beaconBlockRoot, state.latestBlockHeader.hashTreeRoot())) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Envelope's block is not the latest block header envelope=${toRootHex(envelope.beaconBlockRoot)} latestBlockHeader=${toRootHex(state.latestBlockHeader.hashTreeRoot())}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (envelope.slot !== state.slot) {
|
|
106
|
-
throw new Error(`Slot mismatch between envelope and state envelope=${envelope.slot} state=${state.slot}`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Verify consistency with the committed bid
|
|
110
|
-
const committedBid = state.latestExecutionPayloadBid;
|
|
111
|
-
if (envelope.builderIndex !== committedBid.builderIndex) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`Builder index mismatch between envelope and committed bid envelope=${envelope.builderIndex} committedBid=${committedBid.builderIndex}`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!byteArrayEquals(committedBid.prevRandao, payload.prevRandao)) {
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Prev randao mismatch between committed bid and payload committedBid=${toHex(committedBid.prevRandao)} payload=${toHex(payload.prevRandao)}`
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Verify consistency with expected withdrawals
|
|
124
|
-
const payloadWithdrawalsRoot = ssz.capella.Withdrawals.hashTreeRoot(payload.withdrawals);
|
|
125
|
-
const expectedWithdrawalsRoot = state.payloadExpectedWithdrawals.hashTreeRoot();
|
|
126
|
-
if (!byteArrayEquals(payloadWithdrawalsRoot, expectedWithdrawalsRoot)) {
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Withdrawals mismatch between payload and expected withdrawals payload=${toRootHex(payloadWithdrawalsRoot)} expected=${toRootHex(expectedWithdrawalsRoot)}`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Verify the gas_limit
|
|
133
|
-
if (Number(committedBid.gasLimit) !== payload.gasLimit) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`Gas limit mismatch between envelope's payload and committed bid envelope=${payload.gasLimit} committedBid=${Number(committedBid.gasLimit)}`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Verify the block hash
|
|
140
|
-
if (!byteArrayEquals(committedBid.blockHash, payload.blockHash)) {
|
|
141
|
-
throw new Error(
|
|
142
|
-
`Block hash mismatch between envelope's payload and committed bid envelope=${toRootHex(payload.blockHash)} committedBid=${toRootHex(committedBid.blockHash)}`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Verify consistency of the parent hash with respect to the previous execution payload
|
|
147
|
-
if (!byteArrayEquals(payload.parentHash, state.latestBlockHash)) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
`Parent hash mismatch between envelope's payload and state envelope=${toRootHex(payload.parentHash)} state=${toRootHex(state.latestBlockHash)}`
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Verify timestamp
|
|
154
|
-
if (payload.timestamp !== computeTimeAtSlot(state.config, state.slot, state.genesisTime)) {
|
|
155
|
-
throw new Error(
|
|
156
|
-
`Timestamp mismatch between envelope's payload and state envelope=${payload.timestamp} state=${computeTimeAtSlot(state.config, state.slot, state.genesisTime)}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Skipped: Verify the execution payload is valid
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function verifyExecutionPayloadEnvelopeSignature(
|
|
164
|
-
state: CachedBeaconStateGloas,
|
|
165
|
-
signedEnvelope: gloas.SignedExecutionPayloadEnvelope
|
|
166
|
-
): boolean {
|
|
167
|
-
const signatureSet = getExecutionPayloadEnvelopeSignatureSet(
|
|
168
|
-
state.config,
|
|
169
|
-
state.epochCtx.pubkeyCache,
|
|
170
|
-
new BeaconStateView(state),
|
|
171
|
-
signedEnvelope,
|
|
172
|
-
state.latestBlockHeader.proposerIndex
|
|
173
|
-
);
|
|
174
|
-
return verifySignatureSet(signatureSet);
|
|
175
|
-
}
|