Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
286 commits
Select commit Hold shift + click to select a range
ee06262
feat: model BeaconBlock
twoeths Jul 2, 2025
bf37471
feat: fork aware hashTreeRoot()
twoeths Jul 3, 2025
1b85223
feat: processBlockHeader
twoeths Jul 3, 2025
e32fe1d
feat: processWithdrawals()
twoeths Jul 3, 2025
3d4c33b
feat: convert ExecutionPayload to ExecutionPayloadHeader
twoeths Jul 4, 2025
3ce6986
feat: processExecutionPayload()
twoeths Jul 4, 2025
480e30d
feat: fastAggregateVerify()
twoeths Jul 5, 2025
c571fdc
feat: randao SignatureSet
twoeths Jul 5, 2025
4ee88b8
refactor: move beacon_state and beacon_block and execution_payload to…
twoeths Jul 5, 2025
e96bd16
feat: model IndexedAttestation
twoeths Jul 5, 2025
3cd8b9b
feat: indexed_attestation signature set
twoeths Jul 5, 2025
2c8bf62
feat: AttesterSlashings
twoeths Jul 6, 2025
92eeacd
fix: implement fork in fork.zig
twoeths Jul 6, 2025
71100d8
feat: bls_to_execution_change signature set
twoeths Jul 6, 2025
d97fcbe
feat: proposer signature set
twoeths Jul 7, 2025
bc1872c
refactor: move Fork definition to types folder
twoeths Jul 7, 2025
2c111af
feat: proposer_slashings signature set
twoeths Jul 7, 2025
79bb3a5
feat: voluntary_exits signature set
twoeths Jul 7, 2025
476b8b9
feat: process_randao
twoeths Jul 7, 2025
9f4edb2
feat: process_eth1_data
twoeths Jul 7, 2025
50001d6
feat: slash_validator
twoeths Jul 7, 2025
5590f31
feat: process_proposer_slashing
twoeths Jul 8, 2025
11be1a0
feat: attestation utils
twoeths Jul 8, 2025
76f1658
feat: is_valid_indexed_attestation
twoeths Jul 8, 2025
0c0e8b9
feat: process_attester_slashing
twoeths Jul 8, 2025
5284341
feat: getIndexedAttestation() and getAttestingIndices() in EpochCache
twoeths Jul 9, 2025
86f0748
feat: process_attestation_phase0
twoeths Jul 9, 2025
ee3ef0f
feat: process_attestation_altair
twoeths Jul 9, 2025
b6dc625
feat: process_attestations
twoeths Jul 9, 2025
67b9f41
fix: generic validateAttestation
twoeths Jul 10, 2025
0dbba47
chore: improve processs_attester_slashing
twoeths Jul 10, 2025
2e5a5b4
fix: remove fork on process_attestation flow
twoeths Jul 10, 2025
9d49db4
fix: remove fork in all state_transition functions
twoeths Jul 10, 2025
d6a6b63
feat: process_deposit
twoeths Jul 10, 2025
ab9a3db
feat: process_voluntary_exit
twoeths Jul 10, 2025
e39aa3f
feat: process_bls_to_execution_change
twoeths Jul 10, 2025
2934d44
feat: process_deposit_request
twoeths Jul 10, 2025
82f6bc6
feat: process_withdrawal_request
twoeths Jul 11, 2025
01063aa
feat: process_consolidation_request
twoeths Jul 11, 2025
2946fd7
feat: process_operations
twoeths Jul 11, 2025
0f0526c
feat: getAttestationsSignatureSets()
twoeths Jul 11, 2025
6da285e
feat: process_sync_committee
twoeths Jul 11, 2025
1c5dcbe
feat: process_blob_kzg_commitments
twoeths Jul 11, 2025
8e954ad
feat: process_block
twoeths Jul 11, 2025
8086d77
feat: process_slot
twoeths Jul 11, 2025
d41d26f
fix: change ChainConfig property inside BeaconConfig
twoeths Jul 11, 2025
4cf2709
fix: ForkSeq import path
twoeths Jul 11, 2025
d6418cf
feat: params and config modules
twoeths Jul 11, 2025
a5b716c
fix: add test folder
twoeths Jul 11, 2025
502ceb6
fix: state_transition module in its own folder
twoeths Jul 11, 2025
1f6a720
feat: add network chain configs
twoeths Jul 13, 2025
1a0a306
fix: model EpochCache as reference count in CachedBeaconstateAllForks
twoeths Jul 14, 2025
58c9ba9
fix: create EpochCache from a beacon state
twoeths Jul 15, 2025
714cbd8
feat: separate unit tests and int tests
twoeths Jul 16, 2025
f9df401
fix: SyncCommitteeCache
twoeths Jul 16, 2025
1fea36b
fix: int test createCachedBeaconState
twoeths Jul 16, 2025
8f74bfc
fix: generalize committee_indices
twoeths Jul 16, 2025
cc3c25f
fix: support u64 proposer index
twoeths Jul 16, 2025
01a20b8
refactor: ReferenceCount
twoeths Jul 16, 2025
021e8d9
fix: generalize innerShuffleList()
twoeths Jul 16, 2025
55f19d5
fix: processPendingDeposits
twoeths Jul 16, 2025
5db6efc
feat: implement TestCachedBeaconStateAllForks
twoeths Jul 16, 2025
5aed718
fix: unit test beforeProcessEpoch (#27)
twoeths Jul 19, 2025
cfb5706
fix: stack allocation EpochTransitionCache
twoeths Jul 19, 2025
1de70f3
fix: pass by reference in process_epoch() functions
twoeths Jul 19, 2025
105d74b
fix: rewards and penalties as output params
twoeths Jul 19, 2025
efc7b02
fix: unit test process_justification_and_finalization
twoeths Jul 19, 2025
2b30c77
fix: reuse reards and penalties from EpochTransisionCache
twoeths Jul 19, 2025
2dea67a
fix: process_epoch_fn compilation errors
twoeths Jul 20, 2025
58f3d31
fix: PubkeyIndexMap to support both u32 and u64
twoeths Jul 20, 2025
98ff0c4
fix: processPendingDeposits compilation errors
twoeths Jul 20, 2025
aae8631
chore(types): dedup panic statements (#29)
spiral-ladder Jul 21, 2025
7ce81bd
fix: processPendingConsolidations compilation errors
twoeths Jul 21, 2025
e9b2bfa
Merge remote-tracking branch 'origin/te/naive_state_transition' into …
twoeths Jul 21, 2025
84bc0c3
fix: processEffectiveBalanceUpdates compilation errors
twoeths Jul 21, 2025
f493c47
fix: processSlashingsReset compilation errors
twoeths Jul 21, 2025
158f9f1
fix: processHistoricalSummariesUpdate compilation errors
twoeths Jul 21, 2025
07e9373
fix: processHistoricalRootsUpdate compilation errors
twoeths Jul 23, 2025
a4a527c
fix: processParticipationRecordUpdates compilation errors
twoeths Jul 23, 2025
fb1caff
fix: processParticipationFlagUpdates compiltation errors
twoeths Jul 23, 2025
d341b9d
fix: processSyncCommitteeUpdates compilation errors
twoeths Jul 23, 2025
10547ac
feat: implement and consume getters in EpochCache
twoeths Jul 23, 2025
3feeb50
fix: wrong type for `ExecutionPayloadHeader` methods (#31)
spiral-ladder Jul 28, 2025
ff30ff2
feat(types): add support for blinded block variants
spiral-ladder Jul 17, 2025
319429b
fix(types): correctly type methods in `ExecutionPayloadHeader`
spiral-ladder Jul 28, 2025
02762fd
fix(types): remove `isExecutionType` from `BlindedBeaconBlockBody`
spiral-ladder Jul 28, 2025
d5037aa
Merge pull request #32 from ChainSafe/bing/blinded-types
spiral-ladder Jul 28, 2025
9104966
feat: testProcessRewardsAndPenalties()
twoeths Jul 28, 2025
8f63229
chore: test processInactivityUpdates()
twoeths Jul 28, 2025
d40594f
chore: test processRegistryUpdates()
twoeths Jul 28, 2025
39d3b76
chore: test processSlashings()
twoeths Jul 28, 2025
e6f9c66
fix: missing try in processEpoch()
twoeths Jul 28, 2025
ab19561
fix: testProcessEpochFn to handle no-err functions
twoeths Jul 28, 2025
b12e8fc
fix: unit test processPendingDeposits()
twoeths Jul 28, 2025
7e35a17
fix: unit test processPendingConsolidations()
twoeths Jul 28, 2025
7304364
chore: unit test processEffectiveBalanceUpdates()
twoeths Jul 28, 2025
57f61ab
chore: unit test processSlashingsReset()
twoeths Jul 28, 2025
7c10cfc
chore: unit test processRandaoMixesReset()
twoeths Jul 28, 2025
5c5c131
chore: unit test processHistoricalSummariesUpdate()
twoeths Jul 28, 2025
fbd220f
fix: unit test processParticipationFlagUpdates()
twoeths Jul 28, 2025
19a4ae4
chore: processSyncCommitteeUpdates unit tests
twoeths Jul 28, 2025
8accc2f
fix: append* instead of add*
twoeths Jul 29, 2025
7749313
fix: unit test the main processEpoch() function
twoeths Jul 29, 2025
2edd274
fix: correct method name rotateEpochParticipations()
twoeths Jul 29, 2025
e6d90f7
fix: processSyncCommitteeUpdates next_sync_committee_pubkeys_slices[i]
twoeths Jul 29, 2025
34d049b
fix: wrong type for `ExecutionPayloadHeader` methods (#31)
spiral-ladder Jul 28, 2025
b994af2
feat(types): add support for blinded block variants
spiral-ladder Jul 17, 2025
73851a1
fix(types): correctly type methods in `ExecutionPayloadHeader`
spiral-ladder Jul 28, 2025
04a9067
fix(types): remove `isExecutionType` from `BlindedBeaconBlockBody`
spiral-ladder Jul 28, 2025
f8e92fd
Merge pull request #32 from ChainSafe/bing/blinded-types
spiral-ladder Jul 28, 2025
5922564
main stf
spiral-ladder Jul 17, 2025
366c548
main stf skeleton
spiral-ladder Jul 30, 2025
2f45853
fix: inline else in beacon_state.zig
twoeths Jul 31, 2025
c08cb25
fix: use imported type in beacon_state.zig
twoeths Jul 31, 2025
c721e5f
chore: add comment for ReferenceCount.get() usage
twoeths Jul 31, 2025
f134d1b
chore: avoid optional where possible
twoeths Jul 31, 2025
143b22c
chore: avoid double negative in process_rewards_and_penalties
twoeths Jul 31, 2025
5b38d1f
chore: avoid optional in process_slashings
twoeths Jul 31, 2025
365f04d
fix: expicit params for getTestProcessFn()
twoeths Jul 31, 2025
5c506cf
fix: avoid negative terms in getTestProcessFn() util
twoeths Jul 31, 2025
75a16c3
fix: TestRunner and TestOpt
twoeths Jul 31, 2025
951ac04
main stf skeleton
spiral-ladder Jul 30, 2025
9657926
more compilation fixes
spiral-ladder Aug 1, 2025
d5b342a
process attestation fixes
spiral-ladder Aug 5, 2025
e108f3f
processAttestation
spiral-ladder Aug 6, 2025
ddc94e2
processDeposit
spiral-ladder Aug 6, 2025
be9d30d
more QoL tweaks
spiral-ladder Aug 7, 2025
3f3eeb5
processBlsToExecutionChanges
spiral-ladder Aug 7, 2025
5b0fcfa
fix: verifyMerkleBranch
spiral-ladder Aug 7, 2025
1235ed8
processVoluntaryExits
spiral-ladder Aug 7, 2025
db0eef2
processDepositRequest
spiral-ladder Aug 7, 2025
2879973
processWithdrawalRequest
spiral-ladder Aug 7, 2025
a47c184
processConsolidationRequest
spiral-ladder Aug 7, 2025
71ae865
processSyncCommittee
spiral-ladder Aug 8, 2025
1ac5852
processSyncCommittee pt 2
spiral-ladder Aug 8, 2025
be710be
processBlobKzgCommitments
spiral-ladder Aug 8, 2025
683dc40
unnecessary compileLog; test runs
spiral-ladder Aug 8, 2025
df3ab9b
rename unblinded -> regular for clearer names
spiral-ladder Aug 8, 2025
597e49a
more simplification with regular vs blinded
spiral-ladder Aug 8, 2025
755f9e8
move SignedBlock out
spiral-ladder Aug 8, 2025
6349370
test: processBlockHeader
spiral-ladder Aug 18, 2025
10bbe29
test: processWithdrawals
spiral-ladder Aug 18, 2025
0cc4fbd
test: processExecutionPayload
spiral-ladder Aug 19, 2025
298eb5f
test:processRandao
spiral-ladder Aug 19, 2025
e19cd2d
test: processEth1Data
spiral-ladder Aug 19, 2025
4426acb
test: process operations
spiral-ladder Aug 19, 2025
b53fd69
test: process sync committee and blob kzg
spiral-ladder Aug 19, 2025
6c8b5c7
clean imports
spiral-ladder Aug 19, 2025
72adad9
remove print
spiral-ladder Aug 19, 2025
0bed7eb
ergonomic pending withdrawals
spiral-ladder Aug 19, 2025
34b86ef
Merge pull request #28 from ChainSafe/te/fix_process_epoch
spiral-ladder Aug 21, 2025
0dfb30d
Merge pull request #38 from ChainSafe/bing/stf-sanity-testse
spiral-ladder Aug 21, 2025
2b2af67
Merge branch 'te/naive_state_transition' into bing/state-transition-fn
spiral-ladder Aug 21, 2025
ea1bd49
Merge branch 'main' into te/naive_state_transition
spiral-ladder Aug 26, 2025
e111ff6
zbuild sync
spiral-ladder Aug 26, 2025
1285d3b
fix utils
spiral-ladder Aug 26, 2025
7c76c8e
Merge branch 'te/naive_state_transition' into bing/state-transition-fn
spiral-ladder Aug 26, 2025
d584870
fix build
spiral-ladder Aug 26, 2025
3f88008
test: skip stf test for now
spiral-ladder Aug 28, 2025
e33e201
uncomment beforeProcessEpoch and processEpoch
spiral-ladder Aug 28, 2025
9926dde
slot, fork, latestBlockHeader api changes
spiral-ladder Aug 28, 2025
302ced4
feat(beacon_state): more un-OOPing of API
spiral-ladder Aug 28, 2025
58d7115
feat(beacon_state): more unOOP
spiral-ladder Aug 28, 2025
9eda855
feat(beacon_state): finish simplifying beacon_state
spiral-ladder Aug 31, 2025
bdee0c2
feat(beacon_block): unoops
spiral-ladder Sep 1, 2025
8838fe6
feat(beacon_block): fin
spiral-ladder Sep 1, 2025
85663ae
feat(signed_block): clean up
spiral-ladder Sep 1, 2025
863e71f
feat(signed_block): move to types/
spiral-ladder Sep 1, 2025
9286266
fix imports
spiral-ladder Sep 1, 2025
0a5f3ca
feat: revamp types
spiral-ladder Sep 2, 2025
7feec3d
remove ValidatorIndices
spiral-ladder Sep 2, 2025
229ae18
feat(process_block): ProcessBlockOpts
spiral-ladder Sep 2, 2025
c1a5a31
remove unnecessary TODO for blockToHeader
spiral-ladder Sep 2, 2025
c3e7c47
missed out removing appendPendingDeposit
spiral-ladder Sep 2, 2025
f03933e
chore: remove TODOs
spiral-ladder Sep 3, 2025
6e8545f
fix(bls): blst test
spiral-ladder Sep 3, 2025
9c9c5cb
fix: compilation issues
spiral-ladder Sep 3, 2025
f07e53f
chore: nuke primitives.zig
spiral-ladder Sep 3, 2025
ebceff7
chore: remove script
spiral-ladder Sep 3, 2025
a9cbeaa
feat(stf): implement isMergeTransitionComplete
spiral-ladder Sep 3, 2025
2fe35d0
feat: add download_spec_tests executable (#45)
wemeetagain Sep 2, 2025
c4164dd
Add minimal config
ensi321 Sep 4, 2025
b76caea
use clone
spiral-ladder Sep 5, 2025
f76ba82
comments
spiral-ladder Sep 5, 2025
819d237
feat(process_epoch): use toBoolArray for justification bits
spiral-ladder Sep 5, 2025
eebad1e
fix(epoch_transition_cache): use initCapacity
spiral-ladder Sep 5, 2025
18e5bf3
style changes
spiral-ladder Sep 5, 2025
a913649
fix(validator): snake_case instead of camelCase
spiral-ladder Sep 5, 2025
3da2bd0
chore: style
spiral-ladder Sep 5, 2025
2473c6d
slight stylistic change for readability
spiral-ladder Sep 5, 2025
dfa941b
fix: typo: acrive -> active
spiral-ladder Sep 5, 2025
d863c47
fix(epoch_participation): prefer `clearRetainingCapacity` over `deinit`
spiral-ladder Sep 5, 2025
3f02498
feat(processBlock): handle expected_withdrawals_result deinit
spiral-ladder Sep 5, 2025
cd284e6
remove unused allocator params
spiral-ladder Sep 5, 2025
08c1029
fix(proposer_slashing): verify_signature as bool instead of ?bool
spiral-ladder Sep 5, 2025
73dcb14
feat(slash_validator): use switch/case instead of if/else to set slas…
spiral-ladder Sep 5, 2025
ba4533a
feat(slash_validator): switch/case for all fork dependent values
spiral-ladder Sep 5, 2025
6dc4ed0
fix(processBlsToExecutionChange): verify_signature as bool instead of…
spiral-ladder Sep 5, 2025
e5b2b3e
style
spiral-ladder Sep 5, 2025
56bb256
fix(processSyncAggregate): verify_signature as bool instead of ?bool
spiral-ladder Sep 5, 2025
5ff1531
update zbuild
spiral-ladder Sep 6, 2025
0d380ed
Add write_spec_tests
ensi321 Sep 6, 2025
99fcf90
build: update zbuild
spiral-ladder Sep 7, 2025
4161500
fix: deinit expected withdrawal result
spiral-ladder Sep 7, 2025
7f346e3
fix(beacon_state): properly implement rotateEpochParticipation
spiral-ladder Sep 7, 2025
206a431
feat(beacon_state): fully impl clone
spiral-ladder Sep 7, 2025
38109bf
feat(stf): upgrade state
spiral-ladder Sep 7, 2025
c27331d
chore: move options into params
spiral-ladder Sep 8, 2025
bdbf487
fix upgrade state
spiral-ladder Sep 8, 2025
015bcda
chore(test_utils): move test_utils into state_transition module
spiral-ladder Sep 8, 2025
0ae04e7
test: test process attestations
spiral-ladder Sep 8, 2025
3a39bea
chore: remove test/utils
spiral-ladder Sep 8, 2025
55de148
Merge pull request #30 from ChainSafe/bing/state-transition-fn
spiral-ladder Sep 8, 2025
f3d8433
Update dep
ensi321 Sep 9, 2025
9cd8343
Add types
ensi321 Sep 9, 2025
5e57d9f
Merge branch 'te/naive_state_transition' into nc/spec-test
ensi321 Sep 9, 2025
078c83c
Fix merge
ensi321 Sep 9, 2025
3911692
Add test_case.zig
ensi321 Sep 9, 2025
ee2980f
Add operations test_case
ensi321 Sep 9, 2025
edd9f42
Fix path
ensi321 Sep 9, 2025
118f24d
git ignore
ensi321 Sep 9, 2025
d6be103
Improve test
ensi321 Sep 9, 2025
e509867
Fix type
ensi321 Sep 9, 2025
7da22c0
Improve test
ensi321 Sep 10, 2025
89c595b
test
ensi321 Sep 10, 2025
7660ff7
Update ssz-z dep
ensi321 Sep 10, 2025
25e02cc
Address gemini's comment
ensi321 Sep 10, 2025
d2bb150
use pointer for SchemaOut
ensi321 Sep 10, 2025
f275590
refactor
ensi321 Sep 11, 2025
215eb16
Add attester slashing test
ensi321 Sep 11, 2025
decb924
Add test logger
ensi321 Sep 12, 2025
584660e
Silence stack trace
ensi321 Sep 13, 2025
96817e4
Polish
ensi321 Sep 13, 2025
9b25012
Finish process_attestations
ensi321 Sep 13, 2025
7ed8227
Add process_proposer_slashing
ensi321 Sep 13, 2025
1f3567f
Finish all operations tests for phase0 and altair
ensi321 Sep 15, 2025
126d842
Temporary workaround
ensi321 Sep 15, 2025
1980e30
Clean up
ensi321 Sep 15, 2025
676de1a
Fix merge
ensi321 Sep 15, 2025
cd35728
Add execution_payload
ensi321 Sep 18, 2025
3842b2d
FInish withdrawals
ensi321 Sep 18, 2025
31bf3b5
Support all forks for operations
ensi321 Sep 18, 2025
0053c86
Temporary workaround 2
ensi321 Sep 18, 2025
1a10a4a
Merge branch 'main' into nc/spec-test
ensi321 Oct 7, 2025
018e7f8
Fix merge
ensi321 Oct 7, 2025
8fcb386
fix merge
ensi321 Oct 8, 2025
3bbbf04
Merge branch 'main' into nc/spec-test
ensi321 Oct 8, 2025
d0664f5
Address @twoeths's comment
ensi321 Oct 8, 2025
93dc0fd
Initiate tc properly
ensi321 Oct 8, 2025
700bf42
Copy state pointer
ensi321 Oct 8, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ test/bun/benchmark_data/
bun/node_modules/
bun/benchmark_data/
test/spec/spec_tests/
test/spec/test_case/operations_tests.zig
74 changes: 74 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub fn build(b: *std.Build) void {

const dep_ssz = b.dependency("ssz", .{});

const dep_snappy = b.dependency("snappy", .{});

const options_build_options = b.addOptions();
const option_preset = b.option([]const u8, "preset", "") orelse "mainnet";
options_build_options.addOption([]const u8, "preset", option_preset);
Expand Down Expand Up @@ -89,6 +91,29 @@ pub fn build(b: *std.Build) void {
const tls_run_exe_download_spec_tests = b.step("run:download_spec_tests", "Run the download_spec_tests executable");
tls_run_exe_download_spec_tests.dependOn(&run_exe_download_spec_tests.step);

const module_write_spec_tests = b.createModule(.{
.root_source_file = b.path("test/spec/write_spec_tests.zig"),
.target = target,
.optimize = optimize,
});
b.modules.put(b.dupe("write_spec_tests"), module_write_spec_tests) catch @panic("OOM");

const exe_write_spec_tests = b.addExecutable(.{
.name = "write_spec_tests",
.root_module = module_write_spec_tests,
});

const install_exe_write_spec_tests = b.addInstallArtifact(exe_write_spec_tests, .{});

const tls_install_exe_write_spec_tests = b.step("build-exe:write_spec_tests", "Install the write_spec_tests executable");
tls_install_exe_write_spec_tests.dependOn(&install_exe_write_spec_tests.step);
b.getInstallStep().dependOn(&install_exe_write_spec_tests.step);

const run_exe_write_spec_tests = b.addRunArtifact(exe_write_spec_tests);
if (b.args) |args| run_exe_write_spec_tests.addArgs(args);
const tls_run_exe_write_spec_tests = b.step("run:write_spec_tests", "Run the write_spec_tests executable");
tls_run_exe_write_spec_tests.dependOn(&run_exe_write_spec_tests.step);

const tls_run_test = b.step("test", "Run all tests");

const test_hex = b.addTest(.{
Expand Down Expand Up @@ -189,6 +214,20 @@ pub fn build(b: *std.Build) void {
tls_run_test_download_spec_tests.dependOn(&run_test_download_spec_tests.step);
tls_run_test.dependOn(&run_test_download_spec_tests.step);

const test_write_spec_tests = b.addTest(.{
.name = "write_spec_tests",
.root_module = module_write_spec_tests,
.filters = &[_][]const u8{},
});
const install_test_write_spec_tests = b.addInstallArtifact(test_write_spec_tests, .{});
const tls_install_test_write_spec_tests = b.step("build-test:write_spec_tests", "Install the write_spec_tests test");
tls_install_test_write_spec_tests.dependOn(&install_test_write_spec_tests.step);

const run_test_write_spec_tests = b.addRunArtifact(test_write_spec_tests);
const tls_run_test_write_spec_tests = b.step("test:write_spec_tests", "Run the write_spec_tests test");
tls_run_test_write_spec_tests.dependOn(&run_test_write_spec_tests.step);
tls_run_test.dependOn(&run_test_write_spec_tests.step);

const module_int = b.createModule(.{
.root_source_file = b.path("test/int/root.zig"),
.target = target,
Expand All @@ -210,6 +249,27 @@ pub fn build(b: *std.Build) void {
tls_run_test_int.dependOn(&run_test_int.step);
tls_run_test.dependOn(&run_test_int.step);

const module_spec_tests = b.createModule(.{
.root_source_file = b.path("test/spec/root.zig"),
.target = target,
.optimize = optimize,
});
b.modules.put(b.dupe("spec_tests"), module_spec_tests) catch @panic("OOM");

const test_spec_tests = b.addTest(.{
.name = "spec_tests",
.root_module = module_spec_tests,
.filters = &[_][]const u8{},
});
const install_test_spec_tests = b.addInstallArtifact(test_spec_tests, .{});
const tls_install_test_spec_tests = b.step("build-test:spec_tests", "Install the spec_tests test");
tls_install_test_spec_tests.dependOn(&install_test_spec_tests.step);

const run_test_spec_tests = b.addRunArtifact(test_spec_tests);
const tls_run_test_spec_tests = b.step("test:spec_tests", "Run the spec_tests test");
tls_run_test_spec_tests.dependOn(&run_test_spec_tests.step);
tls_run_test.dependOn(&run_test_spec_tests.step);

module_config.addImport("build_options", options_module_build_options);
module_config.addImport("preset", module_preset);
module_config.addImport("consensus_types", module_consensus_types);
Expand All @@ -234,11 +294,25 @@ pub fn build(b: *std.Build) void {

module_download_spec_tests.addImport("spec_test_options", options_module_spec_test_options);

module_write_spec_tests.addImport("spec_test_options", options_module_spec_test_options);
module_write_spec_tests.addImport("config", module_config);
module_write_spec_tests.addImport("preset", module_preset);
module_write_spec_tests.addImport("consensus_types", module_consensus_types);
module_write_spec_tests.addImport("state_transition", module_state_transition);

module_int.addImport("build_options", options_module_build_options);
module_int.addImport("ssz", dep_ssz.module("ssz"));
module_int.addImport("state_transition", module_state_transition);
module_int.addImport("config", module_config);
module_int.addImport("consensus_types", module_consensus_types);
module_int.addImport("preset", module_preset);
module_int.addImport("constants", module_constants);

module_spec_tests.addImport("consensus_types", module_consensus_types);
module_spec_tests.addImport("config", module_config);
module_spec_tests.addImport("preset", module_preset);
module_spec_tests.addImport("snappy", dep_snappy.module("snappy"));
module_spec_tests.addImport("state_transition", module_state_transition);
module_spec_tests.addImport("ssz", dep_ssz.module("ssz"));
module_spec_tests.addImport("blst", dep_blst.module("blst"));
}
6 changes: 5 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
.hash = "blst_z-0.0.0-td3FNDOMAACf6Apg5icx1KkzpVeIR-9oOSK0WSILFHx8",
},
.ssz = .{
.url = "git+https://github.com/chainsafe/ssz-z#76cde3c7ea23b33d2789e8e372003272abe0e335",
.url = "git+https://github.com/ChainSafe/ssz-z.git#76cde3c7ea23b33d2789e8e372003272abe0e335",
.hash = "ssz-0.1.0-yORmzN0NBQDTFE4aEPt3iwqZCa66VEPtpWTZ9_eS3cYO",
},
.snappy = .{
.url = "git+https://github.com/chainsafe/snappy.zig#ede2ad602ac9ffa506e3724a2bf5fc14c806187f",
.hash = "snappy-0.1.0-n4AaqtMYAACgB1kHWQ2_CFI-gbtYEUCbXyYlQZ2ENyfd",
},
},
.paths = .{ "build.zig", "build.zig.zon", "src" },
}
88 changes: 88 additions & 0 deletions src/config/chain/networks/minimal.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const std = @import("std");
const hex_utils = @import("hex");
const Preset = @import("preset").Preset;
const ChainConfig = @import("../chain_config.zig").ChainConfig;
const BlobScheduleEntry = @import("../chain_config.zig").BlobScheduleEntry;
const b = hex_utils.hexToBytesComptime;

pub const minimal_chain_config = ChainConfig{
.PRESET_BASE = Preset.minimal,
.CONFIG_NAME = "minimal",

.TERMINAL_TOTAL_DIFFICULTY = 115792089237316195423570985008687907853269984665640564039457584007913129638912,
.TERMINAL_BLOCK_HASH = b(32, "0x0000000000000000000000000000000000000000000000000000000000000000"),
.TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH = std.math.maxInt(u64),

// Genesis
.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT = 64,
.MIN_GENESIS_TIME = 1578009600,
.GENESIS_FORK_VERSION = b(4, "0x00000001"),
.GENESIS_DELAY = 300,

// Forking
.ALTAIR_FORK_VERSION = b(4, "0x01000001"),
.ALTAIR_FORK_EPOCH = 74240,
.BELLATRIX_FORK_VERSION = b(4, "0x02000001"),
.BELLATRIX_FORK_EPOCH = std.math.maxInt(u64),
.CAPELLA_FORK_VERSION = b(4, "0x03000001"),
.CAPELLA_FORK_EPOCH = std.math.maxInt(u64),
.DENEB_FORK_VERSION = b(4, "0x04000001"),
.DENEB_FORK_EPOCH = std.math.maxInt(u64),
.ELECTRA_FORK_VERSION = b(4, "0x05000001"),
.ELECTRA_FORK_EPOCH = std.math.maxInt(u64),
.FULU_FORK_VERSION = b(4, "0x06000001"),
.FULU_FORK_EPOCH = std.math.maxInt(u64),

// Time parameters
.SECONDS_PER_SLOT = 6,
.SECONDS_PER_ETH1_BLOCK = 14,
.MIN_VALIDATOR_WITHDRAWABILITY_DELAY = 256,
.SHARD_COMMITTEE_PERIOD = 64,
.ETH1_FOLLOW_DISTANCE = 16,

// Validator cycle
.INACTIVITY_SCORE_BIAS = 4,
.INACTIVITY_SCORE_RECOVERY_RATE = 16,
.EJECTION_BALANCE = 16000000000,
.MIN_PER_EPOCH_CHURN_LIMIT = 2,
.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT = 4,
.CHURN_LIMIT_QUOTIENT = 32,

// Fork choice
.PROPOSER_SCORE_BOOST = 40,
.REORG_HEAD_WEIGHT_THRESHOLD = 20,
.REORG_PARENT_WEIGHT_THRESHOLD = 160,
.REORG_MAX_EPOCHS_SINCE_FINALIZATION = 2,

// Deposit contract
.DEPOSIT_CHAIN_ID = 5,
.DEPOSIT_NETWORK_ID = 5,
.DEPOSIT_CONTRACT_ADDRESS = b(20, "0x1234567890123456789012345678901234567890"),

// Networking
.MIN_EPOCHS_FOR_BLOCK_REQUESTS = 272,

// Deneb
.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS = 4096,
.BLOB_SIDECAR_SUBNET_COUNT = 6,
.MAX_BLOBS_PER_BLOCK = 6,
.MAX_REQUEST_BLOB_SIDECARS = 768,

// Electra
.MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT = 128000000000,
.MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA = 64000000000,
.BLOB_SIDECAR_SUBNET_COUNT_ELECTRA = 9,
.MAX_BLOBS_PER_BLOCK_ELECTRA = 9,
.MAX_REQUEST_BLOB_SIDECARS_ELECTRA = 1152,

// Fulu
.MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS = 4096,
.SAMPLES_PER_SLOT = 8,
.CUSTODY_REQUIREMENT = 4,
.NODE_CUSTODY_REQUIREMENT = 1,
.VALIDATOR_CUSTODY_REQUIREMENT = 8,
.BALANCE_PER_ADDITIONAL_CUSTODY_GROUP = 32000000000,

// Blob Scheduling
.BLOB_SCHEDULE = &[_]BlobScheduleEntry{},
};
1 change: 1 addition & 0 deletions src/config/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub const ForkInfo = @import("./fork.zig").ForkInfo;
pub const forkSeqByForkName = @import("./fork.zig").forkSeqByForkName;
pub const TOTAL_FORKS = @import("./fork.zig").TOTAL_FORKS;
pub const mainnet_chain_config = @import("./chain/networks/mainnet.zig").mainnet_chain_config;
pub const minimal_chain_config = @import("./chain/networks/minimal.zig").minimal_chain_config;
pub const gnosis_chain_config = @import("./chain/networks/gnosis.zig").gnosis_chain_config;
pub const chiado_chain_config = @import("./chain/networks/chiado.zig").chiado_chain_config;
pub const sepolia_chain_config = @import("./chain/networks/sepolia.zig").sepolia_chain_config;
Expand Down
14 changes: 10 additions & 4 deletions src/state_transition/block/process_attestation_phase0.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ pub fn validateAttestation(comptime AT: type, cached_state: *const CachedBeaconS
if (data.index != 0) {
return error.InvalidAttestationNonZeroDataIndex;
}
var committee_indices: []usize = undefined;
_ = try attestation.committee_bits.getTrueBitIndexes(committee_indices[0..]);
var committee_indices_buffer: [preset.MAX_COMMITTEES_PER_SLOT]usize = undefined;
const committee_indices_len = try attestation.committee_bits.getTrueBitIndexes(committee_indices_buffer[0..]);
const committee_indices = committee_indices_buffer[0..committee_indices_len];
if (committee_indices.len == 0) {
return error.InvalidAttestationCommitteeBitsEmpty;
}
Expand All @@ -85,12 +86,17 @@ pub fn validateAttestation(comptime AT: type, cached_state: *const CachedBeaconS
return error.InvalidAttestationInvalidLstCommitteeIndex;
}

var aggregation_bits_array: []bool = undefined;
try attestation.aggregation_bits.toBoolSlice(&aggregation_bits_array);
var aggregation_bits_buffer: [preset.MAX_VALIDATORS_PER_COMMITTEE * preset.MAX_COMMITTEES_PER_SLOT]bool = undefined;
var aggregation_bits_slice = aggregation_bits_buffer[0..attestation.aggregation_bits.bit_len];
try attestation.aggregation_bits.toBoolSlice(&aggregation_bits_slice);
const aggregation_bits_array = aggregation_bits_slice;
// instead of implementing/calling getBeaconCommittees(slot, committee_indices.items), we call getBeaconCommittee(slot, index)
var committee_offset: usize = 0;
for (committee_indices) |committee_index| {
const committee_validators = try epoch_cache.getBeaconCommittee(slot, committee_index);
if (committee_offset + committee_validators.len > aggregation_bits_array.len) {
return error.InvalidAttestationCommitteeAggregationBitsLengthTooShort;
}
const committee_aggregation_bits = aggregation_bits_array[committee_offset..(committee_offset + committee_validators.len)];

// Assert aggregation bits in this committee have at least one true bit
Expand Down
4 changes: 4 additions & 0 deletions src/state_transition/block/process_proposer_slashing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pub fn assertValidProposerSlashing(
return error.InvalidProposerSlashingProposerIndexMismatch;
}

if (header_1.proposer_index >= state.validators().items.len) {
return error.InvalidProposerSlashingProposerIndexOutOfRange;
}

// verify headers are different
if (ssz.phase0.BeaconBlockHeader.equals(&header_1, &header_2)) {
return error.InvalidProposerSlashingHeadersEqual;
Expand Down
5 changes: 5 additions & 0 deletions src/state_transition/block/process_voluntary_exit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub fn isValidVoluntaryExit(cached_state: *CachedBeaconStateAllForks, signed_vol
const epoch_cache = cached_state.getEpochCache();
const config = cached_state.config.chain;
const voluntary_exit = signed_voluntary_exit.message;

if (voluntary_exit.validator_index >= state.validators().items.len) {
return false;
}

const validator = state.validators().items[voluntary_exit.validator_index];
const current_epoch = epoch_cache.epoch;

Expand Down
8 changes: 6 additions & 2 deletions src/state_transition/block/process_withdrawals.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Withdrawal = ssz.capella.Withdrawal.Type;
const Withdrawals = ssz.capella.Withdrawals.Type;
const ValidatorIndex = ssz.primitive.ValidatorIndex.Type;
const ExecutionAddress = ssz.primitive.ExecutionAddress.Type;
const PendingPartialWithdrawal = ssz.electra.PendingPartialWithdrawal.Type;
const ExecutionPayload = @import("../types/execution_payload.zig").ExecutionPayload;
const hasExecutionWithdrawalCredential = @import("../utils/electra.zig").hasExecutionWithdrawalCredential;
const hasEth1WithdrawalCredential = @import("../utils/capella.zig").hasEth1WithdrawalCredential;
Expand Down Expand Up @@ -38,7 +39,10 @@ pub fn processWithdrawals(

if (state.isPostElectra()) {
const pending_partial_withdrawals = state.pendingPartialWithdrawals();
@memcpy(pending_partial_withdrawals.items, state.pendingPartialWithdrawals().items[processed_partial_withdrawals_count..]);
const keep_len = pending_partial_withdrawals.items.len - processed_partial_withdrawals_count;

std.mem.copyForwards(PendingPartialWithdrawal, pending_partial_withdrawals.items[0..keep_len], pending_partial_withdrawals.items[processed_partial_withdrawals_count..]);
pending_partial_withdrawals.shrinkRetainingCapacity(keep_len);
}

const next_withdrawal_index = state.nextWithdrawalIndex();
Expand Down Expand Up @@ -134,7 +138,7 @@ pub fn getExpectedWithdrawals(
const withdraw_balance: u64 = if (withdraw_balance_gop.found_existing) withdraw_balance_gop.value_ptr.* else 0;
const balance = if (state.isPostElectra())
// Deduct partially withdrawn balance already queued above
balances.items[validator_index] - withdraw_balance
if (balances.items[validator_index] > withdraw_balance) balances.items[validator_index] - withdraw_balance else 0
else
balances.items[validator_index];

Expand Down
5 changes: 3 additions & 2 deletions src/state_transition/cache/epoch_cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,9 @@ pub const EpochCache = struct {
// In the spec it means a list of committee indices according to committeeBits
// This `committeeIndices` refers to the latter
// TODO Electra: resolve the naming conflicts
var committee_indices: []usize = undefined;
_ = try committee_bits.getTrueBitIndexes(committee_indices[0..]);
var committee_indices_buffer: [preset.MAX_COMMITTEES_PER_SLOT]usize = undefined;
const committee_indices_len = try committee_bits.getTrueBitIndexes(committee_indices_buffer[0..]);
const committee_indices = committee_indices_buffer[0..committee_indices_len];

var total_len: usize = 0;
for (committee_indices) |committee_index| {
Expand Down
12 changes: 11 additions & 1 deletion src/state_transition/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@ pub const processSyncCommitteeUpdates = @import("./epoch/process_sync_committee_
// Block
pub const processBlockHeader = @import("./block/process_block_header.zig").processBlockHeader;
pub const processWithdrawals = @import("./block/process_withdrawals.zig").processWithdrawals;
pub const getExpectedWithdrawalsResult = @import("./block/process_withdrawals.zig").getExpectedWithdrawals;
pub const getExpectedWithdrawals = @import("./block/process_withdrawals.zig").getExpectedWithdrawals;
pub const processExecutionPayload = @import("./block/process_execution_payload.zig").processExecutionPayload;
pub const processRandao = @import("./block/process_randao.zig").processRandao;
pub const processEth1Data = @import("./block/process_eth1_data.zig").processEth1Data;
pub const processOperations = @import("./block/process_operations.zig").processOperations;
pub const processSyncAggregate = @import("./block/process_sync_committee.zig").processSyncAggregate;
pub const processBlobKzgCommitments = @import("./block/process_blob_kzg_commitments.zig").processBlobKzgCommitments;
pub const processAttestations = @import("./block/process_attestations.zig").processAttestations;
pub const processAttesterSlashing = @import("./block/process_attester_slashing.zig").processAttesterSlashing;
pub const processDeposit = @import("./block/process_deposit.zig").processDeposit;
pub const processProposerSlashing = @import("./block/process_proposer_slashing.zig").processProposerSlashing;
pub const processVoluntaryExit = @import("./block/process_voluntary_exit.zig").processVoluntaryExit;
pub const processBlsToExecutionChange = @import("./block/process_bls_to_execution_change.zig").processBlsToExecutionChange;
pub const processDepositRequest = @import("./block/process_deposit_request.zig").processDepositRequest;
pub const processWithdrawalRequest = @import("./block/process_withdrawal_request.zig").processWithdrawalRequest;
pub const processConsolidationRequest = @import("./block/process_consolidation_request.zig").processConsolidationRequest;

pub const WithdrawalsResult = @import("./block/process_withdrawals.zig").WithdrawalsResult;

Expand All @@ -55,6 +64,7 @@ pub const state_transition = @import("./state_transition.zig");
const EpochShuffling = @import("./utils/epoch_shuffling.zig");
pub const SignedBlock = @import("./types/signed_block.zig").SignedBlock;
pub const SignedBeaconBlock = @import("./types/beacon_block.zig").SignedBeaconBlock;
pub const Attestations = @import("./types/attestation.zig").Attestations;

test {
testing.refAllDecls(@This());
Expand Down
Loading
Loading