Skip to content

Commit

Permalink
Merge pull request #50 from NilFoundation/zkllvm-diagram-reordering
Browse files Browse the repository at this point in the history
added a new page in Overview with usage flows
  • Loading branch information
khannanov-nil authored May 22, 2024
2 parents af1f6e3 + 91539a5 commit 2c31d80
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 106 deletions.
7 changes: 6 additions & 1 deletion sidebar-zkllvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default {
label: 'Key components and tools',
id: 'overview/key-components-tools'
},
{
type: 'doc',
label: 'Usage flow',
id: 'overview/usage-flow'
}
]
},
{
Expand Down Expand Up @@ -86,7 +91,7 @@ export default {
collapsed: true,
items: [
{

type: 'doc',
label: 'Refactoring if/else statements',
id: 'best-practices-limitations/avoiding-if-else-statements'
Expand Down
78 changes: 3 additions & 75 deletions zkllvm/getting-started/compiling-a-circuit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,85 +13,13 @@ There are two possible ways for transforming a circuit into a proof binary and S

## Calling individual tools

The following diagram shows the flow for converting a `.cpp` or a `.rs` file into a proof binary and Solidity code for deployment.

```mermaid
%%{
init: {
'theme': 'base',
'themeVariables': {
'primaryColor': '#0f0f0f',
'primaryTextColor': '#f1f1f1',
'primaryBorderColor': '#f1f1f1',
'lineColor': '#87B6FC',
'secondaryColor': '#f1f1f1',
'tertiaryColor': '#2f2f2f',
},
'flowchart':
{
'defaultRenderer': 'elk',
'curve': 'step'
}
}
}%%
flowchart TB
classDef transpilerTitle margin-right: 250px;
Transpiler:::transpilerTitle
CPP(C++ code)
RUST(Rust code)
CLANG(<code>clang</code>)
RUSTCOMP(<code>cargo</code> #40;<code>rustc</code>#41;)
IR(Circuit IR)
INPUTS(Circuit inputs)
ASSIGNER(Assigner)
ASSIGNERRESULT(<code>.tbl</code> and <code>.crct</code> files)
TRANSPILER(<code>transpiler</code>)
PROOFBIN(Proof binary)
SOLIDITY(Solidity contracts)
CPP --> CLANG
RUST --> RUSTCOMP
CLANG --> IR
RUSTCOMP --> IR
IR --> ASSIGNER
INPUTS --> ASSIGNER
ASSIGNER --> ASSIGNERRESULT
ASSIGNERRESULT --> TRANSPILER
TRANSPILER --> PROOFBIN
TRANSPILER --> SOLIDITY
subgraph Code
CPP
RUST
end
subgraph Compilation
direction LR
CLANG
RUSTCOMP
IR
end
subgraph Assigner
direction LR
INPUTS
ASSIGNER
ASSIGNERRESULT
end
subgraph Transpiler
direction LR
TRANSPILER
PROOFBIN
SOLIDITY
end
```

Complete the below steps to follow this flow.

### Running the compiler
### Run the compiler

To generate the circuit IR, complete one of the following tutorials.

<DocCardList/>

### Passing the IR to `assigner`
### Pass the IR to `assigner`

At this stage, the newly generated IR and the public info file are ready to be passed to `assigner`.

Expand All @@ -101,7 +29,7 @@ Run the following command to generate the circuit constraints and the assignment
assigner -b path/to/circuit.ll -i path/to/public_input.inp -c circuit.crct -t assignment.tbl -e pallas --generate-type circuit-assignment
```

### Using `transpiler` to generate the circuit proof
### Use `transpiler` to generate the circuit proof

The `.crct` and `.tbl` files can be passed to the `transpiler` tool to generate a binary with the proof and Solidity files containing the circuit.

Expand Down
111 changes: 111 additions & 0 deletions zkllvm/overview/usage-flow.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Usage flow

## Diagram

The following diagram shows the flow for converting a `.cpp` or a `.rs` file into a proof binary and Solidity code for deployment.

```mermaid
%%{
init: {
'theme': 'base',
'themeVariables': {
'primaryColor': '#0f0f0f',
'primaryTextColor': '#f1f1f1',
'primaryBorderColor': '#f1f1f1',
'lineColor': '#87B6FC',
'secondaryColor': '#f1f1f1',
'tertiaryColor': '#2f2f2f',
},
'flowchart':
{
'defaultRenderer': 'elk',
'curve': 'step'
}
}
}%%
flowchart TB
classDef transpilerTitle margin-right: 250px;
Transpiler:::transpilerTitle
CPP(C++ code)
RUST(Rust code)
CLANG(<code>clang</code>)
RUSTCOMP(<code>cargo</code> #40;<code>rustc</code>#41;)
IR(Circuit IR)
INPUTS(Circuit inputs)
ASSIGNER(Assigner)
ASSIGNERRESULT(<code>.tbl</code> and <code>.crct</code> files)
TRANSPILER(<code>transpiler</code>)
PROOFBIN(Proof binary)
SOLIDITY(Solidity contracts)
CPP --> CLANG
RUST --> RUSTCOMP
CLANG --> IR
RUSTCOMP --> IR
IR --> ASSIGNER
INPUTS --> ASSIGNER
ASSIGNER --> ASSIGNERRESULT
ASSIGNERRESULT --> TRANSPILER
TRANSPILER --> PROOFBIN
TRANSPILER --> SOLIDITY
subgraph Code
CPP
RUST
end
subgraph Compilation
direction LR
CLANG
RUSTCOMP
IR
end
subgraph Assigner
direction LR
INPUTS
ASSIGNER
ASSIGNERRESULT
end
subgraph Transpiler
direction LR
TRANSPILER
PROOFBIN
SOLIDITY
end
```

## Key stages

Here is a breakdown of the key stages a circuit must pass before being proven.

### Write code in C++ or Rust

There is no need to use any special syntax when working with zkLLVM. A circuit is defined by simply adding a `[[circuit]]` (C++) or a `#[circuit]` (Rust) directive before a function. With some modifications, almost any existing C++ or Rust code can be reused for zkLLVM.

:::tip[Examples]

The [**zkLLVM repository**](https://github.com/NilFoundation/zkllvm) contains several ready-made examples of circuits. They can be reused wholly or repurposed depending on the use case.

:::

:::info[Limitations]

Read the materials in the **Best practices and limitations** section to learn more about the changes that would need to be made to existing C++ or Rust code for reuse in zkLLVM.

:::

### Compile the code into a circuit

Compiling takes only a few seconds and the entire process is done via a CLI tool which is a replacement for `clang` and `rustc`. This tool can be easily integrated to a CI/CD pipeline or any development environment.

It is also possible to use dedicated build management systems (Cargo and CMake) if a circuit requires the use of external dependencies.

### Pass the circuit to the `assigner` tool

The `assigner` tool is used to prepare all inputs and witnesses for the circuit. It generates the circuit constraints and the assignment table.

After this stage is complete, the circuit should be ready for use with dynamic inputs.

### Generate proof for the circuit

At this point, the circuit and its inputs can be passed to [**the `transpiler` tool**](../getting-started/compiling-a-circuit#using-transpiler-to-generate-the-circuit-proof) to generate a proof and Solidity contract files.

Alternatively, the circuit proof can be generated by [**using the `proof-generator` tool**](../getting-started/verifying-a-circuit#generate-a-proof-using-proof-producer).
31 changes: 1 addition & 30 deletions zkllvm/overview/what-is-zkllvm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ If you are using a Windows machine, an Ubuntu distribution can be accessed via [

## Pipeline

### Overview

The following diagram outlines the key components and stages of the zkLLVM circuit generation pipeline. Note that some of these components are currently unsupported.

```mermaid
Expand Down Expand Up @@ -141,32 +139,5 @@ flowchart TB
end
```

### Step-by-step

Working with zkLLVM involves the following steps.

#### Write the code in C++ or Rust

There is no need to use any special syntax when working with zkLLVM. A circuit is defined by simply adding a `[[circuit]]` (C++) or a `#[circuit]` (Rust) directive before a function. With some modifications, almost any existing C++ or Rust code can be reused for zkLLVM.

:::tip[Examples]

The [**zkLLVM repository**](https://github.com/NilFoundation/zkllvm) contains several ready-made examples of circuits. They can be reused wholly or repurposed depending on the use case.

:::

:::info[Limitations]

Read the materials in the **Best practices and limitations** section to learn more about the changes that would need to be made to existing C++ or Rust code for reuse in zkLLVM.

:::

#### Compile the code into a circuit

Compiling takes only a few seconds and the entire process is done via a CLI tool which is a replacement for `clang` and `rustc`. This tool can be easily integrated to a CI/CD pipeline or any development environment.

#### Pass the circuit to the `assigner` tool

The `assigner` tool is used to prepare all inputs and witnesses for the circuit.
For a more detailed explanation of transforming code into a provable circuit and generating proof for it, [**click here**](./usage-flow).

After this stage is complete, the circuit should be ready for use with dynamic inputs.

0 comments on commit 2c31d80

Please sign in to comment.