From 97ecfa33ee5cb94f7fb75a385ab6323385b0d46f Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Fri, 18 Oct 2024 22:26:50 +0800 Subject: [PATCH] feat:add genesis helper Signed-off-by: Chen Kai <281165273grape@gmail.com> --- src/consensus/helpers/genesis.zig | 434 ++++++++++++++++++++++++++++ src/consensus/helpers/validator.zig | 81 ++++++ src/consensus/types.zig | 87 ++++++ src/primitives/constants.zig | 1 + src/root.zig | 1 + src/ssz/ssz.zig | 6 +- 6 files changed, 607 insertions(+), 3 deletions(-) create mode 100644 src/consensus/helpers/genesis.zig diff --git a/src/consensus/helpers/genesis.zig b/src/consensus/helpers/genesis.zig new file mode 100644 index 0000000..eb91e67 --- /dev/null +++ b/src/consensus/helpers/genesis.zig @@ -0,0 +1,434 @@ +const std = @import("std"); +const primitives = @import("../../primitives/types.zig"); +const consensus = @import("../../consensus/types.zig"); +const configs = @import("../../configs/config.zig"); +const constants = @import("../../primitives/constants.zig"); +const preset = @import("../../presets/preset.zig"); +const phase0 = @import("../../consensus/phase0/types.zig"); +const altair = @import("../../consensus/altair/types.zig"); +const bellatrix = @import("../../consensus/bellatrix/types.zig"); +const capella = @import("../../consensus/capella/types.zig"); +const electra = @import("../../consensus/electra/types.zig"); +const deneb = @import("../../consensus/deneb/types.zig"); +const validator_helper = @import("../../consensus/helpers/validator.zig"); +const ssz = @import("../../ssz/ssz.zig"); + +pub fn isValidGenesisState(state: *const consensus.BeaconState, allocator: std.mem.Allocator) !bool { + if (state.genesisTime() < configs.ActiveConfig.get().MIN_GENESIS_TIME) { + return false; + } + const indices = try validator_helper.getActiveValidatorIndices(state, constants.GENESIS_EPOCH, allocator); + if (indices.len < configs.ActiveConfig.get().MIN_GENESIS_ACTIVE_VALIDATOR_COUNT) { + return false; + } + return true; +} + +pub fn initializeBeaconStateFromEth1( + fork_type: primitives.ForkType, + eth1_block_hash: primitives.Hash32, + eth1_timestamp: u64, + deposits: []const consensus.Deposit, + execution_payload_header: ?consensus.ExecutionPayloadHeader, + allocator: std.mem.Allocator, +) !consensus.BeaconState { + if (execution_payload_header == null) {} + const fork = switch (fork_type) { + .phase0 => consensus.Fork{ + .previous_version = configs.ActiveConfig.get().GENESIS_FORK_VERSION, + .current_version = configs.ActiveConfig.get().GENESIS_FORK_VERSION, + .epoch = constants.GENESIS_EPOCH, + }, + .altair => consensus.Fork{ + .previous_version = configs.ActiveConfig.get().ALTAIR_FORK_VERSION, + .current_version = configs.ActiveConfig.get().ALTAIR_FORK_VERSION, + .epoch = constants.GENESIS_EPOCH, + }, + .bellatrix => consensus.Fork{ + .previous_version = configs.ActiveConfig.get().BELLATRIX_FORK_VERSION, + .current_version = configs.ActiveConfig.get().BELLATRIX_FORK_VERSION, + .epoch = constants.GENESIS_EPOCH, + }, + .capella => consensus.Fork{ + .previous_version = configs.ActiveConfig.get().CAPELLA_FORK_VERSION, + .current_version = configs.ActiveConfig.get().CAPELLA_FORK_VERSION, + .epoch = constants.GENESIS_EPOCH, + }, + .deneb => consensus.Fork{ + .previous_version = configs.ActiveConfig.get().DENEB_FORK_VERSION, + .current_version = configs.ActiveConfig.get().DENEB_FORK_VERSION, + .epoch = constants.GENESIS_EPOCH, + }, + .electra => consensus.Fork{ + .previous_version = configs.ActiveConfig.get().ELECTRA_FORK_VERSION, + .current_version = configs.ActiveConfig.get().ELECTRA_FORK_VERSION, + .epoch = constants.GENESIS_EPOCH, + }, + }; + + const beacon_block_body = switch (fork_type) { + .phase0 => consensus.BeaconBlockBody{ + .phase0 = phase0.BeaconBlockBody{ + .randao_reveal = undefined, + .eth1_data = undefined, + .graffiti = undefined, + .proposer_slashings = undefined, + .attester_slashings = undefined, + .attestations = undefined, + .deposits = undefined, + .voluntary_exits = undefined, + }, + }, + .altair => consensus.BeaconBlockBody{ + .altair = altair.BeaconBlockBody{ + .randao_reveal = undefined, + .eth1_data = undefined, + .graffiti = undefined, + .proposer_slashings = undefined, + .attester_slashings = undefined, + .attestations = undefined, + .deposits = undefined, + .voluntary_exits = undefined, + .sync_aggregate = undefined, + }, + }, + .bellatrix => consensus.BeaconBlockBody{ + .bellatrix = bellatrix.BeaconBlockBody{ + .randao_reveal = undefined, + .eth1_data = undefined, + .graffiti = undefined, + .proposer_slashings = undefined, + .attester_slashings = undefined, + .attestations = undefined, + .deposits = undefined, + .voluntary_exits = undefined, + .sync_aggregate = undefined, + .execution_payload = undefined, + }, + }, + .capella => consensus.BeaconBlockBody{ + .capella = capella.BeaconBlockBody{ + .randao_reveal = undefined, + .eth1_data = undefined, + .graffiti = undefined, + .proposer_slashings = undefined, + .attester_slashings = undefined, + .attestations = undefined, + .deposits = undefined, + .voluntary_exits = undefined, + .sync_aggregate = undefined, + .execution_payload = undefined, + .bls_to_execution_changes = undefined, + }, + }, + .deneb, .electra => consensus.BeaconBlockBody{ + .deneb = deneb.BeaconBlockBody{ + .randao_reveal = undefined, + .eth1_data = undefined, + .graffiti = undefined, + .proposer_slashings = undefined, + .attester_slashings = undefined, + .attestations = undefined, + .deposits = undefined, + .voluntary_exits = undefined, + .sync_aggregate = undefined, + .execution_payload = undefined, + .bls_to_execution_changes = undefined, + .blob_kzg_commitments = undefined, + }, + }, + }; + + var body_root: primitives.Root = undefined; + try ssz.hashTreeRoot(beacon_block_body, &body_root, allocator); + + var randao_mixes = try std.ArrayList(primitives.Bytes32).initCapacity(allocator, preset.ActivePreset.get().EPOCHS_PER_HISTORICAL_VECTOR); + defer randao_mixes.deinit(); + for (0..preset.ActivePreset.get().EPOCHS_PER_HISTORICAL_VECTOR) |_| { + try randao_mixes.append(eth1_block_hash); + } + const randao_mixes_slice = try randao_mixes.toOwnedSlice(); + const state = switch (fork_type) { + .phase0 => consensus.BeaconState{ + .phase0 = phase0.BeaconState{ + .genesis_time = eth1_timestamp + configs.ActiveConfig.get().GENESIS_DELAY, + .fork = fork, + .eth1_data = consensus.Eth1Data{ + .block_hash = eth1_block_hash, + .deposit_count = @as(u64, deposits.len), + .deposit_root = undefined, + }, + .latest_block_header = consensus.BeaconBlockHeader{ + .body_root = body_root, + .parent_root = undefined, + .state_root = undefined, + .proposer_index = 0, + .slot = 0, + }, + .randao_mixes = randao_mixes_slice, + .genesis_validators_root = undefined, + .slot = 0, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = undefined, + .validators = undefined, + .balances = undefined, + .slashings = undefined, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = undefined, + }, + }, + .altair => consensus.BeaconState{ + .altair = altair.BeaconState{ + .genesis_time = eth1_timestamp + configs.ActiveConfig.get().GENESIS_DELAY, + .fork = fork, + .eth1_data = consensus.Eth1Data{ + .block_hash = eth1_block_hash, + .deposit_count = @as(u64, deposits.len), + .deposit_root = undefined, + }, + .latest_block_header = consensus.BeaconBlockHeader{ + .body_root = body_root, + .parent_root = undefined, + .state_root = undefined, + .proposer_index = 0, + .slot = 0, + }, + .randao_mixes = randao_mixes_slice, + .genesis_validators_root = undefined, + .slot = 0, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = undefined, + .validators = undefined, + .balances = undefined, + .slashings = undefined, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = undefined, + .inactivity_scores = undefined, + .current_sync_committee = undefined, + .next_sync_committee = undefined, + }, + }, + .bellatrix => consensus.BeaconState{ + .bellatrix = bellatrix.BeaconState{ + .genesis_time = eth1_timestamp + configs.ActiveConfig.get().GENESIS_DELAY, + .fork = fork, + .eth1_data = consensus.Eth1Data{ + .block_hash = eth1_block_hash, + .deposit_count = @as(u64, deposits.len), + .deposit_root = undefined, + }, + .latest_block_header = consensus.BeaconBlockHeader{ + .body_root = body_root, + .parent_root = undefined, + .state_root = undefined, + .proposer_index = 0, + .slot = 0, + }, + .randao_mixes = randao_mixes_slice, + .genesis_validators_root = undefined, + .slot = 0, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = undefined, + .validators = undefined, + .balances = undefined, + .slashings = undefined, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = undefined, + .inactivity_scores = undefined, + .current_sync_committee = undefined, + .next_sync_committee = undefined, + .latest_execution_payload_header = undefined, + }, + }, + .capella => consensus.BeaconState{ + .capella = capella.BeaconState{ + .genesis_time = eth1_timestamp + configs.ActiveConfig.get().GENESIS_DELAY, + .fork = fork, + .eth1_data = consensus.Eth1Data{ + .block_hash = eth1_block_hash, + .deposit_count = @as(u64, deposits.len), + .deposit_root = undefined, + }, + .latest_block_header = consensus.BeaconBlockHeader{ + .body_root = body_root, + .parent_root = undefined, + .state_root = undefined, + .proposer_index = 0, + .slot = 0, + }, + .randao_mixes = randao_mixes_slice, + .genesis_validators_root = undefined, + .slot = 0, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = undefined, + .validators = undefined, + .balances = undefined, + .slashings = undefined, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = undefined, + .inactivity_scores = undefined, + .current_sync_committee = undefined, + .next_sync_committee = undefined, + .latest_execution_payload_header = undefined, + .historical_summaries = undefined, + }, + }, + .deneb => consensus.BeaconState{ + .deneb = capella.BeaconState{ + .genesis_time = eth1_timestamp + configs.ActiveConfig.get().GENESIS_DELAY, + .fork = fork, + .eth1_data = consensus.Eth1Data{ + .block_hash = eth1_block_hash, + .deposit_count = @as(u64, deposits.len), + .deposit_root = undefined, + }, + .latest_block_header = consensus.BeaconBlockHeader{ + .body_root = body_root, + .parent_root = undefined, + .state_root = undefined, + .proposer_index = 0, + .slot = 0, + }, + .randao_mixes = randao_mixes_slice, + .genesis_validators_root = undefined, + .slot = 0, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = undefined, + .validators = undefined, + .balances = undefined, + .slashings = undefined, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = undefined, + .inactivity_scores = undefined, + .current_sync_committee = undefined, + .next_sync_committee = undefined, + .latest_execution_payload_header = undefined, + .historical_summaries = undefined, + }, + }, + .electra => consensus.BeaconState{ + .electra = electra.BeaconState{ + .genesis_time = eth1_timestamp + configs.ActiveConfig.get().GENESIS_DELAY, + .fork = fork, + .eth1_data = consensus.Eth1Data{ + .block_hash = eth1_block_hash, + .deposit_count = @as(u64, deposits.len), + .deposit_root = undefined, + }, + .latest_block_header = consensus.BeaconBlockHeader{ + .body_root = body_root, + .parent_root = undefined, + .state_root = undefined, + .proposer_index = 0, + .slot = 0, + }, + .randao_mixes = randao_mixes_slice, + .genesis_validators_root = undefined, + .slot = 0, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = undefined, + .validators = undefined, + .balances = undefined, + .slashings = undefined, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = undefined, + .inactivity_scores = undefined, + .current_sync_committee = undefined, + .next_sync_committee = undefined, + .latest_execution_payload_header = undefined, + .historical_summaries = undefined, + .pending_balance_deposits = undefined, + .pending_partial_withdrawals = undefined, + .pending_consolidations = undefined, + .deposit_requests_start_index = constants.UNSET_DEPOSIT_REQUESTS_START_INDEX, + }, + }, + }; + + // + // // Process deposits + // var leaves = try std.ArrayList(DepositData).initCapacity(std.heap.page_allocator, deposits.len); + // defer leaves.deinit(); + // + // for (deposits, 0..) |deposit, index| { + // try leaves.append(deposit.data); + // var deposit_data_list = try std.ArrayList(DepositData).initCapacity(std.heap.page_allocator, DEPOSIT_CONTRACT_TREE_DEPTH); + // defer deposit_data_list.deinit(); + // try deposit_data_list.appendSlice(leaves.items[0..index + 1]); + // state.eth1_data.deposit_root = try hash_tree_root(deposit_data_list.items); + // try process_deposit(&state, deposit); + // } + // + // // Process deposit balance updates + // for (state.pending_balance_deposits) |deposit| { + // try increase_balance(&state, deposit.index, deposit.amount); + // } + // state.pending_balance_deposits.clearRetainingCapacity(); + // + // // Process activations + // for (state.validators) |*validator, index| { + // const balance = state.balances[index]; + // validator.effective_balance = @min( + // balance - balance % EFFECTIVE_BALANCE_INCREMENT, + // try get_max_effective_balance(validator), + // ); + // if (validator.effective_balance >= MIN_ACTIVATION_BALANCE) { + // validator.activation_eligibility_epoch = GENESIS_EPOCH; + // validator.activation_epoch = GENESIS_EPOCH; + // } + // } + // + // // Set genesis validators root for domain separation and chain versioning + // state.genesis_validators_root = try hash_tree_root(state.validators); + // + // // Fill in sync committees + // state.current_sync_committee = try get_next_sync_committee(&state); + // state.next_sync_committee = try get_next_sync_committee(&state); + // + // // Initialize the execution payload header + // state.latest_execution_payload_header = execution_payload_header; + + return state; +} diff --git a/src/consensus/helpers/validator.zig b/src/consensus/helpers/validator.zig index 6d63b3e..8eb55d6 100644 --- a/src/consensus/helpers/validator.zig +++ b/src/consensus/helpers/validator.zig @@ -832,3 +832,84 @@ test "test computeProposerIndex" { const proposer_index = try computeProposerIndex(&state, &validator_index, .{1} ** 32); try std.testing.expectEqual(0, proposer_index); } + +test "test slashValidator" { + preset.ActivePreset.set(preset.Presets.minimal); + defer preset.ActivePreset.reset(); + const finalized_checkpoint = consensus.Checkpoint{ + .epoch = 5, + .root = .{0} ** 32, + }; + + var validators = std.ArrayList(consensus.Validator).init(std.testing.allocator); + defer validators.deinit(); + + const validator1 = consensus.Validator{ + .pubkey = undefined, + .withdrawal_credentials = undefined, + .effective_balance = 100000000000, + .slashed = false, + .activation_eligibility_epoch = 0, + .activation_epoch = 0, + .exit_epoch = 10, + .withdrawable_epoch = 10, + }; + + const validator2 = consensus.Validator{ + .pubkey = undefined, + .withdrawal_credentials = undefined, + .effective_balance = 100000000000, + .slashed = false, + .activation_eligibility_epoch = 0, + .activation_epoch = 0, + .exit_epoch = 20, + .withdrawable_epoch = 20, + }; + try validators.append(validator1); + try validators.append(validator2); + + var slashings = [_]primitives.Gwei{1000000000000000} ** 4; + var balances = [_]primitives.Gwei{10000000000000000000} ** 4; + + var randao_mixes = try std.ArrayList(primitives.Bytes32).initCapacity(std.testing.allocator, preset.ActivePreset.get().EPOCHS_PER_HISTORICAL_VECTOR); + defer randao_mixes.deinit(); + for (0..preset.ActivePreset.get().EPOCHS_PER_HISTORICAL_VECTOR) |slot_index| { + try randao_mixes.append(.{@as(u8, @intCast(slot_index))} ** 32); + } + var state = consensus.BeaconState{ + .altair = altair.BeaconState{ + .genesis_time = 0, + .genesis_validators_root = .{0} ** 32, + .slot = 0, + .fork = undefined, + .block_roots = undefined, + .state_roots = undefined, + .historical_roots = undefined, + .eth1_data = undefined, + .eth1_data_votes = undefined, + .eth1_deposit_index = 0, + .validators = validators.items, + .balances = &balances, + .randao_mixes = randao_mixes.items, + .slashings = &slashings, + .previous_epoch_attestations = undefined, + .current_epoch_attestations = undefined, + .justification_bits = undefined, + .previous_justified_checkpoint = undefined, + .current_justified_checkpoint = undefined, + .finalized_checkpoint = finalized_checkpoint, + .latest_block_header = undefined, + .inactivity_scores = undefined, + .current_sync_committee = undefined, + .next_sync_committee = undefined, + }, + }; + + try slashValidator(&state, 0, 1, std.testing.allocator); + try std.testing.expectEqual(true, state.altair.validators[0].slashed); + try std.testing.expectEqual(false, state.altair.validators[1].slashed); + try std.testing.expectEqual(64, state.altair.validators[0].withdrawable_epoch); + try std.testing.expectEqual(20, state.altair.validators[1].withdrawable_epoch); + try std.testing.expectEqual(10, state.altair.validators[0].exit_epoch); + try std.testing.expectEqual(20, state.altair.validators[1].exit_epoch); +} diff --git a/src/consensus/types.zig b/src/consensus/types.zig index f72979d..4ebbfb2 100644 --- a/src/consensus/types.zig +++ b/src/consensus/types.zig @@ -265,6 +265,87 @@ pub const ExecutionPayloadHeader = union(primitives.ForkType) { capella: capella.ExecutionPayloadHeader, deneb: deneb.ExecutionPayloadHeader, electra: electra.ExecutionPayloadHeader, + + pub fn default(fork_type: primitives.ForkType) ExecutionPayloadHeader { + return switch (fork_type) { + primitives.ForkType.phase0 => .{ .phase0 = NonExistType{} }, + primitives.ForkType.altair => .{ .altair = NonExistType{} }, + primitives.ForkType.bellatrix => .{ .bellatrix = bellatrix.ExecutionPayloadHeader{ + .parent_hash = undefined, + .fee_recipient = undefined, + .state_root = undefined, + .receipts_root = undefined, + .logs_bloom = undefined, + .prev_randao = undefined, + .block_number = 0, + .gas_used = 0, + .gas_limit = 0, + .timestamp = 0, + .extra_data = undefined, + .base_fee_per_gas = 0, + .block_hash = undefined, + .transactions_root = undefined, + } }, + primitives.ForkType.capella => .{ .capella = capella.ExecutionPayloadHeader{ + .parent_hash = undefined, + .fee_recipient = undefined, + .state_root = undefined, + .receipts_root = undefined, + .logs_bloom = undefined, + .prev_randao = undefined, + .block_number = 0, + .gas_used = 0, + .gas_limit = 0, + .timestamp = 0, + .extra_data = undefined, + .base_fee_per_gas = 0, + .block_hash = undefined, + .transactions_root = undefined, + .withdrawals_root = undefined, + } }, + primitives.ForkType.deneb => .{ .deneb = deneb.ExecutionPayloadHeader{ + .parent_hash = undefined, + .fee_recipient = undefined, + .state_root = undefined, + .receipts_root = undefined, + .logs_bloom = undefined, + .prev_randao = undefined, + .block_number = 0, + .gas_used = 0, + .gas_limit = 0, + .timestamp = 0, + .extra_data = undefined, + .base_fee_per_gas = 0, + .block_hash = undefined, + .transactions_root = undefined, + .withdrawals_root = undefined, + .blob_gas_used = 0, + .excess_blob_gas = 0, + } }, + primitives.ForkType.electra => .{ .electra = electra.ExecutionPayloadHeader{ + .parent_hash = undefined, + .fee_recipient = undefined, + .state_root = undefined, + .receipts_root = undefined, + .logs_bloom = undefined, + .prev_randao = undefined, + .block_number = 0, + .gas_used = 0, + .gas_limit = 0, + .timestamp = 0, + .extra_data = undefined, + .base_fee_per_gas = 0, + .block_hash = undefined, + .transactions_root = undefined, + .withdrawals_root = undefined, + .blob_gas_used = 0, + .excess_blob_gas = 0, + .deposit_requests_root = undefined, + .withdrawal_requests_root = undefined, + .consolidation_requests_root = undefined, + } }, + }; + } }; pub const ExecutionPayload = union(primitives.ForkType) { @@ -446,6 +527,12 @@ pub const BeaconState = union(primitives.ForkType) { deneb: capella.BeaconState, electra: electra.BeaconState, + pub fn genesisTime(self: *const BeaconState) u64 { + return switch (self.*) { + inline else => |state| state.genesis_time, + }; + } + pub fn slashings(self: *const BeaconState) []primitives.Gwei { return switch (self.*) { inline else => |state| state.slashings, diff --git a/src/primitives/constants.zig b/src/primitives/constants.zig index 3cac36f..1a00900 100644 --- a/src/primitives/constants.zig +++ b/src/primitives/constants.zig @@ -41,3 +41,4 @@ pub const MAX_BLOBS_PER_BLOCK: usize = 6; pub const PROPOSER_WEIGHT: u64 = 8; pub const WEIGHT_DENOMINATOR: u64 = 64; +pub const UNSET_DEPOSIT_REQUESTS_START_INDEX: u64 = std.math.maxInt(u64); diff --git a/src/root.zig b/src/root.zig index 52ece1a..8965fe3 100644 --- a/src/root.zig +++ b/src/root.zig @@ -24,6 +24,7 @@ pub const balance_helper = @import("consensus/helpers/balance.zig"); pub const ssz = @import("./ssz/ssz.zig"); pub const snappy = @import("./snappy/snappy.zig"); pub const merkle = @import("consensus/helpers/merkle.zig"); +pub const genesis_helper = @import("consensus/helpers/genesis.zig"); test { @import("std").testing.refAllDeclsRecursive(@This()); diff --git a/src/ssz/ssz.zig b/src/ssz/ssz.zig index cffbe7f..bd895cf 100644 --- a/src/ssz/ssz.zig +++ b/src/ssz/ssz.zig @@ -981,15 +981,15 @@ pub fn hashTreeRoot(value: anytype, out: *[32]u8, allocator: Allocator) !void { } }, .pointer => { - switch (type_info.Pointer.size) { + switch (type_info.pointer.size) { .One => hashTreeRoot(value.*, out, allocator), .Slice => { - switch (@typeInfo(type_info.Pointer.child)) { + switch (@typeInfo(type_info.pointer.child)) { .int => { var list = ArrayList(u8).init(allocator); defer list.deinit(); const chunks = try pack(value, &list); - merkleize(chunks, null, out); + try merkleize(chunks, null, out); }, else => return error.UnSupportedPointerType, }