> For the complete documentation index, see [llms.txt](https://docs.voting.works/vxsuite-tdp-v4.1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.voting.works/vxsuite-tdp-v4.1/system-security-auditing-and-logging/software-security/artifact-authentication/hashing-of-continuously-exported-cast-vote-records.md). Agents can also search and read this documentation through its [MCP server](https://docs.voting.works/vxsuite-tdp-v4.1/~gitbook/mcp).

# Hashing of Continuously Exported Cast Vote Records

## Continuous Export

VxSuite precinct scanners export cast vote records (CVRs) to USB drive continuously, as ballots are cast. Continuous export also allows for a speedy polls close, as cast vote records need not be exported all at once on polls close.

## Merkle Tree Structure

To perform continuous export while also keeping signatures, i.e., authenticity information, up-to-date, the scanner must be able to write both CVRs and authenticity information incrementally. Hashing and signing only the new data is not sufficient; an up-to-date root hash and signature are required. A [Merkle tree](https://en.wikipedia.org/wiki/Merkle_tree) structure accomplishes this efficiently.

<figure><img src="https://629495352-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ4bC0rbmogHEUUuMLAUa%2Fuploads%2Fgit-blob-7a95f5a614e4c0cef9e1570a7511ddce5e550032%2Fdiagram-cvr-hash-tree.svg?alt=media" alt="Merkle tree in which leaf data block hashes combine pairwise up to a single top hash" width="563"><figcaption></figcaption></figure>

Assuming every CVR has a random universally unique identifier (UUID), e.g., 4d6a9dad-e6d6-4a29-89bc-9ab915012b73, the following structure can be used:

```
<cvr-directory-name>.vxsig ← Signature on root-hash.txt
<cvr-directory-name>/
  root-hash.txt ← hash( concatenation of all * hashes )
  4/
    4-hash.txt ← hash( concatenation of all 4* hashes )
    4d/
      4d-hash.txt ← hash( concatenation of all 4d****... hashes )
      4d6a9dad-e6d6-4a29-89bc-9ab915012b73/
        4d6a9dad-e6d6-4a29-89bc-9ab915012b73-hash.txt
        cast-vote-record-report.json
        Images
```

### On the Machine and on the USB Drive

The nested structure above describes the tree; it is not how files are laid out on the USB drive. The scanner keeps the tree's intermediate hashes on its internal disk and updates them as each cast vote record is added, so the root hash can be recomputed without reading anything back from the USB drive. Computing hashes only from the scanner's own records protects against [compromised or faulty USB drives](https://github.com/votingworks/vxsuite/pull/3554).

The USB drive holds a flat structure, one directory per cast vote record, and VxSuite signs a `metadata.json` file that carries the root hash along with other export metadata:

```
<cvr-directory-name>.vxsig ← Signature on metadata.json
<cvr-directory-name>/
  metadata.json
  4d6a9dad-e6d6-4a29-89bc-9ab915012b73/
    cast-vote-record-report.json
    Images
```

Sample `metadata.json`:

```
{
  "arePollsClosed": false,
  "castVoteRecordRootHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
  ...
}
```

## Import

Whenever a machine imports a CVR directory, it authenticates the CVRs by 1) verifying the signature on the metadata.json file and 2) recomputing the “castVoteRecordRootHash” in metadata.json from scratch to confirm that it is correct.

## Code Links

Refer to the following code links for more details:

* [libs/auth/src/cast\_vote\_record\_hashes.ts](https://github.com/votingworks/vxsuite/blob/v4.1.1/libs/auth/src/cast_vote_record_hashes.ts) — CVR hashing logic, including the Merkle tree implementation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.voting.works/vxsuite-tdp-v4.1/system-security-auditing-and-logging/software-security/artifact-authentication/hashing-of-continuously-exported-cast-vote-records.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
