Skip to content
Merged
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
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.version = "0.0.0",
.dependencies = .{
.ssz = .{
.url = "https://github.com/blockblaz/ssz.zig/archive/refs/tags/v0.0.7.tar.gz",
.hash = "ssz-0.0.4-Lfwd65-iAgBkwCIZmHkrOvD3oCjooiBD73Nmp4gCNMG6",
.url = "git+https://github.com/blockblaz/ssz.zig#5ce7322fc45cab4f215021cae2579d1343e05d55",
.hash = "ssz-0.0.9-Lfwd61PEAgAUPJfUQiK4R5gRX_lTWOd_qYwNT-KAhRLA",
},
.zigcli = .{
.url = "git+https://github.com/jiacai2050/zigcli?ref=main#dcbc59d70b4787671c8a4e484ffd2b725aa17af5",
Expand Down
2 changes: 1 addition & 1 deletion leanSpec
Submodule leanSpec updated 106 files
28 changes: 16 additions & 12 deletions pkgs/database/src/rocksdb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,14 @@ test "save and load block" {
try std.testing.expect(loaded.block.body.attestations.len() == 0);

// Verify signatures match
try std.testing.expect(loaded_block.?.signature.len() == 2);
const loaded_sig1 = try loaded_block.?.signature.get(0);
const loaded_sig2 = try loaded_block.?.signature.get(1);
try std.testing.expect(std.mem.eql(u8, &loaded_sig1, &test_sig1));
try std.testing.expect(std.mem.eql(u8, &loaded_sig2, &test_sig2));
const signature_groups = loaded_block.?.signature.attestation_signatures;
try std.testing.expect(signature_groups.len() == 1);
const loaded_group = try signature_groups.get(0);
try std.testing.expect(loaded_group.len() == test_signatures.len);
for (test_signatures, 0..) |expected_sig, idx| {
const loaded_sig = try loaded_group.get(idx);
try std.testing.expect(std.mem.eql(u8, &loaded_sig, &expected_sig));
}

// Test loading a non-existent block
const non_existent_root = test_helpers.createDummyRoot(0xFF);
Expand Down Expand Up @@ -1134,13 +1137,14 @@ test "batch write and commit" {
try std.testing.expect(std.mem.eql(u8, &loaded_block_data.block.state_root, &signed_block.message.block.state_root));

// Verify signatures match
try std.testing.expect(loaded_block.?.signature.len() == 3);
const loaded_sig1 = try loaded_block.?.signature.get(0);
const loaded_sig2 = try loaded_block.?.signature.get(1);
const loaded_sig3 = try loaded_block.?.signature.get(2);
try std.testing.expect(std.mem.eql(u8, &loaded_sig1, &test_sig1));
try std.testing.expect(std.mem.eql(u8, &loaded_sig2, &test_sig2));
try std.testing.expect(std.mem.eql(u8, &loaded_sig3, &test_sig3));
const batch_signature_groups = loaded_block.?.signature.attestation_signatures;
try std.testing.expect(batch_signature_groups.len() == 1);
const loaded_group = try batch_signature_groups.get(0);
try std.testing.expect(loaded_group.len() == test_signatures.len);
for (test_signatures, 0..) |expected_sig, idx| {
const loaded_sig = try loaded_group.get(idx);
try std.testing.expect(std.mem.eql(u8, &loaded_sig, &expected_sig));
}

// Verify state was saved and can be loaded
const loaded_state = db.loadState(database.DbStatesNamespace, test_state_root);
Expand Down
29 changes: 23 additions & 6 deletions pkgs/database/src/test_helpers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ const types = @import("@zeam/types");

/// Helper function to create a dummy block for testing
pub fn createDummyBlock(allocator: Allocator, slot: u64, proposer_index: u64, parent_root_fill: u8, state_root_fill: u8, signatures: []const types.SIGBYTES) !types.SignedBlockWithAttestation {
const attestations_list = try types.AggregatedAttestations.init(allocator);

var test_block = types.BeamBlock{
.slot = slot,
.proposer_index = proposer_index,
.parent_root = undefined,
.state_root = undefined,
.body = types.BeamBlockBody{
.attestations = try types.Attestations.init(allocator),
.attestations = attestations_list,
},
};
@memset(&test_block.parent_root, parent_root_fill);
Expand Down Expand Up @@ -40,14 +42,29 @@ pub fn createDummyBlock(allocator: Allocator, slot: u64, proposer_index: u64, pa
.proposer_attestation = proposer_attestation,
};

var block_signatures = try types.BlockSignatures.init(allocator);
errdefer block_signatures.deinit();
var attestation_signatures = try types.AttestationSignatures.init(allocator);
var attestation_signatures_cleanup = true;
errdefer if (attestation_signatures_cleanup) attestation_signatures.deinit();

if (signatures.len > 0) {
var validator_signatures = try types.NaiveAggregatedSignature.init(allocator);
var validator_signatures_cleanup = true;
errdefer if (validator_signatures_cleanup) validator_signatures.deinit();

for (signatures) |sig| {
try validator_signatures.append(sig);
}

// Add all provided signatures to the list
for (signatures) |sig| {
try block_signatures.append(sig);
try attestation_signatures.append(validator_signatures);
validator_signatures_cleanup = false;
}

const block_signatures = types.BlockSignatures{
.attestation_signatures = attestation_signatures,
.proposer_signature = types.ZERO_SIGBYTES,
};
attestation_signatures_cleanup = false;

const signed_block = types.SignedBlockWithAttestation{
.message = block_with_attestation,
.signature = block_signatures,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/key-manager/src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub const KeyManager = struct {

const signing_timer = zeam_metrics.lean_pq_signature_attestation_signing_time_seconds.start();
var message: [32]u8 = undefined;
try ssz.hashTreeRoot(types.Attestation, attestation.*, &message, allocator);
try ssz.hashTreeRoot(types.AttestationData, attestation.data, &message, allocator);

const epoch: u32 = @intCast(attestation.data.slot);

Expand Down
2 changes: 1 addition & 1 deletion pkgs/network/src/mock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ test "Mock messaging across two subscribers" {
try network.gossip.subscribe(&topics, subscriber2.getCallbackHandler());

// Create a simple block message
var attestations = try types.Attestations.init(allocator);
var attestations = try types.AggregatedAttestations.init(allocator);

const block_message = try allocator.create(interface.GossipMessage);
defer allocator.destroy(block_message);
Expand Down
Loading