Protocol
Protocol
The frozen consensus rules, canonical byte format, proof-of-work, difficulty, and peer-to-peer transport behind XSL.
This page summarises SPEC.md version 1.0 (mainnet candidate). Consensus constants and validation rules are frozen; changing them requires a coordinated network upgrade. Node policy such as mempool limits, dust, and relay behaviour can change without a fork.
Design goals
Scruple is a minimalist UTXO chain built for long-term ossification and bounded hardware requirements:
- Post-quantum signatures. SQIsign Round-3 Level 1 for every spend; no ECDSA or Schnorr fallback.
- CPU-first proof-of-work. RandomX with automatic epoch rotation and no ASIC-friendly hash.
- No scripting VM. No
OP_RETURN, no general smart contracts, no witness discount. Native M-of-N multisig is a first-class address version. - Fixed tail emission. Exactly 1 XSL per block forever, with no halvings and no premine.
- Compact chain references. UTXOs are referenced by
(height, tx_index, out_index)rather than 36-byte txid pointers, while a reorg-safe sighash binds the exact prevout. - Deterministic everything. Genesis blocks, RandomX epoch-zero seeds, address encodings, wire formats, and difficulty are derived with integer math and fixed domain tags.
Units and frozen constants
| Parameter | Value | Notes |
|---|---|---|
| Name / ticker / symbol | Scruple / XSL / ℈ (U+2108) | Base unit: grains |
| Subdivision | 100,000,000 grains per XSL | All amounts are u64 grains |
| Block subsidy | 100,000,000 grains (1 XSL) | Fixed forever; ~105,120 XSL/year at 5-minute blocks |
| Target block time | 300 seconds | Mainnet, testnet, and devnet |
| Maximum block size | 1,000,000 bytes | Full serialized block; 1:1 weight |
| Maximum transaction size | 100,000 bytes | Full serialized transaction |
| Maximum inputs / outputs / auth entries | 1,024 each | Per transaction |
| Maximum transactions per block | 10,000 | Wire decode upper bound |
| Consensus minimum output | 1 grain | Strict consensus floor |
| Policy dust floor | 5,000 grains | Non-consensus mempool and wallet policy |
| Block version | 1 | Strict equality |
| Maximum multisig keys | 15 | Upper bound for N |
| Coinbase maturity | Mainnet 24 · Testnet 6 · Devnet 2 | Spendable when spend_height >= outpoint.height + maturity |
| LWMA window | 60 intervals | Per-block difficulty adjustment |
| RandomX epoch length | 2,048 blocks | ~7.1 days |
| RandomX epoch lag | 64 blocks | Pre-initialisation window |
| Maximum future block time | 1,200 seconds | Relative to local wall clock |
| Mainnet target bits | Initial 0x1e0fffff · max 0x1f7fffff | Compact Bitcoin-style nBits |
| Testnet target bits | Initial 0x1f0fffff · max 0x207fffff | Fast start, then LWMA adapts |
| Devnet target bits | Initial 0x200fffff · max 0x207fffff | Fast local testing |
Networks
| Network | P2P magic | P2P / RPC port | Address HRP | Genesis seed |
|---|---|---|---|---|
| Mainnet | XSL1 (58534C31) | 18333 / 18332 | xsl | scruple-mainnet-genesis-v1 |
| Testnet | XSLT (58534C54) | 28333 / 28332 | txsl | scruple-testnet-genesis-v1 |
| Devnet | XSLD (58534C44) | 18333 / 18332 | dxsl | scruple-devnet-genesis-v1 |
P2P peers from different networks reject each other immediately at the 4-byte framing magic, before any payload is decoded. Addresses use a network-specific human-readable prefix, so a testnet address sent to a mainnet wallet or node is rejected client-side.
Addresses
An address commits to either one SQIsign public key (v1) or a canonical M-of-N multisig key set (v2). The 32-byte commitment is rendered as checksummed Bech32m with a witness version and network HRP, or as a legacy hex string.
v1 single-key
addr_hash = BLAKE3("scruple-addr-v1" || pubkey_83)
bech32m = bech32m_encode(hrp, witness_ver=1, addr_hash) // xsl1p... / txsl1p... / dxsl1p...
legacy = "xsl1:" || lowercase_hex(addr_hash)
v2 native M-of-N multisig
addr_hash = BLAKE3(
"scruple-addr-v2"
|| u8(threshold)
|| u8(n)
|| pubkeys[0] || pubkeys[1] || ... || pubkeys[n-1]
)
bech32m = bech32m_encode(hrp, witness_ver=2, addr_hash) // xsl1z... / txsl1z... / dxsl1z...
legacy = "xsl2:" || lowercase_hex(addr_hash)
Multisig rules: 1 <= threshold <= n <= 15, and public keys must be in strictly ascending lexicographical byte order. The canonical ordering makes the address independent of the order in which cosigners supply their keys, and forbids duplicate or permuted key sets.
| Form | Example prefix | Notes |
|---|---|---|
| Bech32m v1 | xsl1p... | Single-key; 6-character BCH checksum |
| Bech32m v2 | xsl1z... | Multisig; checksummed and network-scoped |
| Legacy v1 | xsl1:<64-hex> | Still accepted; no checksum |
| Legacy v2 | xsl2:<64-hex> | Still accepted; no checksum |
Legacy xsl1: and xsl2: strings have no checksum. A single mistyped hex character produces a valid-looking but wrong address. Bech32m catches typos and wrong-network addresses before a transaction is built.
Cryptographic primitives
Domain-separated BLAKE3
Every consensus hash is BLAKE3(domain || data) with an explicit ASCII domain tag. The tags prevent cross-protocol collisions and make the purpose of each digest unambiguous.
| Domain tag | Input | Purpose |
|---|---|---|
scruple-addr-v1 | pubkey (83 B) | v1 address hash |
scruple-addr-v2 | threshold || n || pubkeys... | v2 multisig address hash |
scruple-txid-v1 | encode_body(tx) | Non-malleable transaction id |
scruple-wtxid-v1 | encode(tx) | Witness transaction id (includes auth) |
scruple-sighash-v1 | txid || Σ(utxo.txid || encode(utxo.output)) | Reorg-safe signature digest |
scruple-merkle-leaf | leaf_hash (32 B) | Merkle leaf |
scruple-merkle-node | left || right (64 B) | Merkle internal node |
scruple-block-root-v1 | tx_root || wt_root | Dual root in the header |
scruple-header-v1 | header_bytes (85 B) | Block hash |
scruple-genesis-v1 | genesis_seed || timestamp_le | Genesis commitment |
scruple-rx-genesis | genesis_seed || timestamp_le | RandomX epoch-zero seed |
scruple-hd-v1 | master_seed || index_le | HD child key derivation |
scruple-rbf-shrink-v1 | old_txid || new_txid | Ownership proof for FSS-RBF shrink |
SQIsign Round-3 Level 1
| Item | Size | Notes |
|---|---|---|
| Public key | 83 bytes | PublicKey::<Level1>::to_bytes() |
| Compressed signature | 176 bytes | Signature::compress().to_bytes() |
| Single-sig auth entry | 260 bytes | 1 B tag + 83 B pk + 176 B sig |
| Multisig auth entry | 4 + 83n + 177m bytes | tag + threshold + n + m + pubkeys + (signer_idx, sig)* |
| 2-of-3 multisig auth | 607 bytes | One auth entry for all inputs sharing the vault |
SQIsign is not strongly unforgeable under chosen-message attacks: an observer might transform a valid signature into a different valid signature for the same message. Scruple therefore excludes the auth section from txid, while wtxid commits to the full transaction including signatures. The block header commits to both trees, so signatures remain immutable once mined without letting signature malleability change transaction identity.
Canonical wire format
Every consensus object has exactly one valid byte representation. Decoders reject non-canonical encodings and trailing bytes.
Primitive types
u8: one byte.u32_le: 4-byte little-endian.u64_le: 8-byte little-endian.varint: canonical unsigned LEB128, 7 payload bits per byte, little-endian groups. Multi-byte encodings must not end in0x00; at most 10 bytes; the 10th byte may only carry one payload bit.- EOF rule: decoding a standalone transaction or block must consume every byte. Trailing bytes are rejected.
Block header (85 bytes)
| Offset | Length | Field | Description |
|---|---|---|---|
| 0 | 1 | version | Must be 1 |
| 1 | 32 | prev_hash | Parent block hash; genesis commitment for height 0 |
| 33 | 32 | merkle_root | Dual txid/wtxid root |
| 65 | 8 | timestamp | Unix seconds, little-endian |
| 73 | 4 | target_bits | Compact target, little-endian |
| 77 | 8 | nonce | PoW nonce, little-endian |
block_hash = BLAKE3("scruple-header-v1" || header[0..85]). RandomX hashes the exact same 85-byte header for proof-of-work.
Compact OutPoint
OutPoint :=
height : varint(u64) // block height that created the UTXO
tx_index : varint(u32) // transaction index within that block (0 = coinbase)
out_index : varint(u32) // output index within that transaction
OutPoints are ordered lexicographically by (height, tx_index, out_index). This keeps references compact while remaining deterministic.
Output
Output :=
addr_version : u8 // 1 = single-key, 2 = M-of-N multisig
addr_hash : [u8; 32]
amount : varint(u64) // grains; consensus >= 1
Outputs are ordered lexicographically by (addr_version, addr_hash, amount).
TxAuth
TxAuth :=
tag : u8
if tag == 1: // 260 bytes fixed
pubkey : [u8; 83]
sig : [u8; 176]
else if tag == 2: // 4 + 83n + 177m bytes
threshold : u8 // 1 <= threshold <= n
n : u8 // 1 <= n <= 15
pubkeys : [u8; 83][n] // strictly ascending
m : u8 // must equal threshold
sigs : (signer_idx: u8, sig: [u8; 176])[m] // ascending indices
Strict decode and consensus rules:
- Unknown tags are rejected.
threshold == 0,n == 0,n > 15,threshold > n, andm != thresholdare rejected.- Public keys must be strictly ascending, forbidding duplicates and permutations.
- Signer indices must satisfy
signer_idx < nand be strictly ascending, forbidding duplicate signer reuse and permutation malleability. - The decoder checks remaining bytes cover
n * 83 + 1 + threshold * 177before allocating vectors.
Transaction
TransactionBody :=
flag : u8 // 1 = coinbase, 0 = normal spend
if flag == 1:
coinbase_height : varint(u64)
else if flag == 0:
input_count : varint(usize <= 1024)
inputs : OutPoint[input_count]
else:
INVALID
output_count : varint(usize <= 1024)
outputs : Output[output_count]
Transaction :=
body : TransactionBody
if flag == 0:
auth_count : varint(usize <= 1024)
auth : TxAuth[auth_count]
Coinbase transactions serialize no inputs and no auth trailer.
Block
Block :=
header : BlockHeader (85 bytes)
tx_count : varint(usize <= 10000)
transactions : Transaction[tx_count]
The full serialized block must be at most 1,000,000 bytes.
Identifiers, sighash, and Merkle commitment
txid and wtxid
txid(tx) = BLAKE3("scruple-txid-v1" || encode_body(tx))
wtxid(tx) = BLAKE3("scruple-wtxid-v1" || encode(tx))
Reorg-safe sighash
sighash(tx, spent_utxos) = BLAKE3(
"scruple-sighash-v1"
|| txid(tx)
|| spent_utxos[0].txid || encode(spent_utxos[0].output)
|| spent_utxos[1].txid || encode(spent_utxos[1].output)
|| ...
)
Because outpoints are positional, a deep reorg could otherwise remap the same (height, tx_index, out_index) to a different UTXO. Binding every spent UTXO's creating txid and full output into the digest makes signatures reorg-safe with zero extra on-chain bytes. It also commits to every input amount and, through txid, every output amount, protecting offline and hardware signers against fee-drain attacks.
Dual Merkle root
- For each 32-byte leaf
L[i], computeN[i] = BLAKE3("scruple-merkle-leaf" || L[i]). - While more than one node remains, pair adjacent nodes and replace each pair with
BLAKE3("scruple-merkle-node" || left || right). Duplicate the last node when the count is odd. - An empty list hashes to 32 zero bytes.
tx_root = merkle_root(txids),wt_root = merkle_root(wtxids), andmerkle_root = BLAKE3("scruple-block-root-v1" || tx_root || wt_root).
Transaction validation
Every non-coinbase transaction must satisfy all of the following consensus rules:
- Size and bounds: encoded size at most 100,000 bytes; 1–1,024 inputs; 1–1,024 outputs; 1–1,024 auth entries, and at most one auth entry per input.
- Strictly ascending inputs:
inputs[i] < inputs[i+1]. Duplicate inputs are impossible. - Non-decreasing outputs:
outputs[i] <= outputs[i+1]. This removes change-position fingerprinting. - Output validity: version is 1 or 2, amount is at least 1 grain, and the sum does not overflow
u64. Mempool and wallet policy additionally enforce the 5,000-grain dust floor. - UTXO resolution and maturity: every outpoint exists in the active UTXO set; coinbase outputs obey maturity; input sum does not overflow and is at least the output sum.
- Deduplicated, sorted auth: compute the sorted unique set of
(addr_version, addr_hash)across all spent UTXOs. The auth list must be strictly ascending and match that set one-to-one. Spending several UTXOs from one address needs only one auth entry, and a transaction may mixv1andv2inputs. - SQIsign verification: single-sig verifies one compressed signature; multisig verifies exactly
thresholdsignatures from distinct ascending signer indices. - Fee:
fee = sum(inputs) - sum(outputs).
Block validation and fork choice
For a candidate block at height = parent.height + 1:
- Serialized size at most 1,000,000 bytes.
header.version == 1.header.prev_hashrefers to a known valid parent.- Timestamp: greater than the median time past of up to 11 ancestors (
MTP_11) and at most local time plus 1,200 seconds. - Difficulty:
target_bitsequals the LWMA result for the recent 61 headers. - Proof-of-work:
RandomX(seed, header) <= bits_to_target(target_bits). - Merkle root: transactions are non-empty and the header root matches the dual Merkle computation.
- Coinbase: height matches, inputs and auth are empty, 1–1,024 outputs, versions 1 or 2, amounts at least 1 grain, and the output sum is at most subsidy plus total fees. Mining directly to an
xsl2:vault is allowed. - Non-coinbase transactions: validated sequentially against the pre-block UTXO set. Spent inputs are removed immediately to prevent intra-block double spends; new outputs are inserted only after every transaction succeeds, so intra-block chaining is forbidden.
- Fork choice: cumulative work is
cum_work(parent) + work(target_bits)using saturatingU256. The active chain is the valid chain with strictly greatest cumulative work.
Proof-of-work
RandomX
RandomX hashes the 85-byte header. Validating nodes run Light Mode (~256 MB RAM). Solo miners may enable Full-Memory Mode (~2 GB shared dataset) for roughly an order of magnitude more CPU hashrate under identical consensus rules.
Compact target and work
exp = bits >> 24must satisfy1 <= exp <= 32.mant = bits & 0x00ffffffmust be non-zero with the sign bit clear.- The three mantissa bytes are placed big-endian starting at byte
32 - expof a 32-byte zero buffer, producing a 256-bit target. - A 32-byte RandomX hash interpreted as a big-endian integer satisfies PoW when it is less than or equal to the target.
work = floor(2^256 / (target + 1)), withwork(2^256 - 1) = 1.
Epoch rotation
if height < 2048 + 64: // heights 1 ..= 2111
seed = genesis_randomx_seed(network)
else: // height >= 2112
seed_height = floor((height - 64) / 2048) * 2048
seed = ancestor_block_hash(parent, seed_height)
The seed is looked up along the candidate header's own ancestor chain, so competing forks compute the same key deterministically without consensus ambiguity. The 64-block lag lets nodes pre-initialise the next epoch's cache or dataset without stalling at the boundary.
LWMA difficulty
Difficulty is recalculated for every block using integer Linearly Weighted Moving Average over up to 60 preceding intervals. Headers are ordered oldest to newest, with the parent as the final element.
- With fewer than two headers (mining block 1 on genesis), return the network's initial target.
- Let
N = min(headers.len() - 1, 60)andT = 300. - For each interval, clamp the timestamp delta to
[1, 1800]seconds with a monotonically non-decreasing previous timestamp, then accumulatek * dtand the work of each header. - Compute
expected_weighted = T * N * (N + 1) / 2,avg_work = sum_work / N, andnext_work = avg_work * expected_weighted / max(weighted_solvetimes, 1). - Convert back to a target:
max_targetifnext_work == 0, otherwisemax((2^256 - 1) / next_work, 1). - Clamp the result to between half and twice the tip target (and to the network maximum).
- Encode as compact
target_bits.
All arithmetic is exact u64/U256 integer math with no floating point. The 2× per-block clamp limits difficulty shocks while the weighted average resists timestamp manipulation.
Deterministic genesis
Each network derives its genesis block and RandomX epoch-zero seed from a fixed ASCII seed and timestamp (1796256000):
genesis_preimage = genesis_seed || genesis_timestamp (u64_le)
genesis_commitment = BLAKE3("scruple-genesis-v1" || genesis_preimage)
genesis_randomx_seed = BLAKE3("scruple-rx-genesis" || genesis_preimage)
The genesis block contains one coinbase paying 1 XSL to genesis_commitment. That output is an unspendable burn and is never inserted into the active UTXO set. The header uses the commitment as prev_hash, the genesis timestamp, the network's initial target, and nonce zero. scruple genesis --network <network> prints the block, hash, and epoch-zero seed for verification against a running node.
Peer-to-peer transport
Framing
[4 B p2p_magic][1 B kind][4 B payload_len_le][payload]
The 9-byte header is followed by at most MAX_FRAME_LEN = 1,000,128 bytes. The magic is network-specific, so cross-network connections fail at the first frame. Unknown kinds and oversized frames are rejected.
Message kinds
| ID | Name | Payload | Purpose |
|---|---|---|---|
| 1 | HELLO | height u64_le || tip[32] || addr_len u16_le || addr | Handshake, best height, advertised address |
| 2 | GET_HEADERS | count u16_le || locator hashes | Request headers after a locator (max 64 hashes) |
| 3 | HEADERS | count u16_le || 85-byte headers | Header batch (max 512) |
| 4 | GET_BLOCK | 32-byte block hash | Request a full block |
| 5 | BLOCK | Serialized block | Full block response |
| 6 | TX_STEM | Serialized transaction | Dandelion++ stem hop |
| 7 | TX_FLUFF | Serialized transaction | Dandelion++ fluff broadcast |
| 8 | PING | 8-byte nonce | Keepalive and RTT probe |
| 9 | PONG | 8-byte nonce | Ping reply |
| 10 | GET_PEERS | empty | Request peer gossip |
| 11 | PEERS | count u16_le || (len u16_le || addr)* | Peer gossip (max 64) |
| 12 | TX_BUMP | Serialized TxBump | Ownership-Proven FSS-RBF fee bump |
| 13 | DSPROOF | Serialized DoubleSpendProof | 0-conf double-spend fraud proof |
Handshake and sync
- Both sides send
HELLOimmediately with their height, tip hash, and advertised address. - Only
HELLO,PING, andPONGare accepted before the handshake. Any other pre-HELLO frame adds misbehavior score. - If the peer is ahead, the node requests headers using a locator of known block hashes.
- Headers are validated (PoW, LWMA, MTP, version) before full blocks are requested.
- Missing blocks are fetched by hash with bounded in-flight requests and global cross-peer deduplication.
- Pings run every 30 seconds; a missing pong for 30 seconds closes the session.
Peer management
| Limit | Value |
|---|---|
| Outbound slots | 8 |
| Inbound slots | 32 |
| Inbound slots per IP | 4 |
| Headers per message | 512 |
| Locator hashes | 64 |
| Peers per gossip message | 64 |
| Known addresses | 1,024 |
| Persisted peers | 256 |
| Ban threshold / duration | 100 points / 1 hour |
Outbound dials enforce /16 IPv4 and /32 IPv6 subnet diversity for DNS, gossip, and persisted peers. Explicit --peer and RPC add_peer targets bypass diversity so home-LAN clusters can full-mesh. Healthy peers are persisted atomically to <data-dir>/peers.json (mode 0600) every 60 seconds and on clean shutdown.
Misbehavior is scored per IP. Malformed frames, invalid PoW, invalid blocks, invalid headers, and bad signatures carry the heaviest scores; malformed payloads and pre-HELLO messages carry smaller scores. Reaching 100 points bans the IP for one hour.
Relay policy and mempool
These rules are local policy, not consensus:
- Minimum relay fee: 1 grain per serialized byte.
- Dust floor: 5,000 grains for mempool acceptance and wallet coin selection, while consensus still permits outputs down to 1 grain.
- Mempool bounds: 50,000,000 bytes, evicting the lowest fee-rate transactions first, with a 72-hour expiry and periodic rebroadcast of aged transactions.
- Dandelion++: originated transactions enter a stem phase routed to a per-epoch relay peer with a 20-second embargo. If the transaction is not observed fluffed, it falls back to full broadcast.
fast_fluff: trueor--fast-fluffbypasses the stem phase for point-of-sale use.
Ownership-Proven FSS-RBF
A TxBump { tx, shrink_proofs } can replace conflicting mempool transactions only if it strictly raises both the fee rate (at least the old rate plus 1 grain/byte) and the total fee, and preserves every output of every conflicted transaction at or above its original amount. Any output that is reduced or removed must carry a valid signature over BLAKE3("scruple-rbf-shrink-v1" || old_txid || new_txid) from the output recipient, proving the sender authorised shrinking their own change. At most four shrink proofs are allowed. A merchant's 0-conf output can never be reduced, redirected, or removed on an honest node.
0-conf double-spend proofs
When a node receives a valid conflicting spend that is not an authorised FSS-RBF replacement, it rejects the conflict, records a compact DoubleSpendProof { outpoint, original_txid, conflicting_tx }, broadcasts it to peers, and exposes it through the dsproofs RPC and the double_spend_detected flag on get_tx.
Consensus versus policy
| Consensus (requires a fork to change) | Policy (node-local) |
|---|---|
| Block and transaction size caps | Mempool memory cap and eviction |
| 1 XSL subsidy, 300-second target | Dust floor of 5,000 grains |
| RandomX PoW and epoch schedule | Minimum relay fee of 1 grain/byte |
| LWMA difficulty and 2× clamp | Dandelion++ stem probability and embargo |
| Canonical wire format and sorting | Peer slot counts and rate limits |
| Coinbase maturity and UTXO rules | Ban scoring thresholds and durations |
| Address versions and signature verification | FSS-RBF and double-spend proof relay |
Implementation notes and review findings
- One canonical encoding. Decoders reject non-minimal varints, trailing bytes, unknown auth tags, unsorted keys, and unsorted signer indices. A transaction that is valid on one implementation must be valid on all.
- Genesis coinbase is unspendable. The height-zero output is a burn commitment and is never added to the UTXO set. Do not expect to spend it.
- Positional outpoints are safe only with the sighash binding. The signature commits to each spent UTXO's creating txid and full output, so a reorg cannot replay a signature against a different coin at the same coordinates.
- txid excludes signatures. This is deliberate SQIsign malleability mitigation. Use
wtxidwhen you need to commit to the exact signature bytes. - Auth is per address, not per input. Multiple UTXOs from the same address share one auth entry; the auth list must exactly match the sorted unique spent address set.
- Difficulty is integer-only. The LWMA uses exact
U256arithmetic and clamps each step to half or double the tip target. There is no floating-point drift across platforms. - Epoch seeds follow the candidate's ancestors. Competing forks compute their own RandomX seed from their own chain, so there is no ambiguity about which seed applies at a given height.
- P2P magic is the first line of network isolation. A mainnet node and a testnet node cannot accidentally exchange frames, even if pointed at each other explicitly.
- Pre-HELLO data frames are penalised. A peer must complete the handshake before sending headers, blocks, transactions, or peer gossip.
- Pruning and txindex are storage policy. Pruning discards old block bodies and undo logs while retaining headers, the UTXO set, and the ever-seen address index. The txindex is mutually exclusive with pruning.
- FSS-RBF protects recipients. Fee bumps cannot reduce merchant outputs without a recipient signature, which is what makes 0-conf acceptance viable.