omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / omega_receipt.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef OMEGA_RECEIPT_H |
| 18 | #define OMEGA_RECEIPT_H |
| 19 | |
| 20 | /* omega_receipt: reader for the aien-proof EvidenceReceiptV1 wire contract (VC1 stage 4). |
| 21 | * |
| 22 | * Authority: aien-protocols specs/evidence-receipt/SUBSET.md (pinned source aien-sovereign-core |
| 23 | * 40dd373, crates/aien-proof/src/evidence.rs). This file is a second, independent reader of that |
| 24 | * contract in C: it parses the receipt JSON the way serde_json does for `Receipt` |
| 25 | * (deny_unknown_fields, the same required and defaulted fields), applies every validation that |
| 26 | * `canonical_bytes` applies, builds the canonical byte encoding (domain tag, big-endian integers, |
| 27 | * length-prefixed strings, sorted unique lists) and recomputes the id as BLAKE3 over those bytes. |
| 28 | * tests/resolve/receipts/ holds three receipts written by the Rust implementation; the C id must |
| 29 | * equal the Rust id for each. |
| 30 | * |
| 31 | * NOT replicated (stated, not hidden): the ledger and lease bindings of verify_with_store |
| 32 | * (ledger_bind.rs, lease.rs need the proof board store) and chain walking (the resolver walks the |
| 33 | * Verified Crumb closure itself and ties receipt dependencies to it, SPEC 5.1 rule 6). A receipt |
| 34 | * whose hash matches is only as trustworthy as the store it came from: receipts are not signed. |
| 35 | * |
| 36 | * Every function fails closed: any parse error, unknown field, bad enum, bad hex or oversize input |
| 37 | * is a nonzero return with a plain-text reason. */ |
| 38 | |
| 39 | #include <stddef.h> |
| 40 | #include <stdint.h> |
| 41 | |
| 42 | #define OMEGA_RECEIPT_MAX_BYTES (4u * 1024u * 1024u) |
| 43 | |
| 44 | typedef struct { char *id, *expected, *observed, *source, *note; int pass; } OmegaReceiptAssertion; |
| 45 | |
| 46 | typedef struct { |
| 47 | uint32_t version; |
| 48 | uint8_t id[32]; /* the "id" field, decoded (must equal the recomputed id) */ |
| 49 | char *kind, *tier, *repo, *commit, *toolchain, *procedure, *machine, *env_class, *authority; |
| 50 | uint8_t result; /* 0 PASS 1 FAIL 2 BLOCKED 3 INCOMPLETE 4 SKIPPED */ |
| 51 | int tier_rank; /* 0 TEST_ONLY_TRUST .. 7 PRODUCTION */ |
| 52 | int dirty; |
| 53 | uint64_t timestamp; |
| 54 | char **input_artifacts; size_t n_input; |
| 55 | char **output_artifacts; size_t n_output; |
| 56 | OmegaReceiptAssertion *assertions; size_t n_assertions; |
| 57 | char **dependencies; size_t n_dependencies; |
| 58 | uint8_t declared_mutation, observed_mutation; |
| 59 | uint8_t output_digest[32]; |
| 60 | char **external_refs; size_t n_external; |
| 61 | int has_ledger; uint64_t ledger_index; uint8_t ledger_hash[32]; |
| 62 | int has_lease; uint8_t lease_hold[32]; char *lease_resource; |
| 63 | char **required_features; size_t n_features; |
| 64 | } OmegaReceipt; |
| 65 | |
| 66 | #define OMEGA_RECEIPT_PASS 0 |
| 67 | |
| 68 | /* Parse and validate receipt JSON (everything canonical_bytes validates, plus serde's shape |
| 69 | * rules). 0 ok; -1 with err filled. On failure *r holds nothing to free. */ |
| 70 | int omega_receipt_parse(const uint8_t *json, size_t len, OmegaReceipt *r, char *err, size_t errcap); |
| 71 | void omega_receipt_free(OmegaReceipt *r); |
| 72 | |
| 73 | /* The canonical bytes (malloc'd, caller frees) and id = BLAKE3(canonical bytes). */ |
| 74 | int omega_receipt_canonical(const OmegaReceipt *r, uint8_t **out, size_t *len); |
| 75 | int omega_receipt_compute_id(const OmegaReceipt *r, uint8_t out[32]); |
| 76 | |
| 77 | /* Parse, recompute, and require the "id" field to equal the recomputed id (case-insensitive hex, |
| 78 | * as aien-proof verify_bytes). 0 ok with *r filled and out_id set; -1 with err. */ |
| 79 | int omega_receipt_verify_bytes(const uint8_t *json, size_t len, OmegaReceipt *r, uint8_t out_id[32], |
| 80 | char *err, size_t errcap); |
| 81 | |
| 82 | /* Tier rank by name (-1 unknown) and the aien-proof tier_satisfies rule (chain.rs:259). */ |
| 83 | int omega_tier_rank(const char *tier); |
| 84 | int omega_tier_satisfies(int need_rank, int have_rank); |
| 85 | |
| 86 | #endif /* OMEGA_RECEIPT_H */ |