Skip to content

Commit f7b24c5

Browse files
authored
feat: merge-train/barretenberg (#20051)
BEGIN_COMMIT_OVERRIDE chore: rm ultra rollup flavor (#19984) END_COMMIT_OVERRIDE
2 parents 8ea8713 + afe8981 commit f7b24c5

File tree

62 files changed

+618
-761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+618
-761
lines changed

barretenberg/cpp/src/barretenberg/api/api_ultra_honk.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@
77
#include "barretenberg/common/get_bytecode.hpp"
88
#include "barretenberg/common/map.hpp"
99
#include "barretenberg/common/throw_or_abort.hpp"
10-
#include "barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp"
11-
#include "barretenberg/dsl/acir_proofs/honk_contract.hpp"
12-
#include "barretenberg/dsl/acir_proofs/honk_optimized_contract.hpp"
13-
#include "barretenberg/dsl/acir_proofs/honk_zk_contract.hpp"
14-
#include "barretenberg/honk/proof_system/types/proof.hpp"
1510
#include "barretenberg/numeric/uint256/uint256.hpp"
16-
#include "barretenberg/special_public_inputs/special_public_inputs.hpp"
17-
#include "barretenberg/srs/global_crs.hpp"
18-
#include <optional>
1911

2012
namespace bb {
2113

@@ -205,7 +197,6 @@ void UltraHonkAPI::gates([[maybe_unused]] const Flags& flags,
205197
std::string functions_string = "{\"functions\": [\n ";
206198

207199
// For now, treat the entire bytecode as a single circuit
208-
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1074): Handle multi-circuit programs properly
209200
// Convert flags to ProofSystemSettings
210201
bbapi::ProofSystemSettings settings{ .ipa_accumulation = flags.ipa_accumulation,
211202
.oracle_hash_type = flags.oracle_hash_type,

barretenberg/cpp/src/barretenberg/api/api_ultra_honk.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#pragma once
22

33
#include "barretenberg/api/api.hpp"
4-
#include "barretenberg/flavor/ultra_flavor.hpp"
5-
#include "barretenberg/flavor/ultra_rollup_flavor.hpp"
6-
#include "barretenberg/flavor/ultra_zk_flavor.hpp"
74
#include <filesystem>
85
#include <string>
96

barretenberg/cpp/src/barretenberg/bb/cli.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "barretenberg/common/bb_bench.hpp"
2929
#include "barretenberg/common/thread.hpp"
3030
#include "barretenberg/common/version.hpp"
31-
#include "barretenberg/flavor/ultra_rollup_flavor.hpp"
3231
#include "barretenberg/srs/factories/native_crs_factory.hpp"
3332
#include "barretenberg/srs/global_crs.hpp"
3433
#include "barretenberg/vm2/api_avm.hpp"

barretenberg/cpp/src/barretenberg/bbapi/bbapi_shared.hpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
#include "barretenberg/chonk/chonk.hpp"
1111
#include "barretenberg/common/throw_or_abort.hpp"
1212
#include "barretenberg/dsl/acir_format/acir_format.hpp"
13+
#include "barretenberg/flavor/ultra_flavor.hpp"
14+
#include "barretenberg/flavor/ultra_keccak_flavor.hpp"
15+
#include "barretenberg/flavor/ultra_keccak_zk_flavor.hpp"
16+
#include "barretenberg/flavor/ultra_zk_flavor.hpp"
1317
#include "barretenberg/honk/execution_trace/mega_execution_trace.hpp"
18+
#include "barretenberg/stdlib/special_public_inputs/special_public_inputs.hpp"
19+
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"
20+
#ifdef STARKNET_GARAGA_FLAVORS
21+
#include "barretenberg/flavor/ultra_starknet_flavor.hpp"
22+
#include "barretenberg/flavor/ultra_starknet_zk_flavor.hpp"
23+
#endif
1424
#include <cstdint>
1525
#include <string>
1626
#include <vector>
@@ -208,4 +218,116 @@ struct Shutdown {
208218
bool operator==(const Shutdown&) const = default;
209219
};
210220

221+
/**
222+
* @brief Concatenate public inputs and proof into a complete proof for verification
223+
* @details Joins the separated public_inputs and proof portions back together.
224+
* Handles implicit conversion from uint256_t to the flavor's DataType.
225+
*
226+
* The proof structure after concatenation is: [public_inputs | honk_proof (| ipa_proof)]
227+
* For rollup circuits (RollupIO), the proof portion includes the IPA proof appended at the end.
228+
* This must match the split done in _prove() and the verification in _verify().
229+
*
230+
* @param public_inputs The ACIR public inputs (user inputs, not including IO-specific data)
231+
* @param proof The proof data (Honk proof, plus IPA proof for rollup circuits)
232+
*/
233+
template <typename Flavor>
234+
inline typename Flavor::Transcript::Proof concatenate_proof(const std::vector<uint256_t>& public_inputs,
235+
const std::vector<uint256_t>& proof)
236+
{
237+
typename Flavor::Transcript::Proof result;
238+
result.reserve(public_inputs.size() + proof.size());
239+
result.insert(result.end(), public_inputs.begin(), public_inputs.end());
240+
result.insert(result.end(), proof.begin(), proof.end());
241+
return result;
242+
}
243+
244+
/**
245+
* @brief Convert VK to uint256 field elements, handling flavor-specific return types
246+
*/
247+
template <typename VK> std::vector<uint256_t> vk_to_uint256_fields(const VK& vk)
248+
{
249+
auto fields = vk.to_field_elements();
250+
if constexpr (std::is_same_v<decltype(fields), std::vector<uint256_t>>) {
251+
return fields;
252+
} else {
253+
return std::vector<uint256_t>(fields.begin(), fields.end());
254+
}
255+
}
256+
257+
/**
258+
* @brief Validate rollup circuit settings
259+
* @details Rollup circuits require poseidon2 oracle hash for efficient recursion.
260+
* The disable_zk flag is ignored - rollup always uses UltraFlavor (non-ZK).
261+
*
262+
* @throws If oracle_hash_type is not poseidon2
263+
*/
264+
inline void validate_rollup_settings(const ProofSystemSettings& settings)
265+
{
266+
if (!settings.ipa_accumulation) {
267+
return; // Not a rollup circuit, no validation needed
268+
}
269+
270+
// Rollup circuits must use poseidon2 for efficient recursive verification
271+
if (settings.oracle_hash_type != "poseidon2") {
272+
throw_or_abort("Rollup circuits (ipa_accumulation=true) must use oracle_hash_type='poseidon2', got '" +
273+
settings.oracle_hash_type + "'");
274+
}
275+
}
276+
277+
/**
278+
* @brief Dispatch to the correct Flavor and IO type based on proof system settings
279+
* @details Maps settings (ipa_accumulation, oracle_hash_type, disable_zk) to the appropriate Flavor and IO template
280+
* parameters.
281+
*
282+
* Rollup Path:
283+
* - When ipa_accumulation=true, uses UltraFlavor with RollupIO (includes IPA claim for ECCVM)
284+
* - Validates that rollup settings are compatible (poseidon2, disable_zk=true)
285+
*
286+
* Non-Rollup Paths:
287+
* - Routes to appropriate Flavor based on oracle_hash_type and disable_zk
288+
* - Uses DefaultIO (includes only pairing points, no IPA)
289+
*
290+
* @param settings The proof system settings determining which flavor/IO to use
291+
* @param operation A callable object that will be invoked with <Flavor, IO> template parameters
292+
* @return The result of calling operation.template operator()<Flavor, IO>()
293+
*
294+
*/
295+
template <typename Operation> auto dispatch_by_settings(const ProofSystemSettings& settings, Operation&& operation)
296+
{
297+
// Rollup circuits: UltraFlavor with RollupIO (includes IPA accumulation for ECCVM)
298+
if (settings.ipa_accumulation) {
299+
validate_rollup_settings(settings);
300+
return operation.template operator()<UltraFlavor, RollupIO>();
301+
}
302+
303+
// Non-rollup circuits: route based on oracle hash type and ZK setting
304+
if (settings.oracle_hash_type == "poseidon2") {
305+
if (settings.disable_zk) {
306+
return operation.template operator()<UltraFlavor, DefaultIO>();
307+
}
308+
return operation.template operator()<UltraZKFlavor, DefaultIO>();
309+
}
310+
311+
if (settings.oracle_hash_type == "keccak") {
312+
if (settings.disable_zk) {
313+
return operation.template operator()<UltraKeccakFlavor, DefaultIO>();
314+
}
315+
return operation.template operator()<UltraKeccakZKFlavor, DefaultIO>();
316+
}
317+
318+
#ifdef STARKNET_GARAGA_FLAVORS
319+
if (settings.oracle_hash_type == "starknet") {
320+
if (settings.disable_zk) {
321+
return operation.template operator()<UltraStarknetFlavor, DefaultIO>();
322+
}
323+
return operation.template operator()<UltraStarknetZKFlavor, DefaultIO>();
324+
}
325+
#endif
326+
327+
// Invalid configuration
328+
throw_or_abort("Invalid proof system settings: oracle_hash_type='" + settings.oracle_hash_type +
329+
"', disable_zk=" + std::to_string(settings.disable_zk) +
330+
", ipa_accumulation=" + std::to_string(settings.ipa_accumulation));
331+
}
332+
211333
} // namespace bb::bbapi

0 commit comments

Comments
 (0)