Architecture Deep Dive
Detailed exploration of Zeris SDK internals, onchain program design, and interaction with the Solana runtime.
4.1 SDK Internal Design
The Zeris SDK is architected as a modular pipeline with three core engines:
PoW Engine Pipeline
The PoW engine generates computational proofs using multi-threaded workers with WASM acceleration:
rust
pub struct PoWEngine {
worker_count: usize,
difficulty: u8,
hash_buffer: Arc<Mutex<Vec<u8>>>,
}
impl PoWEngine {
pub fn new(worker_count: usize, difficulty: u8) -> Self {
Self {
worker_count,
difficulty,
hash_buffer: Arc::new(Mutex::new(Vec::new())),
}
}
pub async fn generate_proof(
&self,
data: &[u8]
) -> Result<PoWProof, PoWError> {
let target = Self::calculate_target(self.difficulty);
let workers = self.spawn_workers(data, target);
// First worker to find valid nonce wins
let (nonce, hash) = select_all(workers)
.await
.map_err(|_| PoWError::NoSolution)?;
Ok(PoWProof {
nonce,
hash,
difficulty: self.difficulty,
timestamp: unix_timestamp(),
})
}
fn spawn_workers(
&self,
data: &[u8],
target: U256
) -> Vec<impl Future<Output = (u64, [u8; 32])>> {
(0..self.worker_count).map(|worker_id| {
let data = data.to_vec();
async move {
let mut nonce = worker_id as u64;
loop {
let hash = Self::compute_pow_hash(&data, nonce);
if U256::from_be_bytes(hash) < target {
return (nonce, hash);
}
nonce += self.worker_count as u64;
}
}
}).collect()
}
#[inline(always)]
fn compute_pow_hash(data: &[u8], nonce: u64) -> [u8; 32] {
let mut hasher = Sha256::new();
hasher.update(data);
hasher.update(&nonce.to_le_bytes());
hasher.finalize().into()
}
fn calculate_target(difficulty: u8) -> U256 {
U256::MAX >> difficulty
}
}PoH Anchor Generator
The PoH module creates Merkle-anchored timestamp proofs:
rust
pub struct PoHSequencer {
current_hash: [u8; 32],
tick_count: u64,
pending_txs: VecDeque<Transaction>,
}
impl PoHSequencer {
pub fn new(genesis_hash: [u8; 32]) -> Self {
Self {
current_hash: genesis_hash,
tick_count: 0,
pending_txs: VecDeque::new(),
}
}
pub fn tick(&mut self) -> PoHTick {
self.current_hash = sha256(&self.current_hash);
self.tick_count += 1;
PoHTick {
hash: self.current_hash,
tick_number: self.tick_count,
}
}
pub fn anchor_transaction(
&mut self,
tx: Transaction
) -> PoHAnchor {
// Add transaction to pending batch
self.pending_txs.push_back(tx.clone());
// Build Merkle tree from pending transactions
let tx_hashes: Vec<[u8; 32]> = self.pending_txs
.iter()
.map(|t| t.hash())
.collect();
let merkle_tree = MerkleTree::new(tx_hashes);
let tx_index = self.pending_txs.len() - 1;
// Mix Merkle root into PoH chain
let mut hasher = Sha256::new();
hasher.update(&self.current_hash);
hasher.update(&merkle_tree.root());
self.current_hash = hasher.finalize().into();
self.tick_count += 1;
PoHAnchor {
poh_hash: self.current_hash,
tick_count: self.tick_count,
merkle_root: merkle_tree.root(),
merkle_proof: merkle_tree.get_proof(tx_index),
tx_index: tx_index as u32,
}
}
}PoS Finality Verifiers
rust
pub struct FinalityGuard {
validator_set: ValidatorSet,
finality_threshold: f64,
}
impl FinalityGuard {
pub fn new(validator_set: ValidatorSet) -> Self {
Self {
validator_set,
finality_threshold: 0.67,
}
}
pub async fn wait_for_finality(
&self,
tx_signature: &Signature
) -> Result<FinalityProof, FinalityError> {
let mut signatures = Vec::new();
let mut total_weight = 0.0;
// Poll validators for signatures
while total_weight < self.finality_threshold {
let new_sigs = self.poll_validators(tx_signature).await?;
for sig in new_sigs {
if self.verify_signature(&sig, tx_signature)? {
let validator = self.validator_set.get(&sig.pubkey)?;
total_weight += validator.weight;
signatures.push(sig);
}
}
tokio::time::sleep(Duration::from_millis(500)).await;
}
Ok(FinalityProof {
signatures,
total_weight,
timestamp: unix_timestamp(),
})
}
}4.2 Onchain Verification Program
The Zeris Solana program validates all three proof types onchain:
rust
use anchor_lang::prelude::*;
use anchor_lang::solana_program::keccak;
declare_id!("ZER1sPr0gr4m11111111111111111111111111111111");
#[program]
pub mod zeris_verification {
use super::*;
pub fn verify_triple_proof(
ctx: Context<VerifyProof>,
pow_proof: PoWProof,
poh_anchor: PoHAnchor,
pos_signatures: Vec<ValidatorSignature>,
) -> Result<()> {
// Step 1: Verify PoW
require!(
verify_pow(&pow_proof, &ctx.accounts.transaction_data.data)?,
ZerisError::InvalidPoW
);
// Step 2: Verify PoH sequence
require!(
verify_poh_sequence(&poh_anchor)?,
ZerisError::InvalidPoH
);
// Step 3: Verify PoS finality
require!(
verify_pos_finality(&pos_signatures, &ctx.accounts.validator_set)?,
ZerisError::InsufficientStake
);
// All proofs valid - mark transaction as verified
ctx.accounts.verification_state.is_verified = true;
ctx.accounts.verification_state.verified_at = Clock::get()?.unix_timestamp;
emit!(VerificationSuccessful {
transaction_hash: ctx.accounts.transaction_data.hash(),
pow_difficulty: pow_proof.difficulty,
poh_tick: poh_anchor.tick_count,
finality_weight: calculate_stake_weight(&pos_signatures),
});
Ok(())
}
}
fn verify_pow(proof: &PoWProof, data: &[u8]) -> Result<bool> {
let mut input = Vec::new();
input.extend_from_slice(data);
input.extend_from_slice(&proof.nonce.to_le_bytes());
input.push(proof.difficulty);
let hash = keccak::hash(&input);
let target = U256::MAX >> proof.difficulty;
Ok(U256::from_be_bytes(hash.0) < target)
}
fn verify_poh_sequence(anchor: &PoHAnchor) -> Result<bool> {
// Verify Merkle proof
let computed_root = compute_merkle_root(
&anchor.tx_hash,
&anchor.merkle_proof,
anchor.tx_index,
);
require!(
computed_root == anchor.merkle_root,
ZerisError::InvalidMerkleProof
);
// Verify PoH chain (simplified - actual implementation
// would verify against Solana's PoH)
Ok(true)
}
fn verify_pos_finality(
signatures: &[ValidatorSignature],
validator_set: &ValidatorSet,
) -> Result<bool> {
let mut total_weight = 0.0;
for sig in signatures {
// Verify signature is valid
require!(
sig.verify(&validator_set.transaction_hash),
ZerisError::InvalidSignature
);
// Get validator weight
let validator = validator_set.get_validator(&sig.pubkey)?;
total_weight += validator.weight;
}
Ok(total_weight >= 0.67)
}
#[derive(Accounts)]
pub struct VerifyProof<'info> {
#[account(mut)]
pub verification_state: Account<'info, VerificationState>,
pub transaction_data: Account<'info, TransactionData>,
pub validator_set: Account<'info, ValidatorSet>,
#[account(mut)]
pub payer: Signer<'info>,
}
#[account]
pub struct VerificationState {
pub is_verified: bool,
pub verified_at: i64,
pub pow_difficulty: u8,
pub poh_tick: u64,
pub finality_weight: f64,
}
#[error_code]
pub enum ZerisError {
#[msg("Invalid PoW proof")]
InvalidPoW,
#[msg("Invalid PoH sequence")]
InvalidPoH,
#[msg("Insufficient stake for finality")]
InsufficientStake,
#[msg("Invalid Merkle proof")]
InvalidMerkleProof,
#[msg("Invalid validator signature")]
InvalidSignature,
}4.3 Interaction with Solana Runtime
Compute Unit (CU) Cost Analysis
Each verification operation consumes Solana compute units:
| Operation | CU Cost |
|---|---|
| PoW Verification | ~8,500 CU |
| PoH Merkle Verification | ~12,000 CU |
| PoS Signature Verification | ~3,000 CU per sig |
| Total (10 validators) | ~50,500 CU |
Well within Solana's 1.4M CU limit per transaction. Typical verification uses ~3.6% of available compute budget.
Parallelization Behavior
Zeris verification is fully parallelizable with Sealevel:
rust
// Multiple Zeris verifications can execute in parallel
// as long as they don't write to the same accounts
// Transaction 1: Verify tx A
verify_triple_proof(
verification_state_a, // Unique account
tx_data_a,
validator_set // Read-only, shared
);
// Transaction 2: Verify tx B (executes in parallel)
verify_triple_proof(
verification_state_b, // Different account
tx_data_b,
validator_set // Read-only, shared
);
// No account conflicts → Sealevel parallelizes executionMemory Footprint
Account Sizes
- VerificationState: 64 bytes
- TransactionData: Variable (typically <1 KB)
- ValidatorSet: ~10 KB (100 validators)
- PoW Proof: 48 bytes
- PoH Anchor: ~256 bytes (with Merkle proof)
- PoS Signatures: 64 bytes per validator
SDK Architecture Diagram
┌─────────────────────────────────────────────┐
│ Application Layer │
│ (dApp, Smart Contract, Web3 Frontend) │
└─────────────────┬───────────────────────────┘
│
┌─────────────────▼───────────────────────────┐
│ Zeris SDK (Rust/TS) │
├─────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ PoW │ │ PoH │ │ PoS │ │
│ │ Engine │ │ Sequencer│ │ Finality │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│ │ │ │ │
│ ┌────▼─────────────▼─────────────▼─────┐ │
│ │ Proof Aggregator & Serializer │ │
│ └────┬─────────────────────────────────┘ │
└───────┼─────────────────────────────────────┘
│
│ RPC Call
│
┌───────▼─────────────────────────────────────┐
│ Solana Runtime (Sealevel VM) │
├─────────────────────────────────────────────┤
│ ┌──────────────────────────────────────┐ │
│ │ Zeris Verification Program │ │
│ │ (ZER1sPr0gr4m1111...) │ │
│ ├──────────────────────────────────────┤ │
│ │ • verify_pow() │ │
│ │ • verify_poh_sequence() │ │
│ │ • verify_pos_finality() │ │
│ └──────────────────────────────────────┘ │
└─────────────────────────────────────────────┘