Matrix logo

Deus - Receipts, Vouchers, Metering, and Storage

EIP-712 signing for quotes and receipts, deterministic Merkle hashing, channel voucher lifecycle, invocation metering ledger, and Postgres-backed persistence.

Overview

The financial primitives layer provides EIP-712 signing for quotes and receipts, deterministic Merkle root hashing for receipt batches, caller-funded payment channels with co-signed vouchers, an invocation metering ledger, and Postgres-backed persistence for all financial state.

EIP-712 Signing

Source: deus/internal/receipts/eip712.go

The Signer creates and verifies EIP-712 typed data for quotes, receipts, and vouchers. It is constructed from a chain ID, a verifying-contract address, and a hex-encoded private key.

Signed message types

MethodEIP-712 typeReturns
SignQuoteDeusQuote{digest, signature} (0x-hex)
SignReceiptDeusReceipt{digest, signature} (0x-hex)
VoucherDigestDeusVoucherdigest only (unsigned)
VerifyQuoterecovers signermatches GatewayAddress
VerifyVoucherCallerrecovers signermatches callerWallet

All signing methods use the same domain pattern: EIP712Domain with name, version, chainId, and verifyingContract. Signatures are normalized to {27,28} recovery bytes.

Utility functions

FunctionDescription
RecoverSignerRecovers address from digest + signature
HashPayloadJSON-marshal + Keccak-256 hash (0x-hex)
WeiStringFormats *big.Int as decimal wei string

Merkle Root Construction

Source: deus/internal/receipts/merkle.go

MerkleRoot builds deterministic roots over receipt digests with domain separation:

  • Leaves prefixed with 0x00 before hashing
  • Internal nodes prefixed with 0x01 before hashing
  • First layer is sorted (order-independent output)
  • Odd layers duplicate the trailing node

Channel Voucher Lifecycle

Source: deus/internal/channels/channels.go, deus/internal/channels/voucher.go

Channel operations

MethodDescription
OpenValidates cap, checks on-chain funding (when available), opens channel row
ReserveDecrements available balance atomically
VoidReleases reserved balance without charging
FinalizeApplies charge, cumulative spend, voucher nonce, and signature
ActiveLoads current open channel for a caller

Channels have a fixed 10-minute window. On-chain escrow funding bounds the off-chain cap when EscrowReader is configured.

Voucher operations

MethodDescription
BuildPendingComputes next cumulative total, increments nonce, returns unsigned EIP-712 digest
CosignLoads channel, enforces monotonic nonce, verifies caller signature, commits atomically

The Cosign write path atomically updates the channel row and inserts the voucher row in a single transaction.

Metering Ledger

Source: deus/internal/metering/ledger.go

MethodDescription
ReserveInserts a reserved invocation (idempotent on idempotency_key), reloads it
FinalizeMarks invocation delivered and charged
VoidReleases reservation without charging

InsertReservedInvocation uses ON CONFLICT (idempotency_key) DO NOTHING and reloads the existing row on conflict.

Postgres Store

Source: deus/internal/store/store.go

The Store wraps a pgxpool.Pool and provides forward-only migrations. Key tables:

TablePurpose
developersDeveloper identity + payee DID
servicesService listings with manifest, status, quality
embeddingspgvector embedding vectors
pricing_plansPer-operation pricing (wei + USDX)
invocationsInvocation lifecycle (reserved/ok/voided)
receiptsSigned receipt envelopes
settlementsSettlement windows
deploymentsHosted deployment state

InvocationRow

Key fields: ID, IdempotencyKey, ServiceID, CallerDID, Units, PriceWei, Outcome, LatencyMS, Rail, ChannelID, CreatedAt.

ReceiptRow

Key fields: InvocationID, Digest, GatewaySig, RunnerSig.