26#ifdef STARKNET_GARAGA_FLAVORS
27#include "barretenberg/flavor/ultra_starknet_flavor.hpp"
28#include "barretenberg/flavor/ultra_starknet_zk_flavor.hpp"
42template <
typename Flavor,
typename Circuit =
typename Flavor::CircuitBuilder>
48 if (!witness.empty()) {
51 return acir_format::create_circuit<Circuit>(program, metadata);
54template <
typename Flavor>
56 std::vector<uint8_t>&& witness)
59 auto initial_time = std::chrono::high_resolution_clock::now();
62 auto final_time = std::chrono::high_resolution_clock::now();
63 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(final_time - initial_time);
64 info(
"CircuitProve: Proving key computed in ", duration.count(),
" ms");
65 return prover_instance;
67template <
typename Flavor>
69 std::vector<uint8_t>&& witness,
70 std::vector<uint8_t>&& vk_bytes)
76 if (vk_bytes.empty()) {
77 info(
"WARNING: computing verification key while proving. Pass in a precomputed vk for better performance.");
88 auto num_inner_public_inputs = [&]() {
89 size_t num_public_inputs = prover.prover_instance->num_public_inputs();
93 "Public inputs should contain a pairing point accumulator and an IPA claim.");
98 "Public inputs should contain a pairing point accumulator.");
104 if (vk_bytes.empty()) {
105 auto vk_fields_direct =
vk->to_field_elements();
121 concat_pi_and_proof.begin() +
125 concat_pi_and_proof.end() },
129template <
typename Flavor>
130bool _verify(
const std::vector<uint8_t>& vk_bytes,
135 using VKAndHash =
typename Flavor::VKAndHash;
139 using DataType =
typename Transcript::DataType;
145 std::vector<DataType> complete_proof;
146 complete_proof.reserve(public_inputs.size() + proof.size());
147 complete_proof.insert(complete_proof.end(), public_inputs.begin(), public_inputs.end());
148 complete_proof.insert(complete_proof.end(), proof.begin(), proof.end());
150 Verifier verifier{ vk_and_hash };
152 bool verified = verifier.verify_proof(complete_proof).result;
155 info(
"Proof verified successfully");
157 info(
"Proof verification failed");
167 if (settings.ipa_accumulation) {
168 return _prove<UltraRollupFlavor>(
171 if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
173 return _prove<UltraZKFlavor>(
176 if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
178 return _prove<UltraFlavor>(
181 if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
183 return _prove<UltraKeccakZKFlavor>(
186 if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
187 return _prove<UltraKeccakFlavor>(
189#ifdef STARKNET_GARAGA_FLAVORS
191 if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
192 return _prove<UltraStarknetFlavor>(
195 if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
196 return _prove<UltraStarknetZKFlavor>(
200 throw_or_abort(
"Invalid proving options specified in CircuitProve!");
206 std::vector<uint8_t> vk_bytes;
208 std::vector<uint8_t> vk_hash_bytes;
211 auto compute_vk_and_fields = [&]<
typename Flavor>() {
212 auto prover_instance = _compute_prover_instance<Flavor>(
std::move(circuit.bytecode), {});
216 vk_fields =
vk->to_field_elements();
219 auto uint256_elements =
vk->to_field_elements();
220 vk_fields.reserve(uint256_elements.size());
221 vk_fields.insert(vk_fields.end(), uint256_elements.begin(), uint256_elements.end());
226 if (settings.ipa_accumulation) {
228 }
else if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
230 }
else if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
231 compute_vk_and_fields.template operator()<
UltraFlavor>();
232 }
else if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
234 }
else if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
236#ifdef STARKNET_GARAGA_FLAVORS
237 }
else if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
238 compute_vk_and_fields.template operator()<UltraStarknetZKFlavor>();
239 }
else if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
240 compute_vk_and_fields.template operator()<UltraStarknetFlavor>();
249template <
typename Flavor,
typename Circuit =
typename Flavor::CircuitBuilder>
258 response.
num_acir_opcodes =
static_cast<uint32_t
>(constraint_system.num_acir_opcodes);
261 auto builder = acir_format::create_circuit<Circuit>(program, metadata);
262 builder.finalize_circuit(
true);
264 response.
num_gates =
static_cast<uint32_t
>(
builder.get_finalized_total_circuit_size());
276 if (settings.ipa_accumulation) {
277 return _stats<UltraRollupFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
279 if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
281 return _stats<UltraZKFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
283 if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
285 return _stats<UltraFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
287 if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
289 return _stats<UltraKeccakZKFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
291 if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
292 return _stats<UltraKeccakFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
293#ifdef STARKNET_GARAGA_FLAVORS
295 if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
296 return _stats<UltraStarknetFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
298 if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
299 return _stats<UltraStarknetZKFlavor>(
std::move(circuit.bytecode), include_gates_per_opcode);
302 throw_or_abort(
"Invalid proving options specified in CircuitStats!");
308 const bool ipa_accumulation = settings.ipa_accumulation;
309 bool verified =
false;
312 if (ipa_accumulation) {
313 verified = _verify<UltraRollupFlavor>(verification_key, public_inputs, proof);
314 }
else if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
315 verified = _verify<UltraZKFlavor>(verification_key, public_inputs, proof);
316 }
else if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
317 verified = _verify<UltraFlavor>(verification_key, public_inputs, proof);
318 }
else if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
319 verified = _verify<UltraKeccakZKFlavor>(verification_key, public_inputs, proof);
320 }
else if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
321 verified = _verify<UltraKeccakFlavor>(verification_key, public_inputs, proof);
322#ifdef STARKNET_GARAGA_FLAVORS
323 }
else if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
324 verified = _verify<UltraStarknetZKFlavor>(verification_key, public_inputs, proof);
325 }
else if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
326 verified = _verify<UltraStarknetFlavor>(verification_key, public_inputs, proof);
338 std::vector<bb::fr> fields;
341 auto vk = from_buffer<UltraFlavor::VerificationKey>(verification_key);
342 fields =
vk.to_field_elements();
350 std::vector<bb::fr> fields;
353 auto vk = from_buffer<MegaFlavor::VerificationKey>(verification_key);
354 fields =
vk.to_field_elements();
370 if (settings.disable_zk && settings.optimized_solidity_verifier) {
#define BB_ASSERT_GTE(left, right,...)
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
#define BB_BENCH_NAME(name)
Shared type definitions for the Barretenberg RPC API.
UltraHonk-specific command definitions for the Barretenberg RPC API.
Manages the data that is propagated on the public inputs of an application/function circuit.
static constexpr size_t PUBLIC_INPUTS_SIZE
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
BaseTranscript< Codec, HashFunction > Transcript
The data that is propagated on the public inputs of a rollup circuit.
static constexpr size_t PUBLIC_INPUTS_SIZE
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
UltraRollupFlavor extends UltraFlavor with IPA proof support.
Child class of UltraFlavor that runs with ZK Sumcheck.
ECCVMFlavor::Transcript Transcript
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 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={}) &&
Response execute(const BBApiRequest &request={}) &&
void throw_or_abort(std::string const &err)