MEMRIS_CORE.rs — protocol architecture preview
PROTOCOL ARCHITECTURE PREVIEW
NOT DEPLOYED ONCHAIN
Illustrative Rust + Anchor-style design for finite memory, witnesses, scars and midnight succession. The current product reads Solana data and signs wallet messages; this file is not a deployed program. Token mint: AWAITING BIRTH.
use anchor_lang::prelude::*;

declare_id!("Memris111111111111111111111111111111111111");

pub const MEMORY_SLOTS: u8 = 32;
pub const SURVIVORS: usize = 4;

#[program]
pub mod memris_core {
    use super::*;

    pub fn record(ctx: Context<Record>, id: u64, signal_hash: [u8; 32], confidence: u16) -> Result<()> {
        require!(confidence <= 1000, MemrisError::BadConfidence);
        let memory = &mut ctx.accounts.memory;
        memory.id = id;
        memory.signal_hash = signal_hash;
        memory.born_at = Clock::get()?.unix_timestamp;
        memory.confidence = confidence;
        memory.witness_count = 0;
        memory.awake = true;
        memory.scar = false;
        Ok(())
    }

    pub fn witness(ctx: Context<WitnessMemory>) -> Result<()> {
        let memory = &mut ctx.accounts.memory;
        require!(memory.awake, MemrisError::MemoryAsleep);
        memory.witness_count = memory.witness_count.saturating_add(1);
        Ok(())
    }

    pub fn midnight(ctx: Context<Midnight>, survivors: [u64; SURVIVORS]) -> Result<()> {
        require!(survivors.len() == SURVIVORS, MemrisError::InvalidSurvivors);
        ctx.accounts.epoch.value = ctx.accounts.epoch.value.saturating_add(1);
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Record<'info> {
    #[account(mut)] pub memory: Account<'info, Memory>,
    pub agent: Signer<'info>,
}

#[derive(Accounts)]
pub struct WitnessMemory<'info> {
    #[account(mut)] pub memory: Account<'info, Memory>,
    pub witness: Signer<'info>,
}

#[derive(Accounts)]
pub struct Midnight<'info> {
    #[account(mut)] pub epoch: Account<'info, Epoch>,
    pub agent: Signer<'info>,
}

#[account]
pub struct Memory {
    pub id: u64,
    pub signal_hash: [u8; 32],
    pub born_at: i64,
    pub confidence: u16,
    pub witness_count: u32,
    pub awake: bool,
    pub scar: bool,
}

#[account]
pub struct Epoch { pub value: u64 }

#[error_code]
pub enum MemrisError {
    #[msg("confidence is outside the supported range")] BadConfidence,
    #[msg("memory is no longer awake")] MemoryAsleep,
    #[msg("exactly four survivors are required")] InvalidSurvivors,
}