# Magic bytes and ports

> Pearl's network magic 0x50524C4D (PRLM), why it's stored as 4d 4c 52 50, where it appears now that BIP-324 encrypts everything, and the ports for each network.

Source: https://pearlcodex.com/technical/networking/magic-bytes-and-ports/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

Pearl isn’t one network but several: the real one, mainnet, plus test networks whose coins are worthless. They run the same software. Something has to keep them from mixing, so that a test block never ends up on the real chain.

In Bitcoin, that something is the [magic bytes](https://pearlcodex.com/glossary/#magic-bytes): four bytes that open every message, saying which network it belongs to. Pearl has magic bytes too, “PRLM” for mainnet. But you will never see them on the wire. Pearl encrypts every connection, so the magic does its job in a quieter place.

## Try it

Type `50524C4D` as hex and flip the byte order. You get `4D4C5250`: the same number, stored the way pearld stores it.

_Interactive: Hex converter. Try it on the page: <https://pearlcodex.com/technical/networking/magic-bytes-and-ports/>_

## What are Pearl’s magic bytes?

Each network has a 4-byte number, chosen so that its hex spells letters:

| Network  | Magic (number) | As text | Bytes on disk | P2P port | RPC port |
| -------- | -------------- | ------- | ------------- | -------- | -------- |
| Mainnet  | `0x50524C4D`   | PRLM    | `4d 4c 52 50` | 44108    | 44107    |
| Testnet  | `0x50524C31`   | PRL1    | `31 4c 52 50` | 44110    | 44109    |
| Testnet2 | `0x50524C32`   | PRL2    | `32 4c 52 50` | 44112    | 44111    |
| Regtest  | `0x50524C52`   | PRLR    | `52 4c 52 50` | 18444    | 18334    |
| Simnet   | `0x50524C53`   | PRLS    | `53 4c 52 50` | 18555    | 18556    |
| Signet   | `0x40CF030A`   | (none)  | `0a 03 cf 40` | 38333    | 38332    |

`0x50 0x52 0x4C` is ASCII for “PRL”, and the last byte names the network: `M` for mainnet, `1` and `2` for the testnets, `R` for regtest, `S` for simnet. Signet’s magic is derived from a hash of its challenge script instead, as in Bitcoin.

## Why are the bytes backwards?

Because pearld writes the magic as a 4-byte [little-endian](https://pearlcodex.com/glossary/#little-endian) number, smallest byte first, exactly as Bitcoin does with its own magic (`0xD9B4BEF9`, written `f9 be b4 d9`). So `0x50524C4D` becomes `4d 4c 52 50`, which as ASCII reads “MLRP”. Byte order is explained on [byte order](https://pearlcodex.com/technical/general/byte-order/).

## Where do the magic bytes appear?

Not on the network. Pearl peers only speak [BIP-324 encrypted transport](https://pearlcodex.com/technical/networking/encrypted-transport/), and BIP-324 messages have no plaintext header at all: no magic, no command name, no checksum. To anyone watching, a Pearl connection is a stream of random-looking bytes.

The magic shows up in two places instead:

- **In the key derivation.** When two nodes set up encryption, they turn their shared secret into keys with [HKDF](https://pearlcodex.com/glossary/#hkdf), salted with the text `pearl_v2_shared_secret` followed by the magic’s four bytes.
- **On disk.** pearld’s block files store each block after the network’s magic, as Bitcoin nodes do.

Here is mainnet’s salt, as pearld builds it:

**BIP-324 HKDF salt, mainnet · 26 bytes**

```
706561726c5f76325f7368617265645f736563726574 4d4c5250
```

| Field                    | Bytes        | Value                  |
| ------------------------ | ------------ | ---------------------- |
| "pearl_v2_shared_secret" | 22, offset 0 | 22 bytes of ASCII text |
| Magic, little-endian     | 4, offset 22 | 0x50524C4D, "PRLM"     |

_26 bytes: the ASCII text pearl_v2_shared_secret, then the magic in little-endian order. Bitcoin's uses bitcoin_v2_shared_secret and f9 be b4 d9._

## Then how are networks kept apart?

By that salt. A mainnet node and a testnet node that connect by mistake each derive their encryption keys with their own magic in the salt: `4d4c5250` against `314c5250`. Their keys don’t match, so neither can decrypt the other, and the connection fails before a single real message. In Bitcoin’s old v1 protocol the same job is done by checking the magic at the start of each message; in Pearl it is done by cryptography.

Each network also has its own ports, its own genesis block and its own address prefix (`prl1…` on mainnet, `tprl1…` on testnet), so even outside the wire protocol the networks rarely look alike.

## Which ports does Pearl use?

On mainnet:

- **Peer-to-peer:** 44108 open to the internet for incoming peers
- **pearld RPC:** 44107 local commands; keep it private
- **Oyster wallet RPC:** 44207 the wallet daemon

A node only needs the P2P port open to accept incoming peers. It can run perfectly well with only outgoing connections; it just won’t be listed by the [DNS seeds](https://pearlcodex.com/technical/networking/peers-and-seeds/), which only hand out nodes reachable on 44108.

**Make a guess:** A firewall vendor wants to block Bitcoin and Pearl traffic by spotting magic bytes in packets. Which one can it catch that way?

**Answer:** Only Bitcoin’s v1 connections.

Bitcoin’s unencrypted v1 messages start with `f9 be b4 d9`. Pearl never sends v1 messages, and its encrypted stream contains no fixed bytes to match. A firewall could still block port 44108, or guess from traffic patterns, but not from the magic.

> **Pearl vs Bitcoin**
>
> Bitcoin’s magic `f9 be b4 d9` starts every message of the original, unencrypted protocol, which Bitcoin Core still falls back to when a peer doesn’t support BIP-324. Pearl has no fallback, so its magic never appears on the wire; it lives in the BIP-324 salt (`pearl_v2_shared_secret` instead of `bitcoin_v2_shared_secret`) and in block files. Ports differ too: 44108 and 44107 instead of 8333 and 8332.

**Code: magic values and the salt**

From [`protocol.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/wire/protocol.go#L133-L152):

`node/wire/protocol.go`

```go
MainNet  PearlNet = 0x50524C4D // "PRLM" in ASCII
RegTest  PearlNet = 0x50524C52 // "PRLR" in ASCII
TestNet  PearlNet = 0x50524C31 // "PRL1" in ASCII
TestNet2 PearlNet = 0x50524C32 // "PRL2" in ASCII
SigNet   PearlNet = 0x40CF030A
SimNet   PearlNet = 0x50524C53 // "PRLS" in ASCII
```

And the salt, from [`transport.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/v2transport/transport.go#L194-L200):

`node/v2transport/transport.go`

```go
salt := []byte("pearl_v2_shared_secret")
var magic [4]byte
binary.LittleEndian.PutUint32(magic[:], uint32(net))
salt = append(salt, magic[:]...)
```

## In short

- Each Pearl network has a 4-byte magic number. Mainnet’s is 0x50524C4D, the ASCII letters PRLM.
- Written little-endian, as Pearl’s code does, the bytes come out reversed: 4d 4c 52 50, or MLRP.
- Because every connection is BIP-324 encrypted, the magic never appears on the wire. It goes into the encryption’s key derivation, after the text pearl_v2_shared_secret, and into block files on disk.
- Different magic means different keys, so nodes on different Pearl networks can’t even complete a handshake with each other.
- Mainnet nodes listen for peers on port 44108; pearld’s RPC is on 44107 and the Oyster wallet’s on 44207. Testnets use 44110 and 44112.

## Read the code

- [The network magic values](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/wire/protocol.go#L133-L152) `node/wire/protocol.go:133-152`
- [HKDF salt: pearl_v2_shared_secret plus the magic](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/v2transport/transport.go#L194-L200) `node/v2transport/transport.go:194-200`
- [DefaultPort: 44108](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/chaincfg/params.go#L344) `node/chaincfg/params.go:344`
- [RPC ports per network](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/params.go#L26-L67) `node/params.go:26-67`
- [The magic is written before each stored block](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/database/ffldb/blockio.go#L500-L505) `node/database/ffldb/blockio.go:500-505`

## Sources

### Pearl source

- [Pearl source code at v1.5.5](https://github.com/pearl-research-labs/pearl/tree/v1.5.5)

### Bitcoin standards

- [BIP-324: Version 2 P2P Encrypted Transport Protocol](https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki)

### Other

- [Bitcoin Developer Reference: message headers](https://developer.bitcoin.org/reference/p2p_networking.html#message-headers)
