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(acir)!: Move is_recursive flag to be part of the circuit definition #4221

Merged
merged 34 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
993cc52
move recursive flag onto the circuit itself rather than having it be …
vezenovm Jan 25, 2024
51709d8
missed bberg files
vezenovm Jan 25, 2024
a746985
remove is_recursive flag and add recursive flag to AcirComposer
vezenovm Jan 25, 2024
192beeb
use throw_or_abort
vezenovm Jan 25, 2024
a3a7800
remove is_recursive flag
vezenovm Jan 25, 2024
bc3843f
update dsl bberg tests to use new AcirFormat
vezenovm Jan 25, 2024
3fd6edc
uncomment serde_reflection test
vezenovm Jan 25, 2024
18532f1
Merge branch 'master' into mv/is-recursive-on-circuit
vezenovm Jan 25, 2024
4c074be
make a separate test for recursive assert_statement
vezenovm Jan 25, 2024
018f25f
update noir js to not distinguish between intermediate and final proofs
vezenovm Jan 25, 2024
73975d1
update comment
vezenovm Jan 25, 2024
3c67a55
bb js foramt
vezenovm Jan 25, 2024
545e6f0
missed recursive flag in acir format test
vezenovm Jan 25, 2024
b37e972
remove unused flags
vezenovm Jan 25, 2024
2eba28f
browser-test-app in acir_tests
vezenovm Jan 25, 2024
0b5931c
move is_recursive_circuit to vkey
vezenovm Jan 26, 2024
c9d1629
remove old comment
vezenovm Jan 26, 2024
847fa25
bring back test comment
vezenovm Jan 26, 2024
91b2a16
remove old recursive_ field on acir composer
vezenovm Jan 26, 2024
d2a7e98
cleanup info
vezenovm Jan 26, 2024
2cbeb9c
merge conflicts
vezenovm Jan 29, 2024
3d4ff84
Merge branch 'master' into mv/is-recursive-on-circuit
vezenovm Jan 29, 2024
4a99457
update dep for noir_js_backend_barretenberg
vezenovm Jan 29, 2024
87459cf
docs updates after bootstrapping
vezenovm Jan 29, 2024
07436ed
move back to 0.19.0
vezenovm Jan 29, 2024
a9b123c
resolve merge conflicts w/ master
vezenovm Jan 30, 2024
a706c47
Update barretenberg/cpp/src/barretenberg/proof_system/circuit_builder…
vezenovm Jan 30, 2024
c2abde7
remove floating false on GoblinUltraCircuitBuilder_
vezenovm Jan 30, 2024
64375f4
slight format update
vezenovm Jan 30, 2024
bce2607
merge conflcits w/ master
vezenovm Jan 31, 2024
6a70ef0
don't commit codegen'd docs
vezenovm Jan 31, 2024
4266015
resolve merge conflicts w/ master
vezenovm Feb 1, 2024
2a1b16b
regenerate bindings
kevaundray Feb 1, 2024
11e7571
Empty-Commit
vezenovm Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions barretenberg/acir_tests/browser-test-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ async function runTest(
acirComposer,
bytecode,
witness,
true
);
debug(`verifying...`);
const verified = await api.acirVerifyProof(acirComposer, proof, true);
const verified = await api.acirVerifyProof(acirComposer, proof);
debug(`verified: ${verified}`);

await api.destroy();
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/gen_inner_proof_inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export BRANCH

./clone_test_vectors.sh

cd acir_tests/assert_statement
cd acir_tests/assert_statement_recursive

PROOF_DIR=$PWD/proofs
PROOF_PATH=$PROOF_DIR/$PROOF_NAME
Expand Down
30 changes: 12 additions & 18 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path)
* @return true if the proof is valid
* @return false if the proof is invalid
*/
bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessPath, bool recursive)
bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto witness = get_witness(witnessPath);
Expand All @@ -109,14 +109,14 @@ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessP
write_benchmark("subgroup_size", acir_composer.get_dyadic_circuit_size(), "acir_test", current_dir);

Timer proof_timer;
auto proof = acir_composer.create_proof(recursive);
auto proof = acir_composer.create_proof();
write_benchmark("proof_construction_time", proof_timer.milliseconds(), "acir_test", current_dir);

Timer vk_timer;
acir_composer.init_verification_key();
write_benchmark("vk_construction_time", vk_timer.milliseconds(), "acir_test", current_dir);

auto verified = acir_composer.verify_proof(proof, recursive);
auto verified = acir_composer.verify_proof(proof);

vinfo("verified: ", verified);
return verified;
Expand Down Expand Up @@ -172,9 +172,7 @@ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::strin
* @return true if the proof is valid
* @return false if the proof is invalid
*/
bool proveAndVerifyGoblin(const std::string& bytecodePath,
const std::string& witnessPath,
[[maybe_unused]] bool recursive)
bool proveAndVerifyGoblin(const std::string& bytecodePath, const std::string& witnessPath)
{
// Populate the acir constraint system and witness from gzipped data
auto constraint_system = get_constraint_system(bytecodePath);
Expand Down Expand Up @@ -212,10 +210,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath,
* @param recursive Whether to use recursive proof generation of non-recursive
* @param outputPath Path to write the proof to
*/
void prove(const std::string& bytecodePath,
const std::string& witnessPath,
bool recursive,
const std::string& outputPath)
void prove(const std::string& bytecodePath, const std::string& witnessPath, const std::string& outputPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto witness = get_witness(witnessPath);
Expand All @@ -224,7 +219,7 @@ void prove(const std::string& bytecodePath,
acir_composer.create_circuit(constraint_system, witness);
init_bn254_crs(acir_composer.get_dyadic_circuit_size());
acir_composer.init_proving_key();
auto proof = acir_composer.create_proof(recursive);
auto proof = acir_composer.create_proof();

if (outputPath == "-") {
writeRawBytesToStdout(proof);
Expand Down Expand Up @@ -270,12 +265,12 @@ void gateCount(const std::string& bytecodePath)
* @return true If the proof is valid
* @return false If the proof is invalid
*/
bool verify(const std::string& proof_path, bool recursive, const std::string& vk_path)
bool verify(const std::string& proof_path, const std::string& vk_path)
{
auto acir_composer = verifier_init();
auto vk_data = from_buffer<plonk::verification_key_data>(read_file(vk_path));
acir_composer.load_verification_key(std::move(vk_data));
auto verified = acir_composer.verify_proof(read_file(proof_path), recursive);
auto verified = acir_composer.verify_proof(read_file(proof_path));

vinfo("verified: ", verified);
return verified;
Expand Down Expand Up @@ -491,7 +486,6 @@ int main(int argc, char* argv[])
std::string vk_path = get_option(args, "-k", "./target/vk");
std::string pk_path = get_option(args, "-r", "./target/pk");
CRS_PATH = get_option(args, "-c", CRS_PATH);
bool recursive = flag_present(args, "-r") || flag_present(args, "--recursive");

// Skip CRS initialization for any command which doesn't require the CRS.
if (command == "--version") {
Expand All @@ -504,21 +498,21 @@ int main(int argc, char* argv[])
return 0;
}
if (command == "prove_and_verify") {
return proveAndVerify(bytecode_path, witness_path, recursive) ? 0 : 1;
return proveAndVerify(bytecode_path, witness_path) ? 0 : 1;
}
if (command == "accumulate_and_verify_goblin") {
return accumulateAndVerifyGoblin(bytecode_path, witness_path) ? 0 : 1;
}
if (command == "prove_and_verify_goblin") {
return proveAndVerifyGoblin(bytecode_path, witness_path, recursive) ? 0 : 1;
return proveAndVerifyGoblin(bytecode_path, witness_path) ? 0 : 1;
}
if (command == "prove") {
std::string output_path = get_option(args, "-o", "./proofs/proof");
prove(bytecode_path, witness_path, recursive, output_path);
prove(bytecode_path, witness_path, output_path);
} else if (command == "gates") {
gateCount(bytecode_path);
} else if (command == "verify") {
return verify(proof_path, recursive, vk_path) ? 0 : 1;
return verify(proof_path, vk_path) ? 0 : 1;
} else if (command == "contract") {
std::string output_path = get_option(args, "-o", "./target/contract.sol");
contract(output_path, vk_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ void build_constraints(Builder& builder, AcirFormat const& constraint_system, bo
template <typename Builder>
Builder create_circuit(const AcirFormat& constraint_system, size_t size_hint, WitnessVector const& witness)
{
Builder builder{ size_hint, witness, constraint_system.public_inputs, constraint_system.varnum };
Builder builder{
size_hint, witness, constraint_system.public_inputs, constraint_system.varnum, constraint_system.recursive
};

bool has_valid_witness_assignments = !witness.empty();
build_constraints(builder, constraint_system, has_valid_witness_assignments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace acir_format {
struct AcirFormat {
// The number of witnesses in the circuit
uint32_t varnum;
// Specifies whether a prover that produces SNARK recursion friendly proofs should be used.
// The proof produced when this flag is true should be friendly for recursive verification inside
// of another SNARK. For example, a recursive friendly proof may use Blake3Pedersen for
// hashing in its transcript, while we still want a prove that uses Keccak for its transcript in order
// to be able to verify SNARKs on Ethereum.
bool recursive;

std::vector<uint32_t> public_inputs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs)

AcirFormat constraint_system{
.varnum = 4,
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down Expand Up @@ -141,6 +142,7 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit)
// EXPR [ (-1, _6) 1 ]

AcirFormat constraint_system{ .varnum = 6,
.recursive = false,
.public_inputs = { 1 },
.logic_constraints = { logic_constraint },
.range_constraints = { range_a, range_b },
Expand Down Expand Up @@ -205,6 +207,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass)
.signature = signature,
};
AcirFormat constraint_system{ .varnum = 81,
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = range_constraints,
Expand Down Expand Up @@ -297,6 +300,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange)
};
AcirFormat constraint_system{
.varnum = 81,
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = range_constraints,
Expand Down Expand Up @@ -408,6 +412,7 @@ TEST_F(AcirFormatTests, TestVarKeccak)

AcirFormat constraint_system{
.varnum = 36,
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = { range_a, range_b, range_c, range_d },
Expand Down Expand Up @@ -451,6 +456,7 @@ TEST_F(AcirFormatTests, TestKeccakPermutation)
};

AcirFormat constraint_system{ .varnum = 51,
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
AcirFormat af;
// `varnum` is the true number of variables, thus we add one to the index which starts at zero
af.varnum = circuit.current_witness_index + 1;
af.recursive = circuit.recursive;
af.public_inputs = join({ map(circuit.public_parameters.value, [](auto e) { return e.value; }),
map(circuit.return_values.value, [](auto e) { return e.value; }) });
std::map<uint32_t, BlockConstraint> block_id_to_block_constraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ TEST_F(BigIntTests, TestBigIntConstraintDummy)

AcirFormat constraint_system{
.varnum = 4,
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint)
size_t num_variables = generate_block_constraint(block, witness_values);
AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ TEST_F(EcOperations, TestECOperations)

AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables + 1),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed)
size_t num_variables = generate_ecdsa_constraint(ecdsa_k1_constraint, witness_values);
AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down Expand Up @@ -134,6 +135,7 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier)
size_t num_variables = generate_ecdsa_constraint(ecdsa_k1_constraint, witness_values);
AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down Expand Up @@ -174,6 +176,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail)

AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ TEST(ECDSASecp256r1, test_hardcoded)

AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down Expand Up @@ -170,6 +171,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed)
size_t num_variables = generate_ecdsa_constraint(ecdsa_r1_constraint, witness_values);
AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down Expand Up @@ -214,6 +216,7 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier)
size_t num_variables = generate_ecdsa_constraint(ecdsa_r1_constraint, witness_values);
AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down Expand Up @@ -253,6 +256,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail)

AcirFormat constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Builder create_inner_circuit()
};

AcirFormat constraint_system{ .varnum = 6,
.recursive = true,
.public_inputs = { 1, 2 },
.logic_constraints = { logic_constraint },
.range_constraints = { range_a, range_b },
Expand Down Expand Up @@ -235,6 +236,7 @@ Builder create_outer_circuit(std::vector<Builder>& inner_circuits)
}

AcirFormat constraint_system{ .varnum = static_cast<uint32_t>(witness.size()),
.recursive = false,
.public_inputs = {},
.logic_constraints = {},
.range_constraints = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ struct Circuit {
PublicInputs public_parameters;
PublicInputs return_values;
std::vector<std::tuple<OpcodeLocation, std::string>> assert_messages;
bool recursive;

friend bool operator==(const Circuit&, const Circuit&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -5856,6 +5857,9 @@ inline bool operator==(const Circuit& lhs, const Circuit& rhs)
if (!(lhs.assert_messages == rhs.assert_messages)) {
return false;
}
if (!(lhs.recursive == rhs.recursive)) {
return false;
}
return true;
}

Expand Down Expand Up @@ -5889,6 +5893,7 @@ void serde::Serializable<Circuit::Circuit>::serialize(const Circuit::Circuit& ob
serde::Serializable<decltype(obj.public_parameters)>::serialize(obj.public_parameters, serializer);
serde::Serializable<decltype(obj.return_values)>::serialize(obj.return_values, serializer);
serde::Serializable<decltype(obj.assert_messages)>::serialize(obj.assert_messages, serializer);
serde::Serializable<decltype(obj.recursive)>::serialize(obj.recursive, serializer);
serializer.decrease_container_depth();
}

Expand All @@ -5904,6 +5909,7 @@ Circuit::Circuit serde::Deserializable<Circuit::Circuit>::deserialize(Deserializ
obj.public_parameters = serde::Deserializable<decltype(obj.public_parameters)>::deserialize(deserializer);
obj.return_values = serde::Deserializable<decltype(obj.return_values)>::deserialize(deserializer);
obj.assert_messages = serde::Deserializable<decltype(obj.assert_messages)>::deserialize(deserializer);
obj.recursive = serde::Deserializable<decltype(obj.recursive)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}
Expand Down
Loading
Loading