# Calculator protocol

> Sort a Calculator request by the kind of answer it gets. A bad, unknown or too-large request never gets a number back.

Inspired by UOR-Foundation/calculator-example (https://github.com/UOR-Foundation/calculator-example), live at https://uor-foundation.github.io/calculator-example/. The reference PrismPM product: a checked signed 64-bit calculator built into a Pages application and A/B service releases. Pattern: Decision table, OMG DMN 1.5, hit policy FIRST. To write one of your own, follow How to build a decision table app (../../guides/decision-table/index.md). The prompt below is data, quoted from the example.

**Figure: What the Calculator protocol app does.** A request goes in, the rules decide, and the Lean kernel has already proved what the rules promise.

| Step | What happens |
| --- | --- |
| 1. Request | version, operation, right, range |
| 2. 4 rules | the first that matches wins |
| 3. Answer | ok, overflow, division-by-zero, unsupported-version, unknown-operation |
| 4. Proved | 4 theorems, 44 tests |

Verified by prismpm verify in the pinned SDK. Fingerprint: 99611d14491a9b4721580d28ab0cfef79b63876e97c156725227d230eb70acc7. Acceptance vectors: 44. Claims: 7.

## The prompt

```json
{
  "schema": "prism/prompt/1",
  "pattern": "decisionTable",
  "goal": "Sort a Calculator request by the kind of answer it gets. A bad, unknown or too-large request never gets a number back.",
  "repository": "UOR-Foundation/calculator-example",
  "app": {
    "name": "calculator-protocol",
    "title": "Calculator protocol",
    "purpose": "Classify one Calculator protocol request, from its protocol version, its operation, whether the right operand is zero and whether the exact result fits a signed 64-bit integer, as ok or as the typed error the reference product answers.",
    "fields": [
      {
        "name": "version",
        "kind": "number",
        "min": 0,
        "max": 9,
        "means": "the protocol version the request names; the product speaks version 1"
      },
      {
        "name": "operation",
        "kind": "choice",
        "values": [
          "add",
          "subtract",
          "multiply",
          "divide",
          "other"
        ],
        "means": "the operation name; other is any name the protocol does not define, such as mod"
      },
      {
        "name": "right",
        "kind": "choice",
        "values": [
          "zero",
          "nonzero"
        ],
        "means": "whether the right operand is 0"
      },
      {
        "name": "range",
        "kind": "choice",
        "values": [
          "within",
          "beyond"
        ],
        "means": "whether the exact mathematical result lies within the signed 64-bit range"
      }
    ],
    "outcomes": [
      "ok",
      "overflow",
      "division-by-zero",
      "unsupported-version",
      "unknown-operation"
    ],
    "meanings": {
      "ok": "1 ok and the exact result",
      "overflow": "1 error overflow: the CalculatorError Overflow",
      "division-by-zero": "1 error division-by-zero: the CalculatorError DivisionByZero",
      "unsupported-version": "1 error unsupported-version: the ProtocolError UnsupportedVersion",
      "unknown-operation": "1 error unknown-operation: the ProtocolError UnknownOperation"
    },
    "rules": [
      {
        "when": [
          {
            "field": "version",
            "op": "!=",
            "value": 1
          }
        ],
        "then": "unsupported-version",
        "why": "src/Calculator.lex.tex: decodeRequest refuses any version but 1 with ProtocolError UnsupportedVersion (vector 2 add 1 2)"
      },
      {
        "when": [
          {
            "field": "operation",
            "op": "is",
            "value": "other"
          }
        ],
        "then": "unknown-operation",
        "why": "src/Calculator.lex.tex: parseOperation knows only Add, Subtract, Multiply and Divide; anything else is ProtocolError UnknownOperation (vector 1 mod 1 2)"
      },
      {
        "when": [
          {
            "field": "operation",
            "op": "is",
            "value": "divide"
          },
          {
            "field": "right",
            "op": "is",
            "value": "zero"
          }
        ],
        "then": "division-by-zero",
        "why": "src/Calculator.lex.tex: calculate answers CalculatorError DivisionByZero for a zero divisor (vector 1 divide 1 0)"
      },
      {
        "when": [
          {
            "field": "range",
            "op": "is",
            "value": "beyond"
          }
        ],
        "then": "overflow",
        "why": "src/Calculator.lex.tex: checkedResult answers CalculatorError Overflow outside the i64 range (vectors at 9223372036854775807 and -9223372036854775808)"
      }
    ],
    "otherwise": "ok",
    "otherwiseWhy": "src/Calculator.lex.tex: calculate_correct proves the exact result is returned when it is in range",
    "properties": [
      {
        "kind": "never",
        "when": [
          {
            "field": "operation",
            "op": "is",
            "value": "divide"
          },
          {
            "field": "right",
            "op": "is",
            "value": "zero"
          }
        ],
        "then": "ok",
        "why": "a division by zero has no result"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "range",
            "op": "is",
            "value": "beyond"
          }
        ],
        "then": "ok",
        "why": "a result outside i64 is never wrapped or truncated"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "version",
            "op": "!=",
            "value": 1
          }
        ],
        "then": "ok",
        "why": "an unsupported version is never interpreted as version 1"
      },
      {
        "kind": "always",
        "when": [
          {
            "field": "version",
            "op": "=",
            "value": 1
          },
          {
            "field": "operation",
            "op": "is",
            "value": "other"
          }
        ],
        "then": "unknown-operation",
        "why": "an undefined operation is a typed protocol error"
      }
    ],
    "examples": [
      {
        "request": "1 add nonzero within",
        "response": "ok"
      },
      {
        "request": "1 add nonzero beyond",
        "response": "overflow"
      },
      {
        "request": "1 divide zero within",
        "response": "division-by-zero"
      },
      {
        "request": "1 divide nonzero beyond",
        "response": "overflow"
      },
      {
        "request": "2 add nonzero within",
        "response": "unsupported-version"
      },
      {
        "request": "1 other nonzero within",
        "response": "unknown-operation"
      },
      {
        "request": "1 multiply zero within",
        "response": "ok"
      }
    ]
  },
  "stakeholders": [
    {
      "name": "Calculator user",
      "text": "Enters two operands and an operation in the Pages view and needs an exact result or a typed error, never a wrapped number.",
      "concerns": [
        "Correct answers",
        "Proved guarantees"
      ]
    },
    {
      "name": "Service operator",
      "text": "Runs the A/B service releases and needs every protocol error typed and covered by a negative vector.",
      "concerns": [
        "Refused malformed requests",
        "Proved guarantees"
      ]
    }
  ],
  "components": [
    {
      "name": "Calculator Pages view",
      "text": "The portable Pages application at https://uor-foundation.github.io/calculator-example/.",
      "kind": "staticSite"
    },
    {
      "name": "Calculator service release",
      "text": "The A and B service releases prismpm pushes, deploys and rolls back.",
      "kind": "service"
    }
  ],
  "threats": [
    {
      "name": "Silent overflow",
      "text": "An out-of-range sum or product is wrapped and answered as ok.",
      "stride": "tampering",
      "asset": "answer",
      "likelihood": "medium",
      "impact": "critical",
      "control": {
        "name": "Checked result",
        "text": "A result beyond i64 is answered overflow.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "CalculatorProtocolProofs::inv002Holds"
          },
          {
            "kind": "gate",
            "reference": "UOR-Foundation/calculator-example src/Calculator.lex.tex acceptance vectors at the i64 bounds"
          }
        ]
      }
    },
    {
      "name": "Division by zero answered",
      "text": "A zero divisor yields a number or a trap instead of a typed error.",
      "stride": "denialOfService",
      "asset": "answer",
      "likelihood": "medium",
      "impact": "major",
      "control": {
        "name": "Typed division error",
        "text": "A zero divisor is answered division-by-zero.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "CalculatorProtocolProofs::inv001Holds"
          }
        ]
      }
    },
    {
      "name": "Version downgrade",
      "text": "A client sends another protocol version hoping it is read as version 1.",
      "stride": "spoofing",
      "asset": "request",
      "likelihood": "low",
      "impact": "major",
      "control": {
        "name": "Only version 1",
        "text": "Any version but 1 is unsupported-version.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "CalculatorProtocolProofs::inv003Holds"
          }
        ]
      }
    }
  ],
  "quality": [
    {
      "characteristic": "Functional suitability",
      "subcharacteristic": "Functional completeness",
      "requirement": "Every operation modeled",
      "text": "Each of the four Operation constructors is a value of the operation field.",
      "measure": "Operations modeled",
      "measureText": "Operation constructors of src/Calculator.lex.tex the app distinguishes.",
      "threshold": 4
    },
    {
      "characteristic": "Reliability",
      "subcharacteristic": "Fault tolerance",
      "requirement": "Every error typed",
      "text": "Every CalculatorError and every ProtocolError but MalformedRequest, which the decoder answers invalid, is an answer.",
      "measure": "Untyped errors",
      "measureText": "Error constructors with no answer and no invalid refusal.",
      "threshold": 0
    }
  ],
  "journeys": [
    {
      "stakeholder": "Calculator user",
      "steps": [
        "otherwise",
        "REQ-003",
        "REQ-004",
        "INV-001",
        "INV-002"
      ]
    },
    {
      "stakeholder": "Service operator",
      "steps": [
        "REQ-001",
        "REQ-002",
        "INV-003",
        "INV-004",
        "refuse"
      ]
    }
  ],
  "axioms": {
    "inv001Holds": [
      "Classical.choice",
      "Quot.sound",
      "propext"
    ],
    "inv003Holds": [
      "Classical.choice",
      "Quot.sound",
      "propext"
    ],
    "inv004Holds": [
      "Classical.choice",
      "Quot.sound",
      "propext"
    ]
  },
  "concerns": [],
  "license": "MIT OR Apache-2.0"
}
```

## Claims

- CP-01: The app never answers ok when operation is divide and right is zero
- CP-02: The app never answers ok when range is beyond
- CP-03: The app never answers ok when version differs from 1
- CP-04: The app always answers unknown-operation when version equals 1 and operation is other
- CP-05: The architecture description declares every stakeholder, concern, component, edge, viewpoint and view it references
- CP-06: The ISO/IEC 25010 quality model numbers every characteristic, subcharacteristic, requirement and measure, and every parent it names is declared
- CP-07: Every compliance obligation is numbered in order and names its evidence

## Pattern

Decision table: OMG DMN 1.5, hit policy FIRST. The rules are tried in order, and the first one that matches gives the answer. If none matches, the default answer applies. This is a DMN decision table with the FIRST hit policy.

| Pattern | Standard | Answers |
| --- | --- | --- |
| Decision table | OMG DMN 1.5, hit policy FIRST | ok, overflow, division-by-zero, unsupported-version, unknown-operation |

**Figure: Rules for each answer.** Each bar counts the rules that give one answer. When no rule matches, the answer is ok.

|  | rules |
| --- | --- |
| ok | 0 |
| overflow | 1 |
| division-by-zero | 1 |
| unsupported-version | 1 |
| unknown-operation | 1 |

## Behavior

A request is version, operation, right, range, separated by spaces. The first rule that matches decides. If none matches, the answer is ok. A request over 112 bytes, or in any other form, is answered invalid.

| Rule | When | Answer | Why |
| --- | --- | --- | --- |
| REQ-001 | version differs from 1 | unsupported-version | src/Calculator.lex.tex: decodeRequest refuses any version but 1 with ProtocolError UnsupportedVersion (vector 2 add 1 2) |
| REQ-002 | operation is other | unknown-operation | src/Calculator.lex.tex: parseOperation knows only Add, Subtract, Multiply and Divide; anything else is ProtocolError UnknownOperation (vector 1 mod 1 2) |
| REQ-003 | operation is divide and right is zero | division-by-zero | src/Calculator.lex.tex: calculate answers CalculatorError DivisionByZero for a zero divisor (vector 1 divide 1 0) |
| REQ-004 | range is beyond | overflow | src/Calculator.lex.tex: checkedResult answers CalculatorError Overflow outside the i64 range (vectors at 9223372036854775807 and -9223372036854775808) |
| otherwise | no rule matches | ok | src/Calculator.lex.tex: calculate\_correct proves the exact result is returned when it is in range |

## Properties Lean proves

Each property is a theorem about the same definitions the app is built from. It is proved for every request, not only the tested ones.

| Property | Statement | Theorem | Why |
| --- | --- | --- | --- |
| INV-001 | It never answers ok when operation is divide and right is zero. | CalculatorProtocolProofs::inv001Holds | a division by zero has no result |
| INV-002 | It never answers ok when range is beyond. | CalculatorProtocolProofs::inv002Holds | a result outside i64 is never wrapped or truncated |
| INV-003 | It never answers ok when version differs from 1. | CalculatorProtocolProofs::inv003Holds | an unsupported version is never interpreted as version 1 |
| INV-004 | It always answers unknown-operation when version equals 1 and operation is other. | CalculatorProtocolProofs::inv004Holds | an undefined operation is a typed protocol error |

## Architecture

Stakeholders and the concerns each one views the app through (ISO/IEC/IEEE 42010).

| Stakeholder | Who they are | Concerns |
| --- | --- | --- |
| Calculator user | Enters two operands and an operation in the Pages view and needs an exact result or a typed error, never a wrapped number. | Correct answers, Proved guarantees |
| Service operator | Runs the A/B service releases and needs every protocol error typed and covered by a negative vector. | Refused malformed requests, Proved guarantees |
| Verifier | Anyone who loads the holo, checks its fingerprint and replays its acceptance vectors before trusting an answer. | Integrity of the published app, Refused malformed requests, Proved guarantees |

## Concerns

What the stakeholders care about, and the model each is viewed in.

| Concern | What it means | Model |
| --- | --- | --- |
| Correct answers | Every well-formed request is answered by the first rule that matches it, or ok when none does, as the spec states. | quality |
| Integrity of the published app | What a visitor runs is the holo the build verified, with its fingerprint and signed provenance beside it. | security |
| Proved guarantees | Each of the 4 properties of the spec holds for every request, proved by the Lean kernel. | quality |
| Refused malformed requests | A request that is not the 4 fields in order, or is longer than 112 bytes, is answered invalid and never guessed. | security |

## Components

8 components and 11 edges between them.

| Component | Kind | What it is |
| --- | --- | --- |
| Browser | externalSystem | The visitor's web browser, which loads the page and runs the Calculator protocol guest. |
| Calculator Pages view | staticSite | The portable Pages application at https://uor-foundation.github.io/calculator-example/. |
| Calculator protocol guest | service | The Core-Wasm guest built from the model: it answers one request of at most 112 bytes with one answer of at most 64. |
| Calculator protocol page | staticSite | The page the template publishes: the holo, its fingerprint, its provenance and its acceptance vectors. |
| Calculator service release | service | The A and B service releases prismpm pushes, deploys and rolls back. |
| GitHub Pages | externalSystem | Serves the page and the holo from the repository Pages workflow. |
| Prism build | cliAdapter | prismpm verify in the SDK image prismpm.lock pins: it checks every theorem, builds the guest and replays every vector. |
| Source repository | externalSystem | The repository that holds the prompt, the model and its gate. |

## Design views

The SDK checks each view against the system model and draws it as OPL and PlantUML.

| View | Diagram | Viewpoint |
| --- | --- | --- |
| Deciding a Calculator protocol request | opmObjectProcess | Calculator user: Correct answers |
| Components of Calculator protocol | umlComponent | Verifier: Integrity of the published app |
| Answering a Calculator protocol request | umlSequence | Calculator user: Correct answers |
| States of the Calculator protocol guest | umlStateMachine | Service operator: Refused malformed requests |

## Features and journeys

10 features. Each names the definitions that do the work and the tests that accept it. Each stakeholder has one journey.

| Feature | Calls | Accepted by |
| --- | --- | --- |
| When version differs from 1, the answer is unsupported-version. | CalculatorProtocol::rule1, CalculatorProtocol::judge | CalculatorProtocol::application |
| When operation is other, the answer is unknown-operation. | CalculatorProtocol::rule2, CalculatorProtocol::judge | CalculatorProtocol::application |
| When operation is divide and right is zero, the answer is division-by-zero. | CalculatorProtocol::rule3, CalculatorProtocol::judge | CalculatorProtocol::application |
| When range is beyond, the answer is overflow. | CalculatorProtocol::rule4, CalculatorProtocol::judge | CalculatorProtocol::application |
| When no rule matches, the answer is ok. | CalculatorProtocol::judge | CalculatorProtocol::application |
| A request that is not version, operation, right, range in order, separated by single spaces, or is over 112 bytes, is answered invalid. | CalculatorProtocol::dispatch, CalculatorProtocol::decodeField1 | CalculatorProtocol::application |
| It never answers ok when operation is divide and right is zero. | CalculatorProtocol::judge | CalculatorProtocolProofs::inv001Holds |
| It never answers ok when range is beyond. | CalculatorProtocol::judge | CalculatorProtocolProofs::inv002Holds |
| It never answers ok when version differs from 1. | CalculatorProtocol::judge | CalculatorProtocolProofs::inv003Holds |
| It always answers unknown-operation when version equals 1 and operation is other. | CalculatorProtocol::judge | CalculatorProtocolProofs::inv004Holds |

## Journeys

The ordered features each stakeholder takes.

| Stakeholder | Steps |
| --- | --- |
| Calculator user | otherwise → REQ-003 → REQ-004 → INV-001 → INV-002 |
| Service operator | REQ-001 → REQ-002 → INV-003 → INV-004 → refuse |
| Verifier | refuse → INV-001 → INV-002 → INV-003 → INV-004 |

## Security and threat model

13 threats against 4 assets. Each has a STRIDE category, and either a control with evidence or a risk that is accepted on purpose.

| Threat | STRIDE | Asset | Risk | Answered by |
| --- | --- | --- | --- | --- |
| Answer that breaks INV-001 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-001: proof CalculatorProtocolProofs::inv001Holds |
| Answer that breaks INV-002 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-002: proof CalculatorProtocolProofs::inv002Holds |
| Answer that breaks INV-003 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-003: proof CalculatorProtocolProofs::inv003Holds |
| Answer that breaks INV-004 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-004: proof CalculatorProtocolProofs::inv004Holds |
| Division by zero answered | denialOfService | Answer | medium likelihood, major impact | Typed division error: proof CalculatorProtocolProofs::inv001Holds |
| Granted capability | informationDisclosure | Answer | low likelihood, major impact | No capability granted: gate prism-code check refuses an ungranted guest import |
| Malformed request | tampering | Request bytes | high likelihood, major impact | Strict decoder: gate malformed-request acceptance vectors, replayed in the compiled guest by prismpm verify |
| Oversized request | denialOfService | Request bytes | medium likelihood, minor impact | Bounded request: gate acceptance vectors at the request bound, one byte over it, and at the guest allocation bound, replayed by prismpm verify |
| Silent overflow | tampering | Answer | medium likelihood, critical impact | Checked result: proof CalculatorProtocolProofs::inv002Holds; gate UOR-Foundation/calculator-example src/Calculator.lex.tex acceptance vectors at the i64 bounds |
| Substituted holo | spoofing | Published holo | low likelihood, critical impact | Fingerprint and provenance: gate actions/attest-build-provenance in the pages workflow; gate prism-code check of the holo identities in the page |
| Substituted host | spoofing | Published holo | low likelihood, critical impact | accepted: A page cannot defend against its own host. The holo carries signed build provenance a visitor can check, and the app can be rebuilt from its prompt. |
| Tampered model | tampering | Model source | low likelihood, major impact | Regenerated from the prompt: gate prismpm verify in the SDK image prismpm.lock pins; review app/prompt.json |
| Version downgrade | spoofing | Request bytes | low likelihood, major impact | Only version 1: proof CalculatorProtocolProofs::inv003Holds |

## Quality

ISO/IEC 25010:2023 requirements. Each has a measure and a threshold that a theorem pins.

| Requirement | Characteristic | Measure | Threshold |
| --- | --- | --- | --- |
| Bounded allocation: The guest allocates at most 224 bytes for one request. | Performance efficiency: Resource utilization | Guest allocation bytes | 224 |
| Bounded request: A request over 112 bytes is refused before any field is read. | Performance efficiency: Time behaviour | Request bytes read | 112 |
| Every error typed: Every CalculatorError and every ProtocolError but MalformedRequest, which the decoder answers invalid, is an answer. | Reliability: Fault tolerance | Untyped errors | 0 |
| Every operation modeled: Each of the four Operation constructors is a value of the operation field. | Functional suitability: Functional completeness | Operations modeled | 4 |
| Every property proved: All 4 properties are theorems the Lean kernel checks. | Security: Integrity | Unproved properties | 0 |
| Every request answered: Every request gets an answer: a rule, ok otherwise, or invalid. | Functional suitability: Functional completeness | Unanswered requests | 0 |
| Every vector replays: All 44 acceptance vectors replay in the compiled guest, the shortest 0 bytes long. | Reliability: Faultlessness | Failed vectors | 0 |
| Examples answered as stated: Every one of the 7 examples of the spec is answered as it states. | Functional suitability: Functional correctness | Example mismatches | 0 |

## Compliance

One obligation per standard, each naming its evidence.

| Standard | Subject | Evidence |
| --- | --- | --- |
| ISO/IEC/IEEE 42010:2022 | Architecture description | Architecture::architectureDescriptionHolds |
| ISO/PAS 19450:2015 and OMG UML 2.5.1 | Design views | Design::viewOpmDecide, Design::viewUmlComponents, Design::viewUmlRequest, Design::viewUmlStates |
| ISO/IEC 25010:2023 | Product quality | Quality::qualityModelHolds |
| ISO/IEC 27034-1:2011 and ISO/IEC 27005:2022 | Application security and risk | Security::controlSet |
| OMG DMN 1.5, hit policy FIRST | Decision table | CalculatorProtocol::judge |
| OpenSpec | Requirements | CalculatorProtocol::application |
| SPDX MIT OR Apache-2.0 | Licensing | CalculatorProtocol::application |

## Rendered design views

Written by the SDK from the design records when it verified the app.

### design/Design.viewOpmDecide.opl

```
View: Design::viewOpmDecide
Title: Deciding a Calculator protocol request
Viewpoint: Architecture::viewpointCalculatorUserCorrectAnswers
Notation: ISO/PAS 19450:2015 OPM, Prism OPL profile

componentBrowser is an object.
componentCalculatorProtocolGuest is an object.
componentCalculatorProtocolGuest can be stateDeciding or stateIdle.
processDecide is a process.
processEncodeAnswer is a process.
processJudge is a process.
processParseRequest is a process.
componentCalculatorProtocolGuest handles processDecide.
processParseRequest requires componentBrowser.
processEncodeAnswer affects componentBrowser.
processJudge invokes processEncodeAnswer.
processParseRequest invokes processJudge.
processDecide zooms into processParseRequest, processJudge, and processEncodeAnswer, in that sequence.

```

### design/Design.viewUmlComponents.puml

```
@startuml
' UML 2.5.1 component diagram
' view: Design::viewUmlComponents
' viewpoint: Architecture::viewpointVerifierIntegrityOfThePublishedApp
title Components of Calculator protocol
component "componentBrowser" as c0
component "componentCalculatorPagesView" as c1
component "componentCalculatorProtocolGuest" as c2
component "componentCalculatorProtocolPage" as c3
component "componentCalculatorServiceRelease" as c4
component "componentGitHubPages" as c5
component "componentPrismBuild" as c6
component "componentSourceRepository" as c7
c0 --> c2 : edgeBrowserToCalculatorProtocolGuest
c1 --> c2 : edgeCalculatorPagesViewToCalculatorProtocolGuest
c2 --> c0 : edgeCalculatorProtocolGuestToBrowser
c2 --> c1 : edgeCalculatorProtocolGuestToCalculatorPagesView
c2 --> c4 : edgeCalculatorProtocolGuestToCalculatorServiceRelease
c3 --> c5 : edgeCalculatorProtocolPageToGitHubPages
c4 --> c2 : edgeCalculatorServiceReleaseToCalculatorProtocolGuest
c5 --> c0 : edgeGitHubPagesToBrowser
c6 --> c2 : edgePrismBuildToCalculatorProtocolGuest
c6 --> c3 : edgePrismBuildToCalculatorProtocolPage
c7 --> c6 : edgeSourceRepositoryToPrismBuild
@enduml

```

### design/Design.viewUmlRequest.puml

```
@startuml
' UML 2.5.1 sequence diagram
' view: Design::viewUmlRequest
' viewpoint: Architecture::viewpointCalculatorUserCorrectAnswers
title Answering a Calculator protocol request
participant "componentBrowser" as p0
participant "componentCalculatorProtocolGuest" as p1
p0 -> p1 : processDecide
p1 --> p0 : processDecide
@enduml

```

### design/Design.viewUmlStates.puml

```
@startuml
' UML 2.5.1 state machine diagram
' view: Design::viewUmlStates
' viewpoint: Architecture::viewpointServiceOperatorRefusedMalformedRequests
title States of the Calculator protocol guest
state "stateAnsweredDivisionByZero" as s0
state "stateAnsweredOk" as s1
state "stateAnsweredOverflow" as s2
state "stateAnsweredUnknownOperation" as s3
state "stateAnsweredUnsupportedVersion" as s4
state "stateDeciding" as s5
state "stateIdle" as s6
state "stateRefused" as s7
[*] --> s6
s6 --> s5 : processParseRequest
s6 --> s7 : processParseRequest
s5 --> s4 : processRule1
s5 --> s3 : processRule2
s5 --> s0 : processRule3
s5 --> s2 : processRule4
s5 --> s1 : processOtherwise
s1 --> s6 : processEncodeAnswer
s2 --> s6 : processEncodeAnswer
s0 --> s6 : processEncodeAnswer
s4 --> s6 : processEncodeAnswer
s3 --> s6 : processEncodeAnswer
s7 --> s6 : processEncodeAnswer
@enduml

```

## Prism source

Every file the builder wrote, laid out as a repository created from UOR-Foundation/template; the download prism-calculator-protocol.zip has them all.

- app/src/Architecture.lex.tex (406 lines)
- app/src/Compliance.lex.tex (56 lines)
- app/src/Design.lex.tex (591 lines)
- app/src/Features.lex.tex (130 lines)
- app/src/Quality.lex.tex (375 lines)
- app/src/Security.lex.tex (607 lines)
- app/src/CalculatorProtocol.lex.tex (243 lines)
- app/src/CalculatorProtocolProofs.lex.tex (161 lines)
- app/lexlean.toml (43 lines)
- app/prompt.json (359 lines)
- model/ids.toml (65 lines)
- features/suites/calculator\_protocol.feature (44 lines)
- crates/conformance/tests/calculator\_protocol.rs (132 lines)
- site/app.json (115 lines)
- openspec/specs/calculator-protocol/spec.md (174 lines)
