Source
tests/purrc/ed25519_sys_test.cpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
// System-level (whole-program) test for the `ed25519` stdlib module, written as a4
// worked EXAMPLE of the signature workflow that backs cheatah's binary-integrity5
// feature: a publisher signs a payload with a secret key, anyone holding only the6
// PUBLIC key can verify it, and ANY tampering — to the payload, the signature, or the7
// key — is rejected. This is the same Ed25519 the runtime uses to refuse a tampered8
// `.so` (see integrity_e2e_test.cpp).9
//10
// Coverage — every function in stdlib/ed25519/ed25519.hpp:11
// generate, public_key, sign, verify.12
//13
// Deterministic: signing is deterministic (RFC 8032), and the generate() result is14
// only exercised by property (a fresh key round-trips), so stdout is fixed.15
#include "e2e_harness.hpp"17
TEST(StdlibE2E, Ed25519) {18
e2e::expect_e2e("ed25519_sys", R"PURR(import io19
import ed2551921
# A publisher's keypair. In real use the secret stays offline (purrc --keygen); only22
# the public key is shipped to verifiers. Here we use a fixed RFC 8032 seed so the23
# signature is reproducible.24
let secret = "c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7"25
let pub = ed25519.public_key(secret)26
io.print("public:", pub)28
# Sign a payload (think: the bytes of a compiled module).29
let payload = "the trusted payload"30
let sig = ed25519.sign(secret, payload)32
# A verifier with ONLY the public key accepts the genuine payload+signature.33
io.print("genuine accepted:", ed25519.verify(pub, payload, sig))35
# An attacker who injects different bytes but keeps the old signature is rejected:36
# the signature no longer matches the payload.37
io.print("tampered payload rejected:", ed25519.verify(pub, "the INJECTED payload", sig) == false)39
# Tampering with the signature itself is rejected.40
let forged = "00" + sig[2:]41
io.print("forged signature rejected:", ed25519.verify(pub, payload, forged) == false)43
# A signature from a DIFFERENT key does not verify under this public key — a verifier44
# only trusts payloads signed by the key it pins.45
let other_secret = ed25519.generate()46
let other_sig = ed25519.sign(other_secret, payload)47
io.print("untrusted signer rejected:", ed25519.verify(pub, payload, other_sig) == false)49
# A freshly generated key still produces a working, verifiable signature.50
let fresh = ed25519.generate()51
let fresh_pub = ed25519.public_key(fresh)52
io.print("fresh keypair verifies:", ed25519.verify(fresh_pub, payload, ed25519.sign(fresh, payload)))53
)PURR",54
"public: fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025\n"55
"genuine accepted: True\n"56
"tampered payload rejected: True\n"57
"forged signature rejected: True\n"58
"untrusted signer rejected: True\n"59
"fresh keypair verifies: True\n");60
}