Barretenberg
The ZK-SNARK library at the core of Aztec
|
Multi-field fuzzer for testing field arithmetic operations across different elliptic curve fields. More...
#include "barretenberg/ecc/curves/bn254/fq.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/ecc/curves/secp256k1/secp256k1.hpp"
#include "barretenberg/ecc/curves/secp256r1/secp256r1.hpp"
#include "barretenberg/ecc/fields/field.fuzzer.hpp"
#include <cassert>
#include <cstddef>
#include <cstring>
#include <vector>
Go to the source code of this file.
Classes | |
struct | VMPhaseHeader |
Header structure for each VM execution phase. More... | |
Enumerations | |
enum class | FieldType : uint8_t { BN254_FQ = 0 , BN254_FR = 1 , SECP256K1_FQ = 2 , SECP256K1_FR = 3 , SECP256R1_FQ = 4 , SECP256R1_FR = 5 } |
Enumeration of supported field types for the multi-field fuzzer. More... | |
Functions | |
template<typename Field > | |
numeric::uint256_t | reduce_to_modulus (const numeric::uint256_t &value) |
Reduces a uint256_t value to be less than the field's modulus. | |
template<typename Field > | |
FieldVM< Field > | create_field_vm (size_t max_steps) |
Creates a field VM with specified maximum steps. | |
template<typename Field > | |
void | import_state_with_reduction (FieldVM< Field > &vm, const std::vector< numeric::uint256_t > &state) |
Imports state into a field VM with automatic modulus reduction. | |
template<typename Field > | |
int | run_vm_phase (FieldVM< Field > &vm, const unsigned char *data, size_t size, const VMPhaseHeader &header, size_t &data_offset) |
Runs a single VM phase with error handling and state management. | |
template<typename Field > | |
int | run_field_vm (const VMPhaseHeader &header, const unsigned char *Data, size_t Size, size_t &data_offset, std::vector< numeric::uint256_t > ¤t_state) |
Creates and runs a VM for a specific field type with state management. | |
template<typename Field > | |
void | run_debug_vm (const VMPhaseHeader &header, const unsigned char *Data, size_t Size, size_t original_data_offset, const std::vector< numeric::uint256_t > ¤t_state) |
Runs a debug VM to analyze failed phases. | |
int | LLVMFuzzerTestOneInput (const unsigned char *Data, size_t Size) |
Main fuzzer entry point for multi-field testing. | |
Variables | |
constexpr size_t | NUM_FIELD_TYPES = 6 |
Total number of supported field types. | |
constexpr size_t | MAX_STEPS = 64 |
Maximum number of VM steps per phase. | |
const size_t | PHASE_HEADER_SIZE = sizeof(VMPhaseHeader) |
Multi-field fuzzer for testing field arithmetic operations across different elliptic curve fields.
This fuzzer implements a multi-phase virtual machine that can execute field arithmetic operations across different elliptic curve fields. The algorithm works as follows:
Definition in file multi_field.fuzzer.cpp.
|
strong |
Enumeration of supported field types for the multi-field fuzzer.
Definition at line 52 of file multi_field.fuzzer.cpp.
FieldVM< Field > create_field_vm | ( | size_t | max_steps | ) |
Creates a field VM with specified maximum steps.
Field | The field type for the VM |
max_steps | Maximum number of steps the VM can execute |
Definition at line 101 of file multi_field.fuzzer.cpp.
void import_state_with_reduction | ( | FieldVM< Field > & | vm, |
const std::vector< numeric::uint256_t > & | state | ||
) |
Imports state into a field VM with automatic modulus reduction.
Field | The field type for the VM |
vm | The VM to import state into |
state | The state values to import |
Definition at line 114 of file multi_field.fuzzer.cpp.
int LLVMFuzzerTestOneInput | ( | const unsigned char * | Data, |
size_t | Size | ||
) |
Main fuzzer entry point for multi-field testing.
Data | Input data from the fuzzer |
Size | Size of the input data |
This is the main entry point for the multi-field fuzzer. It processes input data as a sequence of phases, each with its own field type and step count. The fuzzer supports state transfer between phases and includes comprehensive error detection and debugging capabilities.
Definition at line 257 of file multi_field.fuzzer.cpp.
numeric::uint256_t reduce_to_modulus | ( | const numeric::uint256_t & | value | ) |
Reduces a uint256_t value to be less than the field's modulus.
Field | The field type to reduce the value for |
value | The value to reduce |
Definition at line 86 of file multi_field.fuzzer.cpp.
void run_debug_vm | ( | const VMPhaseHeader & | header, |
const unsigned char * | Data, | ||
size_t | Size, | ||
size_t | original_data_offset, | ||
const std::vector< numeric::uint256_t > & | current_state | ||
) |
Runs a debug VM to analyze failed phases.
Field | The field type for the debug VM |
header | Phase header containing field type and step count |
Data | Input data for the VM |
Size | Size of the input data |
original_data_offset | Original data offset before phase execution |
current_state | Current state to import |
This function creates a debug VM to analyze phases that failed during normal execution. It provides detailed logging and state verification to help identify the root cause of failures.
Definition at line 215 of file multi_field.fuzzer.cpp.
int run_field_vm | ( | const VMPhaseHeader & | header, |
const unsigned char * | Data, | ||
size_t | Size, | ||
size_t & | data_offset, | ||
std::vector< numeric::uint256_t > & | current_state | ||
) |
Creates and runs a VM for a specific field type with state management.
Field | The field type for the VM |
header | Phase header containing field type and step count |
Data | Input data for the VM |
Size | Size of the input data |
data_offset | Current offset in the input data (updated on success) |
current_state | Current state to import (updated on success) |
This function creates a new VM for the specified field type, imports the current state (if any), runs the phase, and updates the current state on successful execution.
Definition at line 183 of file multi_field.fuzzer.cpp.
int run_vm_phase | ( | FieldVM< Field > & | vm, |
const unsigned char * | data, | ||
size_t | size, | ||
const VMPhaseHeader & | header, | ||
size_t & | data_offset | ||
) |
Runs a single VM phase with error handling and state management.
Field | The field type for the VM |
vm | The VM to execute |
data | Input data for the VM |
size | Size of the input data |
header | Phase header containing field type and step count |
data_offset | Current offset in the input data (updated on success) |
This function executes a single phase of VM execution. It sets the step limit, runs the VM, checks internal state consistency, and exports state for potential use in subsequent phases. The data_offset is only advanced on successful execution.
Definition at line 138 of file multi_field.fuzzer.cpp.
|
constexpr |
Maximum number of VM steps per phase.
Definition at line 62 of file multi_field.fuzzer.cpp.
|
constexpr |
Total number of supported field types.
Definition at line 61 of file multi_field.fuzzer.cpp.
const size_t PHASE_HEADER_SIZE = sizeof(VMPhaseHeader) |
Definition at line 77 of file multi_field.fuzzer.cpp.