purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
purify::bppp Namespace Reference

Namespaces

namespace  detail
 Internal access helpers for experimental BPPP backend implementations.
 

Data Structures

struct  BpppBackendResourcesDeleter
 
struct  CommittedPurifyWitness
 Purify witness bundle together with a Pedersen commitment to the output. More...
 
class  ExperimentalCircuitBackend
 Common interface for reusable experimental BPPP backend state. More...
 
class  ExperimentalCircuitCache
 Caller-owned cache for reusable experimental circuit reduction and BPPP backend data. More...
 
class  ExperimentalCircuitCacheLine
 Thread-local clone of one warmed experimental BPPP backend-resource line. More...
 
struct  ExperimentalCircuitNormArgProof
 Experimental transparent circuit proof backed by the standalone BPPP norm argument. More...
 
struct  ExperimentalCircuitZkNormArgProof
 Experimental masked circuit proof that hides the reduced witness before the final BPPP argument. More...
 
struct  GeneratorBackendCacheKeyHash
 
struct  NormArgInputs
 Inputs required to produce a standalone BPPP norm argument. More...
 
struct  NormArgProof
 Standalone BPPP norm-argument proof bundle with all verifier-side inputs. More...
 

Typedefs

using ScalarBytes = std::array< unsigned char, 32 >
 Big-endian 32-byte scalar encoding.
 
using PointBytes = std::array< unsigned char, 33 >
 Compressed 33-byte curve-point encoding.
 
using GeneratorBytes = std::array< unsigned char, 33 >
 Serialized generator encoding used by the BPPP bridge.
 
using OwnedBpppBackendResources = std::unique_ptr< purify_bppp_backend_resources, BpppBackendResourcesDeleter >
 
using GeneratorBackendCacheKey = std::array< unsigned char, 32 >
 
using CircuitNormArgPublicDataCacheKey = std::array< unsigned char, 32 >
 
using CircuitNormArgPublicDataCacheKeyHash = GeneratorBackendCacheKeyHash
 

Functions

GeneratorBytes base_generator (purify_secp_context *secp_context)
 Returns the serialized secp256k1 base generator used as the blind generator.
 
GeneratorBytes value_generator_h (purify_secp_context *secp_context)
 Returns the serialized alternate generator used for committed values.
 
Result< std::vector< PointBytes > > create_generators (std::size_t count, purify_secp_context *secp_context)
 Expands the BPPP generator list.
 
Result< PointBytespedersen_commit_char (const ScalarBytes &blind, const ScalarBytes &value, purify_secp_context *secp_context)
 Computes a Pedersen commitment to an arbitrary 32-byte scalar value using Purify's default generators.
 
Result< PointBytespedersen_commit_char (const ScalarBytes &blind, const ScalarBytes &value, purify_secp_context *secp_context, const GeneratorBytes &value_gen, const GeneratorBytes &blind_gen)
 Computes a Pedersen commitment to an arbitrary 32-byte scalar value with explicit generators.
 
ScalarBytes scalar_bytes (const FieldElement &value)
 Serializes a Purify field element into the scalar encoding expected by the BPPP bridge.
 
std::vector< ScalarBytesscalar_bytes (const std::vector< FieldElement > &values)
 Serializes a vector of Purify field elements into BPPP scalar encodings.
 
Result< PointBytescommit_norm_arg (const NormArgInputs &inputs, purify_secp_context *secp_context)
 Computes the public BPPP commitment for a standalone norm-argument input bundle.
 
Result< NormArgProofprove_norm_arg (const NormArgInputs &inputs, purify_secp_context *secp_context)
 Produces a standalone BPPP norm argument.
 
Result< NormArgProofprove_norm_arg (NormArgInputs &&inputs, purify_secp_context *secp_context)
 Produces a standalone BPPP norm argument, moving large inputs into the returned proof when possible.
 
Result< NormArgProofprove_norm_arg_to_commitment (const NormArgInputs &inputs, const PointBytes &commitment, purify_secp_context *secp_context)
 Produces a standalone BPPP norm argument anchored to a caller-supplied public commitment.
 
bool verify_norm_arg (const NormArgProof &proof, purify_secp_context *secp_context)
 Verifies a standalone BPPP norm argument.
 
Result< PointBytescommit_experimental_circuit_witness (const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Commits to the reduced witness coordinates used by the experimental circuit-to-BPPP reduction.
 
Result< ExperimentalCircuitNormArgProofprove_experimental_circuit_norm_arg (const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Produces an anchored transparent circuit proof using the experimental circuit-to-BPPP reduction.
 
Result< ExperimentalCircuitNormArgProofprove_experimental_circuit_norm_arg_to_commitment (const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, const PointBytes &witness_commitment, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Produces an anchored transparent circuit proof against a caller-supplied reduced witness commitment.
 
Result< bool > verify_experimental_circuit_norm_arg (const NativeBulletproofCircuit &circuit, const ExperimentalCircuitNormArgProof &proof, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Verifies an experimental transparent circuit proof produced by prove_experimental_circuit_norm_arg.
 
Result< ExperimentalCircuitZkNormArgProofprove_experimental_circuit_zk_norm_arg (const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, const ScalarBytes &nonce, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Produces an experimental masked circuit proof over the reduced BPPP relation.
 
Result< bool > verify_experimental_circuit_zk_norm_arg (const NativeBulletproofCircuit &circuit, const ExperimentalCircuitZkNormArgProof &proof, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Verifies an experimental masked circuit proof produced by prove_experimental_circuit_zk_norm_arg.
 
Result< ExperimentalCircuitZkNormArgProofprove_experimental_circuit_zk_norm_arg_with_public_commitments (const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, const ScalarBytes &nonce, std::span< const PointBytes > public_commitments, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Produces an experimental masked circuit proof bound to explicit public commitment points.
 
Result< bool > verify_experimental_circuit_zk_norm_arg_with_public_commitments (const NativeBulletproofCircuit &circuit, const ExperimentalCircuitZkNormArgProof &proof, std::span< const PointBytes > public_commitments, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalCircuitBackend *cache=nullptr)
 Verifies an experimental masked circuit proof against explicit public commitment points.
 
Result< CommittedPurifyWitnesscommit_output_witness (const Bytes &message, const SecretKey &secret, const ScalarBytes &blind, purify_secp_context *secp_context)
 Evaluates Purify, derives its witness, and commits to the output using Purify's default generators.
 
Result< CommittedPurifyWitnesscommit_output_witness (const Bytes &message, const SecretKey &secret, const ScalarBytes &blind, purify_secp_context *secp_context, const GeneratorBytes &value_gen, const GeneratorBytes &blind_gen)
 Evaluates Purify, derives its witness, and commits to the output with explicit generators.
 
template<typename Digest >
std::size_t digest_prefix_hash (const Digest &digest) noexcept
 
GeneratorBackendCacheKey generator_backend_cache_key (std::span< const PointBytes > generators)
 
Result< PointBytescommit_norm_arg_with_cache (const NormArgInputs &inputs, purify_secp_context *secp_context, ExperimentalCircuitBackend *cache=nullptr)
 
Result< NormArgProofprove_norm_arg_to_commitment_with_cache (const NormArgInputs &inputs, const PointBytes &commitment, purify_secp_context *secp_context, ExperimentalCircuitBackend *cache=nullptr)
 
bool verify_norm_arg_with_cache (const NormArgProof &proof, purify_secp_context *secp_context, ExperimentalCircuitBackend *cache=nullptr)
 
Result< ExperimentalCircuitZkNormArgProofprove_experimental_circuit_zk_norm_arg_impl (const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, const ScalarBytes &nonce, std::span< const PointBytes > public_commitments, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding, bool externalize_commitments, ExperimentalCircuitBackend *cache)
 
Result< bool > verify_experimental_circuit_zk_norm_arg_impl (const NativeBulletproofCircuit &circuit, const ExperimentalCircuitZkNormArgProof &proof, std::span< const PointBytes > public_commitments, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding, bool externalize_commitments, ExperimentalCircuitBackend *cache)
 

Typedef Documentation

◆ CircuitNormArgPublicDataCacheKey

using purify::bppp::CircuitNormArgPublicDataCacheKey = typedef std::array<unsigned char, 32>

Definition at line 57 of file bppp.cpp.

◆ CircuitNormArgPublicDataCacheKeyHash

◆ GeneratorBackendCacheKey

using purify::bppp::GeneratorBackendCacheKey = typedef std::array<unsigned char, 32>

Definition at line 40 of file bppp.cpp.

◆ GeneratorBytes

using purify::bppp::GeneratorBytes = typedef std::array<unsigned char, 33>

Definition at line 34 of file bppp.hpp.

◆ OwnedBpppBackendResources

◆ PointBytes

using purify::bppp::PointBytes = typedef std::array<unsigned char, 33>

Definition at line 32 of file bppp.hpp.

◆ ScalarBytes

using purify::bppp::ScalarBytes = typedef std::array<unsigned char, 32>

Definition at line 30 of file bppp.hpp.

Function Documentation

◆ base_generator()

GeneratorBytes purify::bppp::base_generator ( purify_secp_context secp_context)

Definition at line 1064 of file bppp.cpp.

References purify_bppp_base_generator().

Referenced by commit_output_witness(), main(), and pedersen_commit_char().

◆ commit_experimental_circuit_witness()

Result< PointBytes > purify::bppp::commit_experimental_circuit_witness ( const NativeBulletproofCircuit circuit,
const BulletproofAssignmentData assignment,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)
Parameters
circuitNative circuit to reduce.
assignmentWitness assignment to commit.
statement_bindingOptional statement bytes folded into the public reduction challenges.
Returns
Commitment to the reduced hidden witness coordinates.

Definition at line 1303 of file bppp.cpp.

References PURIFY_ASSIGN_OR_RETURN.

Referenced by prove_experimental_circuit_norm_arg().

◆ commit_norm_arg()

Result< PointBytes > purify::bppp::commit_norm_arg ( const NormArgInputs inputs,
purify_secp_context secp_context 
)

Definition at line 1286 of file bppp.cpp.

References commit_norm_arg_with_cache().

◆ commit_norm_arg_with_cache()

◆ commit_output_witness() [1/2]

Result< CommittedPurifyWitness > purify::bppp::commit_output_witness ( const Bytes message,
const SecretKey secret,
const ScalarBytes blind,
purify_secp_context secp_context 
)
Parameters
messageMessage to evaluate.
secretOwned Purify secret key.
blindBlinding factor for the output commitment.
secp_contextActive secp256k1 context.
Returns
Witness bundle extended with the serialized output commitment.

Definition at line 1782 of file bppp.cpp.

References base_generator(), commit_output_witness(), and value_generator_h().

Referenced by commit_output_witness(), and purify::run_cli().

◆ commit_output_witness() [2/2]

Result< CommittedPurifyWitness > purify::bppp::commit_output_witness ( const Bytes message,
const SecretKey secret,
const ScalarBytes blind,
purify_secp_context secp_context,
const GeneratorBytes value_gen,
const GeneratorBytes blind_gen 
)
Parameters
messageMessage to evaluate.
secretOwned Purify secret key.
blindBlinding factor for the output commitment.
secp_contextActive secp256k1 context.
value_genGenerator used for the value term.
blind_genGenerator used for the blind term.
Returns
Witness bundle extended with the serialized output commitment.

Definition at line 1790 of file bppp.cpp.

References pedersen_commit_char(), purify::prove_assignment_data(), purify::bppp::CommittedPurifyWitness::public_key, PURIFY_ASSIGN_OR_RETURN, and scalar_bytes().

◆ create_generators()

Result< std::vector< PointBytes > > purify::bppp::create_generators ( std::size_t  count,
purify_secp_context secp_context 
)
Parameters
countNumber of generators requested.
Returns
Serialized generator points, or a BPPP input/backend error.

Definition at line 1083 of file bppp.cpp.

References purify::BackendRejectedInput, purify_bppp_create_generators(), PURIFY_RETURN_IF_ERROR, purify::require_secp_context(), purify::unexpected_error(), and purify::UnexpectedSize.

Referenced by commit_norm_arg_with_cache(), and prove_norm_arg_to_commitment_with_cache().

◆ digest_prefix_hash()

template<typename Digest >
std::size_t purify::bppp::digest_prefix_hash ( const Digest &  digest)
noexcept

Definition at line 43 of file bppp.cpp.

Referenced by purify::bppp::GeneratorBackendCacheKeyHash::operator()().

◆ generator_backend_cache_key()

GeneratorBackendCacheKey purify::bppp::generator_backend_cache_key ( std::span< const PointBytes generators)

Definition at line 60 of file bppp.cpp.

References generators, and purify_sha256().

Referenced by purify::bppp::ExperimentalCircuitCache::clone_line_for_thread().

◆ pedersen_commit_char() [1/2]

Result< PointBytes > purify::bppp::pedersen_commit_char ( const ScalarBytes blind,
const ScalarBytes value,
purify_secp_context secp_context 
)
Parameters
blindBlinding factor.
valueCommitted scalar value.
secp_contextActive secp256k1 context.
Returns
Serialized compressed commitment point, or a backend rejection error.

Definition at line 1155 of file bppp.cpp.

References base_generator(), pedersen_commit_char(), and value_generator_h().

Referenced by commit_output_witness(), and pedersen_commit_char().

◆ pedersen_commit_char() [2/2]

Result< PointBytes > purify::bppp::pedersen_commit_char ( const ScalarBytes blind,
const ScalarBytes value,
purify_secp_context secp_context,
const GeneratorBytes value_gen,
const GeneratorBytes blind_gen 
)
Parameters
blindBlinding factor.
valueCommitted scalar value.
secp_contextActive secp256k1 context.
value_genGenerator used for the value term.
blind_genGenerator used for the blind term.
Returns
Serialized compressed commitment point, or a backend rejection error.

Definition at line 1163 of file bppp.cpp.

References purify::BackendRejectedInput, purify_pedersen_commit_char(), PURIFY_RETURN_IF_ERROR, purify::require_secp_context(), and purify::unexpected_error().

◆ prove_experimental_circuit_norm_arg()

Result< ExperimentalCircuitNormArgProof > purify::bppp::prove_experimental_circuit_norm_arg ( const NativeBulletproofCircuit circuit,
const BulletproofAssignmentData assignment,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)
Parameters
circuitNative circuit to reduce.
assignmentWitness assignment to prove.
statement_bindingOptional statement bytes folded into the public reduction challenges.
Returns
Proof carrying the reduced witness commitment and BPPP proof bytes.

Definition at line 1379 of file bppp.cpp.

References commit_experimental_circuit_witness(), prove_experimental_circuit_norm_arg_to_commitment(), and PURIFY_ASSIGN_OR_RETURN.

◆ prove_experimental_circuit_norm_arg_to_commitment()

Result< ExperimentalCircuitNormArgProof > purify::bppp::prove_experimental_circuit_norm_arg_to_commitment ( const NativeBulletproofCircuit circuit,
const BulletproofAssignmentData assignment,
const PointBytes witness_commitment,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)
Parameters
circuitNative circuit to reduce.
assignmentWitness assignment to prove.
witness_commitmentPublic reduced witness commitment expected by the verifier.
statement_bindingOptional statement bytes folded into the public reduction challenges.
Returns
Proof carrying the supplied reduced witness commitment and BPPP proof bytes.

Definition at line 1318 of file bppp.cpp.

References purify::BackendRejectedInput, purify::BulletproofAssignmentData::commitments, purify::EquationMismatch, purify::NativeBulletproofCircuit::evaluate(), purify::NativeBulletproofCircuit::has_valid_shape(), purify::InvalidDimensions, purify::is_power_of_two_size(), purify::BulletproofAssignmentData::left, purify::NativeBulletproofCircuit::n_commitments, purify::NativeBulletproofCircuit::n_gates, purify::BulletproofAssignmentData::output, prove_norm_arg_to_commitment_with_cache(), PURIFY_ASSIGN_OR_RETURN, purify::BulletproofAssignmentData::right, purify::SizeMismatch, and purify::unexpected_error().

Referenced by prove_experimental_circuit_norm_arg().

◆ prove_experimental_circuit_zk_norm_arg()

Result< ExperimentalCircuitZkNormArgProof > purify::bppp::prove_experimental_circuit_zk_norm_arg ( const NativeBulletproofCircuit circuit,
const BulletproofAssignmentData assignment,
const ScalarBytes nonce,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)

This wrapper is intended to mimic the outer masking strategy of Bulletproof-style protocols: it commits to the reduced witness, commits to a random mask, derives a challenge, and only proves the challenge-combined witness with the inner BPPP norm argument. The inner BPPP implementation remains variable-time and should still be treated as experimental for secret data.

Parameters
circuitNative circuit to reduce.
assignmentWitness assignment to prove.
nonceDeterministic prover randomness used to derive the outer masking vectors.
statement_bindingOptional statement bytes folded into the public reduction challenges.
Returns
Masked proof bundle, or a reduction/backend error.

Definition at line 1737 of file bppp.cpp.

References nonce, and prove_experimental_circuit_zk_norm_arg_impl().

Referenced by main().

◆ prove_experimental_circuit_zk_norm_arg_impl()

Result< ExperimentalCircuitZkNormArgProof > purify::bppp::prove_experimental_circuit_zk_norm_arg_impl ( const NativeBulletproofCircuit circuit,
const BulletproofAssignmentData assignment,
const ScalarBytes nonce,
std::span< const PointBytes public_commitments,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding,
bool  externalize_commitments,
ExperimentalCircuitBackend cache 
)

◆ prove_experimental_circuit_zk_norm_arg_with_public_commitments()

Result< ExperimentalCircuitZkNormArgProof > purify::bppp::prove_experimental_circuit_zk_norm_arg_with_public_commitments ( const NativeBulletproofCircuit circuit,
const BulletproofAssignmentData assignment,
const ScalarBytes nonce,
std::span< const PointBytes public_commitments,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)

This variant removes the circuit commitment scalars from the hidden reduced witness and instead binds them through caller-supplied compressed secp256k1 points. Each point must equal the exact public commitment assignment.commitments[i] * G for the matching circuit commitment wire.

Definition at line 1758 of file bppp.cpp.

References nonce, and prove_experimental_circuit_zk_norm_arg_impl().

◆ prove_norm_arg() [1/2]

Result< NormArgProof > purify::bppp::prove_norm_arg ( const NormArgInputs inputs,
purify_secp_context secp_context 
)
Parameters
inputsProver inputs and optional generators.
Returns
Proof bundle containing all verifier-side inputs, or a BPPP input/backend error.

Definition at line 1180 of file bppp.cpp.

Referenced by main().

◆ prove_norm_arg() [2/2]

Result< NormArgProof > purify::bppp::prove_norm_arg ( NormArgInputs &&  inputs,
purify_secp_context secp_context 
)

Definition at line 1185 of file bppp.cpp.

◆ prove_norm_arg_to_commitment()

Result< NormArgProof > purify::bppp::prove_norm_arg_to_commitment ( const NormArgInputs inputs,
const PointBytes commitment,
purify_secp_context secp_context 
)

Definition at line 1292 of file bppp.cpp.

References prove_norm_arg_to_commitment_with_cache().

◆ prove_norm_arg_to_commitment_with_cache()

◆ scalar_bytes() [1/2]

ScalarBytes purify::bppp::scalar_bytes ( const FieldElement value)
inline
Parameters
valueField element to serialize.
Returns
Big-endian scalar bytes.

Definition at line 78 of file bppp.hpp.

References purify::FieldElement::to_bytes_be().

Referenced by commit_output_witness(), prove_experimental_circuit_zk_norm_arg_impl(), and scalar_bytes().

◆ scalar_bytes() [2/2]

std::vector< ScalarBytes > purify::bppp::scalar_bytes ( const std::vector< FieldElement > &  values)
inline
Parameters
valuesField elements to serialize.
Returns
Serialized scalar vector.

Definition at line 87 of file bppp.hpp.

References scalar_bytes().

◆ value_generator_h()

GeneratorBytes purify::bppp::value_generator_h ( purify_secp_context secp_context)

Definition at line 1073 of file bppp.cpp.

References purify_bppp_value_generator_h().

Referenced by commit_output_witness(), and pedersen_commit_char().

◆ verify_experimental_circuit_norm_arg()

Result< bool > purify::bppp::verify_experimental_circuit_norm_arg ( const NativeBulletproofCircuit circuit,
const ExperimentalCircuitNormArgProof proof,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)

◆ verify_experimental_circuit_zk_norm_arg()

Result< bool > purify::bppp::verify_experimental_circuit_zk_norm_arg ( const NativeBulletproofCircuit circuit,
const ExperimentalCircuitZkNormArgProof proof,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)
Parameters
circuitNative circuit to reduce.
proofOuter commitments plus the inner masked BPPP proof.
statement_bindingOptional statement bytes folded into the public reduction challenges.
Returns
True when the masked proof verifies against the public circuit statement.

Definition at line 1747 of file bppp.cpp.

References verify_experimental_circuit_zk_norm_arg_impl().

Referenced by main().

◆ verify_experimental_circuit_zk_norm_arg_impl()

◆ verify_experimental_circuit_zk_norm_arg_with_public_commitments()

Result< bool > purify::bppp::verify_experimental_circuit_zk_norm_arg_with_public_commitments ( const NativeBulletproofCircuit circuit,
const ExperimentalCircuitZkNormArgProof proof,
std::span< const PointBytes public_commitments,
purify_secp_context secp_context,
std::span< const unsigned char >  statement_binding = {},
ExperimentalCircuitBackend cache = nullptr 
)

The verifier reconstructs the anchored outer commitment from proof.a_commitment, the folded circuit target, and the supplied public commitment points before checking the inner BPPP proof.

Definition at line 1770 of file bppp.cpp.

References verify_experimental_circuit_zk_norm_arg_impl().

◆ verify_norm_arg()

bool purify::bppp::verify_norm_arg ( const NormArgProof proof,
purify_secp_context secp_context 
)
Parameters
proofProof bundle returned by prove_norm_arg.
Returns
True when the proof verifies.

Definition at line 1298 of file bppp.cpp.

References verify_norm_arg_with_cache().

Referenced by main().

◆ verify_norm_arg_with_cache()