15 if (rhs > std::numeric_limits<std::size_t>::max() - lhs) {
22 constexpr std::size_t max_power =
23 std::size_t{1} << (std::numeric_limits<std::size_t>::digits - 1);
24 if (gates == 0 || gates > max_power) {
27 return std::bit_ceil(gates);
30void append_rows(std::vector<NativeBulletproofCircuitRow>& destination,
31 std::vector<NativeBulletproofCircuitRow>& source,
32 std::size_t constraint_offset) {
33 for (
auto& row : source) {
34 for (
auto& term : row.entries) {
35 term.idx += constraint_offset;
37 destination.push_back(std::move(row));
44 std::span<const NonceBatchGroup> groups) {
50 std::size_t group_index = 0;
51 for (
const auto& group : groups) {
53 "nonce_batch_circuit:template");
55 "nonce_batch_circuit:group");
57 "nonce_batch_circuit:gates");
59 "nonce_batch_circuit:constraints");
60 const std::size_t constraint_offset = result.
c.size();
61 result.
c.insert(result.
c.end(), circuit.c.begin(), circuit.c.end());
62 append_rows(result.
wl, circuit.wl, constraint_offset);
63 append_rows(result.
wr, circuit.wr, constraint_offset);
64 append_rows(result.
wo, circuit.wo, constraint_offset);
65 for (
const auto& term : circuit.wv[0].entries) {
66 result.
wv[group_index].add(constraint_offset + term.idx, term.scalar);
73 "nonce_batch_circuit:padding");
75 result.
wl.resize(gates);
76 result.
wr.resize(gates);
77 result.
wo.resize(gates);
82 std::span<const NonceBatchGroup> groups,
83 std::span<
const std::vector<BulletproofAssignmentData>> assignments) {
87 if (groups.size() != assignments.size()) {
93 for (std::size_t group_index = 0; group_index < groups.size(); ++group_index) {
94 const auto& group = groups[group_index];
96 "nonce_batch_assignments:template");
98 circuit_template.sum_assignments(group.hosts, assignments[group_index]),
99 "nonce_batch_assignments:group");
101 "nonce_batch_assignments:gates");
102 result.
left.insert(result.
left.end(), assignment.left.begin(), assignment.left.end());
103 result.
right.insert(result.
right.end(), assignment.right.begin(), assignment.right.end());
104 result.
output.insert(result.
output.end(), assignment.output.begin(), assignment.output.end());
105 result.
commitments.push_back(assignment.commitments[0]);
109 "nonce_batch_assignments:padding");
static FieldElement zero()
Returns the additive identity of the scalar field.
#define PURIFY_RETURN_IF_ERROR(expr, context)
Evaluates an expected-like expression and returns the wrapped error on failure.
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)
Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
constexpr Unexpected< Error > unexpected_error(ErrorCode code, const char *context=nullptr)
Constructs an unexpected Error value from a machine-readable code.
Result< NativeBulletproofCircuitTemplate > verifier_circuit_template(const Bytes &message)
Builds a reusable public-key-agnostic verifier-circuit template for a message.
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
Result< BulletproofAssignmentData > nonce_batch_assignments(std::span< const NonceBatchGroup > groups, std::span< const std::vector< BulletproofAssignmentData > > assignments)
Validates and combines member assignments for nonce_batch_circuit.
Result< NativeBulletproofCircuit > nonce_batch_circuit(std::span< const NonceBatchGroup > groups)
Builds a public verifier circuit with one output commitment per group.
Columnar witness assignment compatible with the native Bulletproof circuit layout.
BulletproofWitnessColumn left
BulletproofWitnessColumn output
BulletproofWitnessColumn commitments
BulletproofWitnessColumn right
Native in-memory representation of a Bulletproof-style arithmetic circuit.
std::vector< NativeBulletproofCircuitRow > wv
std::vector< NativeBulletproofCircuitRow > wr
std::vector< NativeBulletproofCircuitRow > wl
std::vector< NativeBulletproofCircuitRow > wo
std::vector< FieldElement > c