Skip to main content

rialo_types/
lib.rs

1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! This crate contains basic types used by Rialo network.
5//! When a type is referenced by multiple crates, it is a
6//! good idea to have it in crate for simpler dependency management.
7//!
8//! This crate now includes REX-specific types with TEE attestation support.
9
10/// Transaction validity window in milliseconds.
11///
12/// A transaction is valid from its `valid_from` timestamp until `valid_from + TRANSACTION_VALIDITY_WINDOW_SECS`.
13/// This value is used by both the consensus layer (to filter invalid transactions before proposal)
14/// and the execution layer (to reject transactions during processing).
15///
16/// The value of 120 seconds (2 minutes) provides a reasonable window for:
17/// - Client clock drift tolerance
18/// - Network propagation delays
19/// - Transaction retry attempts
20pub const TRANSACTION_VALIDITY_WINDOW_MS: u64 = 120 * 1000;
21
22/// A random seed value derived from consensus.
23///
24/// This is a newtype wrapper around `u64` that provides type safety for random seed values
25/// used in block execution and transaction processing.
26#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, serde::Deserialize)]
27pub struct RandomSeed(pub [u8; 32]);
28
29impl From<[u8; 32]> for RandomSeed {
30    fn from(value: [u8; 32]) -> Self {
31        Self(value)
32    }
33}
34
35impl From<u64> for RandomSeed {
36    fn from(value: u64) -> Self {
37        Self((0..4).fold([0u8; 32], |mut acc, i| {
38            acc[i * 8..(i + 1) * 8].copy_from_slice(&value.to_le_bytes());
39            acc
40        }))
41    }
42}
43
44impl From<RandomSeed> for u64 {
45    fn from(seed: RandomSeed) -> Self {
46        u64::from_be_bytes(seed.0[0..8].try_into().expect("to succeed"))
47    }
48}
49
50// Admin transaction types (only available in non-pdk builds)
51#[cfg(feature = "non-pdk")]
52pub mod admin;
53
54// Transaction validity utilities (only available in non-pdk builds)
55#[cfg(feature = "non-pdk")]
56pub mod validity;
57
58// Consensus cryptographic types (only available in non-pdk builds)
59#[cfg(feature = "non-pdk")]
60pub mod consensus_crypto;
61
62// Core cryptographic types
63pub mod crypto;
64
65pub mod headers;
66pub mod http_filter;
67#[cfg(test)]
68mod http_filter_tests;
69#[cfg(feature = "non-pdk")]
70pub mod multiaddr;
71pub mod nonce;
72#[cfg(test)]
73mod nonce_tests;
74mod prelude;
75pub mod shared_rpc_types;
76pub mod transaction_execution_results;
77
78// REX-specific modules
79pub mod attestation;
80pub mod duties;
81pub mod duty_config;
82pub mod error;
83pub mod modified_entries;
84pub mod output;
85pub mod rex;
86pub mod rex_info;
87pub mod tee_types;
88#[cfg(test)]
89mod tests;
90pub mod websocket;
91pub mod websocket_op;
92
93// Re-export REX types
94// Re-export admin types (only available in non-pdk builds)
95#[cfg(feature = "non-pdk")]
96pub use admin::{
97    AdminTransaction, Blake3Hash, EpochChangeConfig, EpochConsensusConfig, EpochIdentifier,
98    HandoverCertificate, ValidatorInfo, ValidatorReadyMessage, BLAKE3_HASH_SIZE,
99    BLS12381_PUBLIC_KEY_SIZE, ED25519_PUBLIC_KEY_SIZE, READY_MESSAGE_SIGNING_SIZE,
100};
101// Re-export consensus crypto types (only available in non-pdk builds)
102#[cfg(feature = "non-pdk")]
103pub use attestation::{ed25519_keypair_to_pubkey_slice, ed25519_signature_to_slice};
104pub use attestation::{
105    AttestationReport, AttestationReportInner, VerificationError, VerifiedAttestation,
106};
107#[cfg(feature = "non-pdk")]
108pub use consensus_crypto::{
109    AuthorityPublicKey, NetworkKeyPair, NetworkPrivateKey, NetworkPublicKey, ProtocolKeyPair,
110    ProtocolKeySignature, ProtocolPublicKey,
111};
112// Re-export crypto types
113pub use crypto::{PublicKey, TeeUserData, TEE_USER_DATA_SIZE, X25519_KEY_SIZE};
114pub use duties::{AuthorityKeyBytes, RexDutiesMap, RexDutiesMapKey, RexDutiesMapValue};
115pub use duty_config::*;
116pub use error::*;
117pub use modified_entries::*;
118// Re-export multiaddr types
119#[cfg(feature = "non-pdk")]
120pub use multiaddr::{Multiaddr, Protocol};
121pub use output::*;
122/// Re-export for convenience
123pub use prelude::*;
124pub use rex_info::*;
125pub use tee_types::{
126    parse_evidence, AttestationEvidence, AwsSevSnpEvidenceData, AzureSevSnpEvidenceData,
127    SevSnpEvidenceData, TeeEvidenceError, TeeType,
128};
129pub use websocket_op::*;
130
131/// A wrapper enum to distinguish different types of messages processed in consensus.
132#[cfg(feature = "non-pdk")]
133#[derive(serde::Deserialize, serde::Serialize)]
134pub enum ConsensusMessage {
135    RexUpdateResult(Box<RexUpdateResult>),
136    VersionedTransaction(rialo_s_sdk::transaction::VersionedTransaction),
137    /// Admin transactions for privileged operations like epoch changes.
138    AdminTransaction(Box<AdminTransaction>),
139}
140
141// Re-export validity functions for convenience
142// Re-export test helpers when testing feature is enabled
143#[cfg(feature = "testing")]
144pub use validity::{
145    create_admin_transaction, create_rex_update_with_target_timestamp,
146    create_versioned_transaction_with_timestamp,
147};
148#[cfg(feature = "non-pdk")]
149pub use validity::{
150    extract_valid_from, extract_valid_until, is_expired, is_not_yet_valid, is_too_far_in_future,
151    MAX_FUTURE_VALID_FROM_MS,
152};