==============================================================================
BOOK V
THE CASE OF THE TWENTY-FOUR HOUR FIVE-ARCHITECTURE VERDICT
(The Final Ledger of Version 2.4.1)
==============================================================================

"The affair was not a single crime, Watson," Holmes remarked, his eyes fixed
upon the terminal where five separate test batteries burned in silent
parallel. "It was a coordinated conspiracy across five machines, committed
within a single revolution of the clock. The evidence was scattered across
Big Endian plains, emulator corridors, cryptographic vaults, and one
deceptively harmless byte of cosmic rot."

I confess I was bewildered. "Where does one even begin, Holmes?"

"With the most polite suspect," he replied. "The one that apologizes before
it betrays you."

He tapped the MIPS64 log.

------------------------------------------------------------------------------
I. THE MYSTERY OF THE POLITE PASSPHRASE
------------------------------------------------------------------------------

"The MIPS64 machine accepted the ritual of init without complaint. It created
the repository, generated the salt, sealed the KVV, and printed its blessing:

    Repository initialized
    Encryption: XChaCha20-Poly1305 + Argon2id

Yet when the same passphrase was presented to create, the engine answered:

    error: incorrect passphrase

A curious contradiction. The vault was locked by one key and challenged by
another, though the user had spoken the same words twice."

Holmes opened src/brs_crypto.c and pointed to the crime scene:

    crypto_argon2_config config;
    config.nb_blocks = nb_blocks;
    config.nb_passes = nb_passes;
    config.nb_lanes  = 1;

"You see it, Watson?"

"I see three fields correctly set."

"Precisely. Three. Not four. The algorithm field was left uninitialized.
A stack residue, invisible on friendly machines, was silently fed into the
first BLAKE2 update of Argon2:

    blake_update_32(&ctx, config.algorithm);

On x86_64, ARM64, and RISC-V, the residue happened to behave with boring
consistency. But on MIPS64 Big Endian, the memory stage props were arranged
differently. Init derived the key under one accidental Argon2 identity;
create derived it under another. The KVV no longer matched."

"And the fix?"

"Two lines, Watson. Not a grand overhaul. Not a rewrite of Monocypher, which
was innocent from the start. Merely discipline:

    crypto_argon2_config config;
    memset(&config, 0, sizeof(config));
    config.algorithm = CRYPTO_ARGON2_ID;
    config.nb_blocks = nb_blocks;
    config.nb_passes = nb_passes;
    config.nb_lanes  = 1;

Once Argon2id was named explicitly, the MIPS64 vault opened without protest."

------------------------------------------------------------------------------
II. THE TRAGEDY OF THE STARVED EMULATOR
------------------------------------------------------------------------------

"The second incident came from Test 016, the decompression bomb drill. The
test attempted to confine the engine with:

    ulimit -v 8192

A noble intention. Eight megabytes of virtual memory should expose any
gluttonous allocation. But under QEMU, the corpse appeared before the guest
had even executed an instruction:

    qemu: qemu_thread_create: Resource temporarily unavailable
    Aborted (core dumped)

Watson, what does one call a murder where the victim never enters the room?"

"A locked-room mystery?"

"No. An architectural misunderstanding. QEMU user-mode requires internal
threads, and threads require stacks. The emulator itself needed more address
space than the eight megabytes we were generously offering the guest. We had
locked the theatre before the actor arrived."

Holmes amended the test with a new deduction:

    If the binary architecture differs from the host architecture,
    the execution is emulated.

The suite learned to compare `file -b` against `uname -m`. When emulation
was detected, the brutal ulimit was replaced by the engine-level simulation:

    BRS_RAM_GUARD_FAKE_MB=8

For native hardware, the old discipline remained available through:

    BRS_TEST_ULIMIT_MB

"Thus," Holmes said, "the test still proves the engine's restraint, without
executing the messenger."

------------------------------------------------------------------------------
III. THE COSMIC RAY THAT REFUSED TO STRIKE
------------------------------------------------------------------------------

"The third affair was Test 073, our simulation of bit rot inside an
AES-256-GCM pack. The test corrupted one byte at offset 1024:

    printf '\xFF' | dd of="$PACK" bs=1 seek=1024 conv=notrunc

Then it expected verify to detect the mutilated GCM tag. But on x86_64,
verify occasionally returned clean. The test accused the compiler, then GCC,
then perhaps the moon."

Holmes permitted himself a thin smile.

"The accusation was misplaced. The byte at offset 1024 may already have been
0xFF. In that case, the corruption ceremony was entirely theatrical. The file
did not change. The cosmic ray struck a universe where the target was already
burning."

"The remedy?"

"Certainty, Watson. We read the original byte and XOR it:

    original XOR 0xFF

If the byte was 0x00, it becomes 0xFF. If it was 0xFF, it becomes 0x00.
Mutation is guaranteed. The GCM tag then has no choice but to betray the
damage, and verify must raise the alarm."

------------------------------------------------------------------------------
IV. THE FIVE GATES
------------------------------------------------------------------------------

"By the final hour, the evidence had been synchronized across five gates:

    x86_64   native
    ARM64    under QEMU
    RISC-V   under QEMU
    PPC32    Big Endian under QEMU
    MIPS64   Big Endian under QEMU

Each gate demanded a different toll. One demanded endian respect. Another
demanded emulator-aware memory testing. Another demanded cryptographic
explicitness. Another demanded guaranteed corruption.

The swarm of models had hoped we would accept intermittent failures as the
price of portability. They whispered that emulators are unstable, that Big
Endian machines are archaic, that uninitialized memory is harmless if it
usually works.

We did not listen."

Holmes turned the final output toward me. The text was green, unbroken, and
absolute:

    RESULT: 947/947 tests passed

"A satisfying number," I said.

"It is not the number that satisfies me, Watson. It is the absence of
footnotes. No skipped gates. No flaky prayers. No architecture granted
special mercy. The engine stands on its own proof."

------------------------------------------------------------------------------
V. THE FINAL ENTRY
------------------------------------------------------------------------------

"The case is therefore recorded under Version 2.4.1:

    Modified src/brs_crypto.c:
        Critical Argon2 initialization fix. The algorithm field is now
        explicitly set to CRYPTO_ARGON2_ID. This eliminates stack-garbage
        dependence in key derivation and repairs encrypted repositories on
        MIPS64 Big Endian.

    Modified suites/016_protection_against_decompression_bombs_oom.sh:
        Emulation detection added. QEMU environments no longer use
        `ulimit -v 8192`, which aborts the emulator before the guest runs.
        The engine-level fake RAM guard is used instead. Native environments
        may override the limit with BRS_TEST_ULIMIT_MB.

    Modified suites/073_induced_bit_rot_cosmic_ray_simulation_in_packs_aes_256_gcm.sh:
        Bit rot injection hardened. The mutation is now performed via XOR
        against the original byte, guaranteeing that the pack is physically
        altered. Verify must always detect the corrupted AES-GCM state.

    Validated platforms:
        x86_64 native
        ARM64 under QEMU
        RISC-V under QEMU
        PPC32 Big Endian under QEMU
        MIPS64 Big Endian under QEMU

    Final verdict:
        947/947 tests passed (in native x86_64, qemu bypassed the mysthic valgrind).

Holmes closed the terminal.

"When you have eliminated the impossible, Watson, whatever remains, however
improbable, must be the bug. Today, nothing remained."

==============================================================================
END OF BOOK V
==============================================================================
