Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pedersen.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#include "pedersen.hpp"
10namespace bb::stdlib {
11
12using namespace bb;
13
28template <typename Builder>
30{
32 using Curve = EmbeddedCurve;
33
34 const auto base_points = context.generators->get(inputs.size(), context.offset, context.domain_separator);
35
38 scalars.emplace_back(cycle_scalar::create_from_bn254_scalar(field_ct(inputs.size())));
40 for (const auto [point, scalar] : zip_view(base_points, inputs)) {
41 scalars.emplace_back(cycle_scalar::create_from_bn254_scalar(scalar));
42 // Construct circuit-constant cycle_group objects (non-witness)
43 points.emplace_back(point);
44 }
45
46 auto result = cycle_group::batch_mul(points, scalars);
47 // pedersen hash doesn't use y coordinate of result anymore in the circuit except for hashing
48 // so we can put result.y in used_witnesses
49 auto builder_ptr = result.y.get_context();
50 if (builder_ptr != nullptr) {
51 builder_ptr->update_used_witnesses(result.y.witness_index);
52 }
53 return result.x;
54}
55
58
59} // namespace bb::stdlib
Performs pedersen hashes!
Definition pedersen.hpp:30
::bb::stdlib::cycle_scalar< Builder > cycle_scalar
static cycle_group batch_mul(const std::vector< cycle_group > &base_points, const std::vector< BigScalarField > &scalars, GeneratorContext context={})
Represents a member of the Grumpkin curve scalar field (i.e. BN254 base field).
static cycle_scalar create_from_bn254_scalar(const field_t &_in)
Construct a cycle scalar (grumpkin scalar field element) from a bn254 scalar field element.
stdlib class that evaluates in-circuit pedersen hashes, consistent with behavior in crypto::pedersen_...
Definition pedersen.hpp:23
static field_ct hash(const std::vector< field_ct > &in, GeneratorContext context={})
Computes a pedersen hash of the provided inputs.
Definition pedersen.cpp:29
typename cycle_group< Builder >::Curve EmbeddedCurve
Definition pedersen.hpp:28
StrictMock< MockContext > context
stdlib::field_t< Builder > field_ct
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13