diff --git a/src/consensus/altair/types.zig b/src/consensus/altair/types.zig index bdf5aba..421bf4c 100644 --- a/src/consensus/altair/types.zig +++ b/src/consensus/altair/types.zig @@ -2,6 +2,7 @@ const std = @import("std"); const primitives = @import("../../primitives/types.zig"); const preset = @import("../../presets/preset.zig"); const consensus = @import("../../consensus/types.zig"); +const phase0 = @import("../../consensus/phase0/types.zig"); pub const LightClientHeader = struct { beacon: ?*consensus.BeaconBlockHeader, @@ -78,45 +79,57 @@ pub const SignedContributionAndProof = struct { signature: primitives.BLSSignature, }; -pub const BeaconBlockBody = struct { - randao_reveal: primitives.BLSSignature, - eth1_data: *consensus.Eth1Data, // Eth1 data vote - graffiti: primitives.Bytes32, // Arbitrary data - // Operations - proposer_slashings: []consensus.ProposerSlashing, - attester_slashings: []consensus.AttesterSlashing, - attestations: []consensus.Attestation, - deposits: []consensus.Deposit, - voluntary_exits: []consensus.SignedVoluntaryExit, - sync_aggregate: ?*consensus.SyncAggregate, -}; - -pub const BeaconState = struct { - genesis_time: u64, - genesis_validators_root: primitives.Root, - slot: primitives.Slot, - fork: *consensus.Fork, - latest_block_header: consensus.BeaconBlockHeader, - block_roots: []primitives.Root, - state_roots: []primitives.Root, - historical_roots: []primitives.Root, - eth1_data: ?*consensus.Eth1Data, - eth1_data_votes: []consensus.Eth1Data, - eth1_deposit_index: u64, - validators: []consensus.Validator, - balances: []primitives.Gwei, - randao_mixes: []primitives.Bytes32, - slashings: []primitives.Gwei, - previous_epoch_attestations: []consensus.PendingAttestation, - current_epoch_attestations: []consensus.PendingAttestation, - justification_bits: []bool, - previous_justified_checkpoint: *consensus.Checkpoint, - current_justified_checkpoint: *consensus.Checkpoint, - finalized_checkpoint: *consensus.Checkpoint, - inactivity_scores: []u64, - current_sync_committee: ?*consensus.SyncCommittee, - next_sync_committee: ?*consensus.SyncCommittee, -}; +pub const BeaconBlockBody = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(phase0.BeaconBlockBody).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "sync_aggregate", + .type = ?*consensus.SyncAggregate, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(?*consensus.SyncAggregate), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); + +pub const BeaconState = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(phase0.BeaconState).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "inactivity_scores", + .type = []u64, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]u64), + }, + .{ + .name = "current_sync_committee", + .type = ?*consensus.SyncCommittee, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(?*consensus.SyncCommittee), + }, + .{ + .name = "next_sync_committee", + .type = ?*consensus.SyncCommittee, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(?*consensus.SyncCommittee), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); test "test BeaconState" { const state = BeaconState{ diff --git a/src/consensus/bellatrix/types.zig b/src/consensus/bellatrix/types.zig index 49f828d..f06ff3b 100644 --- a/src/consensus/bellatrix/types.zig +++ b/src/consensus/bellatrix/types.zig @@ -2,6 +2,7 @@ const std = @import("std"); pub const primitives = @import("../../primitives/types.zig"); const preset = @import("../../presets/preset.zig"); const consensus = @import("../../consensus/types.zig"); +const altair = @import("../../consensus/altair/types.zig"); pub const PowBlock = struct { block_hash: primitives.Hash32, @@ -46,47 +47,43 @@ pub const ExecutionPayload = struct { transactions: []primitives.Transaction, // with a maximum length of MAX_TRANSACTIONS_PER_PAYLOAD }; -pub const BeaconBlockBody = struct { - randao_reveal: primitives.BLSSignature, - eth1_data: *consensus.Eth1Data, // Eth1 data vote - graffiti: primitives.Bytes32, // Arbitrary data - // Operations - proposer_slashings: []consensus.ProposerSlashing, - attester_slashings: []consensus.AttesterSlashing, - attestations: []consensus.Attestation, - deposits: []consensus.Deposit, - voluntary_exits: []consensus.SignedVoluntaryExit, - sync_aggregate: ?*consensus.SyncAggregate, - execution_payload: ?*consensus.ExecutionPayload, -}; +pub const BeaconBlockBody = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(altair.BeaconBlockBody).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "execution_payload", + .type = ?*consensus.ExecutionPayload, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(?*consensus.ExecutionPayload), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); -pub const BeaconState = struct { - genesis_time: u64, - genesis_validators_root: primitives.Root, - slot: primitives.Slot, - fork: *consensus.Fork, - latest_block_header: consensus.BeaconBlockHeader, - block_roots: []primitives.Root, - state_roots: []primitives.Root, - historical_roots: []primitives.Root, - eth1_data: ?*consensus.Eth1Data, - eth1_data_votes: []consensus.Eth1Data, - eth1_deposit_index: u64, - validators: []consensus.Validator, - balances: []primitives.Gwei, - randao_mixes: []primitives.Bytes32, - slashings: []primitives.Gwei, - previous_epoch_attestations: []consensus.PendingAttestation, - current_epoch_attestations: []consensus.PendingAttestation, - justification_bits: []bool, - previous_justified_checkpoint: *consensus.Checkpoint, - current_justified_checkpoint: *consensus.Checkpoint, - finalized_checkpoint: *consensus.Checkpoint, - inactivity_scores: []u64, - current_sync_committee: ?*consensus.SyncCommittee, - next_sync_committee: ?*consensus.SyncCommittee, - latest_execution_payload_header: ?*consensus.ExecutionPayloadHeader, -}; +pub const BeaconState = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(altair.BeaconState).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "latest_execution_payload_header", + .type = ?*consensus.ExecutionPayloadHeader, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(?*consensus.ExecutionPayloadHeader), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); test "test ExecutionPayloadHeader" { const header = ExecutionPayloadHeader{ diff --git a/src/consensus/capella/types.zig b/src/consensus/capella/types.zig index fdba0e5..5370215 100644 --- a/src/consensus/capella/types.zig +++ b/src/consensus/capella/types.zig @@ -2,6 +2,8 @@ const std = @import("std"); pub const primitives = @import("../../primitives/types.zig"); const preset = @import("../../presets/preset.zig"); const consensus = @import("../../consensus/types.zig"); +const bellatrix = @import("../../consensus/bellatrix/types.zig"); +const altair = @import("../../consensus/altair/types.zig"); pub const HistoricalSummary = struct { // HistoricalSummary matches the components of the phase0 HistoricalBatch @@ -10,11 +12,31 @@ pub const HistoricalSummary = struct { state_summary_root: primitives.Root, }; -pub const LightClientHeader = struct { - beacon: ?*consensus.BeaconBlockHeader, - execution: ?*consensus.ExecutionPayloadHeader, - execution_branch: primitives.ExecutionBranch, -}; +pub const LightClientHeader = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(altair.LightClientHeader).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "execution", + .type = ?*consensus.ExecutionPayloadHeader, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(?*consensus.ExecutionPayloadHeader), + }, + .{ + .name = "execution_branch", + .type = primitives.ExecutionBranch, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(primitives.ExecutionBranch), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); pub const Withdrawal = struct { index: primitives.WithdrawalIndex, @@ -34,90 +56,91 @@ pub const SignedBLSToExecutionChange = struct { signature: primitives.BLSSignature, }; -pub const ExecutionPayloadHeader = struct { - parent_hash: primitives.Hash32, - fee_recipient: primitives.ExecutionAddress, - state_root: primitives.Root, - receipts_root: primitives.Root, - logs_bloom: []u8, - prev_randao: primitives.Bytes32, - block_number: u64, - gas_used: u64, - gas_limit: u64, - timestamp: u64, - extra_data: []u8, - base_fee_per_gas: u256, - // Extra payload fields - block_hash: primitives.Hash32, - transactions_root: primitives.Root, - withdrawals_root: primitives.Root, -}; +pub const ExecutionPayloadHeader = @Type(.{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(bellatrix.ExecutionPayloadHeader).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "withdrawals_root", + .type = primitives.Root, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(primitives.Root), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, +}); -pub const ExecutionPayload = struct { - // Execution block header fields - parent_hash: primitives.Hash32, - fee_recipient: primitives.ExecutionAddress, // 'beneficiary' in the yellow paper - state_root: primitives.Bytes32, - receipts_root: primitives.Bytes32, - logs_bloom: []u8, - prev_randao: primitives.Bytes32, // 'difficulty' in the yellow paper - block_number: u64, // 'number' in the yellow paper - gas_limit: u64, - gas_used: u64, - timestamp: u64, - extra_data: []u8, // with a maximum length of MAX_EXTRA_DATA_BYTES - base_fee_per_gas: u256, - // Extra payload fields - block_hash: primitives.Hash32, // Hash of execution block - transactions: []primitives.Transaction, // with a maximum length of MAX_TRANSACTIONS_PER_PAYLOAD - withdrawals: []consensus.Withdrawal, // with a maximum length of MAX_WITHDRAWALS_PER_PAYLOAD -}; +pub const ExecutionPayload = @Type(.{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(bellatrix.ExecutionPayload).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "withdrawals", + .type = []consensus.Withdrawal, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.Withdrawal), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, +}); -pub const BeaconBlockBody = struct { - randao_reveal: primitives.BLSSignature, - eth1_data: *consensus.Eth1Data, // Eth1 data vote - graffiti: primitives.Bytes32, // Arbitrary data - // Operations - proposer_slashings: []consensus.ProposerSlashing, - attester_slashings: []consensus.AttesterSlashing, - attestations: []consensus.Attestation, - deposits: []consensus.Deposit, - voluntary_exits: []consensus.SignedVoluntaryExit, - sync_aggregate: ?*consensus.SyncAggregate, - execution_payload: ?*consensus.ExecutionPayload, - bls_to_execution_changes: []consensus.SignedBLSToExecutionChange, -}; +pub const BeaconBlockBody = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(bellatrix.BeaconBlockBody).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "bls_to_execution_changes", + .type = []consensus.SignedBLSToExecutionChange, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.SignedBLSToExecutionChange), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); -pub const BeaconState = struct { - genesis_time: u64, - genesis_validators_root: primitives.Root, - slot: primitives.Slot, - fork: *consensus.Fork, - latest_block_header: consensus.BeaconBlockHeader, - block_roots: []primitives.Root, - state_roots: []primitives.Root, - historical_roots: []primitives.Root, - eth1_data: ?*consensus.Eth1Data, - eth1_data_votes: []consensus.Eth1Data, - eth1_deposit_index: u64, - validators: []consensus.Validator, - balances: []primitives.Gwei, - randao_mixes: []primitives.Bytes32, - slashings: []primitives.Gwei, - previous_epoch_attestations: []consensus.PendingAttestation, - current_epoch_attestations: []consensus.PendingAttestation, - justification_bits: []bool, - previous_justified_checkpoint: *consensus.Checkpoint, - current_justified_checkpoint: *consensus.Checkpoint, - finalized_checkpoint: *consensus.Checkpoint, - inactivity_scores: []u64, - current_sync_committee: ?*consensus.SyncCommittee, - next_sync_committee: ?*consensus.SyncCommittee, - latest_execution_payload_header: ?*consensus.ExecutionPayloadHeader, - next_withdrawal_index: primitives.WithdrawalIndex, - next_withdrawal_validator_index: primitives.ValidatorIndex, - historical_summaries: []consensus.HistoricalSummary, -}; +pub const BeaconState = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(bellatrix.BeaconState).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "next_withdrawal_index", + .type = primitives.WithdrawalIndex, + .default_value = @ptrCast(&@as(primitives.WithdrawalIndex, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.WithdrawalIndex), + }, + .{ + .name = "next_withdrawal_validator_index", + .type = primitives.ValidatorIndex, + .default_value = @ptrCast(&@as(primitives.ValidatorIndex, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.ValidatorIndex), + }, + .{ + .name = "historical_summaries", + .type = []consensus.HistoricalSummary, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.HistoricalSummary), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); test "test ExecutionPayloadHeader" { const header = ExecutionPayloadHeader{ diff --git a/src/consensus/deneb/types.zig b/src/consensus/deneb/types.zig index c9e2701..d632c76 100644 --- a/src/consensus/deneb/types.zig +++ b/src/consensus/deneb/types.zig @@ -2,6 +2,7 @@ const std = @import("std"); pub const primitives = @import("../../primitives/types.zig"); const preset = @import("../../presets/preset.zig"); const consensus = @import("../../consensus/types.zig"); +const capella = @import("../../consensus/capella/types.zig"); pub const BlobIdentifier = struct { block_root: primitives.Root, @@ -17,64 +18,76 @@ pub const BlobSidecar = struct { kzg_commitment_inclusion_proof: []primitives.Bytes32, }; -pub const ExecutionPayloadHeader = struct { - parent_hash: primitives.Hash32, - fee_recipient: primitives.ExecutionAddress, - state_root: primitives.Root, - receipts_root: primitives.Root, - logs_bloom: []u8, - prev_randao: primitives.Bytes32, - block_number: u64, - gas_used: u64, - gas_limit: u64, - timestamp: u64, - extra_data: []u8, - base_fee_per_gas: u256, - // Extra payload fields - block_hash: primitives.Hash32, - transactions_root: primitives.Root, - withdrawals_root: primitives.Root, - blob_gas_used: u64, - excess_blob_gas: u64, -}; +pub const ExecutionPayload = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(capella.ExecutionPayload).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "blob_gas_used", + .type = u64, + .default_value = @ptrCast(&@as(u64, 0)), + .is_comptime = false, + .alignment = @alignOf(u64), + }, + .{ + .name = "excess_blob_gas", + .type = u64, + .default_value = @ptrCast(&@as(u64, 0)), + .is_comptime = false, + .alignment = @alignOf(u64), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); -pub const ExecutionPayload = struct { - // Execution block header fields - parent_hash: primitives.Hash32, - fee_recipient: primitives.ExecutionAddress, // 'beneficiary' in the yellow paper - state_root: primitives.Bytes32, - receipts_root: primitives.Bytes32, - logs_bloom: []u8, - prev_randao: primitives.Bytes32, // 'difficulty' in the yellow paper - block_number: u64, // 'number' in the yellow paper - gas_limit: u64, - gas_used: u64, - timestamp: u64, - extra_data: []u8, // with a maximum length of MAX_EXTRA_DATA_BYTES - base_fee_per_gas: u256, - // Extra payload fields - block_hash: primitives.Hash32, // Hash of execution block - transactions: []primitives.Transaction, // with a maximum length of MAX_TRANSACTIONS_PER_PAYLOAD - withdrawals: []consensus.Withdrawal, // with a maximum length of MAX_WITHDRAWALS_PER_PAYLOAD - blob_gas_used: u64, - excess_blob_gas: u64, -}; +pub const ExecutionPayloadHeader = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(capella.ExecutionPayloadHeader).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "blob_gas_used", + .type = u64, + .default_value = @ptrCast(&@as(u64, 0)), + .is_comptime = false, + .alignment = @alignOf(u64), + }, + .{ + .name = "excess_blob_gas", + .type = u64, + .default_value = @ptrCast(&@as(u64, 0)), + .is_comptime = false, + .alignment = @alignOf(u64), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); -pub const BeaconBlockBody = struct { - randao_reveal: primitives.BLSSignature, - eth1_data: *consensus.Eth1Data, // Eth1 data vote - graffiti: primitives.Bytes32, // Arbitrary data - // Operations - proposer_slashings: []consensus.ProposerSlashing, - attester_slashings: []consensus.AttesterSlashing, - attestations: []consensus.Attestation, - deposits: []consensus.Deposit, - voluntary_exits: []consensus.SignedVoluntaryExit, - sync_aggregate: ?*consensus.SyncAggregate, - execution_payload: ?*consensus.ExecutionPayload, - bls_to_execution_changes: []consensus.SignedBLSToExecutionChange, - blob_kzg_commitments: []primitives.KZGCommitment, -}; +pub const BeaconBlockBody = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(capella.BeaconBlockBody).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "blob_kzg_commitments", + .type = []primitives.KZGCommitment, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]primitives.KZGCommitment), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); test "test ExecutionPayloadHeader" { const header = ExecutionPayloadHeader{ diff --git a/src/consensus/electra/types.zig b/src/consensus/electra/types.zig index 03cf024..e1eb3a7 100644 --- a/src/consensus/electra/types.zig +++ b/src/consensus/electra/types.zig @@ -2,6 +2,9 @@ const std = @import("std"); pub const primitives = @import("../../primitives/types.zig"); const preset = @import("../../presets/preset.zig"); const consensus = @import("../../consensus/types.zig"); +const phase0 = @import("../../consensus/phase0/types.zig"); +const deneb = @import("../../consensus/deneb/types.zig"); +const capella = @import("../../consensus/capella/types.zig"); pub const PendingConsolidation = struct { source_index: primitives.ValidatorIndex, @@ -39,63 +42,90 @@ pub const ConsolidationRequest = struct { target_pubkey: primitives.BLSPubkey, }; -pub const Attestation = struct { - aggregation_bits: []bool, // # [Modified in Electra:EIP7549] - data: ?*consensus.AttestationData, - signature: primitives.BLSSignature, - committee_bits: []bool, // # [New in Electra:EIP7549] -}; +pub const Attestation = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(phase0.Attestation).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "committee_bits", // # [New in Electra:EIP7549] + .type = []bool, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]bool), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); -pub const ExecutionPayload = struct { - // Execution block header fields - parent_hash: primitives.Hash32, - fee_recipient: primitives.ExecutionAddress, // 'beneficiary' in the yellow paper - state_root: primitives.Bytes32, - receipts_root: primitives.Bytes32, - logs_bloom: []u8, - prev_randao: primitives.Bytes32, // 'difficulty' in the yellow paper - block_number: u64, // 'number' in the yellow paper - gas_limit: u64, - gas_used: u64, - timestamp: u64, - extra_data: []u8, // with a maximum length of MAX_EXTRA_DATA_BYTES - base_fee_per_gas: u256, - // Extra payload fields - block_hash: primitives.Hash32, // Hash of execution block - transactions: []primitives.Transaction, // with a maximum length of MAX_TRANSACTIONS_PER_PAYLOAD - withdrawals: []consensus.Withdrawal, // with a maximum length of MAX_WITHDRAWALS_PER_PAYLOAD - blob_gas_used: u64, - excess_blob_gas: u64, - deposit_requests: []consensus.DepositRequest, // with a maximum length of MAX_DEPOSIT_REQUESTS_PER_PAYLOAD - // # [New in Electra:EIP7002:EIP7251] - withdrawal_requests: []consensus.WithdrawalRequest, // with a maximum length of MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD - // # [New in Electra:EIP7002:EIP7251] - consolidation_requests: []consensus.ConsolidationRequest, // with a maximum length of MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD -}; +pub const ExecutionPayload = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(deneb.ExecutionPayload).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "deposit_requests", // # [New in Electra:EIP7002:EIP7251] + .type = []consensus.DepositRequest, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.DepositRequest), + }, + .{ + .name = "withdrawal_requests", // # [New in Electra:EIP7002:EIP7251] + .type = []consensus.WithdrawalRequest, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.WithdrawalRequest), + }, + .{ + .name = "consolidation_requests", // # [New in Electra:EIP7002:EIP7251] + .type = []consensus.ConsolidationRequest, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.ConsolidationRequest), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); -pub const ExecutionPayloadHeader = struct { - parent_hash: primitives.Hash32, - fee_recipient: primitives.ExecutionAddress, - state_root: primitives.Root, - receipts_root: primitives.Root, - logs_bloom: []u8, - prev_randao: primitives.Bytes32, - block_number: u64, - gas_used: u64, - gas_limit: u64, - timestamp: u64, - extra_data: []u8, - base_fee_per_gas: u256, - // Extra payload fields - block_hash: primitives.Hash32, - transactions_root: primitives.Root, - withdrawals_root: primitives.Root, - blob_gas_used: u64, - excess_blob_gas: u64, - deposit_requests_root: primitives.Root, - withdrawal_requests_root: primitives.Root, - consolidation_requests_root: primitives.Root, -}; +pub const ExecutionPayloadHeader = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(deneb.ExecutionPayloadHeader).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "deposit_requests_root", // # [New in Electra:EIP7002:EIP7251] + .type = primitives.Root, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(primitives.Root), + }, + .{ + .name = "withdrawal_requests_root", // # [New in Electra:EIP7002:EIP7251] + .type = primitives.Root, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(primitives.Root), + }, + .{ + .name = "consolidation_requests_root", // # [New in Electra:EIP7002:EIP7251] + .type = primitives.Root, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf(primitives.Root), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); test "test ExecutionPayloadHeader" { const header = ExecutionPayloadHeader{ @@ -125,55 +155,91 @@ test "test ExecutionPayloadHeader" { try std.testing.expectEqual(header.block_number, 21); } -pub const BeaconState = struct { - genesis_time: u64, - genesis_validators_root: primitives.Root, - slot: primitives.Slot, - fork: *consensus.Fork, - latest_block_header: consensus.BeaconBlockHeader, - block_roots: []primitives.Root, - state_roots: []primitives.Root, - historical_roots: []primitives.Root, - eth1_data: ?*consensus.Eth1Data, - eth1_data_votes: []consensus.Eth1Data, - eth1_deposit_index: u64, - validators: []consensus.Validator, - balances: []primitives.Gwei, - randao_mixes: []primitives.Bytes32, - slashings: []primitives.Gwei, - previous_epoch_attestations: []consensus.PendingAttestation, - current_epoch_attestations: []consensus.PendingAttestation, - justification_bits: []bool, - previous_justified_checkpoint: *consensus.Checkpoint, - current_justified_checkpoint: *consensus.Checkpoint, - finalized_checkpoint: *consensus.Checkpoint, - inactivity_scores: []u64, - current_sync_committee: ?*consensus.SyncCommittee, - next_sync_committee: ?*consensus.SyncCommittee, - latest_execution_payload_header: ?*consensus.ExecutionPayloadHeader, - next_withdrawal_index: primitives.WithdrawalIndex, - next_withdrawal_validator_index: primitives.ValidatorIndex, - historical_summaries: []consensus.HistoricalSummary, - deposit_requests_start_index: u64, - deposit_balance_to_consume: primitives.Gwei, - exit_balance_to_consume: primitives.Gwei, - earliest_exit_epoch: primitives.Epoch, - consolidation_balance_to_consume: primitives.Gwei, - earliest_consolidation_epoch: primitives.Epoch, - pending_balance_deposits: []consensus.PendingBalanceDeposit, - pending_partial_withdrawals: []consensus.PendingPartialWithdrawal, - pending_consolidations: []consensus.PendingConsolidation, -}; +pub const BeaconState = @Type( + .{ + .@"struct" = .{ + .layout = .auto, + .fields = @typeInfo(capella.BeaconState).@"struct".fields ++ &[_]std.builtin.Type.StructField{ + .{ + .name = "deposit_requests_start_index", // # [New in Electra:EIP6110] + .type = u64, + .default_value = @ptrCast(&@as(u64, 0)), + .is_comptime = false, + .alignment = @alignOf(u64), + }, + .{ + .name = "deposit_balance_to_consume", // # [New in Electra:EIP7251] + .type = primitives.Gwei, + .default_value = @ptrCast(&@as(primitives.Gwei, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.Gwei), + }, + .{ + .name = "exit_balance_to_consume", // # [New in Electra:EIP7251] + .type = primitives.Gwei, + .default_value = @ptrCast(&@as(primitives.Gwei, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.Gwei), + }, + .{ + .name = "earliest_exit_epoch", // # [New in Electra:EIP7251] + .type = primitives.Epoch, + .default_value = @ptrCast(&@as(primitives.Epoch, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.Epoch), + }, + .{ + .name = "consolidation_balance_to_consume", // # [New in Electra:EIP7251] + .type = primitives.Gwei, + .default_value = @ptrCast(&@as(primitives.Gwei, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.Gwei), + }, + .{ + .name = "earliest_consolidation_epoch", // # [New in Electra:EIP7251] + .type = primitives.Epoch, + .default_value = @ptrCast(&@as(primitives.Epoch, 0)), + .is_comptime = false, + .alignment = @alignOf(primitives.Epoch), + }, + .{ + .name = "pending_balance_deposits", // # [New in Electra:EIP7251] + .type = []consensus.PendingBalanceDeposit, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.PendingBalanceDeposit), + }, + .{ + .name = "pending_partial_withdrawals", // # [New in Electra:EIP7251] + .type = []consensus.PendingPartialWithdrawal, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.PendingPartialWithdrawal), + }, + .{ + .name = "pending_consolidations", // # [New in Electra:EIP7251] + .type = []consensus.PendingConsolidation, + .default_value = null, + .is_comptime = false, + .alignment = @alignOf([]consensus.PendingConsolidation), + }, + }, + .decls = &.{}, + .is_tuple = false, + }, + }, +); test "test Attestation" { const attestation = Attestation{ .aggregation_bits = &[_]bool{}, .data = undefined, .signature = undefined, - .committee_bits = undefined, + .committee_bits = &[_]bool{}, }; try std.testing.expectEqual(attestation.aggregation_bits.len, 0); + try std.testing.expectEqual(attestation.committee_bits.len, 0); } test "test ExecutionPayload" {