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// Consensus cryptographic types (only available in non-pdk builds)
51#[cfg(feature = "non-pdk")]
52pub mod consensus_crypto;
53
54// Core cryptographic types
55pub mod crypto;
56
57pub mod headers;
58pub mod http_filter;
59#[cfg(test)]
60mod http_filter_tests;
61#[cfg(feature = "non-pdk")]
62pub mod multiaddr;
63pub mod nonce;
64#[cfg(test)]
65mod nonce_tests;
66mod prelude;
67pub mod shared_rpc_types;
68pub mod transaction_execution_results;
69
70// REX-specific modules
71pub mod attestation;
72pub mod duties;
73pub mod duty_config;
74pub mod error;
75pub mod modified_entries;
76pub mod output;
77pub mod program_format;
78pub use program_format::{PVM_MAGIC, WASM_COMPONENT_MAGIC, WASM_MAGIC};
79pub mod rex;
80pub mod rex_info;
81pub mod tee_types;
82#[cfg(test)]
83mod tests;
84pub mod websocket;
85pub mod websocket_op;
86
87// Re-export consensus crypto types (only available in non-pdk builds)
88#[cfg(feature = "non-pdk")]
89pub use attestation::{ed25519_keypair_to_pubkey_slice, ed25519_signature_to_slice};
90pub use attestation::{
91    AttestationReport, AttestationReportInner, VerificationError, VerifiedAttestation,
92};
93#[cfg(feature = "non-pdk")]
94pub use consensus_crypto::{
95    AuthorityPublicKey, GenesisSignature, NetworkKeyPair, NetworkPrivateKey, NetworkPublicKey,
96    ProtocolKeyPair, ProtocolKeySignature, ProtocolPublicKey,
97};
98// Re-export crypto types
99pub use crypto::{PublicKey, TeeUserData, TEE_USER_DATA_SIZE, X25519_KEY_SIZE};
100pub use duties::{AuthorityKeyBytes, RexDutiesMap, RexDutiesMapKey, RexDutiesMapValue};
101pub use duty_config::*;
102pub use error::*;
103pub use modified_entries::*;
104// Re-export multiaddr types
105#[cfg(feature = "non-pdk")]
106pub use multiaddr::{Multiaddr, Protocol, EPOCH_PORT_OFFSET};
107pub use output::*;
108/// Re-export for convenience
109pub use prelude::*;
110pub use rex_info::*;
111pub use tee_types::{
112    parse_evidence, AttestationEvidence, AwsSevSnpEvidenceData, AzureSevSnpEvidenceData,
113    AzureSnpHclEvidence, AzureSnpVtpmEvidence, SevSnpEvidenceData, TeeEvidenceError, TeeType,
114};
115pub use websocket_op::*;