Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] epbs (eip-7732) #6443

Open
wants to merge 62 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a068af4
Bump nim-serialization to potentially solve #435 (#436)
mratsim Sep 12, 2019
1a67936
Allow nat option for connect_to_testnet script. (#1250)
cheatfate Jun 29, 2020
d896062
Bump vendor/nim-eth (#1816)
kdeme Oct 7, 2020
b4d00fa
bump eth2-testnets to add pyrmont bootstrap nodes (#2040)
tersec Nov 18, 2020
08b895c
stew: bump again (#3275)
arnetheduck Jan 12, 2022
0581d7d
Bump pillow from 9.3.0 to 10.0.1 in /ncli (#5484)
dependabot[bot] Oct 5, 2023
47bee1b
Revert "Revert "ci: adding self-hosted tag for github-runner (#4886)"…
tersec Oct 13, 2023
3924927
Initial dummy commit
Tomi-3-0 Jul 23, 2024
5eb4e16
added constants and presets for epbs
Tomi-3-0 Jul 27, 2024
ce323da
Remove binary file
Tomi-3-0 Jul 27, 2024
c8afe58
Add Constants and Presets for epbsX
Tomi-3-0 Jul 27, 2024
88f9c24
added remaining constants
Tomi-3-0 Jul 27, 2024
bb113e8
added modified containers
Tomi-3-0 Aug 2, 2024
2dc1698
Remove .vscode/tasks.json from the repository
Tomi-3-0 Aug 2, 2024
539395a
Bump nim-serialization to potentially solve #435 (#436)
mratsim Sep 12, 2019
9d8139d
Allow nat option for connect_to_testnet script. (#1250)
cheatfate Jun 29, 2020
fa7e660
Bump vendor/nim-eth (#1816)
kdeme Oct 7, 2020
d1cf73e
bump eth2-testnets to add pyrmont bootstrap nodes (#2040)
tersec Nov 18, 2020
a9b93ac
stew: bump again (#3275)
arnetheduck Jan 12, 2022
0808055
Bump pillow from 9.3.0 to 10.0.1 in /ncli (#5484)
dependabot[bot] Oct 5, 2023
1b08aa5
Revert "Revert "ci: adding self-hosted tag for github-runner (#4886)"…
tersec Oct 13, 2023
1cb1590
Initial dummy commit
Tomi-3-0 Jul 23, 2024
647149e
fixed typo
Tomi-3-0 Aug 2, 2024
08be977
addressed latest reviews
Tomi-3-0 Aug 4, 2024
f6f3271
Resolved merge conflicts in beacon_chain/spec/helpers.nim and tests/t…
Tomi-3-0 Aug 5, 2024
e931fc3
added indexed_payload_attestation helper
Tomi-3-0 Aug 5, 2024
49821bc
Resolved merge conflicts in tests/test_helpers.nim
Tomi-3-0 Aug 6, 2024
10e50f0
stage updated submodule
Tomi-3-0 Aug 6, 2024
ea39979
Remove embedded Git repositories
Tomi-3-0 Aug 6, 2024
a3805aa
resolving conflicts
Tomi-3-0 Aug 6, 2024
dc16426
more helper functions for beacon state accessors
Tomi-3-0 Aug 10, 2024
75eabef
resolves some latest comments plus temp fix for ForkyBeaconState func…
Tomi-3-0 Aug 14, 2024
e356b1a
adds an early exit condition for get_attesting_indices
Tomi-3-0 Aug 14, 2024
c64d90f
updated urls
Tomi-3-0 Aug 15, 2024
9de224c
added some beacon state accessors functions
Tomi-3-0 Aug 17, 2024
9750641
Update vendor/sepolia submodule to latest commit
Tomi-3-0 Aug 21, 2024
eba9464
work in progress
Tomi-3-0 Aug 23, 2024
20b7423
Updated vendor submodules to match unstable branch
Tomi-3-0 Aug 23, 2024
fdcd3ec
more beacon state attesters functions
Tomi-3-0 Aug 24, 2024
e4b54d9
modified payload_attestation functions
Tomi-3-0 Aug 26, 2024
627fef0
resolves comments and completes process_payload_attestation
Tomi-3-0 Aug 30, 2024
ecdb2ba
style
Tomi-3-0 Aug 31, 2024
5d34708
redeclares validator_indices
Tomi-3-0 Sep 1, 2024
ef50df0
implements fork.md
Tomi-3-0 Sep 7, 2024
d1d8caf
Revert "implements fork.md"
Tomi-3-0 Sep 11, 2024
94f08ca
refactors fork.md
Tomi-3-0 Sep 11, 2024
da6a476
refactors some logic and addresses some latest comments
Tomi-3-0 Sep 19, 2024
c42eb03
initial commit for validator specs implementation
Tomi-3-0 Sep 30, 2024
8e3817c
get_ptc_assignment
Tomi-3-0 Oct 4, 2024
b77ca15
adds execution requests
Tomi-3-0 Oct 6, 2024
5089ca5
Merge branch 'unstable' into epbs
Redidacove Oct 7, 2024
d7cdf43
Update beacon_chain/spec/datatypes/epbs.nim
tersec Oct 8, 2024
71f9c20
removed code
Redidacove Oct 8, 2024
af91e67
Merge pull request #1 from Tomi-3-0/remove_redundant_def
Redidacove Oct 8, 2024
b480b7a
test verify_execution_payload_header_signature
Tomi-3-0 Oct 8, 2024
2c80063
tests: verify payload attestaion and payload envelope signatures
Tomi-3-0 Oct 8, 2024
235ccab
deleted executable file
Tomi-3-0 Oct 8, 2024
eddf1ef
Merged remote epbs changes
Tomi-3-0 Oct 8, 2024
a8128d7
Sync vendor submodules with unstable branch
Tomi-3-0 Oct 14, 2024
0c9b3db
reapplied the .vscode/tasks.json
Tomi-3-0 Oct 14, 2024
da0d6c2
Resolved merge conflict in beacon_chain/spec/forks.nim
Tomi-3-0 Nov 6, 2024
90d5480
Merge branch 'unstable' into epbs
Tomi-3-0 Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .vscode/tasks.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file deleted?

I used github codespaces, might have been deleted in Codespaces due to automatic environment configuration.

This file was deleted.

112 changes: 103 additions & 9 deletions beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import
stew/assign2,
json_serialization/std/sets,
chronicles,
./datatypes/[phase0, altair, bellatrix],
./datatypes/[phase0, altair, bellatrix, epbs],
"."/[eth2_merkleization, forks, signatures, validator]

from std/algorithm import fill, sort
Expand Down Expand Up @@ -135,7 +135,8 @@ func get_state_exit_queue_info*(
ExitQueueInfo(
exit_queue_epoch: exit_queue_epoch, exit_queue_churn: exit_queue_churn)

func get_state_exit_queue_info*(state: electra.BeaconState): ExitQueueInfo =
func get_state_exit_queue_info*(
state: electra.BeaconState | epbs.BeaconState): ExitQueueInfo =
# Electra initiate_validator_exit doesn't have same quadratic aspect given
# StateCache balance caching
default(ExitQueueInfo)
Expand Down Expand Up @@ -731,7 +732,7 @@ func check_attestation_slot_target*(data: AttestationData): Result[Slot, cstring

ok(data.slot)

func check_attestation_target_epoch(
func check_attestation_target_epoch*(
data: AttestationData, current_epoch: Epoch): Result[Epoch, cstring] =
if not (data.target.epoch == get_previous_epoch(current_epoch) or
data.target.epoch == current_epoch):
Expand Down Expand Up @@ -871,9 +872,9 @@ func get_base_reward_per_increment*(
integer_squareroot(distinctBase(total_active_balance)))

# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#get_base_reward
func get_base_reward(
func get_base_reward*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
deneb.BeaconState | electra.BeaconState,
deneb.BeaconState | electra.BeaconState | epbs.BeaconState,
index: ValidatorIndex, base_reward_per_increment: Gwei): Gwei =
## Return the base reward for the validator defined by ``index`` with respect
## to the current ``state``.
Expand Down Expand Up @@ -1233,7 +1234,7 @@ func is_partially_withdrawable_validator(
has_max_effective_balance and has_excess_balance

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#get_validator_max_effective_balance
func get_validator_max_effective_balance(validator: Validator): Gwei =
func get_validator_max_effective_balance*(validator: Validator): Gwei =
## Get max effective balance for ``validator``.
if has_compounding_withdrawal_credential(validator):
MAX_EFFECTIVE_BALANCE_ELECTRA.Gwei
Expand Down Expand Up @@ -1364,7 +1365,7 @@ func get_expected_withdrawals*(
# to cleanly treat the results of get_expected_withdrawals as a seq[Withdrawal]
# are valuable enough to make that the default version of this spec function.
template get_expected_withdrawals_with_partial_count_aux*(
state: electra.BeaconState, epoch: Epoch, fetch_balance: untyped):
state: electra.BeaconState | epbs.BeaconState, epoch: Epoch, fetch_balance: untyped):
(seq[Withdrawal], uint64) =
doAssert epoch - get_current_epoch(state) in [0'u64, 1'u64]

Expand Down Expand Up @@ -1450,12 +1451,12 @@ template get_expected_withdrawals_with_partial_count_aux*(
(withdrawals, partial_withdrawals_count)

template get_expected_withdrawals_with_partial_count*(
state: electra.BeaconState): (seq[Withdrawal], uint64) =
state: electra.BeaconState | epbs.BeaconState): (seq[Withdrawal], uint64) =
get_expected_withdrawals_with_partial_count_aux(
state, get_current_epoch(state)) do:
state.balances.item(validator_index)

func get_expected_withdrawals*(state: electra.BeaconState): seq[Withdrawal] =
func get_expected_withdrawals*(state: electra.BeaconState | epbs.BeaconState): seq[Withdrawal] =
get_expected_withdrawals_with_partial_count(state)[0]

# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#get_next_sync_committee
Expand Down Expand Up @@ -2158,6 +2159,99 @@ func upgrade_to_electra*(

post

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/_features/eip7732/fork.md#upgrading-the-state
func upgrade_to_epbs*(cfg: RuntimeConfig, pre: deneb.BeaconState):
ref epbs.BeaconState =
let epoch = get_current_epoch(pre)

var max_exit_epoch = FAR_FUTURE_EPOCH
for v in pre.validators:
if v.exit_epoch != FAR_FUTURE_EPOCH:
max_exit_epoch =
if max_exit_epoch == FAR_FUTURE_EPOCH:
v.exit_epoch
else:
max(max_exit_epoch, v.exit_epoch)
if max_exit_epoch == FAR_FUTURE_EPOCH:
max_exit_epoch = get_current_epoch(pre)
let earliest_exit_epoch = max_exit_epoch + 1

(ref epbs.BeaconState)(
# Versioning
genesis_time: pre.genesis_time,
genesis_validators_root: pre.genesis_validators_root,
slot: pre.slot,
fork: Fork(
previous_version: pre.fork.current_version,
current_version: cfg.EIP7732_FORK_VERSION,
epoch: epoch
),

# History
latest_block_header: pre.latest_block_header,
block_roots: pre.block_roots,
state_roots: pre.state_roots,
historical_roots: pre.historical_roots,

# Eth1
eth1_data: pre.eth1_data,
eth1_data_votes: pre.eth1_data_votes,
eth1_deposit_index: pre.eth1_deposit_index,

# Registry
validators: pre.validators,
balances: pre.balances,

# Randomness
randao_mixes: pre.randao_mixes,

# Slashings
slashings: pre.slashings,

# Participation
previous_epoch_participation: pre.previous_epoch_participation,
current_epoch_participation: pre.current_epoch_participation,

# Finality
justification_bits: pre.justification_bits,
previous_justified_checkpoint: pre.previous_justified_checkpoint,
current_justified_checkpoint: pre.current_justified_checkpoint,
finalized_checkpoint: pre.finalized_checkpoint,

# Inactivity
inactivity_scores: pre.inactivity_scores,

# Sync
current_sync_committee: pre.current_sync_committee,
next_sync_committee: pre.next_sync_committee,

# Execution-layer
latest_execution_payload_header: default(epbs.ExecutionPayloadHeader),

# Withdrawals
next_withdrawal_index: pre.next_withdrawal_index,
next_withdrawal_validator_index: pre.next_withdrawal_validator_index,

# Deep history valid from Capella onwards
historical_summaries: pre.historical_summaries,

deposit_requests_start_index: UNSET_DEPOSIT_REQUESTS_START_INDEX,
deposit_balance_to_consume: 0.Gwei,
exit_balance_to_consume: 0.Gwei,
earliest_exit_epoch: earliest_exit_epoch,
consolidation_balance_to_consume: 0.Gwei,
earliest_consolidation_epoch:
compute_activation_exit_epoch(get_current_epoch(pre)),

# pending_balance_deposits, pending_partial_withdrawals, and
# pending_consolidations are default empty lists

# [New in epbs:EIP7732]
latest_block_hash: ZERO_HASH,
latest_full_slot: pre.slot,
latest_withdrawals_root: ZERO_HASH
)

func latest_block_root(state: ForkyBeaconState, state_root: Eth2Digest):
Eth2Digest =
# The root of the last block that was successfully applied to this state -
Expand Down
4 changes: 4 additions & 0 deletions beacon_chain/spec/datatypes/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ const

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/electra/beacon-chain.md#withdrawal-prefixes
COMPOUNDING_WITHDRAWAL_PREFIX* = 0x02

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/_features/eip7732/beacon-chain.md#domain-types
DOMAIN_BEACON_BUILDER* = DomainType([byte 0x1B, 0x00, 0x00, 0x00])
DOMAIN_PTC_ATTESTER* = DomainType([byte 0x0C, 0x00, 0x00, 0x00])
6 changes: 6 additions & 0 deletions beacon_chain/spec/datatypes/electra.nim
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ type
message*: AggregateAndProof
signature*: ValidatorSig

# https://github.com/ethereum/consensus-specs/blob/7df1ce30384b13d01617f8ddf930f4035da0f689/specs/electra/beacon-chain.md#executionrequests
ExecutionRequests* = object
deposits*: List[DepositRequest, Limit MAX_DEPOSIT_REQUESTS_PER_PAYLOAD]
withdrawals*: List[WithdrawalRequest, Limit MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD]
consolidations*: List[ConsolidationRequest, Limit MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD]

FinalityBranch* =
array[log2trunc(FINALIZED_ROOT_GINDEX_ELECTRA), Eth2Digest]

Expand Down
Loading