-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: solidity honk verifier #5485
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
fa6a841
feat(honk): verifier start
Maddiaa0 fabd169
temp
Maddiaa0 43cd61a
Merge branch 'master' into md/02-26-feat_honk_verifier_start
Maddiaa0 323e7b0
temp - get it compiling
Maddiaa0 ff22c01
Merge branch 'master' into md/02-26-feat_honk_verifier_start
Maddiaa0 1ed41cb
temp
Maddiaa0 78d45b0
temp 2
Maddiaa0 b7881f1
feat: fiat shamir complete
Maddiaa0 a724d30
feat: experiment with a custom Fr type
Maddiaa0 dd85f2d
feat: oink verifier stages
Maddiaa0 538f432
feat: arith, perm, lookup, gen perm relation
Maddiaa0 654ab55
feat: field inversions
Maddiaa0 b9fe7ba
feat: elliptic relation
Maddiaa0 7f94eb2
feat: sumcheck complete
Maddiaa0 b510ca8
feat: start zm
Maddiaa0 1da70e0
feat: more zm
Maddiaa0 6c5da89
feat: honk verification
Maddiaa0 d131397
chore: remove logs for gas accounting
Maddiaa0 b914b69
🧹
Maddiaa0 1443210
🧹
Maddiaa0 ecd7af6
🧹
Maddiaa0 2f9a5d0
🧹
Maddiaa0 60e2a7a
chore: add verifier for 3 circuit types
Maddiaa0 56c28fb
fix: fix fuzz tests
Maddiaa0 3f5a478
fix: add extra check and invert checkSum result
Maddiaa0 f08a0ec
Merge branch 'master' into md/02-26-feat_honk_verifier_start
Maddiaa0 9d7a651
temp
Maddiaa0 10a8eea
fix: Update honk implementation: add logderiv, scaled etas
Maddiaa0 b2e9eee
fix
Maddiaa0 eaa1c0e
Merge branch 'master' into md/02-26-feat_honk_verifier_start
Maddiaa0 4d26743
fix: clean up comments
Maddiaa0 d2906cf
fix: remove box commit
Maddiaa0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,6 +355,7 @@ template <typename Tuple, std::size_t Index = 0> static constexpr auto create_tu | |
namespace bb { | ||
class UltraFlavor; | ||
class ECCVMFlavor; | ||
class UltraKeccakFlavor; | ||
class MegaFlavor; | ||
class TranslatorFlavor; | ||
template <typename BuilderType> class UltraRecursiveFlavor_; | ||
|
@@ -383,16 +384,16 @@ template <typename T> | |
concept IsPlonkFlavor = IsAnyOf<T, plonk::flavor::Standard, plonk::flavor::Ultra>; | ||
|
||
template <typename T> | ||
concept IsUltraPlonkFlavor = IsAnyOf<T, plonk::flavor::Ultra>; | ||
concept IsUltraPlonkFlavor = IsAnyOf<T, plonk::flavor::Ultra, UltraKeccakFlavor>; | ||
|
||
template <typename T> | ||
concept IsUltraPlonkOrHonk = IsAnyOf<T, plonk::flavor::Ultra, UltraFlavor, MegaFlavor>; | ||
concept IsUltraPlonkOrHonk = IsAnyOf<T, plonk::flavor::Ultra, UltraFlavor, UltraKeccakFlavor, MegaFlavor>; | ||
|
||
template <typename T> | ||
concept IsHonkFlavor = IsAnyOf<T, UltraFlavor, MegaFlavor>; | ||
concept IsHonkFlavor = IsAnyOf<T, UltraFlavor, UltraKeccakFlavor, MegaFlavor>; | ||
|
||
template <typename T> | ||
concept IsUltraFlavor = IsAnyOf<T, UltraFlavor, MegaFlavor>; | ||
concept IsUltraFlavor = IsAnyOf<T, UltraFlavor, UltraKeccakFlavor, MegaFlavor>; | ||
|
||
template <typename T> | ||
concept IsGoblinFlavor = IsAnyOf<T, MegaFlavor, | ||
|
@@ -417,6 +418,8 @@ template <typename T> concept IsECCVMRecursiveFlavor = IsAnyOf<T, ECCVMRecursive | |
template <typename T> concept IsGrumpkinFlavor = IsAnyOf<T, ECCVMFlavor>; | ||
|
||
template <typename T> concept IsFoldingFlavor = IsAnyOf<T, UltraFlavor, | ||
// Note(md): must be here to use oink prover | ||
UltraKeccakFlavor, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah something has clearly gone wrong with the use of this concept... |
||
MegaFlavor, | ||
UltraRecursiveFlavor_<UltraCircuitBuilder>, | ||
UltraRecursiveFlavor_<MegaCircuitBuilder>, | ||
|
18 changes: 17 additions & 1 deletion
18
barretenberg/cpp/src/barretenberg/solidity_helpers/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
barretenberg/cpp/src/barretenberg/solidity_helpers/honk_key_gen.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" | ||
#include "barretenberg/ultra_honk/ultra_prover.hpp" | ||
#include "barretenberg/ultra_honk/ultra_verifier.hpp" | ||
|
||
#include "./honk_sol_gen.hpp" | ||
|
||
#include "circuits/add_2_circuit.hpp" | ||
#include "circuits/blake_circuit.hpp" | ||
#include "circuits/ecdsa_circuit.hpp" | ||
|
||
using namespace bb; | ||
|
||
using ProverInstance = ProverInstance_<UltraKeccakFlavor>; | ||
using VerificationKey = UltraKeccakFlavor::VerificationKey; | ||
|
||
template <template <typename> typename Circuit> | ||
void generate_keys_honk(std::string output_path, std::string flavour_prefix, std::string circuit_name) | ||
{ | ||
uint256_t public_inputs[4] = { 0, 0, 0, 0 }; | ||
UltraCircuitBuilder builder = Circuit<UltraCircuitBuilder>::generate(public_inputs); | ||
|
||
auto instance = std::make_shared<ProverInstance>(builder); | ||
UltraKeccakProver prover(instance); | ||
auto verification_key = std::make_shared<VerificationKey>(instance->proving_key); | ||
|
||
// Make verification key file upper case | ||
circuit_name.at(0) = static_cast<char>(std::toupper(static_cast<unsigned char>(circuit_name.at(0)))); | ||
flavour_prefix.at(0) = static_cast<char>(std::toupper(static_cast<unsigned char>(flavour_prefix.at(0)))); | ||
|
||
std::string vk_class_name = circuit_name + flavour_prefix + "VerificationKey"; | ||
std::string base_class_name = "Base" + flavour_prefix + "Verifier"; | ||
std::string instance_class_name = circuit_name + flavour_prefix + "Verifier"; | ||
|
||
{ | ||
auto vk_filename = output_path + "/keys/" + vk_class_name + ".sol"; | ||
std::ofstream os(vk_filename); | ||
bb::output_vk_sol_ultra_honk(os, verification_key, vk_class_name); | ||
info("VK contract written to: ", vk_filename); | ||
} | ||
} | ||
|
||
/* | ||
* @brief Main entry point for the verification key generator | ||
* | ||
* 1. project_root_path: path to the solidity project root | ||
* 2. srs_path: path to the srs db | ||
*/ | ||
int main(int argc, char** argv) | ||
{ | ||
std::vector<std::string> args(argv, argv + argc); | ||
|
||
if (args.size() < 5) { | ||
info("usage: ", args[0], "[plonk flavour] [circuit flavour] [output path] [srs path]"); | ||
return 1; | ||
} | ||
|
||
const std::string plonk_flavour = args[1]; | ||
const std::string circuit_flavour = args[2]; | ||
const std::string output_path = args[3]; | ||
const std::string srs_path = args[4]; | ||
|
||
bb::srs::init_crs_factory(srs_path); | ||
// @todo - Add support for unrolled standard verifier. Needs a new solidity verifier contract. | ||
|
||
if (plonk_flavour != "honk") { | ||
info("honk"); | ||
return 1; | ||
} | ||
|
||
info("Generating ", plonk_flavour, " keys for ", circuit_flavour, " circuit"); | ||
|
||
if (plonk_flavour == "honk") { | ||
if (circuit_flavour == "add2") { | ||
generate_keys_honk<Add2Circuit>(output_path, plonk_flavour, circuit_flavour); | ||
} else if (circuit_flavour == "blake") { | ||
generate_keys_honk<BlakeCircuit>(output_path, plonk_flavour, circuit_flavour); | ||
} else if (circuit_flavour == "ecdsa") { | ||
generate_keys_honk<bb::EcdsaCircuit>(output_path, plonk_flavour, circuit_flavour); | ||
// TODO: recursive proofs | ||
} else { | ||
info("Unsupported circuit"); | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} // namespace bb |
105 changes: 105 additions & 0 deletions
105
barretenberg/cpp/src/barretenberg/solidity_helpers/honk_proof_gen.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
#include "barretenberg/honk/proof_system/types/proof.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" | ||
#include "barretenberg/ultra_honk/ultra_prover.hpp" | ||
#include "barretenberg/ultra_honk/ultra_verifier.hpp" | ||
|
||
#include "circuits/add_2_circuit.hpp" | ||
#include "circuits/blake_circuit.hpp" | ||
#include "circuits/ecdsa_circuit.hpp" | ||
#include "utils/utils.hpp" | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
|
||
using namespace bb; | ||
using numeric::uint256_t; | ||
|
||
using ProverInstance = ProverInstance_<UltraKeccakFlavor>; | ||
using VerificationKey = UltraKeccakFlavor::VerificationKey; | ||
using Prover = UltraKeccakProver; | ||
using Verifier = UltraKeccakVerifier; | ||
|
||
template <template <typename> typename Circuit> void generate_proof(uint256_t inputs[]) | ||
{ | ||
|
||
UltraCircuitBuilder builder = Circuit<UltraCircuitBuilder>::generate(inputs); | ||
|
||
auto instance = std::make_shared<ProverInstance>(builder); | ||
Prover prover(instance); | ||
auto verification_key = std::make_shared<VerificationKey>(instance->proving_key); | ||
Verifier verifier(verification_key); | ||
|
||
HonkProof proof = prover.construct_proof(); | ||
{ | ||
if (!verifier.verify_proof(proof)) { | ||
throw_or_abort("Verification failed"); | ||
} | ||
|
||
std::vector<uint8_t> proof_bytes = to_buffer(proof); | ||
std::string p = bytes_to_hex_string(proof_bytes); | ||
std::cout << p; | ||
} | ||
} | ||
|
||
std::string pad_left(std::string input, size_t length) | ||
{ | ||
return std::string(length - std::min(length, input.length()), '0') + input; | ||
} | ||
|
||
/** | ||
* @brief Main entry point for the proof generator. | ||
* Expected inputs: | ||
* 1. plonk_flavour: ultra | ||
* 2. circuit_flavour: blake, add2 | ||
* 3. public_inputs: comma separated list of public inputs | ||
* 4. project_root_path: path to the solidity project root | ||
* 5. srs_path: path to the srs db | ||
*/ | ||
int main(int argc, char** argv) | ||
{ | ||
std::vector<std::string> args(argv, argv + argc); | ||
|
||
if (args.size() < 5) { | ||
info("usage: ", args[0], "[plonk flavour] [circuit flavour] [srs path] [public inputs]"); | ||
return 1; | ||
} | ||
|
||
const std::string plonk_flavour = args[1]; | ||
const std::string circuit_flavour = args[2]; | ||
const std::string srs_path = args[3]; | ||
const std::string string_input = args[4]; | ||
|
||
bb::srs::init_crs_factory(srs_path); | ||
|
||
// @todo dynamically allocate this | ||
uint256_t inputs[] = { 0, 0, 0, 0, 0, 0 }; | ||
|
||
size_t count = 0; | ||
std::stringstream s_stream(string_input); | ||
while (s_stream.good()) { | ||
std::string sub; | ||
getline(s_stream, sub, ','); | ||
if (sub.substr(0, 2) == "0x") { | ||
sub = sub.substr(2); | ||
} | ||
std::string padded = pad_left(sub, 64); | ||
inputs[count++] = uint256_t(padded); | ||
} | ||
|
||
if (plonk_flavour != "honk") { | ||
info("Only honk flavor allowed"); | ||
return 1; | ||
} | ||
|
||
if (circuit_flavour == "blake") { | ||
generate_proof<BlakeCircuit>(inputs); | ||
} else if (circuit_flavour == "add2") { | ||
generate_proof<Add2Circuit>(inputs); | ||
} else if (circuit_flavour == "ecdsa") { | ||
generate_proof<EcdsaCircuit>(inputs); | ||
} else { | ||
info("Invalid circuit flavour: " + circuit_flavour); | ||
return 1; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed because we need Keccak hashing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes