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
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub fn build(b: *Builder) !void {
});
zeam_utils.addImport("datetime", datetime);
zeam_utils.addImport("yaml", yaml);
zeam_utils.addImport("ssz", ssz);

// add zeam-params
const zeam_params = b.addModule("@zeam/params", .{
Expand Down Expand Up @@ -221,6 +222,7 @@ pub fn build(b: *Builder) !void {
});
zeam_key_manager.addImport("@zeam/xmss", zeam_xmss);
zeam_key_manager.addImport("@zeam/types", zeam_types);
zeam_key_manager.addImport("@zeam/utils", zeam_utils);
zeam_key_manager.addImport("@zeam/metrics", zeam_metrics);
zeam_key_manager.addImport("ssz", ssz);

Expand Down Expand Up @@ -728,6 +730,7 @@ fn build_zkvm_targets(b: *Builder, main_exe: *Builder.Step, host_target: std.Bui
.optimize = optimize,
.root_source_file = b.path("pkgs/utils/src/lib.zig"),
});
zeam_utils.addImport("ssz", ssz);

// add zeam-metrics (core metrics definitions for ZKVM)
const zeam_metrics = b.addModule("@zeam/metrics", .{
Expand Down
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 = "git+https://github.com/blockblaz/ssz.zig#5ce7322fc45cab4f215021cae2579d1343e05d55",
.hash = "ssz-0.0.9-Lfwd61PEAgAUPJfUQiK4R5gRX_lTWOd_qYwNT-KAhRLA",
.url = "https://github.com/blockblaz/ssz.zig/archive/0ce92a8f093a321b0d0815eec6c90bd4e745d8e1.tar.gz",
.hash = "ssz-0.0.9-Lfwd6wvKAgA3JZjtfbeXeQG6zle1K_K2j6HPmQJJF4an",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we get a new release for ssz?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

merging this PR for now, lets do it in followup

},
.zigcli = .{
.url = "git+https://github.com/jiacai2050/zigcli?ref=main#dcbc59d70b4787671c8a4e484ffd2b725aa17af5",
Expand Down
4 changes: 2 additions & 2 deletions pkgs/cli/src/node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ fn verifyCheckpointState(

// Calculate the block root from the properly constructed block header
var block_root: types.Root = undefined;
try ssz.hashTreeRoot(types.BeamBlockHeader, state_block_header, &block_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamBlockHeader, state_block_header, &block_root, allocator);

logger.info("checkpoint state verified: slot={d}, genesis_time={d}, validators={d}, state_root=0x{s}, block_root=0x{s}", .{
state.slot,
Expand Down Expand Up @@ -1201,7 +1201,7 @@ test "compare roots from genGensisBlock and genGenesisState and genStateBlockHea

// Get state root by hashing the state directly
var state_root_from_genesis: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamState, genesis_state, &state_root_from_genesis, allocator);
try zeam_utils.hashTreeRoot(types.BeamState, genesis_state, &state_root_from_genesis, allocator);

// Generate block header using genStateBlockHeader
const state_block_header = try genesis_state.genStateBlockHeader(allocator);
Expand Down
4 changes: 2 additions & 2 deletions pkgs/key-manager/src/lib.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const xmss = @import("@zeam/xmss");
const types = @import("@zeam/types");
const zeam_utils = @import("@zeam/utils");
const zeam_metrics = @import("@zeam/metrics");
const ssz = @import("ssz");
const Allocator = std.mem.Allocator;

const KeyManagerError = error{
Expand Down Expand Up @@ -152,7 +152,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.AttestationData, attestation.data, &message, allocator);
try zeam_utils.hashTreeRoot(types.AttestationData, attestation.data, &message, allocator);

const epoch: u32 = @intCast(attestation.data.slot);
const signature = try keypair.sign(&message, epoch);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/node/src/chain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub const BeamChain = struct {

// 3. cache state to save recompute while adding the block on publish
var block_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamBlock, block, &block_root, self.allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, block, &block_root, self.allocator);

try self.states.put(block_root, post_state);
post_state_opt = null;
Expand Down Expand Up @@ -491,7 +491,7 @@ pub const BeamChain = struct {
.block => |signed_block| {
const block = signed_block.message.block;
var block_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamBlock, block, &block_root, self.allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, block, &block_root, self.allocator);

//check if we have the block already in forkchoice
const hasBlock = self.forkChoice.hasBlock(block_root);
Expand Down Expand Up @@ -592,7 +592,7 @@ pub const BeamChain = struct {

const block_root: types.Root = blockInfo.blockRoot orelse computedroot: {
var cblock_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamBlock, block, &cblock_root, self.allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, block, &cblock_root, self.allocator);
break :computedroot cblock_root;
};

Expand Down Expand Up @@ -1339,7 +1339,7 @@ test "process and add mock blocks into a node's chain" {
// should have matching states in the state
const block_state = beam_chain.states.get(block_root) orelse @panic("state root should have been found");
var state_root: [32]u8 = undefined;
try ssz.hashTreeRoot(*types.BeamState, block_state, &state_root, allocator);
try zeam_utils.hashTreeRoot(*types.BeamState, block_state, &state_root, allocator);
try std.testing.expect(std.mem.eql(u8, &state_root, &block.state_root));

// fcstore checkpoints should match
Expand Down
4 changes: 2 additions & 2 deletions pkgs/node/src/forkchoice.zig
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub const ForkChoice = struct {
pub fn init(allocator: Allocator, opts: ForkChoiceParams) !Self {
const anchor_block_header = try opts.anchorState.genStateBlockHeader(allocator);
var anchor_block_root: [32]u8 = undefined;
try ssz.hashTreeRoot(
try zeam_utils.hashTreeRoot(
types.BeamBlockHeader,
anchor_block_header,
&anchor_block_root,
Expand Down Expand Up @@ -1062,7 +1062,7 @@ pub const ForkChoice = struct {

const block_root: [32]u8 = opts.blockRoot orelse computedroot: {
var cblock_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamBlock, block, &cblock_root, self.allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, block, &cblock_root, self.allocator);
break :computedroot cblock_root;
};
const is_timely = self.isBlockTimely(opts.blockDelayMs);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/node/src/node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub const BeamNode = struct {
}

var block_root: types.Root = undefined;
if (ssz.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator)) |_| {
if (zeam_utils.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator)) |_| {
_ = self.network.removePendingBlockRoot(block_root);
} else |err| {
self.logger.warn("failed to compute block root for incoming gossip block: {any}", .{err});
Expand Down Expand Up @@ -168,7 +168,7 @@ pub const BeamNode = struct {
if (data.* == .block) {
const signed_block = data.block;
var block_root: types.Root = undefined;
if (ssz.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator)) |_| {
if (zeam_utils.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator)) |_| {
self.logger.info(
"gossip block 0x{s} rejected as pre-finalized; pruning cached descendants",
.{std.fmt.fmtSliceHexLower(block_root[0..])},
Expand Down Expand Up @@ -338,7 +338,7 @@ pub const BeamNode = struct {

fn processBlockByRootChunk(self: *Self, block_ctx: *const BlockByRootContext, signed_block: *const types.SignedBlockWithAttestation) !void {
var block_root: types.Root = undefined;
if (ssz.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator)) |_| {
if (zeam_utils.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator)) |_| {
const current_depth = self.network.getPendingBlockRootDepth(block_root) orelse 0;
const removed = self.network.removePendingBlockRoot(block_root);
if (!removed) {
Expand Down Expand Up @@ -779,7 +779,7 @@ pub const BeamNode = struct {

// 1. Process locally through chain so that produced block first can be confirmed
var block_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, signed_block.message.block, &block_root, self.allocator);

// check if the block has not already been received through the network
const hasBlock = self.chain.forkChoice.hasBlock(block_root);
Expand Down
4 changes: 1 addition & 3 deletions pkgs/node/src/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const zeam_utils = @import("@zeam/utils");
const xev = @import("xev");
const networks = @import("@zeam/network");
const xmss = @import("@zeam/xmss");
const ssz = @import("ssz");

const clockFactory = @import("./clock.zig");

pub const NodeTestOptions = struct {
Expand Down Expand Up @@ -203,7 +201,7 @@ pub const NodeTestContext = struct {

// Compute message hash
var message_hash: [32]u8 = undefined;
try ssz.hashTreeRoot(types.AttestationData, aggregated_attestation.data, &message_hash, allocator);
try zeam_utils.hashTreeRoot(types.AttestationData, aggregated_attestation.data, &message_hash, allocator);

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

Expand Down
4 changes: 2 additions & 2 deletions pkgs/spectest/src/runner/fork_choice_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn runCase(
defer label_map.deinit(allocator);

var anchor_root: types.Root = undefined;
ssz.hashTreeRoot(types.BeamBlock, anchor_block, &anchor_root, allocator) catch |err| {
zeam_utils.hashTreeRoot(types.BeamBlock, anchor_block, &anchor_root, allocator) catch |err| {
std.debug.print(
"fixture {s} case {s}: anchor block hashing failed ({s})\n",
.{ ctx.fixture_label, ctx.case_name, @errorName(err) },
Expand Down Expand Up @@ -607,7 +607,7 @@ fn processBlockStep(
defer block.deinit();

var block_root: types.Root = undefined;
ssz.hashTreeRoot(types.BeamBlock, block, &block_root, ctx.allocator) catch |err| {
zeam_utils.hashTreeRoot(types.BeamBlock, block, &block_root, ctx.allocator) catch |err| {
std.debug.print(
"fixture {s} case {s}{}: hashing block failed ({s})\n",
.{ fixture_path, case_name, formatStep(step_index), @errorName(err) },
Expand Down
6 changes: 2 additions & 4 deletions pkgs/spectest/src/runner/state_transition_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ pub fn baseRelRoot(comptime spec_fork: Fork) []const u8 {
const types = @import("@zeam/types");
const state_transition = @import("@zeam/state-transition");
const zeam_utils = @import("@zeam/utils");
const ssz = @import("ssz");

const JsonValue = std.json.Value;
const Context = expect.Context;

Expand Down Expand Up @@ -245,7 +243,7 @@ fn runCase(
var header_for_check = pre_state.latest_block_header;
if (std.mem.eql(u8, &header_for_check.state_root, &types.ZERO_HASH)) {
var pre_state_root: types.Root = undefined;
ssz.hashTreeRoot(types.BeamState, pre_state, &pre_state_root, allocator) catch |err| {
zeam_utils.hashTreeRoot(types.BeamState, pre_state, &pre_state_root, allocator) catch |err| {
std.debug.print(
"fixture {s} case {s}: unable to hash pre-state ({s})\n",
.{ ctx.fixture_label, ctx.case_name, @errorName(err) },
Expand All @@ -256,7 +254,7 @@ fn runCase(
}

var header_root: types.Root = undefined;
ssz.hashTreeRoot(types.BeamBlockHeader, header_for_check, &header_root, allocator) catch |err| {
zeam_utils.hashTreeRoot(types.BeamBlockHeader, header_for_check, &header_root, allocator) catch |err| {
std.debug.print(
"fixture {s} case {s}: unable to hash latest block header ({s})\n",
.{ ctx.fixture_label, ctx.case_name, @errorName(err) },
Expand Down
6 changes: 3 additions & 3 deletions pkgs/state-transition/src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test "apply transition on mocked chain" {
// check the post state root to be equal to block2's stateroot
// this is reduant though because apply_transition already checks this for each block's state root
var post_state_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamState, beam_state, &post_state_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamState, beam_state, &post_state_root, allocator);
try std.testing.expect(std.mem.eql(u8, &post_state_root, &mock_chain.blocks[mock_chain.blocks.len - 1].message.block.state_root));
}

Expand All @@ -73,11 +73,11 @@ test "genStateBlockHeader" {
// get applied block
const applied_block = mock_chain.blocks[i];
var applied_block_root: types.Root = undefined;
try ssz.hashTreeRoot(types.BeamBlock, applied_block.message.block, &applied_block_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, applied_block.message.block, &applied_block_root, allocator);

const state_block_header = try beam_state.genStateBlockHeader(allocator);
var state_block_header_root: types.Root = undefined;
try ssz.hashTreeRoot(types.BeamBlockHeader, state_block_header, &state_block_header_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamBlockHeader, state_block_header, &state_block_header_root, allocator);

try std.testing.expect(std.mem.eql(u8, &applied_block_root, &state_block_header_root));

Expand Down
6 changes: 3 additions & 3 deletions pkgs/state-transition/src/mock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn genMockChain(allocator: Allocator, numBlocks: usize, from_genesis: ?types
},
};
var block_root: types.Root = undefined;
try ssz.hashTreeRoot(types.BeamBlock, genesis_block, &block_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, genesis_block, &block_root, allocator);

try blockList.append(gen_signed_block);
try blockRootList.append(block_root);
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn genMockChain(allocator: Allocator, numBlocks: usize, from_genesis: ?types

for (1..numBlocks) |slot| {
var parent_root: [32]u8 = undefined;
try ssz.hashTreeRoot(types.BeamBlock, prev_block, &parent_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, prev_block, &parent_root, allocator);

const state_root: [32]u8 = types.ZERO_HASH;
// const timestamp = genesis_config.genesis_time + slot * params.SECONDS_PER_SLOT;
Expand Down Expand Up @@ -331,7 +331,7 @@ pub fn genMockChain(allocator: Allocator, numBlocks: usize, from_genesis: ?types

// prepare pre state to process block for that slot, may be rename prepare_pre_state
try transition.apply_raw_block(allocator, &beam_state, &block, block_building_logger);
try ssz.hashTreeRoot(types.BeamBlock, block, &block_root, allocator);
try zeam_utils.hashTreeRoot(types.BeamBlock, block, &block_root, allocator);

// generate the signed beam block and add to block list
const block_with_attestation = types.BlockWithAttestation{
Expand Down
9 changes: 4 additions & 5 deletions pkgs/state-transition/src/transition.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const ssz = @import("ssz");
const std = @import("std");
const json = std.json;
const types = @import("@zeam/types");
Expand Down Expand Up @@ -51,7 +50,7 @@ pub fn apply_raw_block(allocator: Allocator, state: *types.BeamState, block: *ty
logger.debug("extracting state root\n", .{});
// extract the post state root
var state_root: [32]u8 = undefined;
try ssz.hashTreeRoot(*types.BeamState, state, &state_root, allocator);
try zeam_utils.hashTreeRoot(*types.BeamState, state, &state_root, allocator);
block.state_root = state_root;
}

Expand Down Expand Up @@ -117,7 +116,7 @@ pub fn verifySignatures(

// Compute message hash from attestation data
var message_hash: [32]u8 = undefined;
try ssz.hashTreeRoot(types.AttestationData, aggregated_attestation.data, &message_hash, allocator);
try zeam_utils.hashTreeRoot(types.AttestationData, aggregated_attestation.data, &message_hash, allocator);

const epoch: u64 = aggregated_attestation.data.slot;

Expand Down Expand Up @@ -156,7 +155,7 @@ pub fn verifySingleAttestation(

const verification_timer = zeam_metrics.lean_pq_signature_attestation_verification_time_seconds.start();
var message: [32]u8 = undefined;
try ssz.hashTreeRoot(types.AttestationData, attestation_data.*, &message, allocator);
try zeam_utils.hashTreeRoot(types.AttestationData, attestation_data.*, &message, allocator);

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

Expand Down Expand Up @@ -187,7 +186,7 @@ pub fn apply_transition(allocator: Allocator, state: *types.BeamState, block: ty
if (validateResult) {
// verify the post state root
var state_root: [32]u8 = undefined;
try ssz.hashTreeRoot(*types.BeamState, state, &state_root, allocator);
try zeam_utils.hashTreeRoot(*types.BeamState, state, &state_root, allocator);
if (!std.mem.eql(u8, &state_root, &block.state_root)) {
opts.logger.debug("state root={x:02} block root={x:02}\n", .{ state_root, block.state_root });
return StateTransitionError.InvalidPostState;
Expand Down
1 change: 0 additions & 1 deletion pkgs/types/src/aggregation.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const std = @import("std");
const ssz = @import("ssz");
const params = @import("@zeam/params");
const xmss = @import("@zeam/xmss");

Expand Down
3 changes: 2 additions & 1 deletion pkgs/types/src/attestation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const std = @import("std");
const ssz = @import("ssz");

const params = @import("@zeam/params");
const zeam_utils = @import("@zeam/utils");

const mini_3sf = @import("./mini_3sf.zig");
const utils = @import("./utils.zig");
Expand Down Expand Up @@ -31,7 +32,7 @@ pub const AttestationData = struct {

pub fn sszRoot(self: *const AttestationData, allocator: Allocator) !Root {
var root: Root = undefined;
try ssz.hashTreeRoot(AttestationData, self.*, &root, allocator);
try zeam_utils.hashTreeRoot(AttestationData, self.*, &root, allocator);
return root;
}

Expand Down
9 changes: 5 additions & 4 deletions pkgs/types/src/block.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const ssz = @import("ssz");

const params = @import("@zeam/params");
const xmss = @import("@zeam/xmss");
const zeam_utils = @import("@zeam/utils");

const aggregation = @import("./aggregation.zig");
const attestation = @import("./attestation.zig");
Expand Down Expand Up @@ -154,7 +155,7 @@ pub const BeamBlock = struct {

pub fn blockToHeader(self: *const Self, allocator: Allocator) !BeamBlockHeader {
var body_root: [32]u8 = undefined;
try ssz.hashTreeRoot(
try zeam_utils.hashTreeRoot(
BeamBlockBody,
self.body,
&body_root,
Expand All @@ -172,7 +173,7 @@ pub const BeamBlock = struct {

pub fn blockToLatestBlockHeader(self: *const Self, allocator: Allocator, header: *BeamBlockHeader) !void {
var body_root: [32]u8 = undefined;
try ssz.hashTreeRoot(
try zeam_utils.hashTreeRoot(
BeamBlockBody,
self.body,
&body_root,
Expand Down Expand Up @@ -381,7 +382,7 @@ pub const AggregatedAttestationsResult = struct {
const data_root = group.data_root;
const epoch: u64 = group.data.slot;
var message_hash: [32]u8 = undefined;
try ssz.hashTreeRoot(attestation.AttestationData, group.data, &message_hash, allocator);
try zeam_utils.hashTreeRoot(attestation.AttestationData, group.data, &message_hash, allocator);

// Phase 1: Collect signatures from signatures_map
const max_validator = group.validator_bits.capacity();
Expand Down Expand Up @@ -744,7 +745,7 @@ test "ssz seralize/deserialize signed beam block" {
try std.testing.expect(std.mem.eql(u8, &signed_block.message.block.parent_root, &deserialized_signed_block.message.block.parent_root));

var block_root: [32]u8 = undefined;
try ssz.hashTreeRoot(BeamBlock, signed_block.message.block, &block_root, std.testing.allocator);
try zeam_utils.hashTreeRoot(BeamBlock, signed_block.message.block, &block_root, std.testing.allocator);
}

test "blockToLatestBlockHeader and blockToHeader" {
Expand Down
Loading