Skip to content

Commit

Permalink
63 move excalibur to this repository (#71)
Browse files Browse the repository at this point in the history
* Updated excalibur to work with the main repo.

* Updated excalibur to consume proof system output format.

* Moved excalibur to debug-tools.
  • Loading branch information
Iluvmagick authored Oct 8, 2024
1 parent 5f36296 commit 382ecff
Show file tree
Hide file tree
Showing 18 changed files with 2,005 additions and 14 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ compile_commands.json
CTestTestfile.cmake
build
result
CheckSSE.cmake

### LaTeX ###
## Core latex/pdflatex auxiliary files:
Expand Down
5 changes: 4 additions & 1 deletion crypto3/crypto3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
cmake,
boost,
gdb,
lldb,
cmake_modules,
enableDebugging,
enableDebug ? false,
Expand All @@ -18,7 +19,9 @@ in stdenv.mkDerivation {

src = lib.sourceByRegex ./. [ ".*" ];

nativeBuildInputs = [ cmake ninja pkg-config ] ++ (lib.optional (!stdenv.isDarwin) gdb);
nativeBuildInputs = [ cmake ninja pkg-config ] ++
(lib.optional (!stdenv.isDarwin) gdb) ++
(lib.optional (stdenv.isDarwin) lldb);

# enableDebugging will keep debug symbols in boost
propagatedBuildInputs = [ (if enableDebug then (enableDebugging boost) else boost) ];
Expand Down
3 changes: 2 additions & 1 deletion debug-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ endif ()
# If Nix is used, LSP could not guess the locations of implicit include
# directories, so we need to include them explicitly.
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

Expand Down Expand Up @@ -85,6 +85,7 @@ endif()
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/bin/circgen")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/bin/excalibur")

include(CPack)

Expand Down
5 changes: 5 additions & 0 deletions debug-tools/bin/excalibur/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)

project(excalibur-gui)

add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src/")
33 changes: 33 additions & 0 deletions debug-tools/bin/excalibur/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
A simple circuit visualizer for Placeholder proof system.

# Building and running
1. Do a `nix develop .#debug-test-tools` in the main placeholder directory
2. Run `eval $configurePhase` in debug-tools directory
3. `ninja excalibur`
4. If you encounter an error while trying to open a file, you need to compile the GTK schema used in the dialog, and link the environment variable. In order to do that, find you gtk installation in `/nix/store/`.

The best way of doing this is via `nix-locate org.gtk.gtk4.Settings.FileChooser.gschema.xml` if you have [nix-index](https://github.com/nix-community/nix-index) installed.

Alternatively, run `schema-locator.sh`. If you have multiple versions of gtk4 in the store, use the latest one.

After finding the file, run `glib-compile-schemas --targetdir=. /path/to/schema/directory`.
Note that you need to pass *directory*, and not the file path.
This should create `gschemas.compiled` file in current (build) directory.

Export the `gschemas.compiled` directory via `export GSETTINGS_SCHEMA_DIR=/path/to/compiled/schema/dir`.

Run `./bin/excalibur/src/excalibur --vesta` (or `--pallas`, or one of the other supporting curves).

# FAQ
I get the following error while running the tool:
```
(excalibur:24987): GLib-GIO-ERROR **: 18:39:52.016: Settings schema 'org.gtk.gtk4.Settings.FileChooser' is not installed
Trace/breakpoint trap
```
Check that you've done step 4 above. Export has to be redone each shell session, unless you modify `.bashrc` or do something similar.

How do I export my circuit/assignment table from blueprint?

Use the functions in "test_plonk_component.hpp"

Lookup constraints support is not implemented yet.
3 changes: 3 additions & 0 deletions debug-tools/bin/excalibur/schema-locator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for dir in $(ls /nix/store | grep gtk4); do
find /nix/store/$dir -name "org.gtk.gtk4.Settings.FileChooser.gschema.xml"
done
75 changes: 75 additions & 0 deletions debug-tools/bin/excalibur/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 3.21)

set(CMAKE_EXPORT_COMPILE_COMMANDS true)

message (STATUS "PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH}")

# get header files; only needed by CMake generators,
# expr.g., for creating proper Xcode projects
set(${CMAKE_PROJECT_NAME}_HEADERS)

set(C3_TARGET "excalibur")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-pg)
link_libraries(-pg)
endif()

# list cpp files excluding platform-dependent files
list(APPEND ${CMAKE_PROJECT_NAME}_SOURCES main.cpp)

find_package(Boost COMPONENTS random)
find_package(PkgConfig REQUIRED)

pkg_check_modules(GTK REQUIRED gtk4)

if(NOT GTK_FOUND)
message(FATAL_ERROR "GTK4 not found!")
endif()

pkg_check_modules(GTKMM REQUIRED gtkmm-4.0)

if (NOT GTKMM_FOUND)
message(FATAL_ERROR "GTKMM not found!")
endif()

pkg_check_modules(PANGO REQUIRED pango)

if (NOT PANGO_FOUND)
message(FATAL_ERROR "Pango not found!")
endif()

pkg_check_modules(PANGOMM REQUIRED pangomm-1.4)

if(NOT PANGOMM_FOUND)
message(FATAL_ERROR "PANGOMM not found!")
endif()

find_package(crypto3 REQUIRED)

include_directories(
${GTKMM_INCLUDE_DIRS} ${GTK_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} ${PANGOMM_INCLUDE_DIRS})
link_directories(
${GTKMM_LIBRARY_DIRS} ${GTK_LIBRARY_DIRS} ${PANGO_LIBRARY_DIRS} ${PANGOMM_LIBRARY_DIRS})

add_executable(${C3_TARGET}
${${CMAKE_PROJECT_NAME}_HEADERS}
${${CMAKE_PROJECT_NAME}_SOURCES})

set_target_properties(${C3_TARGET} PROPERTIES
LINKER_LANGUAGE CXX
EXPORT_NAME ${CMAKE_PROJECT_NAME}
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE)

target_link_directories(
${C3_TARGET} PRIVATE ${GTKMM_LIBRARY_DIRS}
${GTK_LIBRARY_DIRS} ${PANGO_LIBRARY_DIRS} ${PANGOMM_LIBRARY_DIRS})

target_link_libraries(${C3_TARGET}
crypto3::all
${Boost_LIBRARIES}
${GTKMM_LIBRARIES}
${GTK_LIBRARIES}
${PANGOMM_LIBRARIES}
${PANGO_LIBRARIES})
165 changes: 165 additions & 0 deletions debug-tools/bin/excalibur/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// MIT License
//
// Copyright (c) 2023 Dmitrii Tabalin <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <gtkmm/application.h>

#include <giomm/menu.h>

#include <glibmm/optioncontext.h>
#include <glibmm/optiongroup.h>

#include <numeric>

#include <nil/crypto3/algebra/fields/vesta/base_field.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/vesta.hpp>
#include <nil/crypto3/algebra/curves/vesta.hpp>
#include <nil/crypto3/algebra/fields/pallas/base_field.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>
#include <nil/crypto3/algebra/curves/pallas.hpp>

#include <nil/crypto3/algebra/fields/mnt4/base_field.hpp>
#include <nil/crypto3/algebra/fields/mnt6/base_field.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/goldilocks64.hpp>
#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/fields/alt_bn128/scalar_field.hpp>
#include <nil/crypto3/algebra/fields/bls12/scalar_field.hpp>

#include "table.hpp"

int main(int argc, char* argv[]) {
auto app = Gtk::Application::create("foundation.nil.excalibur");

using vesta_curve_type = nil::crypto3::algebra::curves::vesta::base_field_type;
using pallas_curve_type = nil::crypto3::algebra::curves::pallas::base_field_type;
using bls12_fr_381_curve_type = nil::crypto3::algebra::fields::bls12_fr<381>;
using bls12_fq_381_curve_type = nil::crypto3::algebra::fields::bls12_fq<381>;
using mnt4_curve_type = nil::crypto3::algebra::fields::mnt4_fq<298>;
using mnt6_curve_type = nil::crypto3::algebra::fields::mnt6_fq<298>;
using goldilocks64_field_type = nil::crypto3::algebra::fields::goldilocks64;
using bn_base_field_type = nil::crypto3::algebra::fields::alt_bn128<254>;
using bn_scalar_field_type = nil::crypto3::algebra::fields::alt_bn128_scalar_field<254>;

Glib::OptionGroup::vecustrings main_option_vector;
Glib::OptionGroup main_group("curves", "Curves", "Curve used in the program");

bool vesta = false, pallas = false, bls12_fr_381 = false, bls12_fq_381 = false,
mnt4 = false, mnt6 = false, goldilocks64 = false, bn_base = false, bn_scalar = false;
Glib::OptionEntry vesta_entry, pallas_entry, bls12_fr_381_entry, bls12_fq_381_entry,
mnt4_entry, mnt6_entry, goldilocks64_entry, bn_entry;

vesta_entry.set_long_name("vesta");
vesta_entry.set_short_name('v');
vesta_entry.set_description("Use Vesta curve");
main_group.add_entry(vesta_entry, vesta);

pallas_entry.set_long_name("pallas");
pallas_entry.set_short_name('p');
pallas_entry.set_description("Use Pallas curve");
main_group.add_entry(pallas_entry, pallas);

bls12_fr_381_entry.set_long_name("bls12_fr_381");
bls12_fr_381_entry.set_short_name('b');
bls12_fr_381_entry.set_description("Use BLS12_fr_381 curve");
main_group.add_entry(bls12_fr_381_entry, bls12_fr_381);

bls12_fq_381_entry.set_long_name("bls12_fq_381");
bls12_fq_381_entry.set_short_name('q');
bls12_fq_381_entry.set_description("Use BLS12_fq_381 curve");
main_group.add_entry(bls12_fq_381_entry, bls12_fq_381);

mnt4_entry.set_long_name("mnt4");
mnt4_entry.set_short_name('4');
mnt4_entry.set_description("Use mnt4 curve");
main_group.add_entry(mnt4_entry, mnt4);

mnt6_entry.set_long_name("mnt6");
mnt6_entry.set_short_name('6');
mnt6_entry.set_description("Use mnt6 curve");
main_group.add_entry(mnt6_entry, mnt6);

goldilocks64_entry.set_long_name("goldilocks64");
goldilocks64_entry.set_short_name('g');
goldilocks64_entry.set_description("Use Goldilocks64 curve");
main_group.add_entry(goldilocks64_entry, goldilocks64);

bn_entry.set_long_name("bn");
bn_entry.set_short_name('n');
bn_entry.set_description("Use BN curve base field");
main_group.add_entry(bn_entry, bn_base);

bn_entry.set_long_name("bn_scalar");
bn_entry.set_short_name('s');
bn_entry.set_description("Use BN curve scalar field");
main_group.add_entry(bn_entry, bn_scalar);

// Add the main group to the context
Glib::OptionContext context;
context.set_main_group(main_group);
context.set_help_enabled(true);
context.set_ignore_unknown_options(true);
context.parse(argc, argv);

// check that only a single curve is selected
std::vector<bool> curve_selections = {
vesta, pallas, bls12_fr_381, bls12_fq_381,mnt4, mnt6, goldilocks64,
bn_base, bn_scalar};
uint8_t curve_count = std::accumulate(curve_selections.begin(), curve_selections.end(), 0);
if (curve_count > 1) {
std::cerr << "Error: only one curve can be used at a time." << std::endl;
return 1;
}
// check that at least one curve is selected
if (curve_count == 0) {
std::cerr << "Error: no curve selected. Use --vesta or --pallas or --bls12_fr_381, or --bls12_fq_381"
<< " or --mnt4 or --mnt6 or --goldilocks64, or --bn, or --bn_scalar."
<< std::endl;
return 1;
}

if (vesta) {
return app->make_window_and_run<ExcaliburWindow<vesta_curve_type>>(argc, argv);
}
if (pallas) {
return app->make_window_and_run<ExcaliburWindow<pallas_curve_type>>(argc, argv);
}
if (bls12_fr_381) {
return app->make_window_and_run<ExcaliburWindow<bls12_fr_381_curve_type>>(argc, argv);
}
if (bls12_fq_381) {
return app->make_window_and_run<ExcaliburWindow<bls12_fq_381_curve_type>>(argc, argv);
}
if (mnt4) {
return app->make_window_and_run<ExcaliburWindow<mnt4_curve_type>>(argc, argv);
}
if (mnt6) {
return app->make_window_and_run<ExcaliburWindow<mnt6_curve_type>>(argc, argv);
}
if (goldilocks64) {
return app->make_window_and_run<ExcaliburWindow<goldilocks64_field_type>>(argc, argv);
}
if (bn_base) {
return app->make_window_and_run<ExcaliburWindow<bn_base_field_type>>(argc, argv);
}
if (bn_scalar) {
return app->make_window_and_run<ExcaliburWindow<bn_scalar_field_type>>(argc, argv);
}
}
Loading

0 comments on commit 382ecff

Please sign in to comment.