22#ifdef STARKNET_GARAGA_FLAVORS
23#include "barretenberg/flavor/ultra_starknet_flavor.hpp"
24#include "barretenberg/flavor/ultra_starknet_zk_flavor.hpp"
33 uint32_t honk_recursion = 0;
40#ifdef STARKNET_GARAGA_FLAVORS
49template <
typename Flavor,
typename Circuit =
typename Flavor::CircuitBuilder>
50Circuit
_compute_circuit(std::vector<uint8_t>&& bytecode, std::vector<uint8_t>&& witness)
55 if (!witness.empty()) {
58 return acir_format::create_circuit<Circuit>(program, metadata);
61template <
typename Flavor>
63 std::vector<uint8_t>&& witness)
66 auto initial_time = std::chrono::high_resolution_clock::now();
69 auto final_time = std::chrono::high_resolution_clock::now();
70 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(final_time - initial_time);
71 info(
"CircuitProve: Proving key computed in ", duration.count(),
" ms");
72 return decider_proving_key;
75template <
typename Flavor>
77 std::vector<uint8_t>&& witness,
78 std::vector<uint8_t>&& vk_bytes)
80 using Proof =
typename Flavor::Transcript::Proof;
82 auto proving_key = _compute_proving_key<Flavor>(
std::move(bytecode),
std::move(witness));
84 if (vk_bytes.empty()) {
85 info(
"WARNING: computing verification key while proving. Pass in a precomputed vk for better performance.");
94 Proof concat_pi_and_proof = prover.construct_proof();
96 auto num_inner_public_inputs = [&]() {
97 size_t num_public_inputs = prover.proving_key->num_public_inputs();
101 "Public inputs should contain a pairing point accumulator and an IPA claim.");
106 "Public inputs should contain a pairing point accumulator.");
112 if (vk_bytes.empty()) {
113 auto vk_fields_direct =
vk->to_field_elements();
129 concat_pi_and_proof.begin() +
133 concat_pi_and_proof.end() },
137template <
typename Flavor>
139 const std::vector<uint8_t>& vk_bytes,
152 std::vector<DataType> complete_proof;
153 complete_proof.reserve(public_inputs.size() + proof.size());
154 complete_proof.insert(complete_proof.end(), public_inputs.begin(), public_inputs.end());
155 complete_proof.insert(complete_proof.end(), proof.begin(), proof.end());
159 if (ipa_accumulation) {
164 Verifier verifier{
vk, ipa_verification_key };
166 bool verified =
false;
169 const size_t num_public_inputs =
static_cast<size_t>(
vk->num_public_inputs);
172 HONK_PROOF_LENGTH + IPA_PROOF_LENGTH + num_public_inputs,
173 "Honk proof has incorrect length while verifying.");
175 static_cast<std::ptrdiff_t>(HONK_PROOF_LENGTH + num_public_inputs);
176 auto ipa_proof = Proof(complete_proof.begin() + honk_proof_with_pub_inputs_length, complete_proof.end());
177 auto tube_honk_proof =
178 Proof(complete_proof.begin(), complete_proof.begin() + honk_proof_with_pub_inputs_length);
179 verified = verifier.template verify_proof<RollupIO>(complete_proof, ipa_proof).result;
181 verified = verifier.template verify_proof<DefaultIO>(complete_proof).result;
185 info(
"Proof verified successfully");
187 info(
"Proof verification failed");
196 if (settings.ipa_accumulation) {
197 return _prove<UltraRollupFlavor>(
200 if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
202 return _prove<UltraZKFlavor>(
205 if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
207 return _prove<UltraFlavor>(
210 if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
212 return _prove<UltraKeccakZKFlavor>(
215 if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
216 return _prove<UltraKeccakFlavor>(
218#ifdef STARKNET_GARAGA_FLAVORS
220 if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
221 return _prove<UltraStarknetFlavor>(
224 if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
225 return _prove<UltraStarknetZKFlavor>(
229 throw_or_abort(
"Invalid proving options specified in CircuitProve!");
234 std::vector<uint8_t> vk_bytes;
236 std::vector<uint8_t> vk_hash_bytes;
239 auto compute_vk_and_fields = [&]<
typename Flavor>() {
240 auto proving_key = _compute_proving_key<Flavor>(
std::move(circuit.bytecode), {});
244 vk_fields =
vk->to_field_elements();
247 auto uint256_elements =
vk->to_field_elements();
248 vk_fields.reserve(uint256_elements.size());
249 vk_fields.insert(vk_fields.end(), uint256_elements.begin(), uint256_elements.end());
254 if (settings.ipa_accumulation) {
256 }
else if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
258 }
else if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
259 compute_vk_and_fields.template operator()<
UltraFlavor>();
260 }
else if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
262 }
else if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
264#ifdef STARKNET_GARAGA_FLAVORS
265 }
else if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
266 compute_vk_and_fields.template operator()<UltraStarknetZKFlavor>();
267 }
else if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
268 compute_vk_and_fields.template operator()<UltraStarknetFlavor>();
285 response.
num_acir_opcodes =
static_cast<uint32_t
>(constraint_system.num_acir_opcodes);
288 auto builder = acir_format::create_circuit<UltraCircuitBuilder>(program, metadata);
289 builder.finalize_circuit(
true);
291 response.
num_gates =
static_cast<uint32_t
>(
builder.get_finalized_total_circuit_size());
301 const bool ipa_accumulation = settings.ipa_accumulation;
302 bool verified =
false;
305 if (ipa_accumulation) {
306 verified = _verify<UltraRollupFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
307 }
else if (settings.oracle_hash_type ==
"poseidon2" && !settings.disable_zk) {
308 verified = _verify<UltraZKFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
309 }
else if (settings.oracle_hash_type ==
"poseidon2" && settings.disable_zk) {
310 verified = _verify<UltraFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
311 }
else if (settings.oracle_hash_type ==
"keccak" && !settings.disable_zk) {
312 verified = _verify<UltraKeccakZKFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
313 }
else if (settings.oracle_hash_type ==
"keccak" && settings.disable_zk) {
314 verified = _verify<UltraKeccakFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
315#ifdef STARKNET_GARAGA_FLAVORS
316 }
else if (settings.oracle_hash_type ==
"starknet" && !settings.disable_zk) {
317 verified = _verify<UltraStarknetZKFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
318 }
else if (settings.oracle_hash_type ==
"starknet" && settings.disable_zk) {
319 verified = _verify<UltraStarknetFlavor>(ipa_accumulation, verification_key, public_inputs, proof);
333 auto vk = from_buffer<UltraFlavor::VerificationKey>(verification_key);
334 fields =
vk.to_field_elements();
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_EQ(actual, expected,...)
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...
TranscriptParams::DataType DataType
typename TranscriptParams::Proof 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_honk_zk_solidity_verifier(auto const &verification_key)
acir_format::ProgramMetadata _create_program_metadata()
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)
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)
std::shared_ptr< DeciderProvingKey_< Flavor > > _compute_proving_key(std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness)
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)