# Matrices

> What a matrix is, its shape and how it's stored as bytes, and what Pearl's matrices A and B are: sizes, rules and a real mined block's dimensions.

Source: https://pearlcodex.com/technical/math/matrices/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

A [matrix](https://pearlcodex.com/glossary/#matrix) is a grid of numbers, arranged in rows and columns. That’s all.

Matrices matter to Pearl because they matter to AI. A language model stores what it has learned as huge matrices of numbers, and running it means multiplying matrices, billions of times. Pearl’s mining is exactly that multiplication. This group of pages explains the math behind it, starting with the grids themselves.

## What does a matrix look like?

Here is a small one: the toy matrix A from Pearl’s [worked mining example](https://pearlcodex.com/technical/mining/the-puzzle/). It has 4 rows and 16 columns, filled with whole numbers from −4 to 4. Darker cells hold bigger numbers, positive or negative.

_The toy matrix A, 4 × 16. In an AI model each row would be one token and each column one feature. Toy numbers from the research worked example._

Its **shape** is 4 × 16: rows first, then columns. It has 4 × 16 = 64 entries. The entry in row i and column j is written A_ij, so A\_(0,2) = 4. (Programmers count from 0.)

A matrix with one row or one column is called a vector. A matrix with as many rows as columns is square. Pearl’s are usually rectangular.

## What are Pearl’s matrices A and B?

A Pearl miner multiplies two matrices of its own choosing:

$$
A \;(m \times k) \;\times\; B \;(k \times n) \;=\; C \;(m \times n)
$$

_The inner sizes must match: A has k columns, B has k rows. k is called the shared or common dimension._

In Pearl’s official miner, the multiplication is a layer of a language model running inside the vLLM serving software:

- **A** holds the model’s activations: one row per token (a word piece), one column per feature. Mining only kicks in when a batch has at least 1,024 tokens.
- **B** holds the layer’s weights: k inputs by n outputs.
- **C** = A·B is the layer’s output, which the model needs anyway.

In practice the GPU kernel keeps the weights as an n × k grid and computes A times its transpose. The transpose Bᵀ is B flipped over its diagonal, rows becoming columns. That turns out to be exactly the layout Pearl fingerprints, as you’ll see below.

> **Note: Any matrices will do**
>
> Consensus never asks what A and B mean. Random numbers pass verification exactly like a real model layer, and Pearl’s reference CPU miner multiplies random matrices. Whether mining does useful work is up to the miner. See [useful output](https://pearlcodex.com/technical/mining/useful-output/).

## Where are A and B inside a language model?

In the official miner’s mining mode, any large linear layer can mine: the attention projections (query, key, value and output) and the feed-forward projections (gate, up and down). Each multiplies a batch’s activations by a weight matrix.

Only big multiplications mine: at least 1,024 tokens, n of at least 256 and k of at least 1,024. Smaller ones run as a plain multiplication. That suggests, though Pearl doesn’t say so, that mining happens mostly while a model reads long prompts or large batches, not while it writes one token at a time. Pearl Research Labs publish versions of Llama 3.3 70B and Llama 3.1 8B prepared for the miner.

## What rules do the matrices have to follow?

The certificate declares the sizes, and every node checks them:

| Rule                       | Value                                             |
| -------------------------- | ------------------------------------------------- |
| Entries of A and B         | whole numbers in \[−64, 64]                       |
| Shared size k              | 1,024 to 65,536 (2¹⁶), a multiple of 64           |
| k against the noise rank r | 16·r ≤ k ≤ 4·r², so with r = 128: 2,048 to 65,536 |
| Rows m and columns n       | at most 2²⁴ = 16,777,216 each                     |

The entries’ range is narrow on purpose: the [integers page](https://pearlcodex.com/technical/math/integers-and-quantization/) explains why. The link between k and r comes from the [noise](https://pearlcodex.com/technical/math/rank-and-noise/).

**Make a guess:** The certificate of block 130,825 says m = 131,072, k = 8,192 and n = 262,144. If each entry is one byte, how big are A and B?

**Answer:** About 1 GiB and 2 GiB.

A has 131,072 × 8,192 = 1,073,741,824 entries, exactly 1 GiB at one byte each. B has 8,192 × 262,144 = 2,147,483,648, exactly 2 GiB. Those are the sizes the miner declared and committed to; no node ever downloads them.

## How is a matrix stored as bytes?

A computer’s memory is one long line of bytes, so a grid has to be flattened. There are two natural ways:

- **[Row-major](https://pearlcodex.com/glossary/#row-major):** row 0 left to right, then row 1, and so on.
- **Column-major:** column 0 top to bottom, then column 1, and so on.

_The same 3 × 4 grid, numbered in storage order. Pearl stores A row-major and B column-major._

Each entry is one signed byte (−3 is `fd`, see [bytes](https://pearlcodex.com/technical/general/bytes/)). So the first row of the toy A, `−3, 1, 4, 4, …`, becomes the bytes `fd 01 04 04 …`.

## How does Pearl fingerprint a matrix?

Before mining, the miner commits to both matrices. It takes the bytes of A row by row, and of B column by column, pads each with zero bytes to a multiple of 1,024, and hashes them with keyed [BLAKE3](https://pearlcodex.com/technical/cryptography/hash-functions/), using the job key:

$$
\text{hash}_A = \mathrm{BLAKE3}_{\text{job key}}\big(\text{pad}_{1024}(A \text{ row by row})\big)
$$

BLAKE3 is a [Merkle tree](https://pearlcodex.com/technical/cryptography/merkle-trees/) over 1 KiB chunks, so this fingerprint is a Merkle root. Later, the miner can prove that the two rows and few columns of its winning tile belong to the committed matrices, with short paths of sibling hashes.

That’s why B is stored by columns. A tile needs whole columns of B, and column-major storage makes each column a contiguous run of chunks.

Block 130,825’s certificate carries both fingerprints (raw bytes, as stored):

| Field  | Value                                                              |
| ------ | ------------------------------------------------------------------ |
| hash_A | `8e17f731a0c6f8e09a7a29f19732fc29f65932b63886013274b920b057e6930f` |
| hash_B | `c2e4cb51cff3f95861c45248b6369f5c2dbd623895a3146be39134d060837c8d` |

These fingerprints feed the [noise seeds](https://pearlcodex.com/technical/mining/noise-seeds/): change one entry of A and all of A’s noise changes; change one entry of B and the noise of both matrices changes, because B’s seed feeds into A’s.

**Code: flattening and fingerprinting in JavaScript**

This is the same procedure the codex’s toy miner uses, mirroring Pearl’s reference miner:

```js
import { blake3 } from '@noble/hashes/blake3.js';

const rowMajor = (M) => Int8Array.from(M.flat());                 // A, row by row
const colMajor = (M) => Int8Array.from(M[0].flatMap((_, j) => M.map((row) => row[j]))); // B, column by column
const pad1024 = (b) => { const out = new Uint8Array(Math.ceil(b.length / 1024) * 1024); out.set(new Uint8Array(b.buffer)); return out; };

const hashA = blake3(pad1024(rowMajor(A)), { key: jobKey });
const hashB = blake3(pad1024(colMajor(B)), { key: jobKey });
```

Pearl’s reference CPU miner draws A and B at random and commits to them in [`ffi/mine.rs`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/zk-pow/src/ffi/mine.rs#L15-L52).

## In short

- A matrix is a grid of numbers. Its shape is rows × columns, and an m × k matrix has m·k entries.
- Pearl’s miner multiplies A (m × k) by B (k × n). The shared size k must match; in an AI model, A holds one row per token and B is a layer’s weights.
- Consensus rules fix the ingredients, not the meaning: entries in \[−64, 64], k between 1,024 and 65,536 and a multiple of 64, m and n at most 2²⁴.
- Matrices are stored as long rows of signed bytes: A row by row, B column by column, then fingerprinted with keyed BLAKE3.
- The certificate of block 130,825 declares A as 131,072 × 8,192 and B as 8,192 × 262,144: about 3 GB of data.

## Read the code

- [The size rules for k, m, n and tiles](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/zk-pow/src/api/sanity_checks.rs#L15-L60) `zk-pow/src/api/sanity_checks.rs:15-60`
- [The reference miner draws random matrices and fingerprints them](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/zk-pow/src/ffi/mine.rs#L15-L52) `zk-pow/src/ffi/mine.rs:15-52`
- [Mining inside a model's matrix multiplications](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/miner/vllm-miner/src/vllm_miner/gemm_operators.py#L68-L217) `miner/vllm-miner/src/vllm_miner/gemm_operators.py:68-217`

## Sources

### Pearl docs

- [Pearl INT whitepaper, §4.2–4.3](https://pearlresearch.ai/research/int-whitepaper)
- [Proof of Useful Work from the Ground Up (Pearl Research Labs blog)](https://pearlresearch.ai/research/blog/proof-of-useful-work)

### Other

- [Matrix (mathematics), Wikipedia](https://en.wikipedia.org/wiki/Matrix_\(mathematics\))
