Cortex.Wire.AdmissionArtifact.Phantom
On this page
Imports
Overview
Phantom-adapter artifact rows for decoded Wire admission artifacts.
This page models the persisted shape of generated * adapters: record and
bounded-indexed product rows, gather/scatter direction, multi/singular
boundaries, and the two primitive bulk-contraction ledgers.
namespace Cortex.Wirenamespace AdmissionArtifactopen Cortex.Wire.ElaborationIRPhantom Adapter Artifacts
Product shape serialized for a phantom adapter.
inductive ProductShapeArtifact where
| record (contract : ContractId) (fields : List (FieldLabel × ContractId))
| indexed (elementContract : ContractId) (count : Nat)
deriving Reprnamespace ProductShapeArtifactNumber of immediate product leaves named by the serialized shape.
def arity : ProductShapeArtifact → Nat
| .record _ fields => fields.length
| .indexed _ count => countAggregate contract named by the singular side of the serialized product.
def contract : ProductShapeArtifact → ContractId
| .record contract _ => contract
| .indexed element count => ContractId.boundedIndexed element countRecord-shaped products serialize deterministic field rows and must not repeat field labels.
def FieldLabelsUnique : ProductShapeArtifact → Prop
| .record _ fields => (fields.map Prod.fst).Nodup
| .indexed _ _ => TrueProduct-shape contract rows carry valid field labels and contract identifiers.
def RowsValid : ProductShapeArtifact → Prop
| .record contract fields =>
contract.Valid ∧
∀ field, field ∈ fields → field.fst.Valid ∧ field.snd.Valid
| .indexed elementContract _count => elementContract.Valid
Indexed product elements are not another serialized [T; N].
The executable grammar accepts an identifier in the element position of
[T; N]. This artifact predicate mirrors the nested-product part of that
boundary by rejecting rows whose element text already starts with the
indexed-product delimiter. Full source-identifier grammar remains outside the
non-empty nominal-name approximation used by this proof layer.
def IndexedElementNominal : ProductShapeArtifact → Prop
| .record _ _ => True
| .indexed elementContract _count => elementContract.name.startsWith "[" = falseA serialized multi-side frontier has the field/contract shape claimed by the product row.
Record rows are compared by permutation because Haskell emits deterministic map order while the source-facing contract is field-label exactness, not source-order preservation.
def BoundariesMatch : ProductShapeArtifact → List AdmissionBoundaryPort → Prop
| .record _ fields, multi =>
(multi.filterMap AdmissionBoundaryPort.recordField).Perm fields
| .indexed elementContract _count, multi =>
∀ boundary, boundary ∈ multi → boundary.contract = elementContractRow-level validator obligation for serialized product shapes.
structure Valid (shape : ProductShapeArtifact) : Prop where
fieldLabelsUnique : shape.FieldLabelsUnique
rowsValid : shape.RowsValid
indexedElementNominal : shape.IndexedElementNominal@[simp]
theorem arity_record (contract : ContractId) (fields : List (FieldLabel × ContractId)) :
(ProductShapeArtifact.record contract fields).arity = fields.length :=
rfl@[simp]
theorem arity_indexed (elementContract : ContractId) (count : Nat) :
(ProductShapeArtifact.indexed elementContract count).arity = count :=
rfl@[simp]
theorem contract_record (contract : ContractId) (fields : List (FieldLabel × ContractId)) :
(ProductShapeArtifact.record contract fields).contract = contract :=
rfl@[simp]
theorem contract_indexed (elementContract : ContractId) (count : Nat) :
(ProductShapeArtifact.indexed elementContract count).contract =
ContractId.boundedIndexed elementContract count :=
rflValid record-shaped products expose duplicate-free field labels.
theorem valid_record_fieldsUnique
{contract : ContractId}
{fields : List (FieldLabel × ContractId)}
(hValid : (ProductShapeArtifact.record contract fields).Valid) :
(fields.map Prod.fst).Nodup :=
hValid.fieldLabelsUniqueValid record-shaped products expose validity for the aggregate contract row.
theorem valid_record_contractValid
{contract : ContractId}
{fields : List (FieldLabel × ContractId)}
(hValid : (ProductShapeArtifact.record contract fields).Valid) :
contract.Valid :=
hValid.rowsValid.leftValid record-shaped products expose validity for every field row.
theorem valid_record_fieldValid
{contract : ContractId}
{fields : List (FieldLabel × ContractId)}
(hValid : (ProductShapeArtifact.record contract fields).Valid)
{field : FieldLabel × ContractId}
(hField : field ∈ fields) :
field.fst.Valid ∧ field.snd.Valid :=
hValid.rowsValid.right field hFieldValid indexed products expose validity of the element contract row.
theorem valid_indexed_elementValid
{element : ContractId}
{count : Nat}
(hValid : (ProductShapeArtifact.indexed element count).Valid) :
element.Valid :=
hValid.rowsValid
Valid indexed products expose that their element is not another [T; N].
theorem valid_indexed_elementNominal
{element : ContractId}
{count : Nat}
(hValid : (ProductShapeArtifact.indexed element count).Valid) :
element.name.startsWith "[" = false :=
hValid.indexedElementNominalValid product shapes expose validity of the serialized aggregate contract.
theorem valid_contractValid
{shape : ProductShapeArtifact}
(hValid : shape.Valid) :
shape.contract.Valid := shape:ProductShapeArtifacthValid:shape.Valid⊢ shape.contract.Valid
cases shape with
contract:ContractIdfields:List (FieldLabel × ContractId)hValid:(record contract fields).Valid⊢ (record contract fields).contract.Valid
All goals completed! 🐙
element:ContractIdcount:ℕhValid:(indexed element count).Valid⊢ (indexed element count).contract.Valid
All goals completed! 🐙end ProductShapeArtifactDirection serialized for a phantom adapter artifact.
inductive PhantomAdapterDirection where
| gather
| scatter
deriving Repr
Phantom-adapter artifact row emitted for one generated * adapter.
structure PhantomAdapterArtifact where
direction : PhantomAdapterDirection
node : NodeId
productShape : ProductShapeArtifact
singular : AdmissionBoundaryPort
multi : List AdmissionBoundaryPort
leftBulk : List AdmissionConnection
rightBulk : List AdmissionConnection
deriving Reprnamespace PhantomAdapterArtifactNodes on the serialized multi-side boundary.
def multiNodes (artifact : PhantomAdapterArtifact) : List NodeId :=
artifact.multi.map AdmissionBoundaryPort.nodeSource nodes of the left bulk contraction ledger.
def leftBulkSources (artifact : PhantomAdapterArtifact) : List NodeId :=
artifact.leftBulk.map AdmissionConnection.fromNodeSource endpoint keys of the left bulk contraction ledger.
def leftBulkSourceKeys
(artifact : PhantomAdapterArtifact) :
List (NodeId × FieldLabel × ContractId) :=
artifact.leftBulk.map AdmissionConnection.fromKeyTarget nodes of the left bulk contraction ledger.
def leftBulkTargets (artifact : PhantomAdapterArtifact) : List NodeId :=
artifact.leftBulk.map AdmissionConnection.toNodeTarget endpoint keys of the left bulk contraction ledger.
def leftBulkTargetKeys
(artifact : PhantomAdapterArtifact) :
List (NodeId × FieldLabel × ContractId) :=
artifact.leftBulk.map AdmissionConnection.toKeySource nodes of the right bulk contraction ledger.
def rightBulkSources (artifact : PhantomAdapterArtifact) : List NodeId :=
artifact.rightBulk.map AdmissionConnection.fromNodeSource endpoint keys of the right bulk contraction ledger.
def rightBulkSourceKeys
(artifact : PhantomAdapterArtifact) :
List (NodeId × FieldLabel × ContractId) :=
artifact.rightBulk.map AdmissionConnection.fromKeyTarget nodes of the right bulk contraction ledger.
def rightBulkTargets (artifact : PhantomAdapterArtifact) : List NodeId :=
artifact.rightBulk.map AdmissionConnection.toNodeTarget endpoint keys of the right bulk contraction ledger.
def rightBulkTargetKeys
(artifact : PhantomAdapterArtifact) :
List (NodeId × FieldLabel × ContractId) :=
artifact.rightBulk.map AdmissionConnection.toKeyThe serialized multi-side boundary has the product arity stated by the shape row.
This is a validator obligation, not a proof term embedded in the artifact.
def ProductArityMatches (artifact : PhantomAdapterArtifact) : Prop :=
artifact.multi.length = artifact.productShape.arityThe serialized multi-side boundary has the field/contract shape stated by the product row.
def ProductShapeMatchesMulti (artifact : PhantomAdapterArtifact) : Prop :=
artifact.productShape.BoundariesMatch artifact.multiThe singular endpoint names the aggregate contract stated by the product row.
def ProductContractMatchesSingular (artifact : PhantomAdapterArtifact) : Prop :=
artifact.singular.contract = artifact.productShape.contractSerialized multi-side endpoints are unique by source boundary identity.
def MultiEndpointKeysUnique (artifact : PhantomAdapterArtifact) : Prop :=
(artifact.multi.map AdmissionBoundaryPort.key).Nodup
Indexed multi-side endpoints are unique by the compatibility key => consumes.
Primitive replay also rejects ambiguous duplicate (label, contract) rows, but
the phantom row names the obligation directly so witness consumers do not need
to recover indexed endpoint uniqueness from a later connect trace.
def IndexedMultiCompatibilityKeysUnique (artifact : PhantomAdapterArtifact) : Prop :=
match artifact.productShape with
| ProductShapeArtifact.record _ _ => True
| ProductShapeArtifact.indexed _ _ =>
(artifact.multi.map AdmissionBoundaryPort.compatibilityShape).NodupSerialized bulk contractions match the declared phantom direction.
The artifact does not serialize the generated phantom node's full frontier, so this row-level check pins only the source/sink sides that are present in the row: gather consumes multi-side inputs and produces the singular endpoint; scatter consumes the singular endpoint and produces multi-side outputs.
def BulkEndpointsMatch (artifact : PhantomAdapterArtifact) : Prop :=
match artifact.direction with
| .gather =>
(∀ pair, pair ∈ artifact.leftBulk →
pair.fromPort ∈ artifact.multi ∧ pair.toPort.node = artifact.node) ∧
(∀ pair, pair ∈ artifact.rightBulk →
pair.fromPort.node = artifact.node ∧ pair.toPort = artifact.singular)
| .scatter =>
(∀ pair, pair ∈ artifact.leftBulk →
pair.fromPort = artifact.singular ∧ pair.toPort.node = artifact.node) ∧
(∀ pair, pair ∈ artifact.rightBulk →
pair.fromPort.node = artifact.node ∧ pair.toPort ∈ artifact.multi)Serialized bulk contractions cover the source-visible multi/singular endpoints exactly.
def BulkEndpointPartition (artifact : PhantomAdapterArtifact) : Prop :=
match artifact.direction with
| .gather =>
artifact.leftBulkSourceKeys.Perm
(artifact.multi.map AdmissionBoundaryPort.key) ∧
artifact.rightBulkTargetKeys.Perm [artifact.singular.key]
| .scatter =>
artifact.leftBulkSourceKeys.Perm [artifact.singular.key] ∧
artifact.rightBulkTargetKeys.Perm
(artifact.multi.map AdmissionBoundaryPort.key)Phantom-adapter rows carry valid node, boundary, and bulk connection identities.
structure RowsValid (artifact : PhantomAdapterArtifact) : Prop where
nodeValid : artifact.node.Valid
singularValid : artifact.singular.Valid
multiValid : BoundaryPortsValid artifact.multi
leftBulkValid : ConnectionsValid artifact.leftBulk
rightBulkValid : ConnectionsValid artifact.rightBulkPhantom-adapter rows mention only nodes in the top-level summary.
structure DomainClosed (nodes : List NodeId) (artifact : PhantomAdapterArtifact) : Prop where
nodeClosed : artifact.node ∈ nodes
singularNodeClosed : artifact.singular.node ∈ nodes
multiClosed : BoundaryPortsClosed nodes artifact.multi
leftBulkClosed : ConnectionsClosed nodes artifact.leftBulk
rightBulkClosed : ConnectionsClosed nodes artifact.rightBulkRow-level validator obligation for a phantom-adapter artifact.
structure Valid (artifact : PhantomAdapterArtifact) : Prop where
productShapeValid : artifact.productShape.Valid
productArityMatches : artifact.ProductArityMatches
productShapeMatchesMulti : artifact.ProductShapeMatchesMulti
productContractMatchesSingular : artifact.ProductContractMatchesSingular
multiEndpointKeysUnique : artifact.MultiEndpointKeysUnique
bulkEndpointsMatch : artifact.BulkEndpointsMatch
bulkEndpointPartition : artifact.BulkEndpointPartition
indexedMultiCompatibilityKeysUnique : artifact.IndexedMultiCompatibilityKeysUnique
rowsValid : artifact.RowsValidend PhantomAdapterArtifactend AdmissionArtifactend Cortex.Wire