Skip to content
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

chore: bb contract command now returns the templated contract along with the verification key #2021

Closed
wants to merge 8 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "barretenberg/dsl/acir_format/recursion_constraint.hpp"
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
#include "barretenberg/plonk/proof_system/verification_key/flat_ultra_verification_library/ultra_verifier_templated.h"
#include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "barretenberg/srs/factories/crs_factory.hpp"
Expand Down Expand Up @@ -141,7 +142,7 @@ std::string AcirComposer::get_solidity_verifier()
{
std::ostringstream stream;
output_vk_sol(stream, verification_key_, "UltraVerificationKey");
return stream.str();
return stream.str() + ultra_verifier_template;
}

/**
Expand Down
1 change: 0 additions & 1 deletion circuits/cpp/barretenberg

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Why is this here?

kevaundray marked this conversation as resolved.
Show resolved Hide resolved
For producing a verifier library that is able to verify a plonk proof, we want all data structures to be in one file instead of distributed over multiple files. This means that when one asks for an plonk verifier proof, we just need to paste in the verifier key and send the whole object as a string.

## Why is it only UltraPlonk?

This is currently only being used by the bb binary which exposes the ultra plonk proving system and so we only need to do this for the ultra plonk solidity library.

## Whats with the python script?

When the bb binary is produced, we want to embed the templated contract in the binary, so that we can concatenate it with the verification key. To do this, we need to embed the templated contract into the binary which requires either xxd or the python script which will escape the necessary characters. xxd was not chosen because it converts everything to bytes and is not remotely legible anymore

## Whats the final solution?

We want to ship the binary with a resource folder, that then references the `contract.sol` file and any other resources needed by the binary that we do not want to embed.

## Using the Python script

```
python3 sol_to_cpp_embed.py ultra_verifier_template_contract.sol > ultra
_verifier_templated.h
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys

if len(sys.argv) != 2:
print("Usage: python sol_to_cpp_embed.py <filename>")
sys.exit(1)

filename = sys.argv[1]

with open(filename, 'r') as file:
content = file.read()

# Escape special characters
escaped_content = content.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n")

print(f"static const char* ultra_verifier_template = \"{escaped_content}\";")
Loading