Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
branches:
- main

env:
ZIG_VERSION: 0.14.1

jobs:
zbuild:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -44,9 +47,9 @@ jobs:
uses: actions/checkout@v4

- name: Setup Zig
uses: mlugg/setup-zig@v1
uses: mlugg/setup-zig@v2
with:
version: "0.14.0"
version: ${{ env.ZIG_VERSION }}

- name: Unit tests
run: |
Expand All @@ -63,9 +66,9 @@ jobs:
uses: actions/checkout@v4

- name: Setup Zig
uses: mlugg/setup-zig@v1
uses: mlugg/setup-zig@v2
with:
version: "0.14.0"
version: ${{ env.ZIG_VERSION }}

- name: Cache spec tests
id: spec-tests
Expand Down
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub fn build(b: *std.Build) void {
const options_module_build_options = options_build_options.createModule();

const options_spec_test_options = b.addOptions();
const option_spec_test_url = b.option([]const u8, "spec_test_url", "") orelse "https://github.com/ethereum/consensus-spec-tests";
const option_spec_test_url = b.option([]const u8, "spec_test_url", "") orelse "https://github.com/ethereum/consensus-specs";
options_spec_test_options.addOption([]const u8, "spec_test_url", option_spec_test_url);
const option_spec_test_version = b.option([]const u8, "spec_test_version", "") orelse "v1.5.0";
const option_spec_test_version = b.option([]const u8, "spec_test_version", "") orelse "v1.6.0";
options_spec_test_options.addOption([]const u8, "spec_test_version", option_spec_test_version);
const option_spec_test_out_dir = b.option([]const u8, "spec_test_out_dir", "") orelse "test/spec/spec_tests";
options_spec_test_options.addOption([]const u8, "spec_test_out_dir", option_spec_test_out_dir);
Expand Down
4 changes: 2 additions & 2 deletions src/consensus_types/preset.zig
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ const PresetMinimal = struct {
pub const MAX_WITHDRAWALS_PER_PAYLOAD = 4;
pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP = 16;
pub const FIELD_ELEMENTS_PER_BLOB = 4096;
pub const MAX_BLOB_COMMITMENTS_PER_BLOCK = 32;
pub const MAX_BLOB_COMMITMENTS_PER_BLOCK = 4096;
pub const MAX_BLOBS_PER_BLOCK = 6;
pub const KZG_COMMITMENT_INCLUSION_PROOF_DEPTH = 10;
pub const KZG_COMMITMENT_INCLUSION_PROOF_DEPTH = 17;
pub const MIN_ACTIVATION_BALANCE = 32000000000;
pub const MAX_EFFECTIVE_BALANCE_ELECTRA = 2048000000000;
pub const PENDING_DEPOSITS_LIMIT = 134217728;
Expand Down
36 changes: 29 additions & 7 deletions src/ssz/hasher.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const std = @import("std");

const isBasicType = @import("type/type_kind.zig").isBasicType;
const isFixedType = @import("type/type_kind.zig").isFixedType;
const isBitListType = @import("type/bit_list.zig").isBitListType;
const h = @import("hashing");

Expand All @@ -20,7 +21,7 @@ pub fn Hasher(comptime ST: type) type {
return try HasherData.initCapacity(allocator, hasher_size, children);
}
},
.container => {
.container, .progressive_container => {
const hasher_size = if (ST.chunk_count % 2 == 1) ST.chunk_count + 1 else ST.chunk_count;
var children = try allocator.alloc(HasherData, ST.fields.len);
inline for (ST.fields, 0..) |field, i| {
Expand All @@ -32,7 +33,7 @@ pub fn Hasher(comptime ST: type) type {
}
return try HasherData.initCapacity(allocator, hasher_size, children);
},
.list => {
.list, .progressive_list, .progressive_bit_list => {
// we don't preallocate here since we need the length
const hasher_size = 0;
if (comptime isBasicType(ST.Element)) {
Expand All @@ -43,6 +44,9 @@ pub fn Hasher(comptime ST: type) type {
return try HasherData.initCapacity(allocator, hasher_size, children);
}
},
.compatible_union => {
return try HasherData.initCapacity(allocator, 0, null);
},
else => unreachable,
}
}
Expand All @@ -61,6 +65,9 @@ pub fn Hasher(comptime ST: type) type {
}
} else {
switch (ST.kind) {
.progressive_list, .progressive_bit_list => {
try ST.hashTreeRoot(scratch.allocator(), value, out);
},
.list => {
const chunk_count = ST.chunkCount(value);
const hasher_size = if (chunk_count % 2 == 1) chunk_count + 1 else chunk_count;
Expand Down Expand Up @@ -103,6 +110,17 @@ pub fn Hasher(comptime ST: type) type {
}
try h.merkleize(@ptrCast(scratch.chunks.items), ST.chunk_depth, out);
},
.progressive_container => {
if (comptime isFixedType(ST)) {
try ST.hashTreeRoot(value, out);
} else {
try ST.hashTreeRoot(scratch.allocator(), value, out);
}
},
.compatible_union => {
// CompatibleUnion has its own hashTreeRoot implementation
try ST.hashTreeRoot(scratch.allocator(), value, out);
},
else => unreachable,
}
}
Expand All @@ -114,8 +132,8 @@ pub const HasherData = struct {
chunks: std.ArrayList([32]u8),
children: ?[]HasherData,

pub fn initCapacity(allocator: std.mem.Allocator, capacity: usize, children: ?[]HasherData) !HasherData {
var chunks = try std.ArrayList([32]u8).initCapacity(allocator, capacity);
pub fn initCapacity(alloc: std.mem.Allocator, capacity: usize, children: ?[]HasherData) !HasherData {
var chunks = try std.ArrayList([32]u8).initCapacity(alloc, capacity);
chunks.expandToCapacity();
@memset(chunks.items, [_]u8{0} ** 32);
return HasherData{
Expand All @@ -124,13 +142,17 @@ pub const HasherData = struct {
};
}

pub fn deinit(self: HasherData, allocator: std.mem.Allocator) void {
pub fn deinit(self: HasherData, alloc: std.mem.Allocator) void {
if (self.children) |children| {
for (children) |child| {
child.deinit(allocator);
child.deinit(alloc);
}
allocator.free(children);
alloc.free(children);
}
self.chunks.deinit();
}

pub fn allocator(self: *HasherData) std.mem.Allocator {
return self.chunks.allocator;
}
};
18 changes: 18 additions & 0 deletions src/ssz/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub const types = @import("type/root.zig");
pub const TypeKind = types.TypeKind;
pub const isBasicType = types.isBasicType;
pub const isFixedType = types.isFixedType;
pub const isProgressiveListType = types.isProgressiveListType;
pub const isCompatibleUnionType = types.isCompatibleUnionType;

pub const BoolType = types.BoolType;
pub const UintType = types.UintType;
Expand Down Expand Up @@ -33,6 +35,22 @@ pub const VariableVectorType = types.VariableVectorType;
pub const FixedContainerType = types.FixedContainerType;
pub const VariableContainerType = types.VariableContainerType;

// Progressive container types
pub const FixedProgressiveContainerType = types.FixedProgressiveContainerType;
pub const VariableProgressiveContainerType = types.VariableProgressiveContainerType;

// Progressive list types
pub const FixedProgressiveListType = types.FixedProgressiveListType;
pub const VariableProgressiveListType = types.VariableProgressiveListType;

// Progressive bit list
pub const ProgressiveBitListType = types.ProgressiveBitListType;
pub const ProgressiveBitList = types.ProgressiveBitList;
pub const isProgressiveBitListType = types.isProgressiveBitListType;

// Compatible union
pub const CompatibleUnionType = types.CompatibleUnionType;

const hasher = @import("hasher.zig");
pub const Hasher = hasher.Hasher;
pub const HasherData = hasher.HasherData;
Expand Down
Loading