Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
poseidon2_pedersen.fuzzer.cpp File Reference

Fuzzer for testing Poseidon2 and Pedersen hash Ultra circuits against native implementations. More...

Go to the source code of this file.

Typedefs

using Fr = fr
 
using native_poseidon2 = crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams >
 
using native_pedersen = crypto::pedersen_hash
 

Functions

std::vector< Frparse_input_and_generate_elements (const uint8_t *data, size_t size)
 Parse input structure and generate field elements using FieldVM.
 
template<typename Builder >
bool test_poseidon2_circuit (const std::vector< Fr > &inputs)
 Test Poseidon2 circuit with specified builder type.
 
template<typename Builder >
bool test_pedersen_circuit (const std::vector< Fr > &inputs)
 Test Pedersen circuit with specified builder type.
 
int LLVMFuzzerTestOneInput (const uint8_t *Data, size_t Size)
 Main fuzzer entry point.
 

Detailed Description

Fuzzer for testing Poseidon2 and Pedersen hash Ultra circuits against native implementations.

This fuzzer implements differential testing of both Poseidon2 and Pedersen hash function circuits by comparing Ultra circuit outputs with native implementation results. The fuzzer:

  1. Dual Algorithm Testing: Tests both Poseidon2 and Pedersen hash functions in a single fuzzer
  2. Algorithm Selection: Uses the first bit of input data to select between Poseidon2 (0) and Pedersen (1)
  3. Structured Input Format: Uses FieldVM data for deterministic field element generation
  4. Ultra Circuit Testing: Focuses on UltraCircuitBuilder for comprehensive circuit testing
  5. Differential Testing: Compares circuit output with trusted native implementation
  6. Variable Input Lengths: Tests inputs of any length (controlled by fuzzer configuration)
  7. Edge Cases: Tests zero inputs, repeated inputs, and boundary conditions
  8. Circuit Verification: Validates circuit correctness using CircuitChecker

Definition in file poseidon2_pedersen.fuzzer.cpp.

Typedef Documentation

◆ Fr

using Fr = fr

Definition at line 42 of file poseidon2_pedersen.fuzzer.cpp.

◆ native_pedersen

◆ native_poseidon2

Function Documentation

◆ LLVMFuzzerTestOneInput()

int LLVMFuzzerTestOneInput ( const uint8_t *  Data,
size_t  Size 
)

Main fuzzer entry point.

Parameters
DataInput data from libfuzzer
SizeSize of input data
Returns
0 for success, non-zero for failure

Definition at line 210 of file poseidon2_pedersen.fuzzer.cpp.

◆ parse_input_and_generate_elements()

std::vector< Fr > parse_input_and_generate_elements ( const uint8_t *  data,
size_t  size 
)

Parse input structure and generate field elements using FieldVM.

Parameters
dataRaw input data
sizeData size
Returns
Vector of field elements for Poseidon2

Definition at line 55 of file poseidon2_pedersen.fuzzer.cpp.

◆ test_pedersen_circuit()

template<typename Builder >
bool test_pedersen_circuit ( const std::vector< Fr > &  inputs)

Test Pedersen circuit with specified builder type.

Template Parameters
BuilderCircuit builder type
Parameters
inputsVector of field elements to hash
Returns
true if test passes, false otherwise

Definition at line 157 of file poseidon2_pedersen.fuzzer.cpp.

◆ test_poseidon2_circuit()

template<typename Builder >
bool test_poseidon2_circuit ( const std::vector< Fr > &  inputs)

Test Poseidon2 circuit with specified builder type.

Template Parameters
BuilderCircuit builder type
Parameters
inputsVector of field elements to hash
Returns
true if test passes, false otherwise

Definition at line 105 of file poseidon2_pedersen.fuzzer.cpp.