@lodestar/state-transition 1.40.0-dev.0ae7a89ead → 1.40.0-dev.193b2e2047
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 +1 -0
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -0
- package/lib/block/index.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedAttestation.js +2 -2
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +2 -2
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processConsolidationRequest.d.ts +1 -2
- package/lib/block/processConsolidationRequest.d.ts.map +1 -1
- package/lib/block/processConsolidationRequest.js +2 -2
- package/lib/block/processConsolidationRequest.js.map +1 -1
- package/lib/block/processDepositRequest.d.ts +8 -2
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +81 -8
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +16 -29
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +26 -25
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processOperations.js +2 -2
- package/lib/block/processOperations.js.map +1 -1
- package/lib/block/processProposerSlashing.js +2 -2
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processSyncCommittee.d.ts +1 -2
- package/lib/block/processSyncCommittee.d.ts.map +1 -1
- package/lib/block/processSyncCommittee.js +5 -5
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.d.ts +1 -1
- package/lib/block/processVoluntaryExit.d.ts.map +1 -1
- package/lib/block/processVoluntaryExit.js +45 -3
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js +1 -1
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/block/processWithdrawals.d.ts +1 -0
- package/lib/block/processWithdrawals.d.ts.map +1 -1
- package/lib/block/processWithdrawals.js +121 -66
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.d.ts.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.js +1 -4
- package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.d.ts +3 -4
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
- package/lib/signatureSets/attesterSlashings.js +6 -6
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.d.ts +3 -3
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/executionPayloadBid.d.ts +4 -0
- package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -0
- package/lib/signatureSets/executionPayloadBid.js +8 -0
- package/lib/signatureSets/executionPayloadBid.js.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.d.ts +4 -0
- package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.js +8 -0
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -0
- package/lib/signatureSets/index.d.ts +3 -2
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +10 -8
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.d.ts +3 -4
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedAttestation.js +6 -6
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.d.ts +5 -4
- package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.js +3 -3
- package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +3 -3
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +12 -12
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.d.ts +2 -3
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
- package/lib/signatureSets/proposerSlashings.js +6 -6
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +1 -1
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +4 -4
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +2 -2
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +6 -6
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/util/electra.d.ts.map +1 -1
- package/lib/util/electra.js +1 -2
- package/lib/util/electra.js.map +1 -1
- package/lib/util/gloas.d.ts +46 -5
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +91 -5
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/signatureSets.d.ts +38 -5
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +48 -6
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/validator.d.ts +6 -1
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +26 -16
- package/lib/util/validator.js.map +1 -1
- package/package.json +7 -7
- package/src/block/index.ts +1 -0
- package/src/block/isValidIndexedAttestation.ts +3 -2
- package/src/block/isValidIndexedPayloadAttestation.ts +4 -1
- package/src/block/processAttestationsAltair.ts +2 -8
- package/src/block/processConsolidationRequest.ts +2 -3
- package/src/block/processDepositRequest.ts +101 -8
- package/src/block/processExecutionPayloadBid.ts +20 -42
- package/src/block/processExecutionPayloadEnvelope.ts +34 -30
- package/src/block/processOperations.ts +2 -2
- package/src/block/processProposerSlashing.ts +2 -2
- package/src/block/processSyncCommittee.ts +3 -6
- package/src/block/processVoluntaryExit.ts +60 -5
- package/src/block/processWithdrawalRequest.ts +1 -1
- package/src/block/processWithdrawals.ts +168 -70
- package/src/epoch/processBuilderPendingPayments.ts +1 -5
- package/src/signatureSets/attesterSlashings.ts +3 -7
- package/src/signatureSets/blsToExecutionChange.ts +3 -3
- package/src/signatureSets/executionPayloadBid.ts +14 -0
- package/src/signatureSets/executionPayloadEnvelope.ts +13 -0
- package/src/signatureSets/index.ts +8 -9
- package/src/signatureSets/indexedAttestation.ts +2 -7
- package/src/signatureSets/indexedPayloadAttestation.ts +9 -7
- package/src/signatureSets/proposer.ts +8 -12
- package/src/signatureSets/proposerSlashings.ts +4 -7
- package/src/signatureSets/randao.ts +4 -8
- package/src/signatureSets/voluntaryExits.ts +5 -10
- package/src/util/electra.ts +1 -4
- package/src/util/gloas.ts +116 -10
- package/src/util/index.ts +1 -0
- package/src/util/signatureSets.ts +84 -8
- package/src/util/validator.ts +31 -16
|
@@ -1,24 +1,26 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
1
2
|
import {DOMAIN_PTC_ATTESTER} from "@lodestar/params";
|
|
2
|
-
import {gloas, ssz} from "@lodestar/types";
|
|
3
|
-
import {CachedBeaconStateGloas} from "../types.
|
|
4
|
-
import {ISignatureSet, computeSigningRoot, createAggregateSignatureSetFromComponents} from "../util/index.
|
|
3
|
+
import {Slot, gloas, ssz} from "@lodestar/types";
|
|
4
|
+
import {CachedBeaconStateGloas} from "../types.js";
|
|
5
|
+
import {ISignatureSet, computeSigningRoot, createAggregateSignatureSetFromComponents} from "../util/index.js";
|
|
5
6
|
|
|
6
7
|
export function getIndexedPayloadAttestationSignatureSet(
|
|
7
8
|
state: CachedBeaconStateGloas,
|
|
8
9
|
indexedPayloadAttestation: gloas.IndexedPayloadAttestation
|
|
9
10
|
): ISignatureSet {
|
|
10
11
|
return createAggregateSignatureSetFromComponents(
|
|
11
|
-
indexedPayloadAttestation.attestingIndices
|
|
12
|
-
getPayloadAttestationDataSigningRoot(state, indexedPayloadAttestation.data),
|
|
12
|
+
indexedPayloadAttestation.attestingIndices,
|
|
13
|
+
getPayloadAttestationDataSigningRoot(state.config, state.slot, indexedPayloadAttestation.data),
|
|
13
14
|
indexedPayloadAttestation.signature
|
|
14
15
|
);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export function getPayloadAttestationDataSigningRoot(
|
|
18
|
-
|
|
19
|
+
config: BeaconConfig,
|
|
20
|
+
stateSlot: Slot,
|
|
19
21
|
data: gloas.PayloadAttestationData
|
|
20
22
|
): Uint8Array {
|
|
21
|
-
const domain =
|
|
23
|
+
const domain = config.getDomain(stateSlot, DOMAIN_PTC_ATTESTER);
|
|
22
24
|
|
|
23
25
|
return computeSigningRoot(ssz.gloas.PayloadAttestationData, data, domain);
|
|
24
26
|
}
|
|
@@ -10,13 +10,12 @@ export function verifyProposerSignature(
|
|
|
10
10
|
index2pubkey: Index2PubkeyCache,
|
|
11
11
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
12
12
|
): boolean {
|
|
13
|
-
const signatureSet = getBlockProposerSignatureSet(config,
|
|
14
|
-
return verifySignatureSet(signatureSet);
|
|
13
|
+
const signatureSet = getBlockProposerSignatureSet(config, signedBlock);
|
|
14
|
+
return verifySignatureSet(signatureSet, index2pubkey);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function getBlockProposerSignatureSet(
|
|
18
18
|
config: BeaconConfig,
|
|
19
|
-
index2pubkey: Index2PubkeyCache,
|
|
20
19
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
21
20
|
): ISignatureSet {
|
|
22
21
|
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
@@ -29,8 +28,8 @@ export function getBlockProposerSignatureSet(
|
|
|
29
28
|
: config.getForkTypes(signedBlock.message.slot).BeaconBlock;
|
|
30
29
|
|
|
31
30
|
return {
|
|
32
|
-
type: SignatureSetType.
|
|
33
|
-
|
|
31
|
+
type: SignatureSetType.indexed,
|
|
32
|
+
index: signedBlock.message.proposerIndex,
|
|
34
33
|
signingRoot: computeSigningRoot(blockType, signedBlock.message, domain),
|
|
35
34
|
signature: signedBlock.signature,
|
|
36
35
|
};
|
|
@@ -38,32 +37,29 @@ export function getBlockProposerSignatureSet(
|
|
|
38
37
|
|
|
39
38
|
export function getBlockHeaderProposerSignatureSetByParentStateSlot(
|
|
40
39
|
config: BeaconConfig,
|
|
41
|
-
index2pubkey: Index2PubkeyCache,
|
|
42
40
|
parentStateSlot: Slot,
|
|
43
41
|
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
44
42
|
) {
|
|
45
|
-
return getBlockHeaderProposerSignatureSet(config,
|
|
43
|
+
return getBlockHeaderProposerSignatureSet(config, signedBlockHeader, parentStateSlot);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
export function getBlockHeaderProposerSignatureSetByHeaderSlot(
|
|
49
47
|
config: BeaconConfig,
|
|
50
|
-
index2pubkey: Index2PubkeyCache,
|
|
51
48
|
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
52
49
|
) {
|
|
53
|
-
return getBlockHeaderProposerSignatureSet(config,
|
|
50
|
+
return getBlockHeaderProposerSignatureSet(config, signedBlockHeader, signedBlockHeader.message.slot);
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
function getBlockHeaderProposerSignatureSet(
|
|
57
54
|
config: BeaconConfig,
|
|
58
|
-
index2pubkey: Index2PubkeyCache,
|
|
59
55
|
signedBlockHeader: phase0.SignedBeaconBlockHeader,
|
|
60
56
|
domainSlot: Slot
|
|
61
57
|
): ISignatureSet {
|
|
62
58
|
const domain = config.getDomain(domainSlot, DOMAIN_BEACON_PROPOSER, signedBlockHeader.message.slot);
|
|
63
59
|
|
|
64
60
|
return {
|
|
65
|
-
type: SignatureSetType.
|
|
66
|
-
|
|
61
|
+
type: SignatureSetType.indexed,
|
|
62
|
+
index: signedBlockHeader.message.proposerIndex,
|
|
67
63
|
signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeader, signedBlockHeader.message, domain),
|
|
68
64
|
signature: signedBlockHeader.signature,
|
|
69
65
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
|
|
3
3
|
import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
4
|
-
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
4
|
import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index.js";
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -9,11 +8,10 @@ import {ISignatureSet, SignatureSetType, computeSigningRoot} from "../util/index
|
|
|
9
8
|
*/
|
|
10
9
|
export function getProposerSlashingSignatureSets(
|
|
11
10
|
config: BeaconConfig,
|
|
12
|
-
index2pubkey: Index2PubkeyCache,
|
|
13
11
|
stateSlot: Slot,
|
|
14
12
|
proposerSlashing: phase0.ProposerSlashing
|
|
15
13
|
): ISignatureSet[] {
|
|
16
|
-
const
|
|
14
|
+
const proposerIndex = proposerSlashing.signedHeader1.message.proposerIndex;
|
|
17
15
|
|
|
18
16
|
// In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
|
|
19
17
|
// clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
|
|
@@ -21,8 +19,8 @@ export function getProposerSlashingSignatureSets(
|
|
|
21
19
|
const domain = config.getDomain(stateSlot, DOMAIN_BEACON_PROPOSER, Number(signedHeader.message.slot as bigint));
|
|
22
20
|
|
|
23
21
|
return {
|
|
24
|
-
type: SignatureSetType.
|
|
25
|
-
|
|
22
|
+
type: SignatureSetType.indexed,
|
|
23
|
+
index: proposerIndex,
|
|
26
24
|
signingRoot: computeSigningRoot(ssz.phase0.BeaconBlockHeaderBigint, signedHeader.message, domain),
|
|
27
25
|
signature: signedHeader.signature,
|
|
28
26
|
};
|
|
@@ -31,13 +29,12 @@ export function getProposerSlashingSignatureSets(
|
|
|
31
29
|
|
|
32
30
|
export function getProposerSlashingsSignatureSets(
|
|
33
31
|
config: BeaconConfig,
|
|
34
|
-
index2pubkey: Index2PubkeyCache,
|
|
35
32
|
signedBlock: SignedBeaconBlock
|
|
36
33
|
): ISignatureSet[] {
|
|
37
34
|
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
38
35
|
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
39
36
|
const blockSlot = signedBlock.message.slot;
|
|
40
37
|
return signedBlock.message.body.proposerSlashings.flatMap((proposerSlashing) =>
|
|
41
|
-
getProposerSlashingSignatureSets(config,
|
|
38
|
+
getProposerSlashingSignatureSets(config, blockSlot, proposerSlashing)
|
|
42
39
|
);
|
|
43
40
|
}
|
|
@@ -15,17 +15,13 @@ export function verifyRandaoSignature(
|
|
|
15
15
|
index2pubkey: Index2PubkeyCache,
|
|
16
16
|
block: BeaconBlock
|
|
17
17
|
): boolean {
|
|
18
|
-
return verifySignatureSet(getRandaoRevealSignatureSet(config,
|
|
18
|
+
return verifySignatureSet(getRandaoRevealSignatureSet(config, block), index2pubkey);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Extract signatures to allow validating all block signatures at once
|
|
23
23
|
*/
|
|
24
|
-
export function getRandaoRevealSignatureSet(
|
|
25
|
-
config: BeaconConfig,
|
|
26
|
-
index2pubkey: Index2PubkeyCache,
|
|
27
|
-
block: BeaconBlock
|
|
28
|
-
): ISignatureSet {
|
|
24
|
+
export function getRandaoRevealSignatureSet(config: BeaconConfig, block: BeaconBlock): ISignatureSet {
|
|
29
25
|
// should not get epoch from epochCtx
|
|
30
26
|
const epoch = computeEpochAtSlot(block.slot);
|
|
31
27
|
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
@@ -33,8 +29,8 @@ export function getRandaoRevealSignatureSet(
|
|
|
33
29
|
const domain = config.getDomain(block.slot, DOMAIN_RANDAO, block.slot);
|
|
34
30
|
|
|
35
31
|
return {
|
|
36
|
-
type: SignatureSetType.
|
|
37
|
-
|
|
32
|
+
type: SignatureSetType.indexed,
|
|
33
|
+
index: block.proposerIndex,
|
|
38
34
|
signingRoot: computeSigningRoot(ssz.Epoch, epoch, domain),
|
|
39
35
|
signature: block.body.randaoReveal,
|
|
40
36
|
};
|
|
@@ -15,7 +15,7 @@ export function verifyVoluntaryExitSignature(
|
|
|
15
15
|
stateSlot: Slot,
|
|
16
16
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
17
17
|
): boolean {
|
|
18
|
-
return verifySignatureSet(getVoluntaryExitSignatureSet(config,
|
|
18
|
+
return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit), index2pubkey);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -23,7 +23,6 @@ export function verifyVoluntaryExitSignature(
|
|
|
23
23
|
*/
|
|
24
24
|
export function getVoluntaryExitSignatureSet(
|
|
25
25
|
config: BeaconConfig,
|
|
26
|
-
index2pubkey: Index2PubkeyCache,
|
|
27
26
|
stateSlot: Slot,
|
|
28
27
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
29
28
|
): ISignatureSet {
|
|
@@ -31,22 +30,18 @@ export function getVoluntaryExitSignatureSet(
|
|
|
31
30
|
const domain = config.getDomainForVoluntaryExit(stateSlot, messageSlot);
|
|
32
31
|
|
|
33
32
|
return {
|
|
34
|
-
type: SignatureSetType.
|
|
35
|
-
|
|
33
|
+
type: SignatureSetType.indexed,
|
|
34
|
+
index: signedVoluntaryExit.message.validatorIndex,
|
|
36
35
|
signingRoot: computeSigningRoot(ssz.phase0.VoluntaryExit, signedVoluntaryExit.message, domain),
|
|
37
36
|
signature: signedVoluntaryExit.signature,
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
export function getVoluntaryExitsSignatureSets(
|
|
42
|
-
config: BeaconConfig,
|
|
43
|
-
index2pubkey: Index2PubkeyCache,
|
|
44
|
-
signedBlock: SignedBeaconBlock
|
|
45
|
-
): ISignatureSet[] {
|
|
40
|
+
export function getVoluntaryExitsSignatureSets(config: BeaconConfig, signedBlock: SignedBeaconBlock): ISignatureSet[] {
|
|
46
41
|
// the getDomain() api requires the state slot as 1st param, however it's the same to block.slot in state-transition
|
|
47
42
|
// and the same epoch when we verify blocks in batch in beacon-node. So we can safely use block.slot here.
|
|
48
43
|
const blockSlot = signedBlock.message.slot;
|
|
49
44
|
return signedBlock.message.body.voluntaryExits.map((voluntaryExit) =>
|
|
50
|
-
getVoluntaryExitSignatureSet(config,
|
|
45
|
+
getVoluntaryExitSignatureSet(config, blockSlot, voluntaryExit)
|
|
51
46
|
);
|
|
52
47
|
}
|
package/src/util/electra.ts
CHANGED
|
@@ -3,12 +3,9 @@ import {ValidatorIndex, ssz} from "@lodestar/types";
|
|
|
3
3
|
import {G2_POINT_AT_INFINITY} from "../constants/constants.js";
|
|
4
4
|
import {CachedBeaconStateElectra, CachedBeaconStateGloas} from "../types.js";
|
|
5
5
|
import {hasEth1WithdrawalCredential} from "./capella.js";
|
|
6
|
-
import {hasBuilderWithdrawalCredential} from "./gloas.ts";
|
|
7
6
|
|
|
8
7
|
export function hasCompoundingWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
|
|
9
|
-
return
|
|
10
|
-
withdrawalCredentials[0] === COMPOUNDING_WITHDRAWAL_PREFIX || hasBuilderWithdrawalCredential(withdrawalCredentials)
|
|
11
|
-
);
|
|
8
|
+
return withdrawalCredentials[0] === COMPOUNDING_WITHDRAWAL_PREFIX;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
export function hasExecutionWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
|
package/src/util/gloas.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import {byteArrayEquals} from "@chainsafe/ssz";
|
|
2
2
|
import {
|
|
3
|
+
BUILDER_INDEX_FLAG,
|
|
3
4
|
BUILDER_PAYMENT_THRESHOLD_DENOMINATOR,
|
|
4
5
|
BUILDER_PAYMENT_THRESHOLD_NUMERATOR,
|
|
5
6
|
BUILDER_WITHDRAWAL_PREFIX,
|
|
6
7
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
8
|
+
FAR_FUTURE_EPOCH,
|
|
9
|
+
MIN_DEPOSIT_AMOUNT,
|
|
7
10
|
SLOTS_PER_EPOCH,
|
|
8
11
|
} from "@lodestar/params";
|
|
9
|
-
import {gloas} from "@lodestar/types";
|
|
12
|
+
import {BuilderIndex, Epoch, ValidatorIndex, gloas} from "@lodestar/types";
|
|
10
13
|
import {AttestationData} from "@lodestar/types/phase0";
|
|
11
|
-
import {CachedBeaconStateGloas} from "../types.
|
|
12
|
-
import {getBlockRootAtSlot} from "./blockRoot.
|
|
13
|
-
import {computeEpochAtSlot} from "./epoch.
|
|
14
|
-
import {RootCache} from "./rootCache.
|
|
14
|
+
import {CachedBeaconStateGloas} from "../types.js";
|
|
15
|
+
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
16
|
+
import {computeEpochAtSlot} from "./epoch.js";
|
|
17
|
+
import {RootCache} from "./rootCache.js";
|
|
15
18
|
|
|
16
|
-
export function
|
|
19
|
+
export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
|
|
17
20
|
return withdrawalCredentials[0] === BUILDER_WITHDRAWAL_PREFIX;
|
|
18
21
|
}
|
|
19
22
|
|
|
@@ -25,14 +28,117 @@ export function getBuilderPaymentQuorumThreshold(state: CachedBeaconStateGloas):
|
|
|
25
28
|
return Math.floor(quorum / BUILDER_PAYMENT_THRESHOLD_DENOMINATOR);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Check if a validator index represents a builder (has the builder flag set).
|
|
33
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-is_builder_index
|
|
34
|
+
*/
|
|
35
|
+
export function isBuilderIndex(validatorIndex: number): boolean {
|
|
36
|
+
return (validatorIndex & BUILDER_INDEX_FLAG) !== 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Convert a builder index to a flagged validator index for use in Withdrawal containers.
|
|
41
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_builder_index_to_validator_index
|
|
42
|
+
*/
|
|
43
|
+
export function convertBuilderIndexToValidatorIndex(builderIndex: BuilderIndex): ValidatorIndex {
|
|
44
|
+
return builderIndex | BUILDER_INDEX_FLAG;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Convert a flagged validator index back to a builder index.
|
|
49
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_validator_index_to_builder_index
|
|
50
|
+
*/
|
|
51
|
+
export function convertValidatorIndexToBuilderIndex(validatorIndex: ValidatorIndex): BuilderIndex {
|
|
52
|
+
return validatorIndex & ~BUILDER_INDEX_FLAG;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Check if a builder is active (deposited and not yet withdrawable).
|
|
57
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#isactivebuilder
|
|
58
|
+
*/
|
|
59
|
+
export function isActiveBuilder(builder: gloas.Builder, finalizedEpoch: Epoch): boolean {
|
|
60
|
+
return builder.depositEpoch < finalizedEpoch && builder.withdrawableEpoch === FAR_FUTURE_EPOCH;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get the total pending balance to withdraw for a builder (from withdrawals + payments).
|
|
65
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-get_pending_balance_to_withdraw_for_builder
|
|
66
|
+
*/
|
|
67
|
+
export function getPendingBalanceToWithdrawForBuilder(
|
|
29
68
|
state: CachedBeaconStateGloas,
|
|
30
|
-
|
|
69
|
+
builderIndex: BuilderIndex
|
|
70
|
+
): number {
|
|
71
|
+
let pendingBalance = 0;
|
|
72
|
+
|
|
73
|
+
// Sum pending withdrawals
|
|
74
|
+
for (let i = 0; i < state.builderPendingWithdrawals.length; i++) {
|
|
75
|
+
const withdrawal = state.builderPendingWithdrawals.getReadonly(i);
|
|
76
|
+
if (withdrawal.builderIndex === builderIndex) {
|
|
77
|
+
pendingBalance += withdrawal.amount;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Sum pending payments
|
|
82
|
+
for (let i = 0; i < state.builderPendingPayments.length; i++) {
|
|
83
|
+
const payment = state.builderPendingPayments.getReadonly(i);
|
|
84
|
+
if (payment.withdrawal.builderIndex === builderIndex) {
|
|
85
|
+
pendingBalance += payment.withdrawal.amount;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return pendingBalance;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Check if a builder has sufficient balance to cover a bid amount.
|
|
94
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-can_builder_cover_bid
|
|
95
|
+
*/
|
|
96
|
+
export function canBuilderCoverBid(
|
|
97
|
+
state: CachedBeaconStateGloas,
|
|
98
|
+
builderIndex: BuilderIndex,
|
|
99
|
+
bidAmount: number
|
|
31
100
|
): boolean {
|
|
32
|
-
const builder = state.
|
|
101
|
+
const builder = state.builders.getReadonly(builderIndex);
|
|
102
|
+
const pendingBalance = getPendingBalanceToWithdrawForBuilder(state, builderIndex);
|
|
103
|
+
const minBalance = MIN_DEPOSIT_AMOUNT + pendingBalance;
|
|
104
|
+
|
|
105
|
+
if (builder.balance < minBalance) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return builder.balance - minBalance >= bidAmount;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Initiate a builder exit by setting their withdrawable epoch.
|
|
114
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-initiate_builder_exit
|
|
115
|
+
*/
|
|
116
|
+
export function initiateBuilderExit(state: CachedBeaconStateGloas, builderIndex: BuilderIndex): void {
|
|
117
|
+
const builder = state.builders.get(builderIndex);
|
|
118
|
+
|
|
119
|
+
// Return if builder already initiated exit
|
|
120
|
+
if (builder.withdrawableEpoch !== FAR_FUTURE_EPOCH) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Set builder exit epoch
|
|
33
125
|
const currentEpoch = computeEpochAtSlot(state.slot);
|
|
126
|
+
builder.withdrawableEpoch = currentEpoch + state.config.MIN_BUILDER_WITHDRAWABILITY_DELAY;
|
|
127
|
+
}
|
|
34
128
|
|
|
35
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Find the index of a builder by their public key.
|
|
131
|
+
* Returns null if not found.
|
|
132
|
+
*
|
|
133
|
+
* May consider builder pubkey cache if performance becomes an issue.
|
|
134
|
+
*/
|
|
135
|
+
export function findBuilderIndexByPubkey(state: CachedBeaconStateGloas, pubkey: Uint8Array): BuilderIndex | null {
|
|
136
|
+
for (let i = 0; i < state.builders.length; i++) {
|
|
137
|
+
if (byteArrayEquals(state.builders.getReadonly(i).pubkey, pubkey)) {
|
|
138
|
+
return i;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
36
142
|
}
|
|
37
143
|
|
|
38
144
|
export function isAttestationSameSlot(state: CachedBeaconStateGloas, data: AttestationData): boolean {
|
package/src/util/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./epochShuffling.js";
|
|
|
15
15
|
export * from "./execution.js";
|
|
16
16
|
export * from "./finality.js";
|
|
17
17
|
export * from "./genesis.js";
|
|
18
|
+
export * from "./gloas.js";
|
|
18
19
|
export * from "./interop.js";
|
|
19
20
|
export * from "./loadState/index.js";
|
|
20
21
|
export * from "./rootCache.js";
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {PublicKey, Signature, fastAggregateVerify, verify} from "@chainsafe/blst";
|
|
1
|
+
import {PublicKey, Signature, aggregatePublicKeys, fastAggregateVerify, verify} from "@chainsafe/blst";
|
|
2
2
|
import {Root} from "@lodestar/types";
|
|
3
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
4
|
|
|
4
5
|
export enum SignatureSetType {
|
|
5
6
|
single = "single",
|
|
6
7
|
aggregate = "aggregate",
|
|
8
|
+
/**
|
|
9
|
+
* Single signature with validator index instead of pubkey.
|
|
10
|
+
* Pubkey lookup is deferred to verification time.
|
|
11
|
+
*/
|
|
12
|
+
indexed = "indexed",
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Single signature with pubkey directly.
|
|
17
|
+
* Used when pubkey comes from the message itself (e.g. BLS to execution change).
|
|
18
|
+
*/
|
|
9
19
|
export type SingleSignatureSet = {
|
|
10
20
|
type: SignatureSetType.single;
|
|
11
21
|
pubkey: PublicKey;
|
|
@@ -13,16 +23,57 @@ export type SingleSignatureSet = {
|
|
|
13
23
|
signature: Uint8Array;
|
|
14
24
|
};
|
|
15
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Single signature with validator index.
|
|
28
|
+
* Pubkey is looked up at verification time.
|
|
29
|
+
*/
|
|
30
|
+
export type IndexedSignatureSet = {
|
|
31
|
+
type: SignatureSetType.indexed;
|
|
32
|
+
index: number;
|
|
33
|
+
signingRoot: Root;
|
|
34
|
+
signature: Uint8Array;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Aggregate signature with validator indices.
|
|
39
|
+
* Pubkeys are looked up and aggregated at verification time.
|
|
40
|
+
*/
|
|
16
41
|
export type AggregatedSignatureSet = {
|
|
17
42
|
type: SignatureSetType.aggregate;
|
|
18
|
-
|
|
43
|
+
indices: number[];
|
|
19
44
|
signingRoot: Root;
|
|
20
45
|
signature: Uint8Array;
|
|
21
46
|
};
|
|
22
47
|
|
|
23
|
-
export type ISignatureSet = SingleSignatureSet | AggregatedSignatureSet;
|
|
48
|
+
export type ISignatureSet = SingleSignatureSet | IndexedSignatureSet | AggregatedSignatureSet;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the pubkey for a signature set, performing aggregation if necessary.
|
|
52
|
+
* Requires index2pubkey cache for indexed and aggregate sets.
|
|
53
|
+
*/
|
|
54
|
+
export function getSignatureSetPubkey(signatureSet: ISignatureSet, index2pubkey: Index2PubkeyCache): PublicKey {
|
|
55
|
+
switch (signatureSet.type) {
|
|
56
|
+
case SignatureSetType.single:
|
|
57
|
+
return signatureSet.pubkey;
|
|
58
|
+
|
|
59
|
+
case SignatureSetType.indexed:
|
|
60
|
+
return index2pubkey[signatureSet.index];
|
|
61
|
+
|
|
62
|
+
case SignatureSetType.aggregate: {
|
|
63
|
+
const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
|
|
64
|
+
return aggregatePublicKeys(pubkeys);
|
|
65
|
+
}
|
|
24
66
|
|
|
25
|
-
|
|
67
|
+
default:
|
|
68
|
+
throw Error("Unknown signature set type");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function verifySignatureSet(signatureSet: SingleSignatureSet, index2pubkey?: Index2PubkeyCache): boolean;
|
|
73
|
+
export function verifySignatureSet(signatureSet: IndexedSignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
74
|
+
export function verifySignatureSet(signatureSet: AggregatedSignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
75
|
+
export function verifySignatureSet(signatureSet: ISignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
76
|
+
export function verifySignatureSet(signatureSet: ISignatureSet, index2pubkey?: Index2PubkeyCache): boolean {
|
|
26
77
|
// All signatures are not trusted and must be group checked (p2.subgroup_check)
|
|
27
78
|
const signature = Signature.fromBytes(signatureSet.signature, true);
|
|
28
79
|
|
|
@@ -30,8 +81,20 @@ export function verifySignatureSet(signatureSet: ISignatureSet): boolean {
|
|
|
30
81
|
case SignatureSetType.single:
|
|
31
82
|
return verify(signatureSet.signingRoot, signatureSet.pubkey, signature);
|
|
32
83
|
|
|
33
|
-
case SignatureSetType.
|
|
34
|
-
|
|
84
|
+
case SignatureSetType.indexed: {
|
|
85
|
+
if (!index2pubkey) {
|
|
86
|
+
throw Error("index2pubkey required for indexed signature set");
|
|
87
|
+
}
|
|
88
|
+
return verify(signatureSet.signingRoot, index2pubkey[signatureSet.index], signature);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
case SignatureSetType.aggregate: {
|
|
92
|
+
if (!index2pubkey) {
|
|
93
|
+
throw Error("index2pubkey required for aggregate signature set");
|
|
94
|
+
}
|
|
95
|
+
const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
|
|
96
|
+
return fastAggregateVerify(signatureSet.signingRoot, pubkeys, signature);
|
|
97
|
+
}
|
|
35
98
|
|
|
36
99
|
default:
|
|
37
100
|
throw Error("Unknown signature set type");
|
|
@@ -51,14 +114,27 @@ export function createSingleSignatureSetFromComponents(
|
|
|
51
114
|
};
|
|
52
115
|
}
|
|
53
116
|
|
|
117
|
+
export function createIndexedSignatureSetFromComponents(
|
|
118
|
+
index: number,
|
|
119
|
+
signingRoot: Root,
|
|
120
|
+
signature: Uint8Array
|
|
121
|
+
): IndexedSignatureSet {
|
|
122
|
+
return {
|
|
123
|
+
type: SignatureSetType.indexed,
|
|
124
|
+
index,
|
|
125
|
+
signingRoot,
|
|
126
|
+
signature,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
54
130
|
export function createAggregateSignatureSetFromComponents(
|
|
55
|
-
|
|
131
|
+
indices: number[],
|
|
56
132
|
signingRoot: Root,
|
|
57
133
|
signature: Uint8Array
|
|
58
134
|
): AggregatedSignatureSet {
|
|
59
135
|
return {
|
|
60
136
|
type: SignatureSetType.aggregate,
|
|
61
|
-
|
|
137
|
+
indices,
|
|
62
138
|
signingRoot,
|
|
63
139
|
signature,
|
|
64
140
|
};
|
package/src/util/validator.ts
CHANGED
|
@@ -2,13 +2,15 @@ import {ChainForkConfig} from "@lodestar/config";
|
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
4
|
ForkSeq,
|
|
5
|
+
MAX_EFFECTIVE_BALANCE,
|
|
5
6
|
MAX_EFFECTIVE_BALANCE_ELECTRA,
|
|
6
7
|
MIN_ACTIVATION_BALANCE,
|
|
7
8
|
} from "@lodestar/params";
|
|
8
9
|
import {Epoch, ValidatorIndex, phase0} from "@lodestar/types";
|
|
9
10
|
import {intDiv} from "@lodestar/utils";
|
|
10
11
|
import {BeaconStateAllForks, CachedBeaconStateElectra, CachedBeaconStateGloas, EpochCache} from "../types.js";
|
|
11
|
-
import {
|
|
12
|
+
import {hasEth1WithdrawalCredential} from "./capella.js";
|
|
13
|
+
import {hasCompoundingWithdrawalCredential, hasExecutionWithdrawalCredential} from "./electra.js";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Check if [[validator]] is active
|
|
@@ -94,8 +96,35 @@ export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): numbe
|
|
|
94
96
|
return MIN_ACTIVATION_BALANCE;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Check if validator is partially withdrawable.
|
|
101
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/electra/beacon-chain.md#modified-is_partially_withdrawable_validator
|
|
102
|
+
*/
|
|
103
|
+
export function isPartiallyWithdrawableValidator(fork: ForkSeq, validator: phase0.Validator, balance: number): boolean {
|
|
104
|
+
const isPostElectra = fork >= ForkSeq.electra;
|
|
105
|
+
|
|
106
|
+
// Check withdrawal credentials
|
|
107
|
+
const hasWithdrawableCredentials = isPostElectra
|
|
108
|
+
? hasExecutionWithdrawalCredential(validator.withdrawalCredentials)
|
|
109
|
+
: hasEth1WithdrawalCredential(validator.withdrawalCredentials);
|
|
110
|
+
|
|
111
|
+
if (!hasWithdrawableCredentials) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Get max effective balance based on fork
|
|
116
|
+
const maxEffectiveBalance = isPostElectra
|
|
117
|
+
? getMaxEffectiveBalance(validator.withdrawalCredentials)
|
|
118
|
+
: MAX_EFFECTIVE_BALANCE;
|
|
119
|
+
|
|
120
|
+
// Check if at max effective balance and has excess balance
|
|
121
|
+
const hasMaxEffectiveBalance = validator.effectiveBalance === maxEffectiveBalance;
|
|
122
|
+
const hasExcessBalance = balance > maxEffectiveBalance;
|
|
123
|
+
|
|
124
|
+
return hasMaxEffectiveBalance && hasExcessBalance;
|
|
125
|
+
}
|
|
126
|
+
|
|
97
127
|
export function getPendingBalanceToWithdraw(
|
|
98
|
-
fork: ForkSeq,
|
|
99
128
|
state: CachedBeaconStateElectra | CachedBeaconStateGloas,
|
|
100
129
|
validatorIndex: ValidatorIndex
|
|
101
130
|
): number {
|
|
@@ -106,19 +135,5 @@ export function getPendingBalanceToWithdraw(
|
|
|
106
135
|
}
|
|
107
136
|
}
|
|
108
137
|
|
|
109
|
-
if (fork >= ForkSeq.gloas) {
|
|
110
|
-
const stateGloas = state as CachedBeaconStateGloas;
|
|
111
|
-
for (const item of stateGloas.builderPendingWithdrawals.getAllReadonly()) {
|
|
112
|
-
if (item.builderIndex === validatorIndex) {
|
|
113
|
-
total += item.amount;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
for (const item of stateGloas.builderPendingPayments.getAllReadonly()) {
|
|
117
|
-
if (item.withdrawal.builderIndex === validatorIndex) {
|
|
118
|
-
total += item.withdrawal.amount;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
138
|
return total;
|
|
124
139
|
}
|