Skip to content

Commit 7cb0a61

Browse files
authored
use EF consensus spec v1.5.0-alpha.10 test vectors (#6761)
1 parent 2bf0df7 commit 7cb0a61

21 files changed

+353
-222
lines changed

AllTests-mainnet.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
196196
OK: 2/2 Fail: 0/2 Skip: 0/2
197197
## EF - EIP7594 - Networking [Preset: mainnet]
198198
```diff
199-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
200-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
201-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
202-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
203-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
204-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
205-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
206-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
207-
+ Networking - Get Custody Columns - mainnet/eip7594/networking/get_custody_columns/pyspec_t OK
199+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
200+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
201+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
202+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
203+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
204+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
205+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
206+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
207+
+ Networking - Get Custody Columns - mainnet/fulu/networking/get_custody_columns/pyspec_test OK
208208
```
209209
OK: 9/9 Fail: 0/9 Skip: 0/9
210210
## EF - KZG

ConsensusSpecPreset-mainnet.md

Lines changed: 80 additions & 68 deletions
Large diffs are not rendered by default.

ConsensusSpecPreset-minimal.md

Lines changed: 82 additions & 70 deletions
Large diffs are not rendered by default.

beacon_chain/spec/beaconstate.nim

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,9 @@ proc process_attestation*(
12121212
ok(proposer_reward)
12131213

12141214
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/specs/altair/beacon-chain.md#get_next_sync_committee_indices
1215-
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/beacon-chain.md#modified-get_next_sync_committee_indices
12161215
func get_next_sync_committee_keys(
12171216
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
1218-
deneb.BeaconState | electra.BeaconState | fulu.BeaconState):
1219-
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
1217+
deneb.BeaconState): array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
12201218
## Return the sequence of sync committee indices, with possible duplicates,
12211219
## for the next sync committee.
12221220
# The sync committe depends on seed and effective balance - it can
@@ -1244,13 +1242,51 @@ func get_next_sync_committee_keys(
12441242
candidate_index = active_validator_indices[shuffled_index]
12451243
random_byte = eth2digest(hash_buffer).data[i mod 32]
12461244
effective_balance = state.validators[candidate_index].effective_balance
1247-
const meb =
1248-
when typeof(state).kind >= ConsensusFork.Electra:
1249-
MAX_EFFECTIVE_BALANCE_ELECTRA.Gwei # [Modified in Electra:EIP7251]
1250-
else:
1251-
MAX_EFFECTIVE_BALANCE.Gwei
1245+
if effective_balance * MAX_RANDOM_BYTE >=
1246+
MAX_EFFECTIVE_BALANCE.Gwei * random_byte:
1247+
res[index] = state.validators[candidate_index].pubkey
1248+
inc index
1249+
i += 1'u64
1250+
res
1251+
1252+
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/electra/beacon-chain.md#modified-get_next_sync_committee_indices
1253+
func get_next_sync_committee_keys(
1254+
state: electra.BeaconState | fulu.BeaconState):
1255+
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
1256+
## Return the sequence of sync committee indices, with possible duplicates,
1257+
## for the next sync committee.
1258+
# The sync committe depends on seed and effective balance - it can
1259+
# thus only be computed for the current epoch of the state, after balance
1260+
# updates have been performed
1261+
1262+
let epoch = get_current_epoch(state) + 1
12521263

1253-
if effective_balance * MAX_RANDOM_BYTE >= meb * random_byte:
1264+
const MAX_RANDOM_VALUE = 65536 - 1 # [Modified in Electra]
1265+
let
1266+
active_validator_indices = get_active_validator_indices(state, epoch)
1267+
active_validator_count = uint64(len(active_validator_indices))
1268+
seed = get_seed(state, epoch, DOMAIN_SYNC_COMMITTEE)
1269+
var
1270+
i = 0'u64
1271+
index = 0
1272+
res: array[SYNC_COMMITTEE_SIZE, ValidatorPubKey]
1273+
hash_buffer: array[40, byte]
1274+
rv_buf: array[8, byte]
1275+
hash_buffer[0..31] = seed.data
1276+
while index < SYNC_COMMITTEE_SIZE:
1277+
hash_buffer[32..39] = uint_to_bytes(uint64(i div 16)) # [Modified in Electra]
1278+
let
1279+
shuffled_index = compute_shuffled_index(
1280+
uint64(i mod active_validator_count), active_validator_count, seed)
1281+
candidate_index = active_validator_indices[shuffled_index]
1282+
random_bytes = eth2digest(hash_buffer).data
1283+
offset = (i mod 16) * 2
1284+
effective_balance = state.validators[candidate_index].effective_balance
1285+
rv_buf[0 .. 1] = random_bytes.toOpenArray(offset, offset + 1)
1286+
let random_value = bytes_to_uint64(rv_buf)
1287+
# [Modified in Electra:EIP7251]
1288+
if effective_balance * MAX_RANDOM_VALUE >=
1289+
MAX_EFFECTIVE_BALANCE_ELECTRA.Gwei * random_value:
12541290
res[index] = state.validators[candidate_index].pubkey
12551291
inc index
12561292
i += 1'u64
@@ -1336,7 +1372,7 @@ func get_pending_balance_to_withdraw*(
13361372
validator_index: ValidatorIndex): Gwei =
13371373
var pending_balance: Gwei
13381374
for withdrawal in state.pending_partial_withdrawals:
1339-
if withdrawal.index == validator_index:
1375+
if withdrawal.validator_index == validator_index:
13401376
pending_balance += withdrawal.amount
13411377

13421378
pending_balance
@@ -1444,10 +1480,10 @@ template get_expected_withdrawals_with_partial_count_aux*(
14441480
break
14451481

14461482
let
1447-
validator = state.validators.item(withdrawal.index)
1483+
validator = state.validators.item(withdrawal.validator_index)
14481484

14491485
# Keep a uniform variable name available for injected code
1450-
validator_index {.inject.} = withdrawal.index
1486+
validator_index {.inject.} = withdrawal.validator_index
14511487

14521488
# Here, can't use the pre-stored effective balance because this template
14531489
# might be called on the next slot and therefore next epoch, after which
@@ -1471,7 +1507,7 @@ template get_expected_withdrawals_with_partial_count_aux*(
14711507
withdrawal.amount)
14721508
var w = Withdrawal(
14731509
index: withdrawal_index,
1474-
validator_index: withdrawal.index,
1510+
validator_index: withdrawal.validator_index,
14751511
amount: withdrawable_balance)
14761512
w.address.data[0..19] = validator.withdrawal_credentials.data[12..^1]
14771513
withdrawals.add w

beacon_chain/spec/datatypes/base.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export
7474
tables, results, endians2, json_serialization, sszTypes, beacon_time, crypto,
7575
digest, presets
7676

77-
const SPEC_VERSION* = "1.5.0-alpha.9"
77+
const SPEC_VERSION* = "1.5.0-alpha.10"
7878
## Spec version we're aiming to be compatible with, right now
7979

8080
const

beacon_chain/spec/datatypes/electra.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type
158158

159159
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.7/specs/electra/beacon-chain.md#pendingpartialwithdrawal
160160
PendingPartialWithdrawal* = object
161-
index*: uint64
161+
validator_index*: uint64
162162
amount*: Gwei
163163
withdrawable_epoch*: Epoch
164164

beacon_chain/spec/presets.nim

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ type
7979
MIN_PER_EPOCH_CHURN_LIMIT*: uint64
8080
CHURN_LIMIT_QUOTIENT*: uint64
8181
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT*: uint64
82-
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA*: uint64
83-
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT*: uint64
8482

8583
# Fork choice
8684
# TODO PROPOSER_SCORE_BOOST*: uint64
@@ -116,6 +114,13 @@ type
116114
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS*: uint64
117115
# TODO BLOB_SIDECAR_SUBNET_COUNT*: uint64
118116

117+
# Electra
118+
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA*: uint64
119+
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT*: uint64
120+
BLOB_SIDECAR_SUBNET_COUNT_ELECTRA*: uint64
121+
MAX_BLOBS_PER_BLOCK_ELECTRA*: uint64
122+
MAX_REQUEST_BLOB_SIDECARS_ELECTRA*: uint64
123+
119124
PresetFile* = object
120125
values*: Table[string, string]
121126
missingValues*: seq[string]
@@ -233,10 +238,6 @@ when const_preset == "mainnet":
233238
CHURN_LIMIT_QUOTIENT: 65536,
234239
# [New in Deneb:EIP7514] 2**3 (= 8)
235240
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8,
236-
# [New in Electra:EIP7251] 2**7 * 10**9 (= 128,000,000,000)
237-
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 128000000000'u64,
238-
# [New in Electra:EIP7251] 2**8 * 10**9 (= 256,000,000,000)
239-
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 256000000000'u64,
240241

241242
# Deposit contract
242243
# ---------------------------------------------------------------
@@ -283,6 +284,18 @@ when const_preset == "mainnet":
283284
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,
284285
# `6`
285286
# TODO BLOB_SIDECAR_SUBNET_COUNT: 6,
287+
288+
# Electra
289+
# 2**7 * 10**9 (= 128,000,000,000)
290+
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 128000000000'u64,
291+
# 2**8 * 10**9 (= 256,000,000,000)
292+
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 256000000000'u64,
293+
# `9`
294+
BLOB_SIDECAR_SUBNET_COUNT_ELECTRA: 9,
295+
# `uint64(9)`
296+
MAX_BLOBS_PER_BLOCK_ELECTRA: 9,
297+
# MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK_ELECTRA
298+
MAX_REQUEST_BLOB_SIDECARS_ELECTRA: 1152
286299
)
287300

288301
elif const_preset == "gnosis":
@@ -385,10 +398,6 @@ elif const_preset == "gnosis":
385398
CHURN_LIMIT_QUOTIENT: 4096,
386399
# [New in Deneb:EIP7514] 2**3 (= 8)
387400
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8,
388-
# [New in Electra:EIP7251] 2**7 * 10**9 (= 128,000,000,000) (copied from EF mainnet)
389-
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 128000000000'u64,
390-
# [New in Electra:EIP7251] 2**8 * 10**9 (= 256,000,000,000) (copied from EF mainnet)
391-
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 256000000000'u64,
392401

393402
# Deposit contract
394403
# ---------------------------------------------------------------
@@ -435,6 +444,18 @@ elif const_preset == "gnosis":
435444
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 16384,
436445
# `6`
437446
# TODO BLOB_SIDECAR_SUBNET_COUNT: 6,
447+
448+
# Electra
449+
# 2**7 * 10**9 (= 128,000,000,000)
450+
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 128000000000'u64,
451+
# 2**8 * 10**9 (= 256,000,000,000)
452+
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 256000000000'u64,
453+
# `9`
454+
BLOB_SIDECAR_SUBNET_COUNT_ELECTRA: 9,
455+
# `uint64(9)`
456+
MAX_BLOBS_PER_BLOCK_ELECTRA: 9,
457+
# MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK_ELECTRA
458+
MAX_REQUEST_BLOB_SIDECARS_ELECTRA: 1152
438459
)
439460

440461
elif const_preset == "minimal":
@@ -532,10 +553,6 @@ elif const_preset == "minimal":
532553
CHURN_LIMIT_QUOTIENT: 32,
533554
# [New in Deneb:EIP7514] [customized]
534555
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 4,
535-
# [New in Electra:EIP7251] 2**6 * 10**9 (= 64,000,000,000)
536-
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 64000000000'u64,
537-
# [New in Electra:EIP7251] 2**7 * 10**9 (= 128,000,000,000)
538-
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 128000000000'u64,
539556

540557

541558
# Deposit contract
@@ -584,6 +601,18 @@ elif const_preset == "minimal":
584601
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,
585602
# `6`
586603
# TODO BLOB_SIDECAR_SUBNET_COUNT: 6,
604+
605+
# Electra
606+
# [customized] 2**6 * 10**9 (= 64,000,000,000)
607+
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 64000000000'u64,
608+
# [customized] 2**7 * 10**9 (= 128,000,000,000)
609+
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 128000000000'u64,
610+
# `9`
611+
BLOB_SIDECAR_SUBNET_COUNT_ELECTRA: 9,
612+
# `uint64(9)`
613+
MAX_BLOBS_PER_BLOCK_ELECTRA: 9,
614+
# MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK_ELECTRA
615+
MAX_REQUEST_BLOB_SIDECARS_ELECTRA: 1152,
587616
)
588617

589618
else:

beacon_chain/spec/presets/gnosis/electra_preset.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const
3939
MAX_ATTESTER_SLASHINGS_ELECTRA*: uint64 = 1
4040
# `uint64(2**3)` (= 8)
4141
MAX_ATTESTATIONS_ELECTRA*: uint64 = 8
42-
# `uint64(2**0)` (= 1)
43-
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD*: uint64 = 1
42+
# `uint64(2**1)` (= 2)
43+
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD*: uint64 = 2
4444

4545
# Execution
4646
# ---------------------------------------------------------------

beacon_chain/spec/presets/mainnet/electra_preset.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const
3939
MAX_ATTESTER_SLASHINGS_ELECTRA*: uint64 = 1
4040
# `uint64(2**3)` (= 8)
4141
MAX_ATTESTATIONS_ELECTRA*: uint64 = 8
42-
# `uint64(2**0)` (= 1)
43-
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD*: uint64 = 1
42+
# `uint64(2**1)` (= 2)
43+
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD*: uint64 = 2
4444

4545
# Execution
4646
# ---------------------------------------------------------------

beacon_chain/spec/presets/minimal/deneb_preset.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const
1313
# `uint64(4096)`
1414
FIELD_ELEMENTS_PER_BLOB*: uint64 = 4096
1515
# [customized]
16-
MAX_BLOB_COMMITMENTS_PER_BLOCK*: uint64 = 16
16+
MAX_BLOB_COMMITMENTS_PER_BLOCK*: uint64 = 32
1717
# `uint64(6)`
1818
MAX_BLOBS_PER_BLOCK*: uint64 = 6
19-
# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9
20-
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH* = 9
19+
# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 5 = 10
20+
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH* = 10

0 commit comments

Comments
 (0)