syntax = "proto3";

package ethereum.eth.v1alpha1;

import "proto/prysm/v1alpha1/attestation.proto";
import "proto/prysm/v1alpha1/beacon_block.proto";
import "proto/prysm/v1alpha1/validator.proto";
import "proto/eth/ext/options.proto";

option csharp_namespace = "Ethereum.Eth.V1Alpha1";
option go_package = "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1;eth";
option java_multiple_files = true;
option java_outer_classname = "BeaconStateProto";
option java_package = "org.ethereum.eth.v1alpha1";
option php_namespace = "Ethereum\\Eth\\v1alpha1";

message BeaconState {
  // Versioning [1001-2000]
  uint64 genesis_time = 1001;
  bytes genesis_validators_root = 1002 [(ethereum.eth.ext.ssz_size) = "32"];
  uint64 slot = 1003 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
  Fork fork = 1004;

  // History [2001-3000]
  BeaconBlockHeader latest_block_header = 2001;
  repeated bytes block_roots = 2002 [(ethereum.eth.ext.ssz_size) = "block_roots.size"];
  repeated bytes state_roots = 2003 [(ethereum.eth.ext.ssz_size) = "state_roots.size"];
  repeated bytes historical_roots = 2004 [(ethereum.eth.ext.ssz_size) = "?,32", (ethereum.eth.ext.ssz_max)  = "16777216"];

  // Eth1 [3001-4000]
  Eth1Data eth1_data = 3001;
  repeated Eth1Data eth1_data_votes = 3002 [(ethereum.eth.ext.ssz_max) = "eth1_data_votes.size"];
  uint64 eth1_deposit_index = 3003;

  // Registry [4001-5000]
  repeated Validator validators = 4001 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
  repeated uint64 balances = 4002 [(ethereum.eth.ext.ssz_max) = "1099511627776"];

  // Randomness [5001-6000]
  repeated bytes randao_mixes = 5001 [(ethereum.eth.ext.ssz_size) = "randao_mixes.size"];

  // Slashings [6001-7000]
  repeated uint64 slashings = 6001 [(ethereum.eth.ext.ssz_size) = "slashings.size"];

  // Attestations [7001-8000]
  repeated PendingAttestation previous_epoch_attestations = 7001 [(ethereum.eth.ext.ssz_max) = "previous_epoch_attestations.max"];
  repeated PendingAttestation current_epoch_attestations = 7002 [(ethereum.eth.ext.ssz_max) = "current_epoch_attestations.max"];

  // Finality [8001-9000]
  // Spec type [4]Bitvector which means this would be a fixed size of 4 bits.
  bytes justification_bits = 8001 [(ethereum.eth.ext.ssz_size) = "1", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
  Checkpoint previous_justified_checkpoint = 8002;
  Checkpoint current_justified_checkpoint = 8003;
  Checkpoint finalized_checkpoint = 8004;
}

// The beacon state for Altair hard fork 1.
// Reference: https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#beaconstate
message BeaconStateAltair {
  // Versioning [1001-2000]
  uint64 genesis_time = 1001;
  bytes genesis_validators_root = 1002 [(ethereum.eth.ext.ssz_size) = "32"];
  uint64 slot = 1003 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
  Fork fork = 1004;

  // History [2001-3000]
  BeaconBlockHeader latest_block_header = 2001;
  repeated bytes block_roots = 2002 [(ethereum.eth.ext.ssz_size) = "block_roots.size"];
  repeated bytes state_roots = 2003 [(ethereum.eth.ext.ssz_size) = "state_roots.size"];
  repeated bytes historical_roots = 2004 [(ethereum.eth.ext.ssz_size) = "?,32", (ethereum.eth.ext.ssz_max)  = "16777216"];

  // Eth1 [3001-4000]
  Eth1Data eth1_data = 3001;
  repeated Eth1Data eth1_data_votes = 3002 [(ethereum.eth.ext.ssz_max) = "eth1_data_votes.size"];
  uint64 eth1_deposit_index = 3003;

  // Registry [4001-5000]
  repeated Validator validators = 4001 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
  repeated uint64 balances = 4002 [(ethereum.eth.ext.ssz_max) = "1099511627776"];

  // Randomness [5001-6000]
  repeated bytes randao_mixes = 5001 [(ethereum.eth.ext.ssz_size) = "randao_mixes.size"];

  // Slashings [6001-7000]
  repeated uint64 slashings = 6001 [(ethereum.eth.ext.ssz_size) = "slashings.size"];

  // Participation [7001-8000]
  bytes previous_epoch_participation = 7001 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Altair, replaced previous_epoch_attestations]
  bytes current_epoch_participation = 7002 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Altair, replaced current_epoch_attestations]

  // Finality [8001-9000]
  // Spec type [4]Bitvector which means this would be a fixed size of 4 bits.
  bytes justification_bits = 8001 [(ethereum.eth.ext.ssz_size) = "1", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
  Checkpoint previous_justified_checkpoint = 8002;
  Checkpoint current_justified_checkpoint = 8003;
  Checkpoint finalized_checkpoint = 8004;

  // New Altair fields [9001-10000]
  repeated uint64 inactivity_scores = 9001 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Altair]
  SyncCommittee current_sync_committee = 9002; // [New in Altair]
  SyncCommittee next_sync_committee = 9003; // [New in Altair]
}

message Fork {
  bytes previous_version = 1 [(ethereum.eth.ext.ssz_size) = "4"];
  bytes current_version = 2 [(ethereum.eth.ext.ssz_size) = "4"];
  uint64 epoch = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Epoch"];
}

message PendingAttestation {
  // Bitfield representation of validator indices that have voted exactly
  // the same vote and have been aggregated into this attestation.
  bytes aggregation_bits = 1 [(ethereum.eth.ext.ssz_max) = "2048", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitlist"];
  AttestationData data = 2;
  // The difference of when attestation gets created and get included on chain.
  uint64 inclusion_delay = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
  // The proposer who included the attestation in the block.
  uint64 proposer_index = 4 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.ValidatorIndex"];
}

message HistoricalBatch {
  repeated bytes block_roots = 1 [(ethereum.eth.ext.ssz_size) = "block_roots.size"];
  repeated bytes state_roots = 2 [(ethereum.eth.ext.ssz_size) = "state_roots.size"];
}

// The state summary object is defined for summarizing a state
// of a given slot. The summary facilitates regeneration of a
// specific state to allow easy playback using pre-saved state
// and blocks.
message StateSummary {
  // The slot of the state.
  uint64 slot = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
  // The block root of the state.
  bytes root = 2;
}

message SigningData {
  // The root of the object being signed.
  bytes object_root = 1 [(ethereum.eth.ext.ssz_size) = "32"];
  // The domain for the particular object being signed.
  bytes domain = 2 [(ethereum.eth.ext.ssz_size) = "32"];
}

message ForkData {
  // The current version of the fork.
  bytes current_version = 4 [(ethereum.eth.ext.ssz_size) = "4"];
  // The genesis validators root of the fork.
  bytes genesis_validators_root = 2 [(ethereum.eth.ext.ssz_size) = "32"];
}

message CheckPtInfo {
  // The randao seed which the check point refers to, this will be used to retrieve shuffled indices.
  bytes seed = 1;
  // The genesis root which the check point refers to. This ensures same seed can't happen on different chain.
  bytes genesis_root = 2;
  // Validators that were active at that check point.
  repeated uint64 active_indices = 3;
  // Validators public keys at that check point.
  repeated bytes pub_keys = 4;
  // The fork data at that check point. This will be used to verify signatures.
  Fork fork = 5;
}

// DepositMessage serves as a subset of deposit data in order to derive the signing root.
message DepositMessage {
  // 48 byte BLS public key of the validator.
  bytes public_key = 1 [(ethereum.eth.ext.ssz_size) = "48", (ethereum.eth.ext.spec_name) = "pubkey"];

  // A 32 byte hash of the withdrawal address public key.
  bytes withdrawal_credentials = 2 [(ethereum.eth.ext.ssz_size) = "32"];

  // Deposit amount in gwei.
  uint64 amount = 3;
}

// SyncCommittee serves as committees to facilitate light client syncing to beacon chain.
message SyncCommittee {
  repeated bytes pubkeys = 1  [(ethereum.eth.ext.ssz_size) = "sync_committee_bits.size,48"];
  bytes aggregate_pubkey = 2 [(ethereum.eth.ext.ssz_size) = "48"];
}

// SyncAggregatorSelectionData is used to sign over and then check whether the aggregator is selected within a subcommittee.
message SyncAggregatorSelectionData {
  // Slot of this signing data.
  uint64 slot = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
  // Subcommittee index of this signing data.
  uint64 subcommittee_index = 2;
}

message BeaconStateBellatrix {
  // Versioning [1001-2000]
  uint64 genesis_time = 1001;
  bytes genesis_validators_root = 1002 [(ethereum.eth.ext.ssz_size) = "32"];
  uint64 slot = 1003 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
  Fork fork = 1004;

  // History [2001-3000]
  BeaconBlockHeader latest_block_header = 2001;
  repeated bytes block_roots = 2002 [(ethereum.eth.ext.ssz_size) = "block_roots.size"];
  repeated bytes state_roots = 2003 [(ethereum.eth.ext.ssz_size) = "state_roots.size"];
  repeated bytes historical_roots = 2004 [(ethereum.eth.ext.ssz_size) = "?,32", (ethereum.eth.ext.ssz_max)  = "16777216"];

  // Eth1 [3001-4000]
  Eth1Data eth1_data = 3001;
  repeated Eth1Data eth1_data_votes = 3002 [(ethereum.eth.ext.ssz_max) = "eth1_data_votes.size"];
  uint64 eth1_deposit_index = 3003;

  // Registry [4001-5000]
  repeated Validator validators = 4001 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
  repeated uint64 balances = 4002 [(ethereum.eth.ext.ssz_max) = "1099511627776"];

  // Randomness [5001-6000]
  repeated bytes randao_mixes = 5001 [(ethereum.eth.ext.ssz_size) = "randao_mixes.size"];

  // Slashings [6001-7000]
  repeated uint64 slashings = 6001 [(ethereum.eth.ext.ssz_size) = "slashings.size"];

  // Participation [7001-8000]
  bytes previous_epoch_participation = 7001 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
  bytes current_epoch_participation = 7002 [(ethereum.eth.ext.ssz_max) = "1099511627776"];

  // Finality [8001-9000]
  // Spec type [4]Bitvector which means this would be a fixed size of 4 bits.
  bytes justification_bits = 8001 [(ethereum.eth.ext.ssz_size) = "1", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
  Checkpoint previous_justified_checkpoint = 8002;
  Checkpoint current_justified_checkpoint = 8003;
  Checkpoint finalized_checkpoint = 8004;

  // Altair fields [9001-10000]
  repeated uint64 inactivity_scores = 9001 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
  SyncCommittee current_sync_committee = 9002; // [New in Altair]
  SyncCommittee next_sync_committee = 9003; // [New in Altair]

  // Bellatrix fields [10001-11000]
  ethereum.eth.v1alpha1.ExecutionPayloadHeader latest_execution_payload_header = 10001; // [New in Bellatrix]
}


// PowBlock is a definition from Bellatrix fork choice spec to represent a block with total difficulty in the PoW chain.
// Spec:
// class PowBlock(Container):
//    block_hash: Hash32
//    parent_hash: Hash32
//    total_difficulty: uint256
message PowBlock {
  bytes block_hash = 1 [(ethereum.eth.ext.ssz_size) = "32"];
  bytes parent_hash = 2 [(ethereum.eth.ext.ssz_size) = "32"];
  bytes total_difficulty = 3 [(ethereum.eth.ext.ssz_size) = "32"];
}
