Deen / Documentation
Deen documentation
How Deen decides which agent memories can move money, and how to run it.
Overview
AI agents remember what they read and act on it later. That memory is an attack surface: one planted sentence in a web page or email ("the landlord's new address is qor1…") can lead a helpful agent to pay the wrong person.
Deen lets an agent keep everything it reads, and limits which memories can move money. A fact that decides a payment, such as a payee or a spending limit, counts only after the owner signs it with their ML-DSA-87 key and the DeenRegistry contract verifies that signature on QoreChain.
Quick start
You need Node.js 20 or later and a little test QOR from the QoreChain dashboard faucet.
git clone https://github.com/IamHarrie-Labs/deen
cd deen
npm install
npm test # 85 tests, no network needed
npm run bench # DeenBench: 49 published attack patterns
To run against testnet, create the two accounts, fund the relayer, then register their keys:
npm run accounts # owner + relayer, mnemonics saved to .env (git-ignored)
npm run setup # register ML-DSA-87 keys with proof of possession
npm run demo # the side-by-side demo and eight attacks
The registry is already deployed (see Deployments). Run npm run deploy only if you want your own copy.
Approval text
The owner signs readable text, which their wallet shows in full. The contract rebuilds the same text from the call's arguments and verifies "qorechain-msg-v1|qorechain-diana|" + text with pqcVerify. This is what QoreX signArbitrary and QoreSign signMessage produce.
Deen approval
action: approve
slot: payee:landlord
memory: 0x4f2c…
commitment: 0x9a71…
owner: 0x0d1832b885830cf3b9b68d8e9c4ed8c992261e0c
registry: 0x6a1e3c4ad78d36bcb50b8b564d179672dea3f48d
chain: 9800
nonce: 0
expires: 1764435600
- The text binds action, slot, memory, commitment, owner, contract, chain, nonce and expiry, so a relayer can deliver an approval but can't change, replay or redirect it.
- Slot names must be printable ASCII (0x21 to 0x7e), at most 64 bytes, so a slot name can't add a line to what the owner reads.
- The commitment is
sha3-256("deen-memory:v1\n" + slot + "\n" + text || salt). Only the commitment goes on chain. - The JavaScript client builds the same text, and a test checks the two match byte for byte.
Architecture
| Part | Role |
|---|---|
contracts/DeenRegistry.sol | Records owner approvals. Reads the owner's key itself and verifies the signature on chain. |
src/vault.mjs | Encrypts each memory with QoreSeal (ML-KEM-1024 + X25519 + AES-256-GCM) to the owner and the current agents. The authenticated data is memoryId || commitment. |
src/agent.mjs | The agent runtime. Resolves a sensitive slot through the registry, opens the envelope and checks it against the on-chain commitment. |
src/mcp-server.mjs | Exposes the agent to MCP clients such as Claude. |
scripts/owner.mjs | The owner's command line for reviewing and signing approvals. |
| Relayer | The agent's service account. Submits approvals through an EVM window scoped to the registry, so its key can call the registry and nothing else. |
Owner and agent ML-KEM-1024 keys are published in QoreChain's key registry. Each recipient card is signed with QoreSign and checked against both on-chain keys before anything is sealed to it.
DeenRegistry
Solidity 0.8.28, deployed on the EVM lane. It never trusts the caller. Each signed action checks, in order: the deadline, the owner's key through pqcKeyStatus (0x…0a02: registered, ML-DSA-87, possession proven), the signature through pqcVerify (0x…0a01), then increments the owner's nonce.
Functions
| Function | Does | Gas |
|---|---|---|
approve(owner, memoryId, slotName, commitment, deadline, signature) | Records an owner-approved memory. Supersedes the previous one in that slot. | ~410k |
revoke(owner, memoryId, slotName, deadline, signature) | Withdraws approval and leaves the slot empty. An older memory is never restored. | ~333k |
rotateAgents(owner, epoch, setRoot, deadline, signature) | Starts a new agent epoch, anchoring the hash of the agent set. | ~313k |
resolve(owner, slotName) | The memory currently approved for a slot. View. | read |
isTrusted(memoryId, commitment) | True only if approved, not revoked, not superseded, and the commitment matches. View. | read |
signingText(owner, action, memoryId, slotName, commitment, deadline) | The exact text the owner signs. View. | read |
Most of the gas in a signed action goes to the 4,627-byte signature in calldata and the 2,592-byte public key the contract reads. Deen verifies on chain only when authority is granted. A recall is one resolve and one isTrusted read.
Errors
| Error | When |
|---|---|
Expired | The deadline has passed. |
KeyNotRegistered / WrongAlgorithm | The owner has no key, or it isn't ML-DSA-87. |
PossessionNotProven | The key was registered without a proof of possession. |
BadSignature | The signature doesn't verify over the rebuilt text. |
InvalidRecord | Empty fields, a bad slot name, or the reserved agents slot. |
MemoryExists / UnknownMemory / AlreadyRevoked | Lifecycle checks on approve and revoke. |
BadEpoch | Agent epochs must increase by exactly one. |
MCP server
Any MCP client can keep its memory in Deen. The server assumes the model calling it may have been prompt-injected, so no tool can grant trust.
| Tool | Input | Behaviour |
|---|---|---|
remember | text, source | Stores the claim, encrypted. The model states the source, so the most it can claim is USER_SESSION. |
recall | slot?, query? | Memories with authority and sources. For a sensitive slot, the one trusted value and the claims it ignored. |
request_approval | memory_id | Asks the owner to sign. It never signs. |
pay | payee, amount, token (QOR or fUSD) | Pays the owner-signed payee, within the owner-signed limit and in that limit's token, and writes a signed receipt. Any extra field, such as an address, is rejected. |
security_events | none | Attempts to change a signed payee or limit. See Alerts. |
Setup
npm run compile # builds the registry ABI
npm run owner -- init # publish and verify the owner's recipient card
Claude Desktop, in claude_desktop_config.json:
{
"mcpServers": {
"deen": { "command": "node", "args": ["/path/to/deen/src/mcp-server.mjs"] }
}
}
Claude Code: claude mcp add deen -- node /path/to/deen/src/mcp-server.mjs
Approving
- QoreX. Set
DEEN_QOREX_OWNERto the owner'sqor1…address in the server's environment. Requests appear athttp://localhost:5179and the owner signs in the wallet. - Scripted owner, for demos. In the owner's own terminal:
npm run owner -- approve <memoryId>. It shows the value and the approval text and asks for a typedyes. It refuses to run without an interactive terminal.
Storage
The vault is saved in .deen/, which is git-ignored. The file holds QoreSeal ciphertext, commitments and slot names, and no memory text. Editing it can remove or add records, but an altered record won't open, and nothing in the file can grant OWNER.
On a single demo machine, .env holds the owner's mnemonic. An agent that can read files or run commands there could sign as the scripted owner. Keep the owner key in QoreX or on another machine.
Spending limits
Through MCP, pay also needs an owner-signed limit:<name> memory, written as Limit for landlord: 0.25 QOR per payment. It is resolved the same way as the payee: on-chain approval, envelope, commitment. A planted "the new limit is 1000 QOR" is ignored. No signed limit, or an amount above it, means no payment. No contract change was needed.
Amounts are parsed with integer maths: at most 6 decimals, 1 QOR = 1,000,000 uqor.
Attack results
Each attack ran against the live contract and vault (npm run demo, recorded in deployments/demo-run.json) and again in the automated tests (test/runtime.test.js, real ML-DSA-87 signatures).
| # | Attack | Result on testnet |
|---|---|---|
| Loading… | ||
DeenBench
The eight attacks above are the ones we thought of. DeenBench tests the ones other people have published: 49 attacks in 13 families re-created from recent research on agent memory poisoning, plus business email compromise. Each runs against an ordinary agent and a Deen agent with identical inputs, and five normal payments check that Deen still pays when it should.
| Attack family | Cases | Ordinary agent fooled | Deen fooled |
|---|---|---|---|
| Loading… | |||
Scope. The cases are our own re-creations of each published attack's pattern, applied to Deen's payment task, not the authors' code or datasets. Both agents are deterministic, so DeenBench measures whether a planted claim can decide a payment, not how a particular language model behaves. Run it with npm run bench. It is also part of npm test, so a change that lets one attack through fails the build.
Measured limits
Two cases Deen can't win also run: an email persuades the owner to sign the attacker's address. Deen pays the attacker, because the owner signed it. Before signing, the owner was shown two and three warnings: where the value came from, that repetition isn't confirmation, and which signed value it replaces.
Alerts and receipts
Poisoning alerts
When a claim tries to change a signed payee or limit, Deen records a security event. Read them with the security_events MCP tool or npm run owner -- alerts. Events are recomputed from the vault and the chain on every call, so deleting a log can't hide one.
| Event | When | Severity |
|---|---|---|
conflicting-claim | A claim contradicts a signed payee | High if it came from outside the owner's session |
limit-raise-attempt | A claim sets a higher limit than the signed one | High if it came from outside |
unapproved-claim | A payee or limit claim with nothing signed yet | Medium from outside, info from the owner |
Warnings before signing
Every approval request carries warnings, and the owner command prints them above the approval text: the value first came from an email, web page or agent rather than the owner; it was repeated by several sources, which isn't confirmation; signing it replaces the currently signed value. The advice follows accounts-payable practice for changed bank details: confirm with the payee on contact details you already hold, never ones from the message.
Decision receipts
Every pay call, paid or refused, writes a receipt to .deen/receipts.jsonl: payee, amount, transaction, the memory that decided it, the signed limit and the claims that were ignored. The agent signs each receipt with ML-DSA-87 from qorechain-pqc, in QoreChain's message-signing format, and each carries the hash of the one before. npm run owner -- receipts checks every signature and the chain; an edited, removed, reordered or forged receipt fails.
2026-12-01T10:02:11Z paid landlord 0.25 QOR qor1lqrp…fw6
OWNER memory: ML-DSA-87 approval verified on chain, envelope matches commitment
ignored: qor1yh0x…tjd (EXTERNAL via email, peer:planner)
2 receipt(s): hash chain intact, every ML-DSA-87 signature valid
Standards
| Framework | Entry | How Deen addresses it |
|---|---|---|
| OWASP Agentic Top 10 | ASI06 Memory and context poisoning | Provenance on every memory; only owner-signed memories fill sensitive slots |
| MITRE ATLAS | AML.T0080.000 Agent context poisoning: memory | Poisoned memories persist but can't decide a payment; alerts surface the attempt |
| NIST FIPS 204, FIPS 203 | ML-DSA-87, ML-KEM-1024 | Approvals, receipts and memory encryption use the highest parameter sets |
| Agent Payments Protocol (AP2) | User-signed mandates with price limits | Owner-signed payee and limit memories play the same role, verified on chain |
| Accounts-payable controls | Confirm changed bank details out of band, hold payments, keep evidence | Unsigned changes never pay; warnings say to confirm out of band; receipts keep the evidence |
Limitations
- With a smart-account session key, the chain caps each payment and each day's total, but within those caps a stolen session key can still choose the recipient. Session keys last at most 23 hours on testnet.
- Without a session key the agent pays from its own account, and code that skips Deen and uses that account's key directly isn't stopped.
- A removed agent keeps what it could already read. Encryption can't take knowledge back, so revoke or replace the memories that matter.
- The contract reads the owner's current key on every signed action. Approvals made before a key change stay trusted until revoked or superseded.
- QoreX only signs. The owner's encryption key is held by Deen, separately from the wallet.
- The MCP server and owner command have no
revokeyet. Signing a new value for a slot supersedes the old one.
Not built yet
- Guardian or social recovery for a lost owner key.
- A recipient allowlist enforced by the chain, to go with the amount limits.
Deployments
qorechain-diana testnet, EVM chain ID 9800. Explorer links open on mainnet by default: switch the explorer header to Testnet.
| Item | Address or transaction |
|---|---|
| DeenRegistry v2 | 0x6a1e3c4ad78d36bcb50b8b564d179672dea3f48d qor1dg0rcjkh35mtedgt3dty69ukwt028aydjgsgzl |
| Deploy | 0x00ec786a442d136f94b8bd6e43ee99f221549c693914a68f60dd6052794e8ec7 |
| Owner | qor1p5vr9wy9svx08wdk3k8fcnkcexfzv8svr0lpwk |
| Relayer / payer agent | qor129r9vxc52rjydj9378p9j7fux43znnv7p8d4p6 |
| Owner key registration | C64C3AF81E2C24250B616994859659CF1395661BE0B5550481FC530ED5C85926 |
| Owner ML-KEM key | 06DB4BF9AC9F0A1335BFCA715BF44D400B06E5CB8B553FAD794C0F415501345E |
| Owner approval | 0xb46bad03172b31e6840f165e4c07279d7cab7112b286114b5063489e6bc1c434 |
| Ordinary agent pays attacker | 2BBDAD1B8DF42B36994F3666E70FBA9B788A504AB74DAE10119BAFDC772A56A4 |
| Deen agent pays landlord | A31FD25957AD1EC213C9568CEF2053ABD0BE66414AF586FB758DDAB5859F0836 |
| Agent epoch rotation | 0x4515643229c1236eddd3916843bc273f1651fa2fbcc3713c3e21dc141c11897a |
| DeenRegistry v1 (superseded) | 0xa57b589af3ae6f8cd201a5cc111bcd312ebf6525 |
Full records: deployments/diana.json, diana-live.json and demo-run.json in the repository.