Contracts and BEX: deterministic state change
Blue Contracts maps one authoritative Root and one eligible event to a deterministic new Root, emitted events, and gas. BEX represents pure computation as Blue data.
The narrow processor interface#
PROCESS(current Root, eligible event)
→ new Root
+ Root-emitted events
+ total gas
The processor does not choose the next external event, contact providers, read the wall clock, search for Mandates, authenticate users, or perform payment. Those responsibilities remain outside the deterministic core.
Contracts are identity-bearing content#
Runtime capabilities live under the reserved contracts field. The Blue Language knows that this field is content. A Contracts processor knows what supported contract types do.
Broad contract roles include:
- Channels — decide whether an event belongs to a route and which payload a handler sees;
- Handlers — react to accepted events and return normalized effects;
- Operations — declare callable behavior and request shape;
- Markers — influence processing, scopes, checkpoints, lifecycle, or policy.
Unsupported active capabilities must fail closed before mutation. Parsing a document is not the same as safely processing every active contract it contains.
Handlers return effects, not mutable control#
A handler returns patches, events, and termination requests. The processor validates and applies them in a defined order. It owns checkpoints, event queues, scopes, gas, and lifecycle markers.
changeset:
- op: replace
path: /status
val: Visit Requested
events:
- type: Visit Requested
This design makes effect order observable and sandboxing practical.
Workflows and cascades#
Sequential workflows run steps in list order. A normal patch can produce a Document Update that triggers another handler. Emitted events enter a deterministic queue. Embedded scopes can react within their boundaries. Gas and cutoff rules bound the cascade.
BEX is computation represented as Blue data#
A BEX program is itself a Blue node. It can be typed, referenced, hashed, embedded, and selected by BlueId. It runs against declared immutable context and returns values, changesets, and events as data.
BEX is appropriate for deterministic validation, calculations, conditional output, and pure transformations. It is not a network client, clock, payment engine, or hidden machine-learning oracle.
Replay#
Given the same initial Root, exact ordered eligible entries, referenced content, supported contract registry, processor profile, and deterministic intrinsics, independent implementations should derive the same states and Root events.