-
Notifications
You must be signed in to change notification settings - Fork 307
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
refactor: CIVC VK #10223
Merged
Merged
refactor: CIVC VK #10223
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,7 +332,6 @@ void client_ivc_prove_output_all_msgpack(const std::string& bytecodePath, | |
using Program = acir_format::AcirProgram; | ||
using ECCVMVK = ECCVMFlavor::VerificationKey; | ||
using TranslatorVK = TranslatorFlavor::VerificationKey; | ||
using DeciderVerificationKey = ClientIVC::DeciderVerificationKey; | ||
|
||
using namespace acir_format; | ||
|
||
|
@@ -378,23 +377,17 @@ void client_ivc_prove_output_all_msgpack(const std::string& bytecodePath, | |
|
||
// Write the proof and verification keys into the working directory in 'binary' format (in practice it seems this | ||
// directory is passed by bb.js) | ||
std::string vkPath = outputDir + "/mega_vk"; // the vk of the last circuit in the stack | ||
std::string vkPath = outputDir + "/client_ivc_vk"; // the vk of the last circuit in the stack | ||
std::string proofPath = outputDir + "/client_ivc_proof"; | ||
std::string translatorVkPath = outputDir + "/translator_vk"; | ||
std::string eccVkPath = outputDir + "/ecc_vk"; | ||
|
||
auto proof = ivc.prove(); | ||
auto eccvm_vk = std::make_shared<ECCVMVK>(ivc.goblin.get_eccvm_proving_key()); | ||
auto translator_vk = std::make_shared<TranslatorVK>(ivc.goblin.get_translator_proving_key()); | ||
|
||
auto last_vk = std::make_shared<DeciderVerificationKey>(ivc.honk_vk); | ||
vinfo("ensure valid proof: ", ivc.verify(proof)); | ||
|
||
vinfo("write proof and vk data to files.."); | ||
write_file(proofPath, to_buffer(proof)); | ||
write_file(vkPath, to_buffer(ivc.honk_vk)); | ||
write_file(translatorVkPath, to_buffer(translator_vk)); | ||
write_file(eccVkPath, to_buffer(eccvm_vk)); | ||
write_file(vkPath, to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); | ||
} | ||
|
||
template <typename T> std::shared_ptr<T> read_to_shared_ptr(const std::filesystem::path& path) | ||
|
@@ -414,24 +407,20 @@ template <typename T> std::shared_ptr<T> read_to_shared_ptr(const std::filesyste | |
* @param accumualtor_path Path to the file containing the serialized protogalaxy accumulator | ||
* @return true (resp., false) if the proof is valid (resp., invalid). | ||
*/ | ||
bool verify_client_ivc(const std::filesystem::path& proof_path, | ||
const std::filesystem::path& mega_vk, | ||
const std::filesystem::path& eccvm_vk_path, | ||
const std::filesystem::path& translator_vk_path) | ||
bool verify_client_ivc(const std::filesystem::path& proof_path, const std::filesystem::path& vk_path) | ||
{ | ||
init_bn254_crs(1); | ||
init_grumpkin_crs(1 << 15); | ||
|
||
const auto proof = from_buffer<ClientIVC::Proof>(read_file(proof_path)); | ||
const auto final_vk = read_to_shared_ptr<ClientIVC::VerificationKey>(mega_vk); | ||
final_vk->pcs_verification_key = std::make_shared<VerifierCommitmentKey<curve::BN254>>(); | ||
|
||
const auto eccvm_vk = read_to_shared_ptr<ECCVMFlavor::VerificationKey>(eccvm_vk_path); | ||
eccvm_vk->pcs_verification_key = | ||
std::make_shared<VerifierCommitmentKey<curve::Grumpkin>>(eccvm_vk->circuit_size + 1); | ||
const auto translator_vk = read_to_shared_ptr<TranslatorFlavor::VerificationKey>(translator_vk_path); | ||
translator_vk->pcs_verification_key = std::make_shared<VerifierCommitmentKey<curve::BN254>>(); | ||
const bool verified = ClientIVC::verify(proof, final_vk, eccvm_vk, translator_vk); | ||
const auto vk = from_buffer<ClientIVC::VerificationKey>(read_file(vk_path)); | ||
|
||
vk.mega->pcs_verification_key = std::make_shared<VerifierCommitmentKey<curve::BN254>>(); | ||
vk.eccvm->pcs_verification_key = | ||
std::make_shared<VerifierCommitmentKey<curve::Grumpkin>>(vk.eccvm->circuit_size + 1); | ||
vk.translator->pcs_verification_key = std::make_shared<VerifierCommitmentKey<curve::BN254>>(); | ||
|
||
const bool verified = ClientIVC::verify(proof, vk); | ||
vinfo("verified: ", verified); | ||
return verified; | ||
} | ||
|
@@ -519,10 +508,8 @@ void client_ivc_prove_output_all(const std::string& bytecodePath, | |
|
||
// Write the proof and verification keys into the working directory in 'binary' format (in practice it seems this | ||
// directory is passed by bb.js) | ||
std::string vkPath = outputPath + "/mega_vk"; // the vk of the last circuit in the stack | ||
std::string vkPath = outputPath + "/client_ivc_vk"; // the vk of the last circuit in the stack | ||
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. stale comment 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. Made the change in my API PR that builds off this one |
||
std::string proofPath = outputPath + "/client_ivc_proof"; | ||
std::string translatorVkPath = outputPath + "/translator_vk"; | ||
std::string eccVkPath = outputPath + "/ecc_vk"; | ||
|
||
auto proof = ivc.prove(); | ||
auto eccvm_vk = std::make_shared<ECCVMVK>(ivc.goblin.get_eccvm_proving_key()); | ||
|
@@ -531,9 +518,7 @@ void client_ivc_prove_output_all(const std::string& bytecodePath, | |
|
||
vinfo("write proof and vk data to files.."); | ||
write_file(proofPath, to_buffer(proof)); | ||
write_file(vkPath, to_buffer(ivc.honk_vk)); // maybe dereference | ||
write_file(translatorVkPath, to_buffer(translator_vk)); | ||
write_file(eccVkPath, to_buffer(eccvm_vk)); | ||
write_file(vkPath, to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); | ||
} | ||
|
||
/** | ||
|
@@ -544,37 +529,31 @@ void client_ivc_prove_output_all(const std::string& bytecodePath, | |
*/ | ||
void prove_tube(const std::string& output_path) | ||
{ | ||
using ClientIVC = stdlib::recursion::honk::ClientIVCRecursiveVerifier; | ||
using StackHonkVK = typename MegaFlavor::VerificationKey; | ||
using ECCVMVk = ECCVMFlavor::VerificationKey; | ||
using TranslatorVk = TranslatorFlavor::VerificationKey; | ||
using GoblinVerifierInput = ClientIVC::GoblinVerifierInput; | ||
using VerifierInput = ClientIVC::VerifierInput; | ||
using namespace stdlib::recursion::honk; | ||
|
||
using GoblinVerifierInput = ClientIVCRecursiveVerifier::GoblinVerifierInput; | ||
using VerifierInput = ClientIVCRecursiveVerifier::VerifierInput; | ||
using Builder = UltraCircuitBuilder; | ||
using GrumpkinVk = bb::VerifierCommitmentKey<curve::Grumpkin>; | ||
|
||
std::string vkPath = output_path + "/mega_vk"; // the vk of the last circuit in the stack | ||
std::string vkPath = output_path + "/client_ivc_vk"; // the vk of the last circuit in the stack | ||
std::string proofPath = output_path + "/client_ivc_proof"; | ||
std::string translatorVkPath = output_path + "/translator_vk"; | ||
std::string eccVkPath = output_path + "/ecc_vk"; | ||
|
||
// Note: this could be decreased once we optimise the size of the ClientIVC recursiveve rifier | ||
init_bn254_crs(1 << 25); | ||
init_grumpkin_crs(1 << 18); | ||
|
||
// Read the proof and verification data from given files | ||
auto proof = from_buffer<ClientIVC::Proof>(read_file(proofPath)); | ||
std::shared_ptr<StackHonkVK> mega_vk = std::make_shared<StackHonkVK>(from_buffer<StackHonkVK>(read_file(vkPath))); | ||
std::shared_ptr<TranslatorVk> translator_vk = | ||
std::make_shared<TranslatorVk>(from_buffer<TranslatorVk>(read_file(translatorVkPath))); | ||
std::shared_ptr<ECCVMVk> eccvm_vk = std::make_shared<ECCVMVk>(from_buffer<ECCVMVk>(read_file(eccVkPath))); | ||
auto vk = from_buffer<ClientIVC::VerificationKey>(read_file(vkPath)); | ||
|
||
// We don't serialise and deserialise the Grumkin SRS so initialise with circuit_size + 1 to be able to recursively | ||
// IPA. The + 1 is to satisfy IPA verification key requirements. | ||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1025) | ||
eccvm_vk->pcs_verification_key = std::make_shared<GrumpkinVk>(eccvm_vk->circuit_size + 1); | ||
vk.eccvm->pcs_verification_key = std::make_shared<GrumpkinVk>(vk.eccvm->circuit_size + 1); | ||
|
||
GoblinVerifierInput goblin_verifier_input{ eccvm_vk, translator_vk }; | ||
VerifierInput input{ mega_vk, goblin_verifier_input }; | ||
GoblinVerifierInput goblin_verifier_input{ vk.eccvm, vk.translator }; | ||
VerifierInput input{ vk.mega, goblin_verifier_input }; | ||
auto builder = std::make_shared<Builder>(); | ||
|
||
// Preserve the public inputs that should be passed to the base rollup by making them public inputs to the tube | ||
|
@@ -588,9 +567,9 @@ void prove_tube(const std::string& output_path) | |
auto offset = bb::HONK_PROOF_PUBLIC_INPUT_OFFSET; | ||
builder->add_public_variable(proof.mega_proof[i + offset]); | ||
} | ||
ClientIVC verifier{ builder, input }; | ||
ClientIVCRecursiveVerifier verifier{ builder, input }; | ||
|
||
ClientIVC::Output client_ivc_rec_verifier_output = verifier.verify(proof); | ||
ClientIVCRecursiveVerifier::Output client_ivc_rec_verifier_output = verifier.verify(proof); | ||
|
||
PairingPointAccumulatorIndices current_aggregation_object = | ||
stdlib::recursion::init_default_agg_obj_indices<Builder>(*builder); | ||
|
@@ -1468,12 +1447,10 @@ int main(int argc, char* argv[]) | |
} | ||
if (command == "verify_client_ivc") { | ||
std::filesystem::path output_dir = get_option(args, "-o", "./target"); | ||
std::filesystem::path client_ivc_proof_path = output_dir / "client_ivc_proof"; | ||
std::filesystem::path mega_vk_path = output_dir / "mega_vk"; | ||
std::filesystem::path eccvm_vk_path = output_dir / "ecc_vk"; | ||
std::filesystem::path translator_vk_path = output_dir / "translator_vk"; | ||
std::filesystem::path proof_path = output_dir / "client_ivc_proof"; | ||
std::filesystem::path vk_path = output_dir / "client_ivc_vk"; | ||
|
||
return verify_client_ivc(client_ivc_proof_path, mega_vk_path, eccvm_vk_path, translator_vk_path) ? 0 : 1; | ||
return verify_client_ivc(proof_path, vk_path) ? 0 : 1; | ||
} | ||
if (command == "fold_and_verify_program") { | ||
return foldAndVerifyProgram(bytecode_path, witness_path) ? 0 : 1; | ||
|
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
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.
the comment is stale
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.
Made the change in my API PR that builds off this one