# Zkproof CLI Guide

## Prerequisites

The snarkjs CLI tool is required.  You can install it from this [repository](https://github.com/iden3/snarkjs).&#x20;

To install, use the following command:&#x20;

`npm install -g snarkjs@latest`.&#x20;

After installation, you can test it by typing `snarkjs --help`.

## Preprocessing Text

To generate a proof two files are needed. &#x20;

The **original text** and the **subtext of the original text** that you want to prove.&#x20;

Both text files must have a length of `15872` symbols. If your original text is smaller, you must add zero byte symbols (`\0x00`) to fill it up to `15872`. \
For the subtext, you must fill it with `\0x00` up to `15872` like the original text, except you must change symbols that you want to hide with zero byte symbols (`\0x00`).&#x20;

After that, you need to process the text to pass it to `snarkjs`. Convert the text and subtext into arrays containing `BigInt` (JavaScript) representation of text chunks (each chunk has a size of 31 bytes). After these transformations, create an `input.json` file with the following format:

```json
{
    "text": [...],
    "subtext": [...]
}
```

Here is example code that generates processed text

```javascript
function convertToByteArray(strToConvert) {
    let byte_arr = [];
    for (let i = 0; i < strToConvert.length; i++) {
        let code = strToConvert.charCodeAt(i);
        byte_arr.push(code);
    }
    return byte_arr
}

function byteArrayToBigInt(byteArray) {
    return BigInt('0x' + Array.from(byteArray, function (byte) {
        return ('0' + (byte & 0xFF).toString(16)).slice(-2);
    }).join(''));
}


function textToBigIntChunks(text) {
    text = text.substr(0, 15872);

    const textBytes = convertToByteArray(text)
    const paddedBytes = new Uint8Array(15872);
    paddedBytes.set(textBytes);

    const chunkSize = 31;
    const chunks = [];
    for (let i = 0; i < paddedBytes.length; i += chunkSize) {
        const chunk = paddedBytes.subarray(i, i + chunkSize);
        const chunkBigInt = byteArrayToBigInt(chunk);
        chunks.push(chunkBigInt);
    }

    return chunks;

}
```

## Generating Proof

To generate proof generation you need to call the `snarkjs groth16 fullprove` CLI command with the following files that you can download from our repository:

* `input.json`: your input file (preprocessed text and subtext in JSON file format)
* `circuit.wasm`: file containing circuits compiled in WASM format (you can find this file in our repository)
* `circuit_final.zkey`: file containing verification keys (you can find this file in our repository)

&#x20;This command creates two files: proof.json and public.json.

* `proof.json` contains the actual proof
* `public.json` contains the values of the public inputs and output

{% hint style="warning" %}
Please save proof.json and public.json, because without these files, you cannot verify the proof!
{% endhint %}

## Verifying Proof

For verification three files are needed - `verification_key.json` (located in our repository), `public.json` and `proof.json` that you get from [Generating Proo](#generating-proof)[f](#generating-proof).&#x20;

To verify proof you must write the following command:

`snarkjs groth16 verify verification_key.json public.json proof.json`&#x20;

If all is well, you should see that OK has been outputted to your console. This signifies the proof is valid.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.r.xyz/main/engram/zkproof-cli-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
