|
10 | 10 | #include "barretenberg/chonk/chonk.hpp" |
11 | 11 | #include "barretenberg/common/throw_or_abort.hpp" |
12 | 12 | #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" |
13 | 17 | #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 |
14 | 24 | #include <cstdint> |
15 | 25 | #include <string> |
16 | 26 | #include <vector> |
@@ -208,4 +218,116 @@ struct Shutdown { |
208 | 218 | bool operator==(const Shutdown&) const = default; |
209 | 219 | }; |
210 | 220 |
|
| 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 | + |
211 | 333 | } // namespace bb::bbapi |
0 commit comments