Skip to content

Commit

Permalink
Merge branch 'visoftsolutions'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Nowak committed Dec 2, 2023
2 parents ed1501a + 86d1b8a commit 05bc021
Show file tree
Hide file tree
Showing 25 changed files with 1,474 additions and 409 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
// C++/Circuits settings
///////////////////////////////////////
"[cpp]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.defaultFormatter": "xaver.clang-format",
"editor.formatOnSave": true
},
//
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.cache/
build*/
install*/
src/wasi-sdk-*
src/barretenberg/proof_system/proving_key/fixtures
src/barretenberg/rollup/proofs/*/fixtures
Expand Down
25 changes: 21 additions & 4 deletions barretenberg/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ configure_file(

option(DISABLE_ASM "Disable custom assembly" OFF)
option(DISABLE_ADX "Disable ADX assembly variant" OFF)
option(MULTITHREADING "Enable multi-threading" ON)
option(MULTITHREADING "Enable multi-threading" OFF)
option(OMP_MULTITHREADING "Enable OMP multi-threading" OFF)
option(TESTING "Build tests" ON)
option(BENCHMARKS "Build benchmarks" ON)
option(TESTING "Build tests" OFF)
option(BENCHMARKS "Build benchmarks" OFF)
option(FUZZING "Build fuzzing harnesses" OFF)
option(DISABLE_TBB "Intel Thread Building Blocks" ON)
option(DISABLE_TBB "Intel Thread Building Blocks" OFF)
option(COVERAGE "Enable collecting coverage from tests" OFF)
option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF)
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)
Expand Down Expand Up @@ -151,3 +151,20 @@ if (ENABLE_ASAN AND NOT(FUZZING))
message(AUTHOR_WARNING "Run `export ASAN_SYMBOLIZER_PATH=\"${LLVM_SYMBOLIZER_PATH}\"` before running tests for better ASAN output (at which lines the bugs are).")
endif()
endif()

install(TARGETS barretenberg DESTINATION lib)

# Get all the .h and .hpp files recursively from the src directory
file(GLOB_RECURSE HEADER_FILES ./*.h ./*.hpp ./*tcc)

# Remove the prefix from each file path
foreach(HEADER ${HEADER_FILES})
# Get the relative path of the header file to the src directory
file(RELATIVE_PATH HEADER_RELATIVE_PATH ${CMAKE_SOURCE_DIR}/src ${HEADER})

# Compute the destination directory for the header
get_filename_component(DEST_DIR ${HEADER_RELATIVE_PATH} DIRECTORY)

# Install the file, preserving its directory structure in the destination
install(FILES ${HEADER} DESTINATION include/${DEST_DIR})
endforeach()
7 changes: 5 additions & 2 deletions barretenberg/cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ echo "# When running cmake directly, remember to use: --build --preset $PRESET"
echo "#################################"

# Build native.
cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert
cmake --build --preset $PRESET --target bb
cmake --preset default -DCMAKE_BUILD_TYPE=RelWithAssert
cmake --build --preset default --target bb

# Install native
cmake --install build --prefix ./install

if [ ! -d ./srs_db/grumpkin ]; then
# The Grumpkin SRS is generated manually at the moment, only up to a large enough size for tests
Expand Down
8 changes: 4 additions & 4 deletions barretenberg/cpp/cmake/arch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(WASM)
add_compile_options(-fno-exceptions -fno-slp-vectorize)
endif()

if(NOT WASM AND NOT APPLE AND NOT ARM)
message(STATUS "Target architecture: ${TARGET_ARCH}")
add_compile_options(-march=${TARGET_ARCH})
endif()
# if(NOT WASM AND NOT APPLE AND NOT ARM)
# message(STATUS "Target architecture: ${TARGET_ARCH}")
# add_compile_options(-march=${TARGET_ARCH})
# endif()
6 changes: 4 additions & 2 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Specifying `-Wno-${ERROR_NAME}` will silence the error completely.
# To preserve the warning, but prevent them from causing the build to fail,
# use the flag `-Wno-error=${ERROR_NAME}`
add_compile_options(-Werror -Wall -Wextra -Wconversion -Wsign-conversion)
add_compile_options(-Wall -Wextra -Wconversion -Wsign-conversion -Wfatal-errors -fPIC)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fcolor-diagnostics -fconstexpr-steps=100000000)
Expand Down Expand Up @@ -99,6 +99,8 @@ message(STATUS "Compiling all-in-one barretenberg archive")
add_library(
barretenberg
STATIC
$<TARGET_OBJECTS:env_objects>
$<TARGET_OBJECTS:dsl_objects>
$<TARGET_OBJECTS:common_objects>
$<TARGET_OBJECTS:crypto_aes128_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
Expand Down Expand Up @@ -202,4 +204,4 @@ if(WASM)
PRIVATE
-nostartfiles -Wl,--no-entry,--export-dynamic,--allow-undefined
)
endif()
endif()
97 changes: 48 additions & 49 deletions barretenberg/cpp/src/barretenberg/common/fuzzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,65 +89,64 @@ class FastRandom {
*/
template <typename T>
concept SimpleRng = requires(T a) {
{
a.next()
} -> std::convertible_to<uint32_t>;
};
{
a.next()
} -> std::convertible_to<uint32_t>;
};
/**
* @brief Concept for forcing ArgumentSizes to be size_t
*
* @tparam T
*/
template <typename T>
concept InstructionArgumentSizes = requires {
{
std::make_tuple(T::CONSTANT,
T::WITNESS,
T::CONSTANT_WITNESS,
T::ADD,
T::SUBTRACT,
T::MULTIPLY,
T::DIVIDE,
T::ADD_TWO,
T::MADD,
T::MULT_MADD,
T::MSUB_DIV,
T::SQR,
T::SQR_ADD,
T::SUBTRACT_WITH_CONSTRAINT,
T::DIVIDE_WITH_CONSTRAINTS,
T::SLICE,
T::ASSERT_ZERO,
T::ASSERT_NOT_ZERO)
} -> std::same_as<std::tuple<size_t>>;
};
{
std::make_tuple(T::CONSTANT,
T::WITNESS,
T::CONSTANT_WITNESS,
T::ADD,
T::SUBTRACT,
T::MULTIPLY,
T::DIVIDE,
T::ADD_TWO,
T::MADD,
T::MULT_MADD,
T::MSUB_DIV,
T::SQR,
T::SQR_ADD,
T::SUBTRACT_WITH_CONSTRAINT,
T::DIVIDE_WITH_CONSTRAINTS,
T::SLICE,
T::ASSERT_ZERO,
T::ASSERT_NOT_ZERO)
} -> std::same_as<std::tuple<size_t>>;
};

/**
* @brief Concept for Havoc Configurations
*
* @tparam T
*/
template <typename T>
concept HavocConfigConstraint =
requires {
{
std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY)
} -> std::same_as<std::tuple<size_t>>;
T::GEN_MUTATION_COUNT_LOG <= 7;
};
concept HavocConfigConstraint = requires {
{
std::make_tuple(T::GEN_MUTATION_COUNT_LOG, T::GEN_STRUCTURAL_MUTATION_PROBABILITY)
} -> std::same_as<std::tuple<size_t>>;
T::GEN_MUTATION_COUNT_LOG <= 7;
};
/**
* @brief Concept specifying the class used by the fuzzer
*
* @tparam T
*/
template <typename T>
concept ArithmeticFuzzHelperConstraint = requires {
typename T::ArgSizes;
typename T::Instruction;
typename T::ExecutionState;
typename T::ExecutionHandler;
InstructionArgumentSizes<typename T::ArgSizes>;
};
typename T::ArgSizes;
typename T::Instruction;
typename T::ExecutionState;
typename T::ExecutionHandler;
InstructionArgumentSizes<typename T::ArgSizes>;
};

/**
* @brief Fuzzer uses only composers with check_circuit function
Expand All @@ -156,10 +155,10 @@ concept ArithmeticFuzzHelperConstraint = requires {
*/
template <typename T>
concept CheckableComposer = requires(T a) {
{
a.check_circuit()
} -> std::same_as<bool>;
};
{
a.check_circuit()
} -> std::same_as<bool>;
};

/**
* @brief The fuzzer can use a postprocessing function that is specific to the type being fuzzed
Expand All @@ -170,10 +169,10 @@ concept CheckableComposer = requires(T a) {
*/
template <typename T, typename Composer, typename Context>
concept PostProcessingEnabled = requires(Composer composer, Context context) {
{
T::postProcess(&composer, context)
} -> std::same_as<bool>;
};
{
T::postProcess(&composer, context)
} -> std::same_as<bool>;
};

/**
* @brief This concept is used when we want to limit the number of executions of certain instructions (for example,
Expand All @@ -183,9 +182,9 @@ concept PostProcessingEnabled = requires(Composer composer, Context context) {
*/
template <typename T>
concept InstructionWeightsEnabled = requires {
typename T::InstructionWeights;
T::InstructionWeights::_LIMIT;
};
typename T::InstructionWeights;
T::InstructionWeights::_LIMIT;
};

/**
* @brief Mutate the value of a field element
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#include "rust_bind.hpp"
#include "barretenberg/common/serialize.hpp"
#include "pedersen.hpp"
#include "pedersen_lookup.hpp"

extern "C" {

using namespace barretenberg;

WASM_EXPORT const char* pedersen___init()
{
try {
crypto::generators::init_generator_data();
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result)
{
try {
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen_commitment::compress_native({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___plookup_compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result)
{
try {
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen_commitment::lookup::compress_native({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
try {
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_commitment::compress_native(to_compress);
barretenberg::fr::serialize_to_buffer(r, output);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___plookup_compress(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
try {
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_commitment::lookup::compress_native(to_compress);
barretenberg::fr::serialize_to_buffer(r, output);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___compress_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output)
{
try {
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen_commitment::compress_native(to_compress, *hash_index);
barretenberg::fr::serialize_to_buffer(r, output);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
try {
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress);

serialize::write(output, pedersen_hash);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output)
{
try {
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::lookup::commit_native(to_compress);

serialize::write(output, pedersen_hash);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer,
uint32_t const* hash_index,
fr::out_buf output)
{
try {
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash =
crypto::pedersen_commitment::lookup::commit_native(to_compress, *hash_index);

serialize::write(output, pedersen_hash);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}

WASM_EXPORT const char* pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r)
{
try {
std::vector<uint8_t> to_compress;
read(data, to_compress);
auto output = crypto::pedersen_commitment::compress_native(to_compress);
write(r, output);
return nullptr;
} catch (const std::exception& e) {
return e.what(); // return the exception message
}
}
}
Loading

0 comments on commit 05bc021

Please sign in to comment.