Skip to main content

Appendix D — Codegen Target Catalog

This appendix enumerates the code-generation targets defined by CADL v0.3 and the mapping to the reference implementation's directory layout. Appendix A §A.9 defines the EBNF for codegen: entries; this appendix pairs each target name with its category, intended artifact, and implementation location in the reference implementation (cadl 0.3).

D.1 Target catalog​

Target nameCategoryEmitted artifactReference-impl moduleCommand
pythonRuntime codePython package (actors, contract monitors, protocols, regime controller, metrics, runtime; for a file that declares norms: 0.1, also a monitor of the norms of Appendix F)cadl.codegencadl codegen -t python
solidityInstitutional contractSolidity [Solidity Documentation] smart contracts, one per contract; for a file that declares norms: 0.1, also a monitor of the norms per contract (D.5)cadl.codegen.soliditycadl codegen -t solidity
opaInstitutional policyRego / OPA [Open Policy Agent] policies, one per contract; for a file that declares norms: 0.1, also a monitor of the norms per contract as a step function (D.5)cadl.codegen.opacadl codegen -t opa
unity-csharpRuntime codeUnity C# classes for the lifecycles and monitors of Appendix Ecadl.codegen.unity_csharpcadl codegen -t unity-csharp
unitySimulator configJSON for a Unity-based simulatorcadl.sim.gen_unitycadl sim-gen -t unity
goSimulator configJSON for a Go-based simulatorcadl.sim.gen_gocadl sim-gen -t go
python (simulator)Simulator configYAML for a Python-based simulatorcadl.sim.gen_pythoncadl sim-gen -t python
agent-regoBoundary policyRego policy that returns the allow / deny / escalate decision of Appendix G for a messagecadl.codegencadl codegen -t agent-rego
agent-cedarBoundary policyCedar policies and a side table for the statically decidable part of Appendix Gcadl.codegencadl codegen -t agent-cedar
ros2Runtime nodeROS 2 [Macenski+, 2022] node scaffoldsnot implemented in cadl 0.3—
other name (user-defined)PluginWhatever the user plugin emitsno plugin mechanism exists in cadl 0.3; other target names are rejected on the command line and get a warning in a codegen: entry—

The name python denotes the runtime-code target in a codegen: entry; the simulator configuration of the same name is requested with cadl sim-gen. The Python simulator config therefore cannot be requested from a codegen: entry in v0.3; use cadl sim-gen -t python. In the reference implementation (cadl 0.3) the target is selected on the command line as shown in the last column; codegen: entries in the file are parsed but do not yet drive generation. From cadl 0.3.9, an entry that names a target the implementation cannot emit gets a warning (D.4).

For a file that declares the norms extension (Appendix F), the python target also emits the module norms_monitor.py (from cadl 0.3.22). It monitors the norms: and counts_as: blocks and the assume: and guarantee: items of each contract, including the items with temporal operators, for one contract instance while the system runs: it is given one observation at a time and returns the norm instances and items whose state or verdict (pending, fulfilled, violated, excused) changed. Unlike the other modules of the package, it does not import cadl: it carries the declared actors and the contracts as data (one JSON text) and the evaluation code of cadl norms-eval, and uses only the standard library of Python. The generator checks the module before it writes it and writes nothing when the check fails. F.10 gives the details. The solidity and opa targets leave the items with temporal operators out of the contract policy, with a comment, and monitor them, with the norms, in a separate file per contract (from cadl 0.3.25; D.5). The unity-csharp target does not monitor norms.

From cadl 0.3.33 the generated code of every file with transitions: follows A.7.1 ("Runs"): the python and solidity controllers start in the initial regime, take at most one transition after the evaluations of a step (a condition that cannot be evaluated, because a value is missing or unset or Solidity cannot express it, does not hold), check its safety invariant explicitly (not with assert; in Solidity only with values that were set) and do not take it when the invariant does not hold or cannot be evaluated or compiled; in Solidity one step is one call of the orchestrator, whose deployer sets the observed state. For a file with regimes: (Appendix A, A.7.1) the generated code also applies the bindings of the current regime, as the list below says; a file with transitions and an empty block (regimes: {}) counts as a file with the block (its Rego contract policies require input.regime). A file without transitions: gets the same code as before, apart from the corrections of the opa target below. Up to cadl 0.3.32 the Python controller checked the invariant with assert, so a failing invariant raised AssertionError and python -O took the transition, and the Solidity RegimeController started in the first regime in alphabetical order, did not check the invariant, had no setters (conditions read 0), and could be called by anyone.

  • python: the regime controller starts in the initial regime of A.7.1 (it still takes another one as an argument, and raises ValueError for a name that is not a regime), checks the safety invariant of a transition explicitly (not with assert) and, when it does not hold or cannot be compiled or evaluated, does not take the transition and records it in refused_transitions and the log, publishes the values of the bound parameters of the current regime in ctx.parameters, and the runtime runs the monitor of a contract only in the regimes in which it is in force. A transition is evaluated after the monitors of a cycle, so the next cycle has the bindings of the new regime. The norms monitor norms_monitor.py reads the key regime of an observation (F.5, F.10).
  • solidity: RegimeController starts in the initial regime and gives contractActive(id). A contract that some regime does not have in force, or whose alpha, beta, or lambda some regime binds, takes the controller as constructor argument; its runMonitorCycle() returns without checking while it is not in force, and ALPHA, BETA, and LAMBDA become view functions with the same getter that return the value of the current regime (times 1000, as the constants). The orchestrator creates the controller first. One step of A.7.1 is one call of the orchestrator's runMonitorCycle(): only its deployer (the reporter) may call it and set the observed state (setUint, setBool, passed to every contract and the controller), and only the orchestrator may run the steps of the contracts and of the controller. A transition whose safety invariant does not hold, or cannot be compiled, is not taken; the event RegimeTransitionRefused names it. The controller records which values were set, per type (isSetUint, isSetBool), and an invariant holds only when every value it reads was set, as the Python check refuses a missing value. An invariant that reads anything but names of the observed state, integers, and booleans with the operators of A.10 (a function such as len(queue), a field of an actor, a text) is compiled as false. In both targets a bare name, such as Idle in mode == Idle, is a quantity of the observed state.
  • opa: each contract policy reads input.regime. A contract that the regime does not have in force is satisfied (allow) and has no violation; alpha, beta, and lambda_ have the value of the regime. Without input.regime, or with a name that is not a regime of the file, nothing is allowed and regime_error (also in violation) says why. main.rego gives regimes, initial_regime, and parameters, the values of the bound parameters in the regime (undefined without a regime of the file). The policies take no transitions: the host that passes the regime takes them and checks their safety invariants (A.7.1).
  • unity-csharp: from cadl 0.3.36, for a file in which a regime does not have a contract with lifecycle: or monitors: in force, the target also writes Generated/CadlRegimes.cs: the regimes, the contracts that each does not have in force, the initial regime, and the current regime, which the host sets with Set(regime, tMs) when its regime controller takes a transition. An instance of such a contract is constructed with the CadlRegimes object (or starts in the initial regime) and follows the current regime: while the contract is not in force it sees no event and no tick, and when it is in force again its deadlines and the last times of its periodic monitors are moved on by the time it was not in force, so that they run on the clock of the contract (F.5, "Contracts not in force"). Events report times of the run. For other files the bindings change nothing that the target writes. In 0.3.33 to 0.3.35 such a file was refused. Given the other versions of a run of which some bind regimes (--version, K.11), Generated/CadlRegimes.cs holds the regimes of every version and the contracts each does not have in force, and the run starts in the initial regime of the version given to its constructor (the first by default); the class that follows the versions takes the object as its last constructor argument and applies K.11, "Versions and regimes": the contract is in force by the bindings of the version in force; the instance starts (its body is created) at the first time the contract is in force, under the version in force then; while it is not in force its clock stops as above (the body also moves on the time at which its deadlines were armed); a version that takes effect then is applied when the contract is in force again, in order and before anything else, on the state the instance had, and the Lifecycle event <version> of a switch it makes carries the time at which the version took effect (the time given to SetVersion, K.11, "Versions and regimes", item 4), while a waiting switch with in_states: carries the time at which it is made; and SetVersion and Set throw for a regime that is not a regime of every version the instance has had in force. Set does not call Tick: a deadline that passed on the clock of the contract before it left force is decided by the first Tick after it is in force again, after the versions that took effect meanwhile, as cadl norms-eval decides it at the next observation of the projection; the host calls Set, then Tick, then posts the events of that time. It is compared with the code generated from the same versions without regimes on the projection of the run (the steps in force on the clock of the contract, the versions that took effect while the contract was not in force applied when it is in force again): 1000 random runs of 25 random sets of two or three versions of the robot town (31 000 steps, 14 549 of them not in force, 459 versions that took effect while the contract was not in force) in the tests of cadl 0.3.36, without a difference (Mono). The combination was refused before 0.3.36.
  • agent-rego and agent-cedar: from cadl 0.3.36, for a file in which a regime does not have an enforced contract in force, the boundary policy reads the current regime from the key regime of the policy input (Cedar: context.regime), and a contract that the regime does not have in force governs no message (Appendix G, G.10). In 0.3.33 to 0.3.35 such a file was refused.
  • The norms monitors of the opa and solidity targets follow the current regime from cadl 0.3.36 (D.5).

Versions. From cadl 0.3.34 a file that declares amendment: 0.1 is one version of a model (Appendix K, K.11). The code generated from it is the code of that version; a host applies versions by running, at each step, the code of the version in force, and for an instance that keeps an older version, the code of that version. For a file with an amendment: block the python target also writes version.py (the version, the version it replaces, the effective time, the transitional rules, and the values of the amendable parameters), and its norms monitor applies the versions of a run (F.10). Code that keeps running contract instances and cannot move them to a new version is refused for a version that may replace another (it names previous:, or from cadl 0.3.35 it gives no previous: and an effective time other than period: 1, K.11): the norms monitors of the opa and solidity targets for a contract whose running instances switch to it (D.5), and the unity-csharp target when a contract with lifecycle: switches. From cadl 0.3.36 cadl codegen --version FILE (repeatable) gives the other versions of the run: the Rego and Solidity monitors and the Unity C# code then follow the version in force that the caller names (D.5; for Solidity, setVersion of the orchestrator; for Unity C#, a class per version and a class with SetVersion). The Unity C# target refuses a version that has no contract of that id with lifecycle: or monitors:, since the instance follows it through every version; the other targets refuse --version (the python target applies the versions at run time, with run_versions of its norms monitor). A file without the extension, or without an amendment: block, gets the same code as before.

Five errors of the opa target are corrected in cadl 0.3.33 for every file. A negated literal (NOT ok, NOT (y == 3)) held when a value it reads was missing, since OPA's not input.y == 3 holds then; each input reference is now bound before the negation (neg_1 := input.y; not neg_1 == 3), so flag != true and NOT (flag == true) agree. An assume: or guarantee: item with a quantifier or a comprehension was written as Rego that OPA rejects (not inside an expression, a comprehension as a comment) or that ranged over no member; it is now a truth value that the host gives, input.items["TEXT"] == true, as is a text (an opaque predicate), as a whole item or as an operand of AND, OR, or NOT, which was a string that Rego reads as true. An item with OR, or with NOT over AND, OR, or NOT, was written as (A) # OR (B), which drops B, or as not A; B; it is now a rule with one body per disjunct of its disjunctive normal form, with NOT pushed to the comparisons. Further, all_violations of main.rego assigned msg once per contract, which OPA rejects for two or more contracts, and is now one rule per contract; and a function call that Rego does not have was written as is (a bare name for a call without arguments, unsafe in OPA, as in all_routes_conflict_free()), and is now a value of the input that the host gives: input.NAME without arguments, input.calls["TEXT"] with them (count, sum, max, min, and abs stay Rego functions). A value that the host does not give leaves a guarantee unsatisfied (a violation) and makes an assumption fail (no violation, nothing allowed); a negation never holds on a missing value.

Environment values (environment.X) appear in ctx.parameters and in main.rego; the Solidity code has no such values.

D.2 Two-tier generator layout​

The reference implementation splits codegen into two tiers, reflecting whether the output is code that enforces or executes the contracts or a configuration for a simulator:

src/cadl/
├── codegen/ ← code tier (cadl codegen)
│ ├── *_gen.py ← Python runtime package
│ ├── solidity/ ← smart-contract enforcement of contracts
│ ├── opa/ ← policy enforcement (Rego) of contracts
│ └── unity_csharp/ ← Unity C# lifecycle / monitor runtime
└── sim/ ← simulator tier (cadl sim-gen)
├── ir.py ← three-layer simulator IR
├── gen_unity.py
├── gen_go.py
└── gen_python.py

A single CADL source file MAY declare targets from both tiers in one codegen: block. The processor SHOULD dispatch each target to its tier independently.

D.3 Selection guidance​

  • Pick unity when the experiment is a multi-agent simulation with graphical inspection, and unity-csharp when contract lifecycles and monitors (Appendix E) are to run inside that simulation.
  • Pick python when you want an executable runtime skeleton of the actors, contract monitors, and protocols, or when the norms of Appendix F are to be monitored while the system runs; ros2 is reserved for driving actual robots and is not implemented in cadl 0.3.
  • Pick solidity when the Institution-layer contracts must be enforced on-chain (blockchain deployment).
  • Pick opa when contracts should be enforced as policies at API / service boundaries (policy-as-code).

Multiple targets in one file are permitted but the resulting artifacts are independent — the CADL toolchain does not guarantee runtime interoperability between, e.g., a Unity simulator config and a Solidity contract generated from the same source.

D.4 Conformance​

A processor is codegen-core-conforming if it supports at least one target from each tier (for example unity together with solidity or opa).

A processor that cannot emit a requested target MUST report a clear diagnostic (for example, "codegen target ros2 is not supported by this processor") rather than silently skipping it.

D.5 Norms monitors of the opa and solidity targets​

For a file that declares norms: 0.1, the opa and solidity targets of the reference implementation emit, from cadl 0.3.25, one monitor of the norms per contract next to the contract policy: opa the Rego package cadl.norms_monitor.<contract> in norms_monitor_<contract>.rego, and solidity the contract <Contract>NormsMonitor in <Contract>NormsMonitor.sol. A monitor evaluates the norms: and counts_as: blocks and the assume: and guarantee: items of one contract instance, including the items with temporal operators, which the contract policy leaves out. One observation is processed in the order of F.5, as cadl norms-eval processes it.

Supported constructs. Both monitors evaluate message events (with the actor patterns of F.3 and arguments), institutional events, predicates with the three-valued reading of F.5 (comparisons, IN, AND, OR, NOT, arithmetic, quantities with and without an actor, fields of request, now, state), triggers, until:, deadlines, reparations, the effects of powers, counts-as rules with if:, and the temporal operators of F.4, also nested. They do not evaluate quantifiers, aggregates, wildcard or range references in predicates, an index that is an expression (A[i+1]), or amendments (F.6). A contract that uses one of these in a norm, a counts-as rule, or an assume: item gets no monitor, and the processor reports which construct prevents it; such a guarantee: item, on which no other verdict depends, is left out of the monitor with a warning. Both compute exactly (F.5): the Rego monitor with decimal numbers, so it refuses /, whose result is not always one. The Solidity monitor uses fixed-point numbers with six decimals and therefore also refuses *, /, and literals with more than six decimals; outside the content of a norm it scans the window of a temporal operator once, as the observations arrive, and therefore refuses there a temporal operator inside another one; in the content of a norm it refused, before cadl 0.3.32, six or more temporal operators (five or more before 0.3.31) and the temporal operators inside another one whose values are not decided in the order of the observations, which from 0.3.32 it decides per observation (see below); and it refuses a contract whose creation code would exceed the 49152 bytes of EIP-3860 or whose runtime code would exceed the 24576 bytes of EIP-170 (cadl codegen estimates both sizes from above). In a guarantee: item these lead to the item being left out, as above. An observation with amend is refused at run time.

Regimes. From cadl 0.3.36 the monitor of a contract that some regime of regimes: does not have in force follows the current regime (A.7.1) as the norms monitor of the python target does (F.5, "Contracts not in force"). Before the first regime is named the run is in the initial regime. At an observation of a regime that does not have the contract in force the monitor reports no change and no deadline, the values of the observation are seen from the next observation in force, its messages are not seen, and the clock of the contract stops: deadlines and the intervals of the temporal operators run on that clock, the time of the trace without the time not in force. now, next_deadline, and every reported time are times of the trace. An instance that ends at such an observation (end, a terminal state, or the end of the instance after it) is settled there on the stopped clock, with nothing else of the observation applied.

  • Rego: an observation may have the key regime, a regime of the file. The state that the host stores has the format cadl-norms-monitor-regimes/1 and holds the current regime, the clock (offset, the time not in force so far, and out_since), the values and the lifecycle state given while the contract was not in force, and the state of the core monitor; the host passes nothing but the observations, so the stateless policy keeps the stopped clock in this state. The result also has in_force. The file is the library of the core monitor with five lines changed (the time of the core is the clock, given as input.clock; now reads the time of the trace; the lifecycle state given while not in force is the state before the first observation in force; its result becomes core_result), followed by the part that reads the regime.
  • Solidity: the monitor derives from CadlNormsMonitorRegimes. Its constructor takes the reporter and the orchestrator (the deployer when zero); setRegime(name), which only the orchestrator may call and which refuses a name that is not a regime of the file, makes the regime current from the next observation on, as the key regime of a trace. inForce(), regime(), and lastTraceT() read the state; lastT() is the clock at the last observation in force. The events carry times of the trace. The regime part adds about 3 kB to the runtime code of the monitor (19.6 kB for the example of the robot delivery with solc 0.8.24 and 0.8.37), and the estimate of the creation code includes it.

The monitors are compared with the norms monitor of the python target after every observation on random traces with regimes in the tests of cadl 0.3.36: 300 traces with OPA and 12 on an EVM with the default counts, and 600 with OPA and 600 on an EVM in a longer run (CADL_REGIME_TARGET_TRACES=300), without a difference. In cadl 0.3.33 to 0.3.35 such a contract got no monitor; up to 0.3.32 the monitor was generated and judged every observation. For a contract that every regime has in force the monitor is the same as without regimes:, since no norm, counts-as rule, or item reads a parameter. A trace that names a regime cannot amend the contract, as in cadl norms-eval.

Versions. Neither monitor applies amendments (F.6). From cadl 0.3.34, in a file that declares amendment: 0.1 and names the version it replaces (previous:), and from 0.3.35 also in one that gives no previous: and an effective time other than period: 1 (such a file may be a later version of its run, K.11, "The versions of a run"; this is a conservative test on one file, not the definition of a first version, see K.11, "Generated code"), a contract whose running instances switch to this version (switch, also by default) gets no monitor, with a warning, since the monitor could not take over an instance that started under the old version (Appendix K, K.11). For a contract whose instances keep their version the monitor is generated; it serves the instances that start under this version.

From cadl 0.3.36 the Rego monitor generated with the other versions of the run (cadl codegen -t opa FILE --version OTHER ...) contains the contract of every version (the models and the predicates of each) and follows the version in force that an observation names with the key version; the caller computes it from the effective times. The instance follows the version in force at its first observation; a version that takes effect applies the transitional rule of the contract in it, and a switch applies the amendment of F.6 as cadl norms-eval does: an instance in force is carried over with its elapsed time (and its pending candidates when the content is the same), discharged, or transformed; it is violated or fulfilled when its new deadline has passed; a new norm without trigger is activated; an item of the same text continues, a new one is evaluated from the amendment on, and an undecided one is closed. Norms and items that a version no longer has stay at the end of the result, and an instance kept from an earlier version still makes acts with the content of its power. The changes are reported as the Python monitor reports them (a new norm has no previous state, a removed one no state). The state format is cadl-norms-monitor-versions/1. A version that names no version of the run is refused also after the end of the instance, as cadl norms-eval refuses it on any line (also with regimes, below). With versions the Rego monitor refuses a version with a guarantee: item that it leaves out. It is compared with the norms monitor of the Python target with run_versions after every observation: 900 random traces of 70 random runs of two or three versions in the tests of cadl 0.3.36, without a difference.

When a version of the run binds regimes (regimes:), the Rego monitor with versions also applies K.11, "Versions and regimes" (from cadl 0.3.36; the combination was refused before). An observation may name the current regime with the key regime and the version in force with the key version; at an observation the regime becomes current first, then the versions take effect. Before the first regime the run is in the initial regime of the version in force at its first observation. The contract is in force by the bindings of the version in force. A regime current at some observation must be a regime of every version in force at some observation (a version without regimes: has only the run in no regime); otherwise the observation is refused. The instance starts at the first observation at which the contract is in force, or at which it ends, under the version in force there. While the contract is not in force the instance sees nothing and its clock stops, as for a file with regimes above; a version that takes effect then reaches the instance (its transitional rule is applied on the lifecycle state that the instance saw last), and the amendment is applied at the next observation in force, or at the end of the instance on the stopped clock, before anything else; a norm it violates at the end is reported without reparation or transition. An observation with amend is refused, as in cadl norms-eval. The state format is cadl-norms-monitor-regimes-versions/1. It is compared with the norms monitor of the Python target with run_versions after every observation: 3600 random traces of 300 random runs of two or three versions whose regimes take the contract out of force (1633 traces with an observation out of force, 502 that switch, 385 that both refuse), in the tests of cadl 0.3.36, without a difference.

From cadl 0.3.36 the Solidity monitor generated with the other versions of the run (cadl codegen -t solidity FILE --version OTHER ...) derives from CadlNormsMonitorVersions and contains the definitions of the contract in every version, one after the other. The instance has its own list of norm instances, each with the definition it follows, and its own list of assume: and guarantee: items, each with its definition, the observation at which it starts and its identity. The temporal content of a norm keeps its candidates in a slot that the definitions of the norm with the same content share across the versions, so a carried instance keeps its pending candidates as F.6 says. The constructor takes the reporter and the orchestrator; the orchestrator calls setVersion(name) before the observation at which the version takes effect, and the first version is in force before the first call. setVersion reverts for a name that is not a version of the run and, until the instance has ended, for a version before the one in force at the last observation. The transitional rules and the amendment of F.6 are applied as in the Rego monitor, before step 1 of the observation; the norms that the amendment violates come first in step 5. normIds() and verdicts() follow the norms and items of the instance (those that the version no longer has at the end), NormChanged reports a norm new in the version with the previous state and verdict 255 and a norm that the version removes with the state and verdict 255, and version() gives the version in force and the version the instance follows. The library CadlNormsVersions is deployed and linked after CadlNormsActs. When a version of the run binds regimes (regimes:), the monitor derives from CadlNormsMonitorRegimesVersions and applies K.11, "Versions and regimes": the orchestrator also sets the regime with setRegime; at an observation the regime becomes current first, then the versions take effect; the contract is in force by the bindings of the version in force, and before the first setRegime the run is in the initial regime of the version in force at its first observation; a regime current at some observation must be a regime of every version that has been in force at some observation, and the monitor refuses (reverts) otherwise. While the contract is not in force its clock stops as above; a version that takes effect then reaches the instance (a waiting switch is judged on the lifecycle state that the instance saw last), and the amendment is applied at the next observation in force or at the end of the instance, before anything else; a norm it violates at the end is reported without reparation or transition. With versions the Solidity monitor refuses a guarantee: item that it leaves out; versions whose lifecycles (states, initial and terminal states) or declared actors differ, since it keeps one lifecycle and one declaration of the actors; and a norm whose content has the same text in two versions but that it reads differently in them, since F.6 keeps the pending candidates of such a content. Its runtime code is 19.3 kB with versions and 23.9 kB with versions and regimes, and that of CadlNormsVersions 13.2 kB, with solc 0.8.24 and 0.8.37 (EIP-170 allows 24 576 bytes). The creation code grows with the versions: for the robot delivery example about 33 kB with two versions and 37 kB with three, and 42 to 43 kB with three versions and regimes (EIP-3860 allows 49 152 bytes; a monitor whose estimated creation code is above that limit is refused); deploying the largest takes about 24 million gas. It is compared with the norms monitor of the Python target with run_versions after every observation on an EVM: with versions, 240 random traces of 20 random runs of two or three versions with random assume: and guarantee: items (1330 observations); with versions and regimes, 372 random traces of 32 random runs whose regimes take the contract out of force (1895 observations, 204 traces with an observation out of force), in the tests of cadl 0.3.36, without a difference.

The Rego monitor. The Rego monitor is a step function. OPA keeps no state, so the policy computes the next state of the monitor from the previous state and one observation; the host stores the state between calls. The rule result takes as input:

KeyMeaning
stateThe state returned by the previous step; null or absent before the first observation
observationOne observation in the trace format of cadl norms-eval (t, values, messages, state, end; bindings and request only in the first)
finishtrue instead of an observation: the instance ends at its last observation (step 6 of F.5)
bindings, requestBindings and request of the instance, when the first observation does not carry them
quantitiesNames of quantities written without an actor, added to the known names (F.5)

result has state (the next state), changes (each norm instance whose state or verdict changed, with the previous ones, and each item that was decided), violations, institutional_events, powers_exercised, unauthorised, verdicts (the state and verdict of every norm, the status of every assumption, the verdict of every guarantee, and ok), ended, and next_deadline (the earliest deadline of an active obligation or prohibition). For an observation that is malformed, result has error and the unchanged state. The state is a JSON object with these keys:

KeyContent
format"cadl-norms-monitor-state/1"
contractId of the contract; a state of another contract is refused
nNumber of observations of the instance processed so far
tTime of the last observation, also of one after the end
ended, end_indexWhether the instance has ended, and at which observation
ignoredNumber of observations after the end (they have no effect)
bindings, requestAs given with the first observation
knownThe known names of quantities (F.5), sorted
valuesThe current value of every quantity observed so far
lcThe lifecycle state after the last observation (null without lifecycle:)
bufferThe observations that are still read: i (index in the instance), t, values (the values at it), st (the lifecycle state before it). It holds the last observation, the observations from the oldest candidate of a norm whose temporal content is not yet decided, and, while a temporal item is not decided, all observations from the first. Older observations are dropped
normsOne record per norm, in the order of the contract: id, state, verdict, at and act (time and index of the first activation), since and before (start of the current active stretch and the active time before it, for the deadline), from (the first observation at which a reparation is judged), cands (indices of the observations at which a temporal content is not yet decided)
itemsassume and guarantee: per item value (null, true, false, or "undefined"), seen (a state predicate held at some observation), verdict, time
failed_atTime at which the first assumption failed, or null

The Solidity monitor. The Solidity monitor is a contract that keeps the state of one contract instance. Its constructor takes the address of the reporter (the deployer when it is the zero address, reporter()); only the reporter may call begin, observe, addQuantities, and finish. The reporter cannot be changed: if its key is lost, the monitor stays as it is and records no further observation. begin(bindings, request, quantities) may be called before the first observation, observe(t, values, messages, hasState, state, end) records one observation, addQuantities(names) adds names of quantities written without an actor, and finish() ends the instance at its last observation. verdicts() returns the states and verdicts of the norms and the marks of the items, in the order of normIds(); contractId(), ok(), nextDeadline(), observations(), lastT() (the time of the last observation, also of one after the end), ended(), and ignored() (the number of observations after the end) can be read, and the events NormChanged, ItemChanged, Violation, InstitutionalEvent, PowerExercised, and Unauthorised report the changes of each call. A value is a tuple of a name, a kind (null, boolean, number, string), a number, and a string; numbers, including the time, are fixed-point numbers times 106. The time is an argument of observe so that a trace can be replayed and tested; a deployment MAY pass block.timestamp times 106. A malformed observation reverts, which leaves the state as it was. The contract stores the model of the CADL contract as data, filled in by its constructor, and interprets it. The model and the state are one struct in storage, which six libraries read and change: they hold the evaluation of predicates, the functions without state, the judgement of contents with one temporal operator, that of contents with two to five or with one inside another (and, from cadl 0.3.32, of the contents decided per observation), the items, and the events, messages, counts-as rules and powers, so that each runtime code stays within the size limit of EIP-170. From cadl 0.3.28 the runtime code of the contract is estimated at 16 840 bytes, which leaves more than 7 × 103 bytes below that limit (24 410 in 0.3.27); from cadl 0.3.30, without the frozen flag of a norm, which the engine no longer needs (F.7, N-16), it is estimated at 16 670 bytes, and CadlNormsActs at 12 080 bytes (12 170 before). From cadl 0.3.29 the libraries CadlNormsMulti and CadlNormsEval are estimated at 7 490 and 10 410 bytes (4 430 and 10 310 in 0.3.28). From cadl 0.3.31, which keeps the values of a content with five temporal operators in four words and treats a nested operator as a chain of levels, CadlNormsMulti, CadlNormsEval and CadlNormsWindows are estimated at 10 120, 11 440 and 5 490 bytes (7 490, 10 410 and 5 230 in 0.3.30). From cadl 0.3.32, which adds the contents decided per observation to CadlNormsMulti, it, CadlNormsEval, CadlNormsActs and the contract are estimated at 16 270, 11 550, 12 200 and 17 250 bytes (10 120, 11 440, 12 080 and 16 670 in 0.3.31). The size of the code does not depend on the number of temporal operators or of levels. The cost of an observation does not grow with the number of earlier observations: the window of a temporal operator is scanned once (each observation adds its own value to the scans that are open), a value is found by binary search, and the values that no later step can read are deleted, a few per new value.

One temporal operator. The content of a norm with one temporal operator is decided, at the observation of a candidate, up to that operator: the rest of the content has its value there (its names are fixed, see the differences below), so the content is a function of the value of the operator, and the monitor reads it there with the operator undecided, true, and false. The content is then true whatever the operator gives (the candidate holds at once), never true (no candidate), true exactly when the operator is true, true exactly when it is false, true when it is true or false, or never true but undecided until the operator is decided (the candidate keeps the norm pending, as F.5 does). An undefined operator makes the content true only when the content is true with the operator undecided, so these cases are all: a comparison, an arithmetic operation, and the left side of IN are undefined when an operand is, and AND, OR, and NOT give a true or false result for an undefined operand only when they give it for an undecided one. This covers an operator under NOT, inside a comparison (within(3s, p) == flag, until(p, q, 3s) <= A.y), and in IN. A norm keeps three queues of candidates, oldest first: those that hold when the operator is true, those that hold when it is false, and those that only wait for it; a candidate that holds in both cases is in the first two. The second queue reads the dual operator on the negated operands: NOT within(d, p) is throughout(d, NOT p), NOT throughout(d, p) is within(d, NOT p), and NOT until(p, q, d) is the release below. Each queue keeps, with what the observations since its last judgement say about the operands: for within, the first time the operand is true; for throughout, the first time it is false and the first time it is undefined; for until, the first observation at which q is true and the first at which p is not; for the release, these two, the first observation at which q is not false, and the first at which p is false. Together with the last candidate whose window has seen an operand that rules it out, these decide every candidate by comparing times (for throughout, the newest candidate whose window ended before the first false or undefined value holds), with a few binary searches over the queue and without scanning a window per candidate; this holds also while the norm is suspended. Decided candidates are deleted a few per observation.

Release. Write the values of a predicate at an observation in the three values of F.5 (true, false, undefined) with the connectives of Kleene, and let W be the observations of the window of candidate k. By F.4, until(p, q, d) at k is

∨j ∈ W ( qj ∧ ∧k ≤ i < j pi ),

decided at the first observation at which a term is true, at the first at which p is false (every later term is false), or when the window is over, and undecided before. The negation of Kleene is an involution and satisfies the laws of De Morgan, so

NOT until(p, q, d) = ∧j ∈ W ( ¬qj ∨ ∨k ≤ i < j ¬pi ),

the release of ¬p and ¬q: ¬q holds at every observation of the window up to and including the first at which ¬p holds. NOT keeps an undecided value undecided and turns a decided value into its negation, so the release is decided at the same observations as until. It is true exactly when every term is false. Let b be the first observation of W at which p is false, or the last of W when there is none. A term with j after b is false through pb. A term with j at or before b has no false pi, so it is false exactly when qj is false. Hence the release is true exactly when q is false at every observation of W up to b, and it is false or undefined otherwise; with undefined values this is the same statement, since a term with an undefined qj and no false pi is not false. The queue of the release therefore holds a candidate when p is false inside its window with q false before and at that observation, or when its window is over with q false in it; it removes every candidate when p is false (each window is then decided), the candidates for which until becomes true (q true with p true since the candidate), and those whose window is over; a candidate that has seen q not false is kept, undecided, until it is decided in one of these ways.

Several temporal operators. For a content with m temporal operators, 2 ≤ m ≤ 5 (m ≤ 4 before cadl 0.3.31), the monitor reads the content once at the observation of a candidate and obtains its value for each of the 4m combinations of values of the operators (undecided, true, false, undefined), as bits of one 256-bit word for m ≤ 4 and of four words for m = 5 (combination c is bit c mod 256 of word ⌊c / 256⌋); this covers a comparison of two operators (within(…) == throughout(…)). An IN with temporal operators in its operands is read once for each combination, at most 45 = 1024 times, a bounded cost. An observation decides an operator for a range of candidates at a time: the candidates whose window is over become false (throughout: true), or undefined when an operand was undefined in the window; an operand true for within, false for throughout, or p false for until decides every open window; q true for until decides the candidates with p true since them. Binary searches over the candidates find these ranges. The candidates are the leaves of a segment tree in storage. A node gives each operator a state: decided, or undecided and taking one of the four values in the future considered. For each of the 5m combinations of states it records whether a candidate below holds in that future and whether one is undecided in it. A decided operator leaves no value in the node: its value is already part of the values of the content that the candidate keeps for the other operators. The 2 × 5m bits fit in one word for m ≤ 3 (250 bits, with 6 bits for the tags of the lazy propagation), in five words for m = 4 and in 25 for m = 5 (the states of the fourth and fifth operators select the word). Deciding operator i to the value v moves the combinations in which i is undecided and takes v to those in which it is decided, and drops the other combinations in which it is undecided: for the first three operators a shift and a mask of each word, for the fourth and fifth an OR of words. This is propagated lazily, so an observation changes a few ranges per operator, each in steps that grow with the logarithm of the number of candidates, and the root says whether a candidate holds and whether one is undecided. The cost of an observation therefore does not grow with the number of observations for any m ≤ 5, and it grows with m by a factor measured below. The tree does not take six or more temporal operators in one content: a node would have 125 words, and an observation, which costs up to 1.0 × 107 gas with five operators in the measurements below, would cost about five times as much, of the order of the gas limit of a block. Up to cadl 0.3.31 such a content was refused; from 0.3.32 it is decided per observation (below). (Up to cadl 0.3.28 a node kept the values of the decided operators too, 7m pairs, which allowed two operators in one word; up to 0.3.30 five operators were refused, since their 45 values do not fit in one word.)

A temporal operator inside another one. In the content of a norm, the operand of within(d, …) or throughout(d, …) may be another within(e, …) or throughout(e, …), or its negation, whose operand is either without a temporal operator (within(5s, throughout(2s, p)), throughout(3s, NOT within(1s, p))) or, from cadl 0.3.31, again such an operator (within(5s, throughout(3s, NOT within(1s, p))), with any number of levels). Call the operators below the outer one the levels of the chain: the first level reads p, each further level reads the values of the level below it (negated when NOT stands between them), and the outer operator reads the values of the last level. The value of a level at an observation j is known only later; the level above reads the sequence of these values, each with the time tj of its observation. The monitor decides every level for every observation from the first candidate of the activation on, with a summary per level, and feeds the decided values of each level to the level above, and those of the last level to the outer operator, in the order of the observations and in runs of equal values; the outer operator is one operator of the segment tree above. For a level with operator O and duration e, call O's decisive value (true for within, false for throughout) decisive and the other truth value final; for one observation n, let G be the first observation whose value below is not fed after n (n + 1 for the first level, which reads p at every observation), F the first observation whose own value was not decided at n − 1, and u the last observation with an undefined value fed before n.

  1. If the values fed to a level are decided for a prefix of the observations at every n, so are its own values. Let the value of observation j be decided at n and i < j. If it is decisive by a decisive value at an observation x of the window of j, either x is in the window of i, which decides i, or the window of i ended before tx ≤ tn, and every value of it is fed since x is, which decides i. If it is decided because the window of j is over and every value in it is fed, the same holds for the window of i, which ends no later. p is decided at every observation, so by induction the decided values of every level are those of the first observations.
  2. Let the runs fed at n cover the observations up to G − 1, with their own values. Let τ be tG when G ≤ n and tn otherwise. An observation j ≥ F is decided at n exactly when a decisive value fed at n is in its window, that is j is in [a, e] for a run [s, e] of decisive values, with a the first observation at or after ts − e (a binary search over the times), or when tj + e < τ: then every value of its window is fed and the window is over. No decisive value fed before n is in the window of such a j, as it would have decided j then. A decided value is decisive when a decisive value is in its window; otherwise it is undefined when an undefined value is in its window, and final otherwise. An undefined value fed before n is in the window of j ≥ F exactly when j ≤ u, since the window of an observation not decided at n − 1 reaches at least Gn−1 − 1 ≥ u, and one fed at n is in it exactly when j is in [a, e] for a run [s, e] of undefined values. By 1 the decided observations are those before the largest of F, the first observation with tj + e ≥ τ, and e + 1 for the runs of decisive values. The value changes only at some a, e + 1, or u + 1; the summary keeps F and u only. At every observation the runs fed to a level, and to the outer operator, have all their undefined runs before every true or false run: the window of an observation not decided at n − 1 reaches Gn−1 − 1, and if j1 < j2 are decided at n with j1 true or false and j2 undefined, the value that decides j1 lies in the window of j2 too (by induction over the levels, starting from the one run of p). Hence a level gives at most three runs: undefined, final, and decisive, in this order, at any depth, and the gas per level does not depend on the depth. The first level receives one run, the value of p at n, and gives undefined up to u, final, and decisive from a when p is decisive at n.
  3. The outer operator (duration d) treats its candidates in the same way. A run [s, e] of decisive values decides the candidates k ≤ e with tk + d ≥ ts. Then, with τ as in 2 for the last level, a candidate with tk + d < τ that is not decided becomes undefined when it is at or before u or in such a range of a run of undefined values, and final otherwise. The decisive runs are applied first, so a candidate whose window has a decisive and an undefined value is decisive. The candidates whose window holds an undefined value and is not over keep the mark u.
  4. These are the values of F.5 at every observation. By 1 the values that F.5 reads in the window of candidate k at n are decided exactly when they are fed, so a decisive value decides k at the same observation, and to the same value. Without one, F.5 gives undecided while the window is not over or holds an undecided value. If G ≤ n, the value at G is undecided: when k ≤ G and tG ≤ tk + d it is in the window of k; when tG > tk + d every value of the window is fed and the window is over, since tn ≥ tG; when k > G, the value at k is undecided by 1 and k is in its own window, while tG ≤ tk leaves the window of k open in 3. If G = n + 1, every value is fed and τ = tn. In each case the monitor decides k at the observation at which F.5 does, from the same values, and so to the same value; the same argument with 2 in place of 3 shows it for each level.

An observation evaluates p once and, per level, makes one binary search over the times and one per run fed, and feeds a bounded number of runs to the outer operator, each with a few binary searches and range updates of the tree, so its cost is bounded as above for any fixed chain. The tree does not take until in a nesting, nor an operand of a level or of the outer operator that is more than another level or its negation (within(5s, throughout(2s, p) AND r)). In them a value of the operand can be decided before that of an earlier observation, and feeding the values in order would decide later than F.5. In within(5s, until(p, q, 3s)), with p undefined and q false at t = 0 and p and q true at t = 1, the inner value at t = 1 is true at once, so the outer operator at t = 0 is true at t = 1 in F.5, while the inner value at t = 0 stays undecided until its window ends after t = 3. In within(d, throughout(e, p) AND r) a false r decides the operand at once. For such an operand, deciding the values out of order would not keep the cost of the tree bounded: after a gap in the times, one observation decides the inner values of all observations of a long stretch at once, and the operand is then true exactly at those with r true, so the candidates whose window holds such an observation become true and the others stay as they were, which can alternate from one candidate to the next as often as there are candidates; one observation would change that many ranges of the tree. Up to cadl 0.3.31 these contents were refused; from 0.3.32 they are decided per observation (below).

Contents decided per observation. From cadl 0.3.32 the Solidity monitor decides the contents that the tree does not take: six or more temporal operators in one content, until in a nesting (inside within or throughout, or with a temporal operator in an operand of until, until(p, within(2s, q), 3s)), and an operand of within or throughout that combines a nested operator with other parts. From the first candidate of an activation on, each temporal operator of such a content keeps, for every observation y, the value of F.5 (undecided, true, false, undefined) of each of its operands at y and its own value at y, two bits each, 128 to a storage word; an observation treats the operators directly inside an operand before the operator. A value once decided is kept, as in F.5, where it does not change with later observations. The operand of an operator at y is read with the values at y of the operators directly inside it. Let W = [y, e] be the window of y among the observations up to n (those from y on with a time at most ty + d), and call it over when an observation up to n has a later time. The value of within(d, p) at y is then true when p is true at an observation of W; otherwise undecided when W is not over or p is undecided at an observation of W; otherwise undefined when p is undefined at one, and false otherwise (throughout exchanges true and false). For until(p, q, d), let b be the first observation of W at which p is false, R = [y, b] (R = W without one), and g the first observation of R at which p is undecided or undefined. The value is true when q is true at an observation of [y, g] (of R without g); otherwise undecided when there is no b and W is not over; otherwise undecided when q is undecided at an observation of R, or true or undefined at one after an observation of R at which p is undecided; otherwise undefined when q is undefined at an observation of R, or true at one after an observation at which p is undefined; and false otherwise. These are the results of the scan of F.4 over W, which cadl norms-eval performs, and each condition is a search for the first observation with given values over the words of W.

The value at y depends only on the operand values in W and on whether W is over. An observation n therefore reads again: the operands at n and at the observations at which it decided a value of an operator directly inside them; the windows that n ends, a range of observations found by binary search; and, of the windows that hold an operand value decided at n, those that this value can decide. For within and throughout, a decisive operand value at x decides every undecided window that holds it (y ≤ x with ty ≥ tx − d). Another value cannot decide a window that is not over, which stays undecided until a decisive value or its end. A window that is over and stays undecided waits for its last undecided operand value: it is read again when that value is decided, and then waits for the next one if another remains. For until, the operand values at n decide a window that holds n only when p is false at n, after which no term of the window can be true, or q is true at n, which makes the windows with p true since them true. The operand values decided at n after their own observation make the windows that hold them read again, once per observation: the undecided windows from the first that holds such a value to the last such value. A window that waits is taken from its list before any window of the list is read again, so that a window that waits again does not change the list being read. The content is read again at the candidates at which an operator of the content was decided; a true candidate decides the norm, and one that is undecided keeps it pending, as with the tree. Each read gives the value of F.5 by the conditions above, and every event that can change the value at y (a new operand value in W, the end of W) leads to a read of y, so the monitor decides every value at the observation at which F.5 decides it, and to the same value.

Every value is decided once, and besides binary searches over the times an observation reads only observations from the oldest undecided window or candidate on, so its gas does not grow with the number of earlier observations, except for the logarithm in these searches. It grows linearly with the number of temporal operators (no node of 5m combinations), and it can grow with the number of observations inside a window: after a gap in the times one observation can decide the values of a whole window, and for until the operand values decided after their observation make the windows that hold them read again. Each window that an observation reads again costs a few searches over the words of the window and a binary search over the times, so an observation costs at most in proportion to the observations of the windows that it decides or reads again. Measured at one observation per second: in until(throughout(60s, p), within(60s, q), 60s) the observation at the 60th second makes p false at all 61 observations of the windows at once and costs 4.0 × 106 gas, with windows of 120 s 7.6 × 106, about 6 × 104 per observation of a window. In a content of six within(10s, …) joined by OR, with an observation every 0.01 s and then one at t = 100 that ends every window, that observation costs 6.7 × 106 gas after 50 observations and 2.2 × 107 after 150; about 200 reach the gas limit of a block in the tests (3 × 107), and the monitor then cannot record that observation. cadl codegen does not refuse such a content, since the bound depends on the trace: a deployment should bound the number of observations inside a window (the rate of observations times the longest duration of the content). Whether these contents can be monitored with a gas that does not grow with the number of observations inside a window is left open. The values are not deleted: two bits per operand and per operator for each observation from the first candidate of an activation on, and two storage slots for each window that waits; the values of the quantities that the operands read are kept from the first observation whose operand or candidate is undecided. The code does not depend on the content; what limits the size of a content is the creation of the monitor. Its constructor stores the model, about 5.5 × 105 gas per operator of the form within(1s, A.x > k): 7.4 × 106 gas for 6 such operators, 1.7 × 107 for 24, and 3.1 × 107 for 48, above the gas limit of a block in the tests (3 × 107); the creation code then has 21 646, 30 688, and 42 760 bytes, and cadl codegen refuses a monitor whose estimated creation code exceeds the limit of EIP-3860, as for every content. The contents that the tree takes are decided by the tree as before, whose gas does not grow with the observations inside a window.

The tree is not pruned: each activation of such a norm adds at least three storage slots per candidate (its observation, its time, its leaf, and the inner nodes above it), which stay in storage; the gas of an observation does not grow with them. Every monitor also keeps two entries per observation (its time and the lifecycle state before it), which are not deleted either.

Gas. The figures below are measured with one value per observation; with two values an observation costs about 20 % more. In the tests, an observation of the example of F.8 costs about 6.4 × 105 gas over 320 observations at one per second while the 300-second window of its assumption is open and after it (at most 1.2 × 106, at the first observation). At one observation per second into windows of 1000 seconds in which every candidate stays undecided, an observation costs, at the 320th and at the 1000th observation, 4.4 × 105 and 4.5 × 105 gas for the content throughout(1000s, …), 5.2 × 105 for NOT until(…, 1000s), 5.1 × 105 for throughout(1000s, …) == true, and 5.9 × 105 for within(1000s, …) OR throughout(1000s, …) (at most 8.0 × 105); from cadl 0.3.29 the last content costs 6.1 × 105 and 6.2 × 105, with a third operator (… OR within(1000s, …)) 8.4 × 105 and 8.5 × 105 (at most 1.1 × 106), with a fourth 1.8 × 106 and 1.9 × 106 (at most 2.6 × 106; the factors over two operators are about 1.4 for three and 3.0 for four, from the five words of a node), and the nested contents within(1000s, throughout(500s, …)) and throughout(1000s, within(10s, …)) 4.9 × 105 and 5.0 × 105, and 6.0 × 105 and 6.3 × 105 (at most 8.3 × 105; the inner values of the second are decided from the eleventh second on, and each then decides the candidates of its window false). From cadl 0.3.31, with the levels, these two nested contents cost 5.1 × 105 and 5.2 × 105, and 6.2 × 105 and 6.5 × 105 (at most 8.5 × 105), three levels (within(1000s, throughout(500s, within(10s, …)))) 5.5 × 105 and 5.6 × 105 (at most 7.6 × 105), four operators 1.9 × 106 and 2.0 × 106 (at most 2.8 × 106), and five operators (… OR within(1000s, …)) 6.7 × 106 and 6.9 × 106 (at most 1.0 × 107; the factor over four is about 3.5, from the 25 words of a node). From cadl 0.3.32 the contents decided per observation cost, at the 320th and at the 1000th observation, 5.4 × 105 and 6.4 × 105 gas for within(1000s, throughout(500s, …) AND …) (with an operand that stays false), 5.3 × 105 and 6.8 × 105 for within(1000s, until(…, …, 500s)) (both rise once, when the inner windows end from the 500th second on, and then stay there), and 9.8 × 105 and 9.9 × 105 for six operators (at most 1.3 × 106; five operators in the tree cost 6.7 × 106); twelve operators cost 1.6 × 106 at the 120th observation. For within(100s, NOT throughout(50s, …) OR …), whose windows end before the values inside them are decided and then wait, an observation costs 5.4 × 105 gas before the 100th second and 7.4 × 105 from the 150th on. cadl 0.3.25 read every candidate at every observation and used 1.3 × 107 gas at the 320th. A monitor whose observation would exceed the block gas limit cannot record it and does not recover, so the bound matters. The generated file is to be compiled with solc 0.8.24 to 0.8.37 (checked; its pragma is >=0.8.24 <=0.8.37) and --optimize --optimize-runs 1, as its header says: without the optimizer the runtime code exceeds the limit of EIP-170, and the estimates of the creation code and of the runtime code hold for the optimizer with 1 or 200 runs.

Differences from cadl norms-eval. The monitors decide each observation with the observations received so far, as the Python monitor does: a passed deadline is detected at the next observation, the instance ends with finish or with an observation that ends it, and the names of quantities written without an actor are those given with quantities (or addQuantities) and those observed so far. Where they differ from cadl norms-eval (which this appendix does not change):

  • Numbers and times are exact in both monitors, as in cadl norms-eval (F.5). The Rego monitor reads a number as the decimal it is written as and keeps numbers and times in its state as {"$q": [n, k]}, the number n / 10k; it refuses / (a quotient is not always a decimal number), and a product whose exact value could have more than 4095 decimals (every number has at most 400, F.5). Both monitors, like cadl norms-eval, refuse a number outside the range of F.5 in an observation, its request or its bindings. The Solidity monitor holds six decimals and refuses *, /, and literals with more decimals; its host passes numbers with at most six decimals. For the inputs that meet these limits, the verdicts agree with cadl norms-eval. The results of the Rego monitor write times as JSON numbers for reference.
  • The monitors refuse inputs that cadl norms-eval accepts: a binding that is not an integer written as one (1.0 and 1e2 are refused) or a string, a value of values that is a list or an object (in Rego a list anywhere in request too), in Rego two keys of values that differ only in whitespace, and an observation with amend. The Solidity monitor takes the request as leaves ("a.b"), the names of values in ASCII, and the actors and names of messages in ASCII letters, digits, and _. It receives bindings as integers or strings, so its host refuses a binding written with a fraction or an exponent.
  • In Solidity, a bare name read inside a temporal operator (a quantity such as flag in throughout(10s, A.s == flag), as opposed to a symbol) must be given in begin (or addQuantities before the first observation) when it is a quantity, or be observed at the first observation; a name that is a binding is not affected: the scans keep the values they have read, so an observe or addQuantities that would make such a name known later is refused (it reverts). cadl norms-eval and the Rego monitor read the earlier observations again with the new name.
  • The Rego monitor trusts the state it is given: it checks the format and the contract of the state, not its content. The host keeps the states it stores intact and passes each one to the next step only.
  • Reasons, warnings, and the timeline of cadl norms-eval are not reported.

Strings of the file. No text of the .cadl file is code in either monitor: the Rego carries the contract as one JSON text and writes the other literals as JSON strings, and the Solidity writes every text as a hex literal. The input check of cadl codegen applies first.

Verification. The reference implementation compares both monitors with cadl norms-eval after every observation: the norm states and verdicts, the item verdicts, the changes, the violations (with severity and sanction), the institutional events, the exercised powers, the unauthorised acts, and the next deadline, on the example traces, the traces of its test suite, random traces, and a long trace. The Rego runs in opa eval, the Solidity on an EVM.

D.6 Cross-reference​