Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify PXE to allow state channel flow #1

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"editor.defaultFormatter": "hashicorp.terraform"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
126 changes: 65 additions & 61 deletions barretenberg/cpp/src/barretenberg/common/fuzzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,78 +88,82 @@ class FastRandom {
* @tparam T
*/
template <typename T>
concept SimpleRng = requires(T a) {
{
a.next()
} -> std::convertible_to<uint32_t>;
};
concept SimpleRng = requires(T a)
{
{
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>>;
};
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>>;
};

/**
* @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>;
};
concept ArithmeticFuzzHelperConstraint = requires
{
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
*
* @tparam T
*/
template <typename T>
concept CheckableComposer = requires(T a) {
{
a.check_circuit()
} -> std::same_as<bool>;
};
concept CheckableComposer = requires(T a)
{
{
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 @@ -169,11 +173,12 @@ concept CheckableComposer = requires(T a) {
* @tparam Context The class containing the full context
*/
template <typename T, typename Composer, typename Context>
concept PostProcessingEnabled = requires(Composer composer, Context context) {
{
T::postProcess(&composer, context)
} -> std::same_as<bool>;
};
concept PostProcessingEnabled = requires(Composer composer, Context context)
{
{
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 @@ -182,10 +187,11 @@ concept PostProcessingEnabled = requires(Composer composer, Context context) {
* @tparam T
*/
template <typename T>
concept InstructionWeightsEnabled = requires {
typename T::InstructionWeights;
T::InstructionWeights::_LIMIT;
};
concept InstructionWeightsEnabled = requires
{
typename T::InstructionWeights;
T::InstructionWeights::_LIMIT;
};

/**
* @brief Mutate the value of a field element
Expand All @@ -196,9 +202,7 @@ concept InstructionWeightsEnabled = requires {
* @param havoc_config Mutation configuration
* @return Mutated element
*/
template <typename T, typename FF>
inline static FF mutateFieldElement(FF e, T& rng)
requires SimpleRng<T>
template <typename T, typename FF> inline static FF mutateFieldElement(FF e, T& rng) requires SimpleRng<T>
{
// With a certain probability, we apply changes to the Montgomery form, rather than the plain form. This
// has merit, since the computation is performed in montgomery form and comparisons are often performed
Expand Down Expand Up @@ -289,7 +293,7 @@ inline static FF mutateFieldElement(FF e, T& rng)
* @tparam T
*/
template <typename T>
requires ArithmeticFuzzHelperConstraint<T>
requires ArithmeticFuzzHelperConstraint<T>
class ArithmeticFuzzHelper {
private:
/**
Expand Down Expand Up @@ -597,8 +601,8 @@ class ArithmeticFuzzHelper {
template <typename Composer>
// TODO(@Rumata888)(from Zac: maybe try to fix? not comfortable refactoring this myself. Issue #1807)
// NOLINTNEXTLINE(readability-function-size, google-readability-function-size)
inline static void executeInstructions(std::vector<typename T::Instruction>& instructions)
requires CheckableComposer<Composer>
inline static void executeInstructions(std::vector<typename T::Instruction>& instructions) requires
CheckableComposer<Composer>
{
typename T::ExecutionState state;
Composer composer = Composer();
Expand Down
28 changes: 17 additions & 11 deletions barretenberg/cpp/src/barretenberg/common/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,23 @@ void run_loop_in_parallel(size_t num_points,
* @param sequential_copy_ops_per_iteration Field element (16 byte) sequential copy number
*/
template <typename FunctionType>
requires(std::is_same_v<FunctionType, std::function<void(size_t, size_t)>> ||
std::is_same_v<FunctionType, std::function<void(size_t, size_t, size_t)>>)
void run_loop_in_parallel_if_effective_internal(size_t num_points,
const FunctionType& func,
size_t finite_field_additions_per_iteration,
size_t finite_field_multiplications_per_iteration,
size_t finite_field_inversions_per_iteration,
size_t group_element_additions_per_iteration,
size_t group_element_doublings_per_iteration,
size_t scalar_multiplications_per_iteration,
size_t sequential_copy_ops_per_iteration)
requires(
std::is_same_v<FunctionType, std::function<void(size_t, size_t)>> ||
std::is_same_v<
FunctionType,
std::function<void(
size_t,
size_t,
size_t)>>) void run_loop_in_parallel_if_effective_internal(size_t num_points,
const FunctionType& func,
size_t finite_field_additions_per_iteration,
size_t
finite_field_multiplications_per_iteration,
size_t finite_field_inversions_per_iteration,
size_t group_element_additions_per_iteration,
size_t group_element_doublings_per_iteration,
size_t scalar_multiplications_per_iteration,
size_t sequential_copy_ops_per_iteration)
{
// Rough cost of operations (the operation costs are derives in basics_bench and the units are nanoseconds):
constexpr size_t FF_ADDITION_COST = 4;
Expand Down
17 changes: 13 additions & 4 deletions barretenberg/cpp/src/barretenberg/common/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ void run_loop_in_parallel(size_t num_points,
size_t no_multhreading_if_less_or_equal = 0);

template <typename FunctionType>
requires(std::is_same_v<FunctionType, std::function<void(size_t, size_t)>> ||
std::is_same_v<FunctionType, std::function<void(size_t, size_t, size_t)>>)
void run_loop_in_parallel_if_effective_internal(
size_t, const FunctionType&, size_t, size_t, size_t, size_t, size_t, size_t, size_t);
requires(
std::is_same_v<FunctionType, std::function<void(size_t, size_t)>> ||
std::is_same_v<FunctionType,
std::function<void(
size_t, size_t, size_t)>>) void run_loop_in_parallel_if_effective_internal(size_t,
const FunctionType&,
size_t,
size_t,
size_t,
size_t,
size_t,
size_t,
size_t);
/**
* @brief Runs loop in parallel if parallelization if useful (costs less than the algorith)
*
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ std::array<uint8_t, Hash::OUTPUT_SIZE> hmac(const MessageContainer& message, con
* @return Fr output field element as uint512_t( H(10...0 || HMAC(k,m)) || H(00...0 || HMAC(k,m)) ) % r
*/
template <typename Hash, typename Fr, typename MessageContainer, typename KeyContainer>
Fr get_unbiased_field_from_hmac(const MessageContainer& message, const KeyContainer& key)
requires(Hash::OUTPUT_SIZE == 32)
Fr get_unbiased_field_from_hmac(const MessageContainer& message,
const KeyContainer& key) requires(Hash::OUTPUT_SIZE == 32)
{
// Strong assumption that works for now with our suite of Hashers
static_assert(Hash::BLOCK_SIZE > Hash::OUTPUT_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ template <typename Fq, typename Fr, typename Params> class alignas(64) affine_el
* @return A randomly chosen point on the curve
*/
static affine_element random_element(numeric::RNG* engine = nullptr) noexcept;
static constexpr affine_element hash_to_curve(const std::vector<uint8_t>& seed, uint8_t attempt_count = 0) noexcept
requires SupportsHashToCurve<Params>;
static constexpr affine_element hash_to_curve(
const std::vector<uint8_t>& seed, uint8_t attempt_count = 0) noexcept requires SupportsHashToCurve<Params>;

constexpr bool operator==(const affine_element& other) const noexcept;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ constexpr std::optional<affine_element<Fq, Fr, T>> affine_element<Fq, Fr, T>::de
* @return constexpr affine_element<Fq, Fr, T>
*/
template <class Fq, class Fr, class T>
constexpr affine_element<Fq, Fr, T> affine_element<Fq, Fr, T>::hash_to_curve(const std::vector<uint8_t>& seed,
uint8_t attempt_count) noexcept
requires SupportsHashToCurve<T>
constexpr affine_element<Fq, Fr, T> affine_element<Fq, Fr, T>::hash_to_curve(
const std::vector<uint8_t>& seed, uint8_t attempt_count) noexcept requires SupportsHashToCurve<T>

{
std::vector<uint8_t> target_seed(seed);
Expand Down
3 changes: 1 addition & 2 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ template <ECCVMFlavor Flavor> class ECCVMComposer_ {
std::vector<uint32_t> recursive_proof_public_input_indices;
bool contains_recursive_proof = false;
bool computed_witness = false;
ECCVMComposer_()
requires(std::same_as<Flavor, honk::flavor::ECCVM>)
ECCVMComposer_() requires(std::same_as<Flavor, honk::flavor::ECCVM>)
{
crs_factory_ = bb::srs::get_grumpkin_crs_factory();
};
Expand Down
Loading
Loading