14
14
#include " barretenberg/dsl/acir_format/proof_surgeon.hpp"
15
15
#include " barretenberg/dsl/acir_proofs/acir_composer.hpp"
16
16
#include " barretenberg/dsl/acir_proofs/honk_contract.hpp"
17
+ #include " barretenberg/dsl/acir_proofs/honk_zk_contract.hpp"
17
18
#include " barretenberg/honk/proof_system/types/proof.hpp"
18
19
#include " barretenberg/numeric/bitop/get_msb.hpp"
19
20
#include " barretenberg/plonk/proof_system/proving_key/serialize.hpp"
@@ -570,7 +571,7 @@ void contract(const std::string& output_path, const std::string& vk_path)
570
571
}
571
572
572
573
/* *
573
- * @brief Writes a Honk Solidity verifier contract for an ACIR circuit to a file
574
+ * @brief Writes a Honk Zero Knowledge Solidity verifier contract for an ACIR circuit to a file
574
575
*
575
576
* Communication:
576
577
* - stdout: The Solidity verifier contract is written to stdout as a string
@@ -603,6 +604,40 @@ void contract_honk(const std::string& output_path, const std::string& vk_path)
603
604
}
604
605
}
605
606
607
+ /* *
608
+ * @brief Writes a zero-knowledge Honk Solidity verifier contract for an ACIR circuit to a file
609
+ *
610
+ * Communication:
611
+ * - stdout: The Solidity verifier contract is written to stdout as a string
612
+ * - Filesystem: The Solidity verifier contract is written to the path specified by outputPath
613
+ *
614
+ * Note: The fact that the contract was computed is for an ACIR circuit is not of importance
615
+ * because this method uses the verification key to compute the Solidity verifier contract
616
+ *
617
+ * @param output_path Path to write the contract to
618
+ * @param vk_path Path to the file containing the serialized verification key
619
+ */
620
+ void contract_honk_zk (const std::string& output_path, const std::string& vk_path)
621
+ {
622
+ using VerificationKey = UltraKeccakZKFlavor::VerificationKey;
623
+ using VerifierCommitmentKey = bb::VerifierCommitmentKey<curve::BN254>;
624
+
625
+ auto g2_data = get_bn254_g2_data (CRS_PATH);
626
+ srs::init_crs_factory ({}, g2_data);
627
+ auto vk = std::make_shared<VerificationKey>(from_buffer<VerificationKey>(read_file (vk_path)));
628
+ vk->pcs_verification_key = std::make_shared<VerifierCommitmentKey>();
629
+
630
+ std::string contract = get_honk_zk_solidity_verifier (vk);
631
+
632
+ if (output_path == " -" ) {
633
+ writeStringToStdout (contract);
634
+ vinfo (" contract written to stdout" );
635
+ } else {
636
+ write_file (output_path, { contract.begin (), contract.end () });
637
+ vinfo (" contract written to: " , output_path);
638
+ }
639
+ }
640
+
606
641
/* *
607
642
* @brief Converts a proof from a byte array into a list of field elements
608
643
*
@@ -870,7 +905,7 @@ UltraProver_<Flavor> compute_valid_prover(const std::string& bytecodePath,
870
905
using Prover = UltraProver_<Flavor>;
871
906
872
907
uint32_t honk_recursion = 0 ;
873
- if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor>) {
908
+ if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor, UltraKeccakZKFlavor >) {
874
909
honk_recursion = 1 ;
875
910
} else if constexpr (IsAnyOf<Flavor, UltraRollupFlavor>) {
876
911
honk_recursion = 2 ;
@@ -886,7 +921,14 @@ UltraProver_<Flavor> compute_valid_prover(const std::string& bytecodePath,
886
921
887
922
auto builder = acir_format::create_circuit<Builder>(program, metadata);
888
923
auto prover = Prover{ builder };
889
- init_bn254_crs (prover.proving_key ->proving_key .circuit_size );
924
+ size_t required_crs_size = prover.proving_key ->proving_key .circuit_size ;
925
+ if constexpr (Flavor::HasZK) {
926
+ // Ensure there are enough points to commit to the libra polynomials required for zero-knowledge sumcheck
927
+ if (required_crs_size < curve::BN254::SUBGROUP_SIZE * 2 ) {
928
+ required_crs_size = curve::BN254::SUBGROUP_SIZE * 2 ;
929
+ }
930
+ }
931
+ init_bn254_crs (required_crs_size);
890
932
891
933
// output the vk
892
934
typename Flavor::VerificationKey vk (prover.proving_key ->proving_key );
@@ -1247,7 +1289,7 @@ void prove_honk_output_all(const std::string& bytecodePath,
1247
1289
using VerificationKey = Flavor::VerificationKey;
1248
1290
1249
1291
uint32_t honk_recursion = 0 ;
1250
- if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor>) {
1292
+ if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor, UltraKeccakZKFlavor >) {
1251
1293
honk_recursion = 1 ;
1252
1294
} else if constexpr (IsAnyOf<Flavor, UltraRollupFlavor>) {
1253
1295
honk_recursion = 2 ;
@@ -1429,6 +1471,9 @@ int main(int argc, char* argv[])
1429
1471
} else if (command == " contract_ultra_honk" ) {
1430
1472
std::string output_path = get_option (args, " -o" , " ./target/contract.sol" );
1431
1473
contract_honk (output_path, vk_path);
1474
+ } else if (command == " contract_ultra_honk_zk" ) {
1475
+ std::string output_path = get_option (args, " -o" , " ./target/contract.sol" );
1476
+ contract_honk_zk (output_path, vk_path);
1432
1477
} else if (command == " write_vk" ) {
1433
1478
std::string output_path = get_option (args, " -o" , " ./target/vk" );
1434
1479
write_vk (bytecode_path, output_path, recursive);
@@ -1485,13 +1530,18 @@ int main(int argc, char* argv[])
1485
1530
} else if (command == " prove_ultra_keccak_honk" ) {
1486
1531
std::string output_path = get_option (args, " -o" , " ./proofs/proof" );
1487
1532
prove_honk<UltraKeccakFlavor>(bytecode_path, witness_path, output_path, recursive);
1533
+ } else if (command == " prove_ultra_keccak_honk_zk" ) {
1534
+ std::string output_path = get_option (args, " -o" , " ./proofs/proof" );
1535
+ prove_honk<UltraKeccakZKFlavor>(bytecode_path, witness_path, output_path, recursive);
1488
1536
} else if (command == " prove_ultra_rollup_honk" ) {
1489
1537
std::string output_path = get_option (args, " -o" , " ./proofs/proof" );
1490
1538
prove_honk<UltraRollupFlavor>(bytecode_path, witness_path, output_path, recursive);
1491
1539
} else if (command == " verify_ultra_honk" ) {
1492
1540
return verify_honk<UltraFlavor>(proof_path, vk_path) ? 0 : 1 ;
1493
1541
} else if (command == " verify_ultra_keccak_honk" ) {
1494
1542
return verify_honk<UltraKeccakFlavor>(proof_path, vk_path) ? 0 : 1 ;
1543
+ } else if (command == " verify_ultra_keccak_honk_zk" ) {
1544
+ return verify_honk<UltraKeccakZKFlavor>(proof_path, vk_path) ? 0 : 1 ;
1495
1545
} else if (command == " verify_ultra_rollup_honk" ) {
1496
1546
return verify_honk<UltraRollupFlavor>(proof_path, vk_path) ? 0 : 1 ;
1497
1547
} else if (command == " write_vk_ultra_honk" ) {
0 commit comments