-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement execution layer exits eip 7002 (#6651)
* feat: implement execution layer exits eip 7002 * lint and tsc fix * apply feedback * improve comment
- Loading branch information
Showing
22 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/state-transition/src/block/processExecutionLayerExit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {CompositeViewDU} from "@chainsafe/ssz"; | ||
import {electra, ssz} from "@lodestar/types"; | ||
import {ETH1_ADDRESS_WITHDRAWAL_PREFIX, FAR_FUTURE_EPOCH} from "@lodestar/params"; | ||
|
||
import {isActiveValidator} from "../util/index.js"; | ||
import {CachedBeaconStateElectra} from "../types.js"; | ||
import {initiateValidatorExit} from "./index.js"; | ||
|
||
/** | ||
* Process execution layer exit messages and initiate exit incase they belong to a valid active validator | ||
* otherwise silent ignore. | ||
*/ | ||
export function processExecutionLayerExit(state: CachedBeaconStateElectra, exit: electra.ExecutionLayerExit): void { | ||
const validator = isValidExecutionLayerExit(state, exit); | ||
if (validator === null) { | ||
return; | ||
} | ||
|
||
initiateValidatorExit(state, validator); | ||
} | ||
|
||
export function isValidExecutionLayerExit( | ||
state: CachedBeaconStateElectra, | ||
exit: electra.ExecutionLayerExit | ||
): CompositeViewDU<typeof ssz.phase0.Validator> | null { | ||
const {config, epochCtx} = state; | ||
const validatorIndex = epochCtx.getValidatorIndex(exit.validatorPubkey); | ||
const validator = validatorIndex !== undefined ? state.validators.getReadonly(validatorIndex) : undefined; | ||
if (validator === undefined) { | ||
return null; | ||
} | ||
|
||
const {withdrawalCredentials} = validator; | ||
if (withdrawalCredentials[0] !== ETH1_ADDRESS_WITHDRAWAL_PREFIX) { | ||
return null; | ||
} | ||
|
||
const executionAddress = withdrawalCredentials.subarray(12, 32); | ||
if (Buffer.compare(executionAddress, exit.sourceAddress) !== 0) { | ||
return null; | ||
} | ||
|
||
const currentEpoch = epochCtx.epoch; | ||
if ( | ||
// verify the validator is active | ||
isActiveValidator(validator, currentEpoch) && | ||
// verify exit has not been initiated | ||
validator.exitEpoch === FAR_FUTURE_EPOCH && | ||
// verify the validator had been active long enough | ||
currentEpoch >= validator.activationEpoch + config.SHARD_COMMITTEE_PERIOD | ||
) { | ||
return validator; | ||
} else { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.