Hand over the proof #
What is new: a whole agent run becomes one file, a proof bundle, that anyone checks offline. They need no account, no network and no copy of your workspace, only the bundle and your admin's public key, which they get from you separately. The run is closed first: what was sent stays valid, and nothing can be added afterwards.
Why it matters: a customer, an auditor or a regulator can check for themselves who said what in a run, that nothing was changed, dropped or added, and that every "done" was recomputed. The bundle states plainly what it does not prove.
Run, close, export #
import copy, json
from tensorchain import agents, bundle, issuers
from tensorchain.sign import canonical
from tensorchain.workspace import Workspace
reg = issuers.Registry("keys")
ws = Workspace("run.sqlite", actor="agent:docs").__enter__()
bus = agents.Bus(ws, reg)
token = {a: bus.enrol(a, "admin:acme") for a in ("planner", "worker", "critic")}
task = bus.send("planner", "worker", "task", canonical({"op": "sum", "input": [10, 20, 12]}), token=token["planner"])
claim = bus.claim("worker", task, canonical(42), token=token["worker"])
said = bus.send("worker", "critic", "claim", canonical({"claim": claim}), reply_to=task, cites=[claim],
token=token["worker"])
review = bus.send("critic", "planner", "review", b"accepted", reply_to=said, cites=[claim], token=token["critic"])
bus.close("admin:acme")
try:
bus.send("planner", "all", "note", b"one more thing", token=token["planner"])
late = "sent"
except agents.BusError as e:
late = e.code
with open("bundle.json", "w") as fh:
json.dump(bundle.export(bus, "admin:acme"), fh)
admin_key = reg.card("admin:acme")["keys"][reg.active_key("admin:acme")]["public_key"]
print("after the close:", late, " admin key to publish:", len(admin_key) // 2, "bytes, hex")
assert late == "bus_closed"
after the close: bus_closed admin key to publish: 32 bytes, hex
The customer verifies it #
They need only the file and the key they got from you through another channel, such as your website or a contract:
report = bundle.verify(json.load(open("bundle.json")), [admin_key])
print("trusted:", report["trusted"], " intact:", report["intact"], " root of trust:", report["root_of_trust"]["admin"])
print("rows:", sorted({(v["row"], v["status"]) for v in report["rows"].values()}))
print("not proved:", report["statement"]["does_not_prove"][0])
assert report["trusted"] and report["intact"] and report["all_valid"]
assert report["rows"][claim]["claimer"] == "worker"
trusted: True intact: True root of trust: admin:acme
rows: [('card', 'valid'), ('claim', 'valid'), ('close', 'valid'), ('message', 'valid')]
not proved: that any message is true, or any output correct beyond what a checker recomputesWhat a forger cannot do #
good = json.load(open("bundle.json"))
edited = copy.deepcopy(good)
edited["messages"].pop() # quietly drop the critic's review
cooked = copy.deepcopy(good)
cooked["claims"][0]["evidence"]["result"] = "NDM=" # base64 of "43": a different answer
results = {"untouched": bundle.verify(good, [admin_key])["intact"],
"a message dropped": bundle.verify(edited, [admin_key])["problems"],
"the answer changed": sorted({v.get("why") for v in bundle.verify(cooked, [admin_key])["rows"].values()} - {None}),
"no key pinned": bundle.verify(good, [])["trusted"]}
for k, v in results.items():
print(f"{k}: {v}")
assert results["untouched"] is True
assert results["a message dropped"] == ["manifest_mismatch"]
assert results["the answer changed"] == ["evidence_mismatch"]
assert results["no key pinned"] is False
ws.__exit__(None, None, None)
untouched: True a message dropped: ['manifest_mismatch'] the answer changed: ['evidence_mismatch'] no key pinned: False
A bundle never vouches for itself: with no key pinned, or the wrong one, it is trusted: false. The admin is the root of trust and is named in every report. Guard its key the way you guard a code-signing key.
From the shell: python -m tensorchain.bundle verify bundle.json --admin-key <hex> exits 0 only when the bundle is intact.