From 7b14928349ebf172808672d0fe57a3d47dc4ff90 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 12:02:53 +0000 Subject: [PATCH 1/7] dummy change to change barretenberg hash --- .../cpp/src/barretenberg/dsl/acir_format/acir_format.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index 528fd947ed3..4ba15ef70d1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -20,10 +20,12 @@ void build_constraints(Builder& builder, bool honk_recursion, bool collect_gates_per_opcode) { + size_t prev_gate_count = 0; + if (collect_gates_per_opcode) { + prev_gate_count = 1; // Dumb change to change the bb hash constraint_system.gates_per_opcode.resize(constraint_system.num_acir_opcodes, 0); } - size_t prev_gate_count = 0; auto compute_gate_diff = [&]() -> size_t { if (!collect_gates_per_opcode) { From 14b658ee0ab3b0ce2c11ee9c4351abbb9a8aa3d5 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 12:17:21 +0000 Subject: [PATCH 2/7] disable test --- .../dsl/acir_format/acir_format.test.cpp | 67 ------------------- 1 file changed, 67 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 6085671fb0a..0fe422a5754 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -563,70 +563,3 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) EXPECT_EQ(verifier.verify_proof(proof), true); } - -TEST_F(AcirFormatTests, TestCollectsGateCounts) -{ - - // Witness 0 + witness 1 = witness 2 - poly_triple first_gate{ - .a = 0, - .b = 1, - .c = 2, - .q_m = 0, - .q_l = 1, - .q_r = 1, - .q_o = -1, - .q_c = 0, - }; - - // Witness 1 = 27 - poly_triple second_gate{ - .a = 1, - .b = 0, - .c = 0, - .q_m = 0, - .q_l = 1, - .q_r = 0, - .q_o = 0, - .q_c = -27, - }; - - AcirFormat constraint_system{ - .varnum = 4, - .recursive = false, - .num_acir_opcodes = 2, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = { first_gate, second_gate }, - .quad_constraints = {}, - .block_constraints = {}, - .original_opcode_indices = create_empty_original_opcode_indices(), - }; - mock_opcode_indices(constraint_system); - WitnessVector witness{ 5, 27, 32 }; - auto builder = - create_circuit(constraint_system, /*size_hint*/ 0, witness, false, std::make_shared(), true); - - EXPECT_EQ(constraint_system.gates_per_opcode, std::vector({ 2, 1 })); -} \ No newline at end of file From 9f9b9a8efe96994b0be2f9d929355f2e5b8bdff1 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 13:01:39 +0000 Subject: [PATCH 3/7] another bb change to get a different hash --- .../cpp/src/barretenberg/dsl/acir_format/acir_format.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index 4ba15ef70d1..a701e669529 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -23,7 +23,7 @@ void build_constraints(Builder& builder, size_t prev_gate_count = 0; if (collect_gates_per_opcode) { - prev_gate_count = 1; // Dumb change to change the bb hash + prev_gate_count = 2; // Dumb change to change the bb hash constraint_system.gates_per_opcode.resize(constraint_system.num_acir_opcodes, 0); } From 6cb2e0366af739fc9a8fdb2c95c89ac78cafc91b Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 13:48:26 +0000 Subject: [PATCH 4/7] bb hash code --- noir-projects/Earthfile | 5 ++++- noir-projects/noir-protocol-circuits/bootstrap.sh | 7 ++++--- .../noir-protocol-circuits/scripts/generate_vk_json.js | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index e7ee3d3eeaa..6f455a441ac 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -26,10 +26,13 @@ build-contracts: SAVE ARTIFACT noir-contracts build-protocol-circuits: + LOCALLY + LET bb_source_hash = $(git ls-tree -r HEAD | grep 'barretenberg/cpp' | awk '{print $3}' | git hash-object --stdin) + FROM +source RUN --secret AWS_ACCESS_KEY_ID --secret AWS_SECRET_ACCESS_KEY mkdir -p ~/.aws && \ bash -c 'echo -e "[default]\naws_access_key_id=$AWS_ACCESS_KEY_ID\naws_secret_access_key=$AWS_SECRET_ACCESS_KEY" > ~/.aws/credentials' - RUN cd noir-protocol-circuits && NARGO=nargo ./bootstrap.sh + RUN cd noir-protocol-circuits && BB_HASH=$bb_source_hash NARGO=nargo ./bootstrap.sh SAVE ARTIFACT noir-protocol-circuits build: diff --git a/noir-projects/noir-protocol-circuits/bootstrap.sh b/noir-projects/noir-protocol-circuits/bootstrap.sh index 5755a31bb16..5d0eab8acd4 100755 --- a/noir-projects/noir-protocol-circuits/bootstrap.sh +++ b/noir-projects/noir-protocol-circuits/bootstrap.sh @@ -20,8 +20,9 @@ node ./generate_variants.js echo "Compiling protocol circuits..." NARGO=${NARGO:-../../noir/noir-repo/target/release/nargo} -$NARGO compile --silence-warnings --use-legacy +BB_HASH=${BB_HASH:-$(cd ../../ && git ls-tree -r HEAD | grep 'barretenberg/cpp' | awk '{print $3}' | git hash-object --stdin)} +echo Using BB hash $BB_HASH mkdir -p "./target/keys" AVAILABLE_MEMORY=0 @@ -43,14 +44,14 @@ if [[ AVAILABLE_MEMORY -lt MIN_PARALLEL_VK_GENERATION_MEMORY ]]; then echo "System does not have enough memory for parallel vk generation, falling back to sequential" for pathname in "./target"/*.json; do - node ./scripts/generate_vk_json.js "$pathname" "./target/keys" + BB_HASH=$BB_HASH node ./scripts/generate_vk_json.js "$pathname" "./target/keys" done else echo "Generating vks in parallel..." for pathname in "./target"/*.json; do - node ./scripts/generate_vk_json.js "$pathname" "./target/keys" & + BB_HASH=$BB_HASH node ./scripts/generate_vk_json.js "$pathname" "./target/keys" & done for job in $(jobs -p); do diff --git a/noir-projects/noir-protocol-circuits/scripts/generate_vk_json.js b/noir-projects/noir-protocol-circuits/scripts/generate_vk_json.js index 85546b60c79..68a60491bfc 100644 --- a/noir-projects/noir-protocol-circuits/scripts/generate_vk_json.js +++ b/noir-projects/noir-protocol-circuits/scripts/generate_vk_json.js @@ -30,6 +30,9 @@ async function getBytecodeHash(artifactPath) { } function getBarretenbergHash() { + if (process.env.BB_HASH) { + return Promise.resolve(process.env.BB_HASH); + } return new Promise((res, rej) => { const hash = crypto.createHash("md5"); From be9d8e1e7ffbe9d0c461c21d5ae622c8d7b17b69 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 15:11:34 +0000 Subject: [PATCH 5/7] oops --- noir-projects/noir-protocol-circuits/bootstrap.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/noir-projects/noir-protocol-circuits/bootstrap.sh b/noir-projects/noir-protocol-circuits/bootstrap.sh index 5d0eab8acd4..155bc7948cf 100755 --- a/noir-projects/noir-protocol-circuits/bootstrap.sh +++ b/noir-projects/noir-protocol-circuits/bootstrap.sh @@ -20,6 +20,7 @@ node ./generate_variants.js echo "Compiling protocol circuits..." NARGO=${NARGO:-../../noir/noir-repo/target/release/nargo} +$NARGO compile --silence-warnings --use-legacy BB_HASH=${BB_HASH:-$(cd ../../ && git ls-tree -r HEAD | grep 'barretenberg/cpp' | awk '{print $3}' | git hash-object --stdin)} echo Using BB hash $BB_HASH From 8dcac0b5714450afa34959e3464988e46b13910e Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 15:27:03 +0000 Subject: [PATCH 6/7] revert dummy changes --- .../dsl/acir_format/acir_format.cpp | 4 +- .../dsl/acir_format/acir_format.test.cpp | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index a701e669529..528fd947ed3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -20,12 +20,10 @@ void build_constraints(Builder& builder, bool honk_recursion, bool collect_gates_per_opcode) { - size_t prev_gate_count = 0; - if (collect_gates_per_opcode) { - prev_gate_count = 2; // Dumb change to change the bb hash constraint_system.gates_per_opcode.resize(constraint_system.num_acir_opcodes, 0); } + size_t prev_gate_count = 0; auto compute_gate_diff = [&]() -> size_t { if (!collect_gates_per_opcode) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 0fe422a5754..6085671fb0a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -563,3 +563,70 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) EXPECT_EQ(verifier.verify_proof(proof), true); } + +TEST_F(AcirFormatTests, TestCollectsGateCounts) +{ + + // Witness 0 + witness 1 = witness 2 + poly_triple first_gate{ + .a = 0, + .b = 1, + .c = 2, + .q_m = 0, + .q_l = 1, + .q_r = 1, + .q_o = -1, + .q_c = 0, + }; + + // Witness 1 = 27 + poly_triple second_gate{ + .a = 1, + .b = 0, + .c = 0, + .q_m = 0, + .q_l = 1, + .q_r = 0, + .q_o = 0, + .q_c = -27, + }; + + AcirFormat constraint_system{ + .varnum = 4, + .recursive = false, + .num_acir_opcodes = 2, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = { first_gate, second_gate }, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); + WitnessVector witness{ 5, 27, 32 }; + auto builder = + create_circuit(constraint_system, /*size_hint*/ 0, witness, false, std::make_shared(), true); + + EXPECT_EQ(constraint_system.gates_per_opcode, std::vector({ 2, 1 })); +} \ No newline at end of file From 225fba578e450984df2c2052bc25055e8332d60c Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 9 Jul 2024 16:03:34 +0000 Subject: [PATCH 7/7] fix hashing --- noir-projects/Earthfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index 6f455a441ac..c5a24bd0a85 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -27,8 +27,7 @@ build-contracts: build-protocol-circuits: LOCALLY - LET bb_source_hash = $(git ls-tree -r HEAD | grep 'barretenberg/cpp' | awk '{print $3}' | git hash-object --stdin) - + LET bb_source_hash = $(cd .. && git ls-tree -r HEAD | grep 'barretenberg/cpp' | awk '{print $3}' | git hash-object --stdin) FROM +source RUN --secret AWS_ACCESS_KEY_ID --secret AWS_SECRET_ACCESS_KEY mkdir -p ~/.aws && \ bash -c 'echo -e "[default]\naws_access_key_id=$AWS_ACCESS_KEY_ID\naws_secret_access_key=$AWS_SECRET_ACCESS_KEY" > ~/.aws/credentials'