26#ifdef STARKNET_GARAGA_FLAVORS
27#include "barretenberg/flavor/ultra_starknet_flavor.hpp"
28#include "barretenberg/flavor/ultra_starknet_zk_flavor.hpp"
37 uint32_t honk_recursion = 0;
44#ifdef STARKNET_GARAGA_FLAVORS
53template <
typename Flavor,
typename Circuit =
typename Flavor::CircuitBuilder>
54Circuit
_compute_circuit(std::vector<uint8_t>&& bytecode, std::vector<uint8_t>&& witness)
59 if (!witness.empty()) {
62 return acir_format::create_circuit<Circuit>(program, metadata);
65template <
typename Flavor>
67 std::vector<uint8_t>&& witness)
70 auto initial_time = std::chrono::high_resolution_clock::now();
73 auto final_time = std::chrono::high_resolution_clock::now();
74 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(final_time - initial_time);
75 info(
"CircuitProve: Proving key computed in ", duration.count(),
" ms");
76 return prover_instance;
78template <
typename Flavor>
80 std::vector<uint8_t>&& witness,
81 std::vector<uint8_t>&& vk_bytes)
83 using Proof =
typename Flavor::Transcript::Proof;
85 auto prover_instance = _compute_prover_instance<Flavor>(
std::move(bytecode),
std::move(witness));
87 if (vk_bytes.empty()) {
88 info(
"WARNING: computing verification key while proving. Pass in a precomputed vk for better performance.");
97 Proof concat_pi_and_proof = prover.construct_proof();
99 auto num_inner_public_inputs = [&]() {
100 size_t num_public_inputs = prover.prover_instance->num_public_inputs();
104 "Public inputs should contain a pairing point accumulator and an IPA claim.");
109 "Public inputs should contain a pairing point accumulator.");
115 if (vk_bytes.empty()) {
116 auto vk_fields_direct =
vk->to_field_elements();
132 concat_pi_and_proof.begin() +
136 concat_pi_and_proof.end() },
140template <
typename Flavor>
142 const std::vector<uint8_t>& vk_bytes,
155 std::vector<DataType> complete_proof;
156 complete_proof.reserve(public_inputs.size() + proof.size());
157 complete_proof.insert(complete_proof.end(), public_inputs.begin(), public_inputs.end());
158 complete_proof.insert(complete_proof.end(), proof.begin(), proof.end());
162 if (ipa_accumulation) {
167 Verifier verifier{
vk, ipa_verification_key };
169 bool verified =
false;
172 const size_t num_public_inputs =
static_cast<size_t>(
vk->num_public_inputs);
175 HONK_PROOF_LENGTH + IPA_PROOF_LENGTH + num_public_inputs,
176 "Honk proof has incorrect length while verifying.");
178 static_cast<std::ptrdiff_t>(HONK_PROOF_LENGTH + num_public_inputs);
179 auto ipa_proof = Proof(complete_proof.begin() + honk_proof_with_pub_inputs_length, complete_proof.end());
180 auto honk_proof = Proof(complete_proof.begin(), complete_proof.begin() + honk_proof_with_pub_inputs_length);
181 verified = verifier.template verify_proof<RollupIO>(complete_proof, ipa_proof).result;
183 verified = verifier.template verify_proof<DefaultIO>(complete_proof).result;
187 info(
"Proof verified successfully");
189 info(
"Proof verification failed");
199 if (settings.ipa_accumulation) {
200 return _prove<UltraRollupFlavor>(
203 if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
205 return _prove<UltraZKFlavor>(
208 if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
210 return _prove<UltraFlavor>(
213 if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
215 return _prove<UltraKeccakZKFlavor>(
218 if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
219 return _prove<UltraKeccakFlavor>(
221#ifdef STARKNET_GARAGA_FLAVORS
223 if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
224 return _prove<UltraStarknetFlavor>(
227 if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
228 return _prove<UltraStarknetZKFlavor>(
232 throw_or_abort(
"Invalid proving options specified in CircuitProve!");
238 std::vector<uint8_t> vk_bytes;
240 std::vector<uint8_t> vk_hash_bytes;
243 auto compute_vk_and_fields = [&]<
typename Flavor>() {
244 auto prover_instance = _compute_prover_instance<Flavor>(
std::move(circuit.bytecode), {});
248 vk_fields =
vk->to_field_elements();
251 auto uint256_elements =
vk->to_field_elements();
252 vk_fields.reserve(uint256_elements.size());
253 vk_fields.insert(vk_fields.end(), uint256_elements.begin(), uint256_elements.end());
258 if (settings.ipa_accumulation) {
260 }
else if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
262 }
else if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
263 compute_vk_and_fields.template operator()<
UltraFlavor>();
264 }
else if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
266 }
else if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
268#ifdef STARKNET_GARAGA_FLAVORS
269 }
else if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
270 compute_vk_and_fields.template operator()<UltraStarknetZKFlavor>();
271 }
else if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
272 compute_vk_and_fields.template operator()<UltraStarknetFlavor>();
281template <
typename Flavor,
typename Circuit =
typename Flavor::CircuitBuilder>
290 response.
num_acir_opcodes =
static_cast<uint32_t
>(constraint_system.num_acir_opcodes);
293 auto builder = acir_format::create_circuit<Circuit>(program, metadata);
294 builder.finalize_circuit(
true);
296 response.
num_gates =
static_cast<uint32_t
>(
builder.get_finalized_total_circuit_size());
308 if (settings.ipa_accumulation) {
309 return _stats<UltraRollupFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
311 if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
313 return _stats<UltraZKFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
315 if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
317 return _stats<UltraFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
319 if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
321 return _stats<UltraKeccakZKFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
323 if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
324 return _stats<UltraKeccakFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
325#ifdef STARKNET_GARAGA_FLAVORS
327 if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
328 return _stats<UltraStarknetFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
330 if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
331 return _stats<UltraStarknetZKFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
334 throw_or_abort(
"Invalid proving options specified in CircuitStats!");
340 const bool ipa_accumulation = settings.ipa_accumulation;
341 bool verified =
false;
344 if (ipa_accumulation) {
345 verified = _verify<UltraRollupFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
346 }
else if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
347 verified = _verify<UltraZKFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
348 }
else if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
349 verified = _verify<UltraFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
350 }
else if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
351 verified = _verify<UltraKeccakZKFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
352 }
else if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
353 verified = _verify<UltraKeccakFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
354#ifdef STARKNET_GARAGA_FLAVORS
355 }
else if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
356 verified = _verify<UltraStarknetZKFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
357 }
else if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
358 verified = _verify<UltraStarknetFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
373 auto vk = from_buffer<UltraFlavor::VerificationKey>(verification_key);
374 fields =
vk.to_field_elements();
390 if (settings.disable_zk && settings.optimized_solidity_verifier) {
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_BENCH_NAME(name)
Shared type definitions for the Barretenberg RPC API.
UltraHonk-specific command definitions for the Barretenberg RPC API.
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
typename Codec::DataType DataType
std::vector< DataType > Proof
static constexpr size_t PUBLIC_INPUTS_SIZE
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
NativeTranscript Transcript
static constexpr size_t PUBLIC_INPUTS_SIZE
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
Child class of UltraFlavor that runs with ZK Sumcheck.
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
std::string get_honk_solidity_verifier(auto const &verification_key)
UltraKeccakFlavor::VerificationKey VerificationKey
std::string get_optimized_honk_solidity_verifier(auto const &verification_key)
std::string get_honk_zk_solidity_verifier(auto const &verification_key)
acir_format::ProgramMetadata _create_program_metadata()
CircuitStats::Response _stats(std::vector< uint8_t > &&bytecode, bool include_gates_per_opcode)
Circuit _compute_circuit(std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness)
CircuitProve::Response _prove(std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness, std::vector< uint8_t > &&vk_bytes)
std::shared_ptr< ProverInstance_< Flavor > > _compute_prover_instance(std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness)
bool _verify(const bool ipa_accumulation, const std::vector< uint8_t > &vk_bytes, const std::vector< uint256_t > &public_inputs, const std::vector< uint256_t > &proof)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< uint8_t > to_buffer(T const &value)
std::vector< uint8_t > bytes
Response execute(const BBApiRequest &request={}) &&
Contains proof and public inputs. Both are given as vectors of fields. To be used for verification....
Response execute(const BBApiRequest &request={}) &&
uint32_t num_gates_dyadic
std::vector< size_t > gates_per_opcode
uint32_t num_acir_opcodes
Response execute(const BBApiRequest &request={}) &&
Response execute(const BBApiRequest &request={}) &&
Response execute(const BBApiRequest &request={}) &&
Response execute(const BBApiRequest &request={}) &&
void throw_or_abort(std::string const &err)