MEMRIS_CORE.sol — protocol preview
Architecture preview for finite memory, witnesses, scars and midnight succession. Token contract: 0x4378973f0442c387dbf570b197a6f54f58dd9e8e.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract MemrisCore {
    uint8 public constant MEMORY_SLOTS = 32;
    uint8 public constant SURVIVORS = 4;

    struct Memory {
        bytes32 signalHash;   // immutable proof of the observation
        uint64 bornAt;        // recorded before the outcome
        uint16 confidence;    // 0–1000, never edited later
        uint32 witnessCount;
        bool awake;
        bool scar;
    }

    address public agent;
    uint64 public epoch;
    uint8 public activeCount;
    mapping(uint256 => Memory) public memoryById;
    mapping(uint256 => mapping(address => bool)) public witnessed;

    event MemoryRecorded(uint256 indexed id, bytes32 signalHash);
    event MemoryWitnessed(uint256 indexed id, address indexed witness);
    event MemoryScarred(uint256 indexed id);
    event Midnight(uint64 indexed epoch, uint256[4] survivors);

    modifier onlyAgent() {
        require(msg.sender == agent, "MEMRIS: NOT THE CAT");
        _;
    }

    function record(
        uint256 id,
        bytes32 signalHash,
        uint16 confidence
    ) external onlyAgent {
        require(activeCount < MEMORY_SLOTS, "MEMRIS: MIND FULL");
        require(memoryById[id].bornAt == 0, "MEMRIS: ALREADY EXISTS");
        require(confidence <= 1000, "MEMRIS: BAD CONFIDENCE");

        memoryById[id] = Memory({
            signalHash: signalHash,
            bornAt: uint64(block.timestamp),
            confidence: confidence,
            witnessCount: 0,
            awake: true,
            scar: false
        });
        activeCount++;
        emit MemoryRecorded(id, signalHash);
    }

    function witness(uint256 id) external {
        Memory storage m = memoryById[id];
        require(m.awake, "MEMRIS: MEMORY ASLEEP");
        require(!witnessed[id][msg.sender], "MEMRIS: ALREADY SEEN");
        witnessed[id][msg.sender] = true;
        m.witnessCount++;
        emit MemoryWitnessed(id, msg.sender);
    }

    function markScar(uint256 id) external onlyAgent {
        require(memoryById[id].bornAt != 0, "MEMRIS: UNKNOWN MEMORY");
        memoryById[id].scar = true;
        emit MemoryScarred(id);
    }

    function midnight(uint256[4] calldata keep) external onlyAgent {
        // Production version verifies four unique, awake memories,
        // seals every other active slot, then begins the next epoch.
        epoch++;
        activeCount = SURVIVORS;
        emit Midnight(epoch, keep);
    }
}