Skip to content

Commit

Permalink
Merge branch 'master' into 309-rework-fri
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil authored Aug 19, 2024
2 parents 9b4483b + e4772b0 commit 08413fc
Show file tree
Hide file tree
Showing 420 changed files with 218,128 additions and 4 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ else()
target_architecture(CMAKE_TARGET_ARCHITECTURE)
endif()

find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system)
if(CMAKE_ENABLE_TESTS)
find_package(Boost REQUIRED COMPONENTS unit_test_framework timer)
endif()
find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system unit_test_framework timer)

add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/")
add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/marshalling")
Expand Down
33 changes: 33 additions & 0 deletions libs/blueprint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include(CMConfig)
include(CMSetupVersion)

cm_project(blueprint WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES C CXX)

include(CMDeploy)

cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})

add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE)

set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES
EXPORT_NAME ${CURRENT_PROJECT_NAME})

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)

target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${Boost_LIBRARIES}
)

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
INCLUDE include
NAMESPACE ${CMAKE_WORKSPACE_NAME}::)

include(CMTest)
cm_add_test_subdirectory(test)

if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()

41 changes: 41 additions & 0 deletions libs/blueprint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Circuit Definition Library for =nil; Foundation's Cryptography Suite

[![Run tests](https://github.com/NilFoundation/zkllvm-blueprint/actions/workflows/run_tests.yml/badge.svg)](https://github.com/NilFoundation/zkllvm-blueprint/actions/workflows/run_tests.yml)

## Dependencies

- [Boost](https://boost.org) (>= 1.76)
- [cmake](https://cmake.org/) (>=3.21.4)
- Following dependencies must be built and installed from sources:
- [CMake Modules](https://github.com/BoostCMake/cmake_modules.git)
- [crypto3](https://github.com/nilfoundation/crypto3.git)

## Building and installation

```bash
cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to/install
make -C build install
```

> Note: if you got an error on `find_package` during cmake configuration, make sure that you provided paths to the installed dependencies (for example, via `CMAKE_PREFIX_PATH` environment variable)
## Nix support
This repository provides Nix flake, so once you have installed Nix with flake support, you can use single command to fetch all the dependencies and build:

```bash
nix build ?submodules=1#
```

To activate Nix development environment:

```bash
nix develop
```

To run all tests:

```bash
nix flake check -L ?submodules=1#
```

To build/develop/test with local crypto3 version, add an argument `--override-input nil-crypto3 /path/to/local/crypto3` to any of the above commands.
32 changes: 32 additions & 0 deletions libs/blueprint/docs/concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Concepts # {#component_concepts}

A ```circuit``` is defined by ```Blueprint``` and ```Blueprint assignment table``` (contains ```Blueprint public assignment table``` and ```Blueprint private assignment table```) instances.
It consist of one or multiple components putted on these two.
While ```Blueprint``` holds information about the circuit itself, its gates, constraints and other fixed expressions, ```Blueprint assignment table``` contains public and private assignments needed by zk-SNARK system.

## Blueprint

## PLONK component concept ## {##plonk_component_concepts}

### PLONK Component interface ###

A ```Component``` ```X``` is a state-less type with following static functions to operate with it:

* ```X::allocate_rows``` - allocates required amount of rows in the given ```Arithmetization table```. The amount of required rows amount is constexpr for the particular component;
* ```X::generate_circuit``` - generates gate expressions, copy constraints and lookup constraints and puts them on the given ```Blueprint```;
* ```X::generate_assignments``` - evaluates assignments values and puts them on the given ```Blueprint assignment table```;

Note that ```generate_circuit``` can modify of the ```Blueprint public assignment table``` setting ```Constant``` or ```Selector``` columns, but they don't use or set data of the ```Blueprint private assignment table```. The only function managing ```Blueprint private assignment table``` is ```generate_assignments``` - which, by the way, also can modify the ```Blueprint public assignment table```. In short, it looks like that:

|Function |Required Input |Can modify |
|-----------------------------|------------------------|-----------------------|
|```X::allocate_rows``` |```Blueprint``` |```Blueprint```|
|```X::generate_circuit``` |```Blueprint```, ```Component params```, ```Allocated data (auxiliary data for the component re-use)```, ```component start row``` |```Blueprint```, ```Allocated data```|
|```X::generate_assignments``` |```Blueprint assignment table```, ```Component params```, ```component start row``` |```Blueprint assignment table```|

The process of adding a component is following:

1. (Optional) Get ```component``` start row by calling ```allocate_rows```. If the ```component``` is used as part of other ```component``` logic, it's not necessary to call the function, because needed rows are allocated by the master ```component```.
2. (Optional) Allocate public input on the ```Blueprint assignment table``` via ```Blueprint assignment table::allocate_public_input```.
3. Set all the gates and constraints on the ```Blueprint``` by calling ```generate_circuit```. ```Allocated data``` is being modified in process of the function working.
4. Set all the assignments on the ```Blueprint assignment table``` table by calling ```generate_assignments```.
3 changes: 3 additions & 0 deletions libs/blueprint/docs/extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Extension {#blueprint_extension_manual}

@tableofcontents
3 changes: 3 additions & 0 deletions libs/blueprint/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Blueprint (Circuit Definition Library) {#blueprint_index}

@subpage blueprint_manual
4 changes: 4 additions & 0 deletions libs/blueprint/docs/manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Manual {#blueprint_manual}

@subpage blueprint_usage_manual
@subpage blueprint_extension_manual
Loading

0 comments on commit 08413fc

Please sign in to comment.