Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
7c671f2
perf: enable advisory scalar deduplication for AVM wires
IlyasRidhuan Nov 5, 2026
652ffb8
Import the complete cumulative AVM stack over the accepted leader
Nov 6, 2026
1230d0b
perf(bigfield): defer multiply-add division until its result is needed
Nov 7, 2026
0fff10b
perf(stdlib): reuse native witness inverse in paired point addition
Nov 6, 2026
7b96fb1
perf(native): materialize only requested lookup result wrappers
Nov 7, 2026
200eb62
perf(native): narrow bounded BN254 host reciprocal division
Nov 7, 2026
4dd1d21
Resolve verified dense lookup tables without map allocation
Nov 7, 2026
f8b07a8
Use represented field constants in dense lookup validation
Nov 7, 2026
67e5154
Use compact row indices behind verified dense lookup resolution
Nov 7, 2026
f0ab123
perf(msm): dynamically schedule native MSM bucket windows
Nov 7, 2026
4721979
Count-sort large bounded range-value lists
Nov 7, 2026
c33d5a9
Reuse native range values with a shared compile-time source policy
Nov 7, 2026
8e6a0b4
Share the native CPU budget across independent large commitment MSMs
Nov 7, 2026
59b2a12
Batch standard native Poseidon sumcheck subrelations
Nov 8, 2026
85745c2
Reduce native Montgomery conversions directly
Nov 7, 2026
1e5316f
perf(stdlib): derive missing cycle_group offset generators in parallel
alejoamiras Nov 10, 2026
f452664
perf(stdlib): add the summed offset generators once per Straus round
alejoamiras Nov 10, 2026
85307e0
perf(stdlib): cheaper native Straus hints in plookup fixed-base batch…
alejoamiras Nov 10, 2026
668e5cc
refactor(bb): draw the default rollup IPA opening apart from proving it
alejoamiras Nov 10, 2026
e0ce866
perf(dsl): skip proving the unused mock Honk proof under a constant p…
alejoamiras Nov 10, 2026
d91b485
perf(numeric): slice lookup keys with one division per digit
alejoamiras Nov 10, 2026
948b5be
perf(plookup): accumulate native lookup columns in place
alejoamiras Nov 10, 2026
7c4c986
perf(builder): reserve the witness index columns of a lookup read
alejoamiras Nov 10, 2026
04f207a
perf(stdlib): read only the used lookup rows in SHA-256
alejoamiras Nov 10, 2026
db66f84
perf(builder): resolve a lookup table once per run of equal table ids
alejoamiras Nov 10, 2026
3d60456
perf(numeric): visit only set bits in map_into_sparse_form
alejoamiras Nov 10, 2026
1d0d282
perf(ipa): reuse the known commitment when proving a fresh IPA claim
alejoamiras Nov 10, 2026
0dd752f
perf(builder): convert each limb once in range_constrain_two_limbs
alejoamiras Nov 10, 2026
6bc97b4
perf(builder): look up the range list once per small range constraint
alejoamiras Nov 10, 2026
adb1049
perf(builder): register new sublimbs straight into their range list
alejoamiras Nov 10, 2026
415e1c7
perf(builder): trim the native bookkeeping of create_limbed_range_con…
alejoamiras Nov 10, 2026
532aa9b
perf(builder): build the integer selector values of gates at compile …
alejoamiras Nov 10, 2026
4ccdca5
perf(builder): convert each distinct sorted range value once
alejoamiras Nov 10, 2026
ac0fcf4
test(builder): pin the range-constraint circuits against reference co…
alejoamiras Nov 10, 2026
42a0576
perf(stdlib): build constant bigfield limbs without Montgomery round …
alejoamiras Nov 10, 2026
ba323f1
perf(stdlib): build the unreduced zero constant once
alejoamiras Nov 10, 2026
e5c9f71
perf(builder): append the delta-range rows of a sort constraint from …
alejoamiras Nov 10, 2026
88d25c0
perf(builder): count range-list values in parallel chunks
alejoamiras Nov 10, 2026
035376f
perf(builder): append the sorted variables of a range list in one step
alejoamiras Nov 10, 2026
8f21f31
perf(builder): deduplicate range lists through a variable bitmap in p…
alejoamiras Nov 10, 2026
99ed5e0
test(builder): pin range-list processing against the serial composition
alejoamiras Nov 10, 2026
84adb3d
perf(common): size gzip output from the ISIZE trailer instead of doub…
alejoamiras Nov 10, 2026
62c7a10
perf(common): read gzip input files in one bulk read
alejoamiras Nov 10, 2026
7d9f81d
perf(srs): read the cached BN254 CRS with parallel pread
alejoamiras Nov 10, 2026
011010b
perf(srs): load the native CRS into uninitialised storage
alejoamiras Nov 10, 2026
3fa757c
perf(polynomials): release large polynomial memory from several threa…
alejoamiras Nov 10, 2026
1b2d435
perf(srs): release the native CRS's pages in parallel when it is dest…
alejoamiras Nov 10, 2026
8019d8e
perf(ecc): check VectorFieldPushSpan bounds once per walk instead of …
alejoamiras Nov 10, 2026
93c3ea3
perf(trace): build copy cycles in uninitialised, parallel-touched sto…
alejoamiras Nov 10, 2026
38253d7
perf(trace): cap the copy-cycle scans at 16 tasks
alejoamiras Nov 10, 2026
07bc1ab
perf(trace): copy selectors in row-chunk tasks
alejoamiras Nov 11, 2026
9a35ffd
perf(srs): read and parse the cached Grumpkin CRS in parallel
alejoamiras Nov 11, 2026
23e6f13
perf(ipa): convert the random opening's draws to field elements in pa…
alejoamiras Nov 11, 2026
959b1b2
perf(ipa): compute the native IPA opening proof of a rollup circuit i…
alejoamiras Nov 10, 2026
8dba008
perf(ipa): fold the SRS in blocks to bound the fold's scratch memory
alejoamiras Nov 11, 2026
815bd06
test(common): cover DeferredValue's joins, shared result, exceptions …
alejoamiras Nov 11, 2026
49a98f0
fix(srs): honour BB_VERIFY_CRS in the BN254 loader, as v6.0.0 does
alejoamiras Nov 12, 2026
fd1f365
fix(srs): close the Grumpkin CRS descriptor on every exit and guard i…
alejoamiras Nov 12, 2026
56a07a2
perf(polynomials): release an instance's polynomial pages with one te…
alejoamiras Nov 11, 2026
fd75fe5
perf(stdlib_circuit_builders): release a builder's large blocks with …
alejoamiras Nov 11, 2026
b8dcdcd
perf(stdlib): keep the offset-generator store alive past exit
alejoamiras Nov 11, 2026
199d1ae
perf(srs): release vector-held BN254 CRS points in parallel before fr…
alejoamiras Nov 11, 2026
158810b
feat(numeric): stream positions and per-thread draw scopes on the ran…
alejoamiras Nov 12, 2026
7107ef5
fix(numeric): close each thread's /dev/urandom descriptor when the th…
alejoamiras Nov 12, 2026
2acc036
feat(stdlib): rebind stdlib values to another builder in place
alejoamiras Nov 12, 2026
5ce81c9
feat(honk): append translated rows to an execution trace block in bulk
alejoamiras Nov 12, 2026
68db5c9
feat(stdlib_circuit_builders): record what a splice must replay while…
alejoamiras Nov 12, 2026
09e8b66
feat(stdlib_circuit_builders): splice a recorded circuit into an Ultr…
alejoamiras Nov 12, 2026
a047543
test(stdlib_circuit_builders): cover a second splice and eight refusa…
alejoamiras Nov 12, 2026
d8b5d83
perf(stdlib_circuit_builders): release every sizeable block of a reco…
alejoamiras Nov 12, 2026
38aeb8b
fix(common): keep the DEBUG_LOG recursion guard per thread
alejoamiras Nov 12, 2026
0442a1f
test(stdlib_circuit_builders): share the all-member Ultra builder com…
alejoamiras Nov 12, 2026
ee76782
feat(dsl): build leading Honk recursion constraints on scratch thread…
alejoamiras Nov 12, 2026
14c29a3
test(dsl): cover four refusals of a scratch-built constraint and the …
alejoamiras Nov 12, 2026
0ca5207
perf(dsl): return the memory a scratch thread freed before its builde…
alejoamiras Nov 12, 2026
35bc7fa
feat(stdlib_circuit_builders): let another thread cancel a build on a…
alejoamiras Nov 12, 2026
2284c63
feat(dsl): build the first Honk recursion constraint in place when it…
alejoamiras Nov 12, 2026
52a905c
fix(dsl): start scratch builds on 8 MiB pthread stacks and only for w…
alejoamiras Nov 12, 2026
b6241dd
fix(dsl): cancel scratch builds before joining them and reap them aft…
alejoamiras Nov 12, 2026
8fd5b11
fix(dsl): keep the message of a scratch build's exception in its refusal
alejoamiras Nov 12, 2026
5ecb886
perf(stdlib_circuit_builders): reserve address space for a builder's …
alejoamiras Nov 12, 2026
a5a5df7
perf(msm): run wide members of concurrent batches as chunks
alejoamiras Nov 12, 2026
a815b1b
perf(msm): run a concurrent batch's chunks on one per-worker arena block
alejoamiras Nov 12, 2026
a0f8dcf
perf(msm): size a concurrent batch's chunks to whole rounds of the pool
alejoamiras Nov 12, 2026
b433d64
perf(msm): chunk a few-member batch when each member is worth 8/3 thr…
alejoamiras Nov 12, 2026
2467bb9
test(msm): draw the concurrent-chunk tests' random inputs on one thread
alejoamiras Nov 12, 2026
160117a
perf(bb): release process memory on several threads before a successf…
alejoamiras Nov 12, 2026
62aa515
perf(bb): keep freed heap memory in AVM and UltraHonk proving
alejoamiras Nov 13, 2026
549b653
feat(stdlib_circuit_builders): splice recordings that hold lookup row…
alejoamiras Nov 13, 2026
629dfc3
refactor(dsl): share the scratch-build helpers of the recursion splicer
alejoamiras Nov 13, 2026
6514690
feat(dsl): build long runs of SHA-256 compression constraints on scra…
alejoamiras Nov 13, 2026
ce9fcf7
test(dsl): cover refusals, chunk counts and cancellation of a scratch…
alejoamiras Nov 13, 2026
f6b7067
perf(stdlib_circuit_builders): let a range list a splice appends to g…
alejoamiras Nov 13, 2026
2723293
perf(bb): free each trace block once it is copied when proving with U…
alejoamiras Nov 13, 2026
944fbc4
feat(dsl): build the root rollup's Honk recursion constraints on scra…
alejoamiras Nov 15, 2026
bdebc3f
perf(stdlib): compute a large fixed-base batch multiplication's nativ…
alejoamiras Nov 15, 2026
38ef46c
perf(bb): release a copied Ultra trace block's pages on several threads
alejoamiras Nov 15, 2026
c4086d7
fix(bb): compile two earlier commits' size conversions for wasm32
alejoamiras Nov 13, 2026
7e3d0dc
perf(sumcheck): split the first two rounds' fold into fixed-size chunks
alejoamiras Nov 15, 2026
0483948
perf(gemini): back the batched polynomial A0 only on the data extent
alejoamiras Nov 15, 2026
44a9f37
Merge the rollup leader's stack
Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "barretenberg/bbapi/bbapi_prove_instance.hpp"
#include "barretenberg/special_public_inputs/special_public_inputs.hpp"
#include "barretenberg/srs/global_crs.hpp"
#include "barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/prover_instance.hpp"
#include "barretenberg/ultra_honk/ultra_prover.hpp"
#include "barretenberg/ultra_honk/ultra_verifier.hpp"

#include <gtest/gtest.h>

namespace bb::bbapi {
namespace {

using Flavor = UltraFlavor;
using Builder = UltraCircuitBuilder;
using ProverInstance = ProverInstance_<Flavor>;
using VerificationKey = Flavor::VerificationKey;

/**
* @brief An Ultra circuit with arithmetic, public-input, lookup, range and ROM/RAM rows, built without randomness so
* that two builds are identical.
*/
Builder build_circuit()
{
Builder builder;
for (uint64_t i = 0; i < 16; ++i) {
const uint32_t a_idx = builder.add_public_variable(fr(i + 1));
const uint32_t b_idx = builder.add_variable(fr((2 * i) + 3));
const uint32_t c_idx = builder.add_variable(fr(7));
const uint32_t d_idx = builder.add_variable(fr(i + 1) + fr((2 * i) + 3) + fr(7));
builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) });
}

constexpr auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR;
for (uint32_t i = 0; i < 8; ++i) {
const fr left = fr{ 0x9e3779b9U * (i + 1), 0, 0, 0 }.to_montgomery_form();
const fr right = fr{ 0x85ebca6bU ^ i, 0, 0, 0 }.to_montgomery_form();
const uint32_t left_idx = builder.add_variable(left);
const uint32_t right_idx = builder.add_variable(right);
const auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup=*/true);
builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx);
}

for (uint64_t i = 0; i < 16; ++i) {
builder.create_dyadic_range_constraint(builder.add_variable(fr(i * 1000)), 16, "range");
}

const size_t rom_id = builder.create_ROM_array(4);
for (size_t i = 0; i < 4; ++i) {
builder.set_ROM_element(rom_id, i, builder.add_variable(fr((i * i) + 1)));
}
builder.read_ROM_array(rom_id, builder.add_variable(fr(2)));

const size_t ram_id = builder.create_RAM_array(2);
builder.init_RAM_element(ram_id, 0, builder.add_variable(fr(5)));
builder.init_RAM_element(ram_id, 1, builder.add_variable(fr(9)));
builder.write_RAM_array(ram_id, builder.add_variable(fr(1)), builder.add_variable(fr(11)));
builder.read_RAM_array(ram_id, builder.add_variable(fr(1)));

DefaultIO::add_default(builder);
return builder;
}

class CircuitProveCopiedCircuitData : public ::testing::Test {
protected:
static void SetUpTestSuite() { srs::init_file_crs_factory(srs::bb_crs_path()); }
};

/**
* @brief The instance CircuitProve builds frees the circuit's blocks and lookup tables, keeps their sizes and offsets,
* and proves the same bytes as an instance that keeps them.
*/
TEST_F(CircuitProveCopiedCircuitData, FreesTheCircuitAndProvesTheSameBytes)
{
Builder kept = build_circuit();
Builder released = build_circuit();
auto kept_instance = std::make_shared<ProverInstance>(kept, CopiedCircuitData::KEEP);
auto released_instance = circuit_prove_instance<Flavor>(released);

EXPECT_FALSE(kept.get_lookup_tables().empty());
EXPECT_TRUE(released.get_lookup_tables().empty());
auto kept_blocks = kept.blocks.get();
auto released_blocks = released.blocks.get();
size_t num_freed_blocks = 0;
for (size_t i = 0; i < kept_blocks.size(); ++i) {
EXPECT_FALSE(kept_blocks[i].data_freed_);
EXPECT_EQ(released_blocks[i].size(), kept_blocks[i].size());
EXPECT_EQ(released_blocks[i].trace_offset(), kept_blocks[i].trace_offset());
// A block without rows has no chunk in the copying pass, so nothing frees it.
EXPECT_EQ(released_blocks[i].data_freed_, kept_blocks[i].size() > 0);
if (released_blocks[i].data_freed_) {
++num_freed_blocks;
}
}
// Arithmetic, public inputs, lookup, delta range and memory at least.
EXPECT_GE(num_freed_blocks, 5U);

auto vk = std::make_shared<VerificationKey>(kept_instance->get_precomputed());
EXPECT_EQ(VerificationKey(released_instance->get_precomputed()), *vk);
UltraProver_<Flavor> kept_prover(kept_instance, vk);
UltraProver_<Flavor> released_prover(released_instance, vk);
const auto kept_proof = kept_prover.construct_proof();
const auto released_proof = released_prover.construct_proof();
EXPECT_EQ(released_proof, kept_proof);

UltraVerifier_<Flavor, DefaultIO> verifier(std::make_shared<Flavor::VKAndHash>(vk));
EXPECT_TRUE(verifier.verify_proof(released_proof).result);
}

} // namespace
} // namespace bb::bbapi
18 changes: 18 additions & 0 deletions barretenberg/cpp/src/barretenberg/bbapi/bbapi_prove_instance.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "barretenberg/trace_to_polynomials/copied_circuit_data.hpp"
#include "barretenberg/ultra_honk/prover_instance.hpp"
#include <memory>

namespace bb::bbapi {

/**
* @brief Builds the prover instance a CircuitProve proof is made from. The request reads nothing from the circuit
* afterwards, so each trace block and lookup table is freed as soon as it has been copied into the polynomials.
*/
template <typename Flavor>
std::shared_ptr<ProverInstance_<Flavor>> circuit_prove_instance(typename Flavor::CircuitBuilder& circuit)
{
return std::make_shared<ProverInstance_<Flavor>>(circuit, CopiedCircuitData::RELEASE);
}

} // namespace bb::bbapi
21 changes: 15 additions & 6 deletions barretenberg/cpp/src/barretenberg/bbapi/bbapi_ultra_honk.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "barretenberg/bbapi/bbapi_ultra_honk.hpp"
#include "barretenberg/bbapi/bbapi_prove_instance.hpp"
#include "barretenberg/bbapi/bbapi_shared.hpp"
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp"
Expand Down Expand Up @@ -35,25 +36,28 @@ Circuit _compute_circuit(std::vector<uint8_t>&& bytecode, std::vector<uint8_t>&&

template <typename Flavor, typename IO>
std::shared_ptr<ProverInstance_<Flavor>> _compute_prover_instance(std::vector<uint8_t>&& bytecode,
std::vector<uint8_t>&& witness)
std::vector<uint8_t>&& witness,
const bool for_proof = false)
{
// Measure function time and debug print
auto initial_time = std::chrono::high_resolution_clock::now();
typename Flavor::CircuitBuilder builder = _compute_circuit<Flavor, IO>(std::move(bytecode), std::move(witness));
auto prover_instance = std::make_shared<ProverInstance_<Flavor>>(builder);
// The VK path keeps the circuit as it was; a proof's instance frees it while copying it.
auto prover_instance =
for_proof ? circuit_prove_instance<Flavor>(builder) : std::make_shared<ProverInstance_<Flavor>>(builder);
auto final_time = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(final_time - initial_time);
info("CircuitProve: Proving key computed in ", duration.count(), " ms");

// Validate consistency between IO type and IPA proof presence
// IO::HasIPA indicates the circuit type requires IPA accumulation (rollup circuits)
// prover_instance->ipa_proof contains the actual IPA proof data from the circuit
// has_ipa_proof() also counts a proof still being computed, without waiting for it
if constexpr (IO::HasIPA) {
BB_ASSERT(!prover_instance->ipa_proof.empty(),
BB_ASSERT(prover_instance->has_ipa_proof(),
"RollupIO circuit expected IPA proof but none was provided. "
"Ensure the circuit includes IPA accumulation data.");
} else {
BB_ASSERT(prover_instance->ipa_proof.empty(),
BB_ASSERT(!prover_instance->has_ipa_proof(),
"Non-rollup circuit should not have IPA proof. "
"Use ipa_accumulation=true in settings for rollup circuits.");
}
Expand Down Expand Up @@ -110,7 +114,8 @@ CircuitProve::Response _prove(std::vector<uint8_t>&& bytecode,
using Proof = typename Flavor::Transcript::Proof;
using VerificationKey = typename Flavor::VerificationKey;

auto prover_instance = _compute_prover_instance<Flavor, IO>(std::move(bytecode), std::move(witness));
auto prover_instance =
_compute_prover_instance<Flavor, IO>(std::move(bytecode), std::move(witness), /*for_proof=*/true);

// Create or deserialize VK
std::shared_ptr<VerificationKey> vk;
Expand Down Expand Up @@ -169,6 +174,8 @@ CircuitComputeVk::Response CircuitComputeVk::execute(BB_UNUSED const BBApiReques
return dispatch_by_settings(settings, [&]<typename Flavor, typename IO>() {
auto prover_instance = _compute_prover_instance<Flavor, IO>(std::move(circuit.bytecode), {});
auto vk = std::make_shared<typename Flavor::VerificationKey>(prover_instance->get_precomputed());
// No proof is exported here, so wait for a pending IPA proof now: its failure must fail the request.
prover_instance->resolve_ipa_proof();
return CircuitComputeVk::Response{ .bytes = to_buffer(*vk),
.fields = vk_to_uint256_fields(*vk),
.hash = to_buffer(vk->hash()) };
Expand All @@ -190,6 +197,8 @@ CircuitStats::Response _stats(std::vector<uint8_t>&& bytecode, bool include_gate
acir_format::AcirProgram program{ std::move(constraint_system), {} };
auto builder = acir_format::create_circuit<Circuit>(program, metadata);
builder.finalize_circuit();
// No proof is exported here, so wait for a pending IPA proof now: its failure must fail the request.
builder.resolve_ipa_proof();

response.num_gates = static_cast<uint32_t>(builder.get_finalized_total_circuit_size());
response.num_gates_dyadic = static_cast<uint32_t>(builder.get_circuit_subgroup_size(response.num_gates));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "barretenberg/circuit_checker/circuit_checker.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
#include "barretenberg/stdlib_circuit_builders/bounded_range_sort.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"

#include <array>
#include <functional>
#include <gtest/gtest.h>

using namespace bb;
Expand Down Expand Up @@ -156,3 +159,90 @@ TEST(UltraCircuitBuilder, RangeChecksOnDuplicates)
}

} // namespace bb

namespace bb {

TEST(BoundedRangeSort, MatchesGeneralSortAndPreservesFallbackInputs)
{
for (const uint64_t maximum : std::array<uint64_t, 7>{ 0, 1, 15, 255, 16383, 65535, 65536 }) {
for (const size_t count : std::array<size_t, 7>{ 0, 1, 255, 256, 257, 16384, 65536 }) {
for (const size_t shape : std::array<size_t, 5>{ 0, 1, 2, 3, 4 }) {
std::vector<uint32_t> values(count);
uint64_t state = 0x9e3779b97f4a7c15ULL;
for (size_t i = 0; i < count; ++i) {
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
values[i] = static_cast<uint32_t>(state % (maximum + 1));
}
if (shape == 1)
std::sort(values.begin(), values.end());
if (shape == 2)
std::sort(values.begin(), values.end(), std::greater<uint32_t>());
if (shape == 3)
std::fill(values.begin(), values.end(), static_cast<uint32_t>(maximum));
if (shape == 4 && !values.empty())
values[count / 2] = static_cast<uint32_t>(maximum + 1);
const auto original = values;
auto expected = values;
std::sort(expected.begin(), expected.end());
const bool eligible =
maximum < 65536 && count >= 256 && count >= maximum + 1 &&
std::all_of(original.begin(), original.end(), [&](uint32_t value) { return value <= maximum; });
const bool admitted = range_sort::try_counting_sort(values, maximum);
EXPECT_EQ(admitted, eligible);
if (admitted) {
EXPECT_EQ(values, expected);
} else {
EXPECT_EQ(values, original);
std::sort(values.begin(), values.end());
EXPECT_EQ(values, expected);
}
}
}
}
}

TEST(UltraCircuitBuilder, BoundedRangeSortValidAndInvalidWitnesses)
{
for (const size_t shape : std::array<size_t, 3>{ 0, 1, 2 }) {
UltraCircuitBuilder builder;
std::vector<uint32_t> indices;
for (size_t i = 0; i < 512; ++i) {
const uint32_t value = shape == 1 && i == 17 ? uint32_t(256) : static_cast<uint32_t>((i * 17) % 256);
const fr field_value = shape == 2 && i == 17 ? fr(uint256_t(1) << 128) + fr(1) : fr(value);
const uint32_t index = builder.add_variable(field_value);
indices.push_back(index);
builder.create_small_range_constraint(index, 255);
}
builder.assert_equal(indices[0], indices[256]); // Equal values with distinct original witness indices.
builder.create_unconstrained_gates(indices);
EXPECT_EQ(CircuitChecker::check(builder), shape == 0);
}
}

} // namespace bb

namespace bb {
TEST(UltraCircuitBuilder, NativeSubLimbAdmissionPreservesRangeChecks)
{
for (const uint64_t bits : std::array<uint64_t, 5>{ 14, 15, 28, 68, 253 }) {
for (const size_t shape : std::array<size_t, 3>{ 0, 1, 2 }) {
UltraCircuitBuilder builder;
const uint256_t value =
shape == 0 ? uint256_t(0) : (shape == 1 ? (uint256_t(1) << bits) - 1 : uint256_t(1) << bits);
const uint32_t index = builder.add_variable(fr(value));
const auto limbs = builder.create_limbed_range_constraint(index, bits, 14, "native-limb-test");
EXPECT_EQ(limbs.size(), (bits + 13) / 14);
for (size_t i = 0; i < limbs.size(); ++i) {
EXPECT_EQ(builder.get_variable(limbs[i]), fr((value >> (i * 14)).data[0] & uint64_t(16383)));
}
EXPECT_EQ(builder.failed(), shape == 2);
if (shape == 2) {
EXPECT_EQ(builder.err(), "native-limb-test");
}
EXPECT_EQ(CircuitChecker::check(builder), shape != 2);
}
}
}
} // namespace bb
Loading
Loading