{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/cache-epoch-v1.json",
  "title": "Cache Epoch Receipt, v1",
  "description": "Canonical schema for the Hive cache epoch receipt, canonical type cache.epoch. A build epoch identifier derived over a named weight build, a named kernel build, and a named numeric configuration is an input to the block key under which each reused key and value block is addressed, so a block computed under one epoch is not addressable under another. On a candidate hit the epoch recorded in the block table entry is compared against the epoch resident in the named high bandwidth memory region at admission, and every block whose recorded epoch differs is unmapped from the request block table and recomputed under the resident weight set before decode proceeds past its prefix range. Residency age and the cross epoch read count are integer quantities recomputed from the recorded monotonic readings rather than accepted as supplied.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_cache[._]epoch_[0-9]{10,}_[0-9a-f]{12}$"
    },
    "payload_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "sig_b64u": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{86}$"
    },
    "key_id": {
      "type": "string",
      "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$"
    },
    "algorithm": {
      "type": "string",
      "const": "Ed25519"
    },
    "ts": {
      "type": "integer",
      "minimum": 1000000000
    },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "epoch_record_id",
        "salt",
        "request_ref",
        "current_epoch",
        "key_construction",
        "blocks",
        "counts",
        "verdict",
        "served_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "cache.epoch"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "epoch_record_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "salt": {
          "type": "object",
          "required": [
            "commitment_sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "commitment_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            }
          }
        },
        "request_ref": {
          "type": "object",
          "required": [
            "commitment",
            "prefix_token_count"
          ],
          "additionalProperties": false,
          "properties": {
            "commitment": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "prefix_token_count": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "current_epoch": {
          "type": "object",
          "required": [
            "epoch_sha256",
            "weight_build_id",
            "kernel_build_id",
            "numeric_config_id",
            "parameter_region_id",
            "weight_load_counter",
            "resident_since_counter"
          ],
          "additionalProperties": false,
          "properties": {
            "epoch_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "weight_build_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "kernel_build_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "numeric_config_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "parameter_region_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "weight_load_counter": {
              "type": "integer",
              "minimum": 0
            },
            "resident_since_counter": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "key_construction": {
          "type": "object",
          "required": [
            "domain_label",
            "epoch_is_key_input",
            "input_order"
          ],
          "additionalProperties": false,
          "properties": {
            "domain_label": {
              "type": "string",
              "const": "cache-epoch-block"
            },
            "epoch_is_key_input": {
              "type": "boolean",
              "const": true
            },
            "input_order": {
              "type": "array",
              "const": [
                "domain_label",
                "parent_block_key",
                "token_id_digest",
                "epoch"
              ],
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "minItems": 4,
              "maxItems": 4
            }
          }
        },
        "blocks": {
          "type": "array",
          "minItems": 0,
          "maxItems": 4096,
          "items": {
            "type": "object",
            "required": [
              "block_index",
              "block_key_sha256",
              "parent_block_key_sha256",
              "token_id_digest_sha256",
              "recorded_epoch_sha256",
              "birth_counter_ns",
              "read_attempt_counter_ns",
              "residency_age_ns",
              "intervening_weight_load_count",
              "birth_weight_load_counter",
              "epoch_relation",
              "disposition",
              "recompute_task_id",
              "recompute_completed_before_decode"
            ],
            "additionalProperties": false,
            "properties": {
              "block_index": {
                "type": "integer",
                "minimum": 0
              },
              "block_key_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "parent_block_key_sha256": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9a-f]{64}$"
              },
              "token_id_digest_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "recorded_epoch_sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "birth_counter_ns": {
                "type": "integer",
                "minimum": 0
              },
              "read_attempt_counter_ns": {
                "type": "integer",
                "minimum": 0
              },
              "residency_age_ns": {
                "type": "integer",
                "minimum": 0
              },
              "intervening_weight_load_count": {
                "type": "integer",
                "minimum": 0
              },
              "birth_weight_load_counter": {
                "type": "integer",
                "minimum": 0
              },
              "epoch_relation": {
                "type": "string",
                "enum": [
                  "same_epoch",
                  "cross_epoch"
                ]
              },
              "disposition": {
                "type": "string",
                "enum": [
                  "read",
                  "unmapped_and_recomputed"
                ]
              },
              "recompute_task_id": {
                "type": [
                  "string",
                  "null"
                ],
                "minLength": 1,
                "maxLength": 256
              },
              "recompute_completed_before_decode": {
                "type": [
                  "boolean",
                  "null"
                ]
              }
            }
          }
        },
        "counts": {
          "type": "object",
          "required": [
            "candidate_hit_count",
            "same_epoch_read_count",
            "cross_epoch_read_count",
            "max_residency_age_ns",
            "unmapped_count",
            "recomputed_block_count"
          ],
          "additionalProperties": false,
          "properties": {
            "candidate_hit_count": {
              "type": "integer",
              "minimum": 0
            },
            "same_epoch_read_count": {
              "type": "integer",
              "minimum": 0
            },
            "cross_epoch_read_count": {
              "type": "integer",
              "minimum": 0
            },
            "max_residency_age_ns": {
              "type": "integer",
              "minimum": 0
            },
            "unmapped_count": {
              "type": "integer",
              "minimum": 0
            },
            "recomputed_block_count": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "verdict": {
          "type": "string",
          "enum": [
            "epoch_clean",
            "cross_epoch_enforced",
            "cross_epoch_read_detected"
          ]
        },
        "served_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
        },
        "boundary": {
          "type": "string",
          "const": "Cache Epoch record. Attests that a build epoch identifier derived over a named weight build, a named kernel build, and a named numeric configuration was an input to the block key under which each listed key and value block was addressed, that the epoch recorded for each block was compared against the epoch of the weight set resident in the named high bandwidth memory region at admission of this request, that every block whose recorded epoch differed was unmapped from this request's block table and recomputed under the resident weight set before decode proceeded past its prefix range, and that the residency age of each reused block and the cross epoch read count were recomputed from the recorded monotonic readings rather than supplied. It does not attest that the response is correct, does not attest anything about latency, does not attest which other parties read any block, does not attest that the resident weight set is the weight set the requesting party expected, and does not attest that any block outside the listed candidate hits was evaluated."
        }
      }
    }
  }
}
