℈Scruple Docs v0.1.0-alpha.1

Protocol

Protocol

The frozen consensus rules, canonical byte format, proof-of-work, difficulty, and peer-to-peer transport behind XSL.

Frozen consensus

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

ParameterValueNotes
Name / ticker / symbolScruple / XSL / ℈ (U+2108)Base unit: grains
Subdivision100,000,000 grains per XSLAll amounts are u64 grains
Block subsidy100,000,000 grains (1 XSL)Fixed forever; ~105,120 XSL/year at 5-minute blocks
Target block time300 secondsMainnet, testnet, and devnet
Maximum block size1,000,000 bytesFull serialized block; 1:1 weight
Maximum transaction size100,000 bytesFull serialized transaction
Maximum inputs / outputs / auth entries1,024 eachPer transaction
Maximum transactions per block10,000Wire decode upper bound
Consensus minimum output1 grainStrict consensus floor
Policy dust floor5,000 grainsNon-consensus mempool and wallet policy
Block version1Strict equality
Maximum multisig keys15Upper bound for N
Coinbase maturityMainnet 24 · Testnet 6 · Devnet 2Spendable when spend_height >= outpoint.height + maturity
LWMA window60 intervalsPer-block difficulty adjustment
RandomX epoch length2,048 blocks~7.1 days
RandomX epoch lag64 blocksPre-initialisation window
Maximum future block time1,200 secondsRelative to local wall clock
Mainnet target bitsInitial 0x1e0fffff · max 0x1f7fffffCompact Bitcoin-style nBits
Testnet target bitsInitial 0x1f0fffff · max 0x207fffffFast start, then LWMA adapts
Devnet target bitsInitial 0x200fffff · max 0x207fffffFast local testing

Networks

NetworkP2P magicP2P / RPC portAddress HRPGenesis seed
MainnetXSL1 (58534C31)18333 / 18332xslscruple-mainnet-genesis-v1
TestnetXSLT (58534C54)28333 / 28332txslscruple-testnet-genesis-v1
DevnetXSLD (58534C44)18333 / 18332dxslscruple-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.

FormExample prefixNotes
Bech32m v1xsl1p...Single-key; 6-character BCH checksum
Bech32m v2xsl1z...Multisig; checksummed and network-scoped
Legacy v1xsl1:<64-hex>Still accepted; no checksum
Legacy v2xsl2:<64-hex>Still accepted; no checksum
Use Bech32m for new addresses

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 tagInputPurpose
scruple-addr-v1pubkey (83 B)v1 address hash
scruple-addr-v2threshold || n || pubkeys...v2 multisig address hash
scruple-txid-v1encode_body(tx)Non-malleable transaction id
scruple-wtxid-v1encode(tx)Witness transaction id (includes auth)
scruple-sighash-v1txid || Σ(utxo.txid || encode(utxo.output))Reorg-safe signature digest
scruple-merkle-leafleaf_hash (32 B)Merkle leaf
scruple-merkle-nodeleft || right (64 B)Merkle internal node
scruple-block-root-v1tx_root || wt_rootDual root in the header
scruple-header-v1header_bytes (85 B)Block hash
scruple-genesis-v1genesis_seed || timestamp_leGenesis commitment
scruple-rx-genesisgenesis_seed || timestamp_leRandomX epoch-zero seed
scruple-hd-v1master_seed || index_leHD child key derivation
scruple-rbf-shrink-v1old_txid || new_txidOwnership proof for FSS-RBF shrink

SQIsign Round-3 Level 1

ItemSizeNotes
Public key83 bytesPublicKey::<Level1>::to_bytes()
Compressed signature176 bytesSignature::compress().to_bytes()
Single-sig auth entry260 bytes1 B tag + 83 B pk + 176 B sig
Multisig auth entry4 + 83n + 177m bytestag + threshold + n + m + pubkeys + (signer_idx, sig)*
2-of-3 multisig auth607 bytesOne 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 in 0x00; 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)

OffsetLengthFieldDescription
01versionMust be 1
132prev_hashParent block hash; genesis commitment for height 0
3332merkle_rootDual txid/wtxid root
658timestampUnix seconds, little-endian
734target_bitsCompact target, little-endian
778noncePoW 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, and m != threshold are rejected.
  • Public keys must be strictly ascending, forbidding duplicates and permutations.
  • Signer indices must satisfy signer_idx < n and be strictly ascending, forbidding duplicate signer reuse and permutation malleability.
  • The decoder checks remaining bytes cover n * 83 + 1 + threshold * 177 before 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

  1. For each 32-byte leaf L[i], compute N[i] = BLAKE3("scruple-merkle-leaf" || L[i]).
  2. 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.
  3. An empty list hashes to 32 zero bytes.
  4. tx_root = merkle_root(txids), wt_root = merkle_root(wtxids), and merkle_root = BLAKE3("scruple-block-root-v1" || tx_root || wt_root).

Transaction validation

Every non-coinbase transaction must satisfy all of the following consensus rules:

  1. 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.
  2. Strictly ascending inputs: inputs[i] < inputs[i+1]. Duplicate inputs are impossible.
  3. Non-decreasing outputs: outputs[i] <= outputs[i+1]. This removes change-position fingerprinting.
  4. 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.
  5. 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.
  6. 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 mix v1 and v2 inputs.
  7. SQIsign verification: single-sig verifies one compressed signature; multisig verifies exactly threshold signatures from distinct ascending signer indices.
  8. Fee: fee = sum(inputs) - sum(outputs).

Block validation and fork choice

For a candidate block at height = parent.height + 1:

  1. Serialized size at most 1,000,000 bytes.
  2. header.version == 1.
  3. header.prev_hash refers to a known valid parent.
  4. Timestamp: greater than the median time past of up to 11 ancestors (MTP_11) and at most local time plus 1,200 seconds.
  5. Difficulty: target_bits equals the LWMA result for the recent 61 headers.
  6. Proof-of-work: RandomX(seed, header) <= bits_to_target(target_bits).
  7. Merkle root: transactions are non-empty and the header root matches the dual Merkle computation.
  8. 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.
  9. 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.
  10. Fork choice: cumulative work is cum_work(parent) + work(target_bits) using saturating U256. 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 >> 24 must satisfy 1 <= exp <= 32.
  • mant = bits & 0x00ffffff must be non-zero with the sign bit clear.
  • The three mantissa bytes are placed big-endian starting at byte 32 - exp of 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)), with work(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.

  1. With fewer than two headers (mining block 1 on genesis), return the network's initial target.
  2. Let N = min(headers.len() - 1, 60) and T = 300.
  3. For each interval, clamp the timestamp delta to [1, 1800] seconds with a monotonically non-decreasing previous timestamp, then accumulate k * dt and the work of each header.
  4. Compute expected_weighted = T * N * (N + 1) / 2, avg_work = sum_work / N, and next_work = avg_work * expected_weighted / max(weighted_solvetimes, 1).
  5. Convert back to a target: max_target if next_work == 0, otherwise max((2^256 - 1) / next_work, 1).
  6. Clamp the result to between half and twice the tip target (and to the network maximum).
  7. 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

IDNamePayloadPurpose
1HELLOheight u64_le || tip[32] || addr_len u16_le || addrHandshake, best height, advertised address
2GET_HEADERScount u16_le || locator hashesRequest headers after a locator (max 64 hashes)
3HEADERScount u16_le || 85-byte headersHeader batch (max 512)
4GET_BLOCK32-byte block hashRequest a full block
5BLOCKSerialized blockFull block response
6TX_STEMSerialized transactionDandelion++ stem hop
7TX_FLUFFSerialized transactionDandelion++ fluff broadcast
8PING8-byte nonceKeepalive and RTT probe
9PONG8-byte noncePing reply
10GET_PEERSemptyRequest peer gossip
11PEERScount u16_le || (len u16_le || addr)*Peer gossip (max 64)
12TX_BUMPSerialized TxBumpOwnership-Proven FSS-RBF fee bump
13DSPROOFSerialized DoubleSpendProof0-conf double-spend fraud proof

Handshake and sync

  1. Both sides send HELLO immediately with their height, tip hash, and advertised address.
  2. Only HELLO, PING, and PONG are accepted before the handshake. Any other pre-HELLO frame adds misbehavior score.
  3. If the peer is ahead, the node requests headers using a locator of known block hashes.
  4. Headers are validated (PoW, LWMA, MTP, version) before full blocks are requested.
  5. Missing blocks are fetched by hash with bounded in-flight requests and global cross-peer deduplication.
  6. Pings run every 30 seconds; a missing pong for 30 seconds closes the session.

Peer management

LimitValue
Outbound slots8
Inbound slots32
Inbound slots per IP4
Headers per message512
Locator hashes64
Peers per gossip message64
Known addresses1,024
Persisted peers256
Ban threshold / duration100 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: true or --fast-fluff bypasses 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 capsMempool memory cap and eviction
1 XSL subsidy, 300-second targetDust floor of 5,000 grains
RandomX PoW and epoch scheduleMinimum relay fee of 1 grain/byte
LWMA difficulty and 2× clampDandelion++ stem probability and embargo
Canonical wire format and sortingPeer slot counts and rate limits
Coinbase maturity and UTXO rulesBan scoring thresholds and durations
Address versions and signature verificationFSS-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 wtxid when 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 U256 arithmetic 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.

Scruple Docs · v0.1.0-alpha.1 · Mainnet candidate

Scruple is alpha software. Verify commands against --help and the protocol specification before relying on them.