DIM · Dagon Inference Marketplace

Conventions

Every component of the marketplace (buyer SDK, seller gateway, discovery indexer and the im-channels program) follows the rules on this page. The normative source is the MVP protocol contract. The tables marked Generated from are produced from the code by bun docs/site/protocol/_gen/generate.ts, and a test fails when they drift.

Numbers

  • Integers in binary messages are fixed-width and little-endian: u8, u16, u32, u64 unsigned, i64 two's-complement signed.
  • Amounts are u64 micro-USDC, the base unit of a 6-decimal USDC mint. One USDC is 1_000_000.
  • Times are Unix seconds (i64 on the wire, integers in JSON, A11). Latencies are integer milliseconds.
  • Ratios in signed JSON are integer basis points, 0 to 10,000 (A17). No floats appear in any signed document.

Keys, hashes and signatures

  • Public keys, hashes and ids are 32 raw bytes. Hashes are SHA-256.
  • Signatures are Ed25519 as in RFC 8032 (pure, no prehash), 64 bytes, over the exact message bytes.
  • Verification is strict in both implementations: a signature whose scalar is not canonical, or whose key or R point has small order, is rejected. The verification equation matches ed25519-dalek's verify_strict.
  • Every verifier must already know which key it expects. Decoding a message never authenticates it.

Binary messages

Every signed binary message starts with a 16-byte ASCII type tag, right-padded with 0x00, followed by the 64-byte domain. There are no optional fields and no trailing bytes: a message of the wrong length, or with an unknown tag, is rejected.

Type tag 16 tag bytes (hex) Message length
IM/HOLD/1 49 4d 2f 48 4f 4c 44 2f 31 00 00 00 00 00 00 00 275
IM/VOUCHER/1 49 4d 2f 56 4f 55 43 48 45 52 2f 31 00 00 00 00 168
IM/RECEIPT/1 49 4d 2f 52 45 43 45 49 50 54 2f 31 00 00 00 00 382

<sub>Generated from packages/protocol/src/wire.ts, crates/im-protocol/src/wire.rs.</sub>

The three messages are IM/HOLD/1, IM/VOUCHER/1 and IM/RECEIPT/1. Probe observations are JSON documents, not binary messages (A2).

Domain

domain = genesis_hash (32 bytes) ‖ program_id (32 bytes), at bytes 16 to 79 of every message. It binds a signature to one cluster and one deployment of the settlement program, so a voucher signed for devnet can never be redeemed on mainnet, or by another program.

The program compiles its genesis hash and USDC mint in through a cargo feature:

Cargo feature GENESIS (domain bytes 0–31) MINT
devnet EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG 2LYaM1PTo4WwkoUx87E4pV39vWPDsohWVLyjUyA4MLUu (override at build time with IM_DEVNET_MINT)
localnet set at build time by IM_LOCALNET_GENESIS_HASH set at build time by IM_LOCALNET_MINT
mainnet 5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

<sub>Generated from programs/programs/im-channels/src/domain.rs.</sub>

Off-chain tests use 32 zero bytes as the genesis hash, plus the program id configured in the test.

Hash prefixes

Hashes that could be confused with each other are separated by a fixed ASCII prefix:

Prefix Bytes Use
IM/EMPTY/1 ASCII, no terminator C0 = SHA256("IM/EMPTY/1") = a982b8b311e6647e5235ee26f1aa4553b8e273d19f3d60d55ab4693ef5ffcbca
IM/APPEND/1 ASCII, no terminator Ci = SHA256("IM/APPEND/1" ‖ C(i−1) ‖ SHA256(receipt_bytes))
IM/JSON/1\0 ASCII plus one 0x00 byte SHA256("IM/JSON/1\0" ‖ jcs(doc)), the message signed for JSON documents

<sub>Generated from packages/protocol/src/crypto.ts, packages/protocol/src/json.ts.</sub>

Signed JSON documents

Listings, price schedules, capacity reports, probe observations and every discovery response are JSON documents.

  • Canonical bytes. A document is serialized with RFC 8785 (JCS) before it is hashed or signed: object members sorted by UTF-16 code units, no insignificant whitespace, minimal string escaping.
  • Integers only. Every number is an integer from 0 to 2^53 − 1 (A1). Encoders and decoders reject floats, negatives and larger values.
  • Envelope. A signed document travels as {"doc": {...}, "sig": "<base64>", "key": "<base58>"}. The signature is Ed25519 over the 32-byte digest SHA256("IM/JSON/1\0" ‖ jcs(doc)).
  • Pinned keys. The key member is self-asserted. Verify against a key you already trust (the seller's listing key, an operator key, the indexer attestation key). Checking a signature under the envelope's own key proves integrity, not identity.
  • Strict parsing. Parse network JSON with the protocol parser (parseJson / parse_json), which rejects duplicate member names, a byte-order mark and oversized input before anything is lost. Do not use JSON.parse.
Limit Value
Largest JSON document (UTF-8 bytes) 1,048,576 (1 MiB)
Deepest container nesting 64
JSON integers 0 to 2^53 − 1 (A1); no floats, negatives, or exponents

<sub>Generated from packages/protocol/src/parse.ts.</sub>

Identifiers

Identifier Definition JSON form
schedule_digest SHA256(jcs(schedule)) 64 lowercase hex characters
model_identity_id SHA256(jcs(model_identity)) 64 lowercase hex characters
route_id SHA256(jcs({seller_id, endpoint, model_identity_id, nonce})), where nonce is 32 bytes of lowercase hex (A4) 64 lowercase hex characters
request_commitment SHA256(salt32 ‖ exact HTTP request body bytes) (A19) binary only
seller_id, keys Ed25519 public key base58

Binary values in HTTP headers and JSON members are standard padded base64. Verifiers recompute route_id, model_identity_id and schedule_digest instead of trusting the values a listing states.