YPC-27
Yakmesh Polynomial Checksum — 27 Trits
"Your packets now carry 7.6 trillion states of armor."
— v2.7.1 Release Theme
Overview
YPC-27 is a checksum algorithm that protects YAKMESH packets from forgery. Unlike traditional CRC or hash-based checksums, YPC-27 operates in ternary space using a 27-trit finite field F_{3^27}.
YPC-27² (Power) adds a multivariate quadratic layer: three input field elements (a, b, c) are mixed linearly, twisted through a 27×27 SST-derived matrix, then amplified through polynomial powers (T²) and cross products (a·b, b·c, a·c). The result is a genuine MQ (multivariate quadratic) structure over F_3 — the same hardness basis as post-quantum multivariate signature schemes.
Why 27 Trits?
Mathematical Properties
- • 27 = 3³ — perfect cube in the ternary domain
- • 3²⁷ ≈ 7.6 trillion possible checksum values
- • Ring structure:
F_3[x]/(f(x))where f is irreducible of degree 27 - • Polynomial operations provide algebraic mixing (avalanche)
Security Properties
- • MQ structure: Polynomial powers + cross products = multivariate quadratic
- • Avalanche effect: Single bit flip → ~60% of trits change
- • Non-degenerate: 10K+ random inputs → all distinct outputs
- • Non-linear: Hash-to-field + quadratic powers break linearity
- • Matrix twist: 27×27 SST-derived matrix mixes all trits
- • Domain separation: SST 24-cycle gives 24 unique configurations
- • Large state space: 3²⁷ ≈ 7.6T possible checksums
Balanced Ternary
YPC-27 uses balanced ternary with values {-1, 0, +1}:
Example checksum: 1T011T0... (27 trits total)
Usage
Basic Checksum
import { ypc27, YPC27Checksum } from 'yakmesh/oracle/ypc27';
// Compute checksum for any data
const data = new TextEncoder().encode('Hello, YAKMESH!');
const checksum = ypc27(data); // Poly27 — 27-trit field element
// → digestBytes() / digestHex() / digestWire() for transport
// Verify checksum
const isValid = YPC27Checksum.verify(data, checksum);
// → true
Domain-Separated Checksums
import { PacketChecksum, PROTOCOL_DOMAIN } from 'yakmesh/oracle/packet-checksum';
// Same data, different domain → different checksums
const data = { content: 'test' };
const stupa = new PacketChecksum(PROTOCOL_DOMAIN.STUPA, myNodeId);
const nakpak = new PacketChecksum(PROTOCOL_DOMAIN.NAKPAK, myNodeId);
const stupaChecksum = stupa.compute(data);
const nakpakChecksum = nakpak.compute(data);
// Domain separation — same bytes, different field elements
console.log(stupaChecksum.equals(nakpakChecksum)); // false
Wrap & Unwrap Helpers
import { wrapWithChecksum, unwrapWithChecksum } from 'yakmesh/oracle/packet-checksum';
// Wrap data with checksum
const wrapped = wrapWithChecksum(myData, 'STUPA');
// → { data: myData, ypc27: 'YPC27:v1:abc123...' }
// Unwrap and verify
const { data, valid } = unwrapWithChecksum(wrapped, 'STUPA');
if (!valid) {
console.error('Checksum mismatch - packet may be corrupted or tampered!');
}
Wire Format
YPC-27 checksums use a versioned wire format. Two encodings are in use: v1 (int8-packed trits, packet-checksum fields) and v2 (compact 5-trits-per-byte, digestWire() / wrapWithChecksum):
YPC27:v1|v2:<base64-encoded-trits>
| Part | Description | Example |
|---|---|---|
YPC27 |
Algorithm identifier | YPC27 |
v1|v2 |
Encoding version — v1 int8-packed, v2 5-trits/byte compact | v2 |
<trits> |
Base64-encoded 27 trits | YXBjZGVm... |
Protocol Integrations
STUPA Broadcasts
Beacon messages now include ypc27 field. Verified on deserialize.
mesh/beacon-broadcast.js
NAKPAK Packets
Routed packets include checksum. Computed during padToFixedSize().
mesh/nakpak-routing.js
KHATA Protocol
ANNOUNCE, REQUEST, RESPONSE, REVOKE messages all include checksums.
security/khata-protocol.js
SHERPA Discovery
Peer discovery messages protected against tampering.
mesh/sherpa-discovery.js
Security Analysis
Attack Resistance
| Attack | Difficulty | Notes |
|---|---|---|
| Brute Force | 3²⁷ ≈ 7.6T operations | Infeasible for online attacks |
| Collision (Classical) | 3²⁷ ≈ 7.6T | Large output space, hash collision resistance |
| Collision (Quantum) | No known speedup | Large output space, no Shor/Grover advantage |
| Cross-Protocol Replay | Prevented | Domain separation ensures uniqueness |
API Reference
oracle/ypc27.js
| Export | Description |
|---|---|
ypc27(data) |
Compute 27-trit checksum for any data (returns Poly27) |
YPC27Checksum.verify(data, expected) |
Verify checksum matches data |
tritsToBytes(trits) / bytesToTrits(bytes) |
Trit array ↔ byte conversion |
oracle/ypc27.js helpers & oracle/packet-checksum.js
| Export | Description |
|---|---|
wrapWithChecksum(data, domain) |
Wrap data with domain-separated checksum |
unwrapWithChecksum(wrapped, domain) |
Unwrap and verify checksum |
PacketChecksum + PROTOCOL_DOMAIN |
Per-domain checksum engines (STUPA, NAKPAK, KHATA, MANTRA, SHERPA, ANNEX, LAMA, KARMA, MANI) |
Provenance full version history →
Introduced in v2.7.1 — Initial release of YPC-27 checksums with STUPA, NAKPAK, KHATA integrations.
- v3.5.0 — YPC-27 v2.0 — verified-irreducible F₃²⁷ polynomial replaces degenerate x²⁷−1 ring; YPC-27² power-magnified checksum (27×27 F₃ matrix); v2 compact wire encoding