Skip to content

Commit

Permalink
updates based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Jun 15, 2023
1 parent 562e6c8 commit a6a1f17
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 37 deletions.
57 changes: 33 additions & 24 deletions cpp/src/barretenberg/benchmark/honk_bench/benchmark_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,31 @@ template <typename Composer> void generate_ecdsa_verification_test_circuit(Compo
std::string message_string = "Instructions unclear, ask again later.";

crypto::ecdsa::key_pair<fr, g1> account;
account.private_key = curve::fr::random_element();
account.public_key = curve::g1::one * account.private_key;
for (size_t i = 0; i < num_iterations; i++) {
// Generate unique signature for each iteration
account.private_key = curve::fr::random_element();
account.public_key = curve::g1::one * account.private_key;

crypto::ecdsa::signature signature =
crypto::ecdsa::construct_signature<Sha256Hasher, fq, fr, g1>(message_string, account);
crypto::ecdsa::signature signature =
crypto::ecdsa::construct_signature<Sha256Hasher, fq, fr, g1>(message_string, account);

bool first_result =
crypto::ecdsa::verify_signature<Sha256Hasher, fq, fr, g1>(message_string, account.public_key, signature);
bool first_result =
crypto::ecdsa::verify_signature<Sha256Hasher, fq, fr, g1>(message_string, account.public_key, signature);

std::vector<uint8_t> rr(signature.r.begin(), signature.r.end());
std::vector<uint8_t> ss(signature.s.begin(), signature.s.end());
uint8_t vv = signature.v;
std::vector<uint8_t> rr(signature.r.begin(), signature.r.end());
std::vector<uint8_t> ss(signature.s.begin(), signature.s.end());
uint8_t vv = signature.v;

typename curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&composer, account.public_key);
typename curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&composer, account.public_key);

proof_system::plonk::stdlib::ecdsa::signature<Composer> sig{ typename curve::byte_array_ct(&composer, rr),
typename curve::byte_array_ct(&composer, ss),
proof_system::plonk::stdlib::uint8<Composer>(&composer,
vv) };
proof_system::plonk::stdlib::ecdsa::signature<Composer> sig{ typename curve::byte_array_ct(&composer, rr),
typename curve::byte_array_ct(&composer, ss),
proof_system::plonk::stdlib::uint8<Composer>(
&composer, vv) };

typename curve::byte_array_ct message(&composer, message_string);
typename curve::byte_array_ct message(&composer, message_string);

for (size_t i = 0; i < num_iterations; i++) {
// Verify ecdsa signature
proof_system::plonk::stdlib::ecdsa::verify_signature<Composer,
curve,
typename curve::fq_ct,
Expand All @@ -141,7 +143,6 @@ template <typename Composer> void generate_ecdsa_verification_test_circuit(Compo
*
* @param composer
* @param num_iterations
* @todo (luke): should we consider deeper tree? non-zero leaf values? variable index?
*/
template <typename Composer> void generate_merkle_membership_test_circuit(Composer& composer, size_t num_iterations)
{
Expand All @@ -153,15 +154,23 @@ template <typename Composer> void generate_merkle_membership_test_circuit(Compos
using MerkleTree_ct = merkle_tree::MerkleTree<MemStore>;

MemStore store;
auto db = MerkleTree_ct(store, 3);

// Check that the leaf at index 0 has value 0.
auto zero = field_ct(witness_ct(&composer, fr::zero())).decompose_into_bits();
field_ct root = witness_ct(&composer, db.root());
const size_t tree_depth = 7;
auto merkle_tree = MerkleTree_ct(store, tree_depth);

for (size_t i = 0; i < num_iterations; i++) {
merkle_tree::check_membership(
root, merkle_tree::create_witness_hash_path(composer, db.get_hash_path(0)), field_ct(0), zero);
// For each iteration update and check the membership of a different value
size_t idx = i;
size_t value = i * 2;
merkle_tree.update_element(idx, value);

field_ct root_ct = witness_ct(&composer, merkle_tree.root());
auto idx_ct = field_ct(witness_ct(&composer, fr(idx))).decompose_into_bits();
auto value_ct = field_ct(value);

merkle_tree::check_membership(root_ct,
merkle_tree::create_witness_hash_path(composer, merkle_tree.get_hash_path(idx)),
field_ct(value),
idx_ct);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools"

# Install requirements (numpy + scipy) for comparison script if necessary.
# Note: By default, installation will occur in $HOME/.local/bin.
pip3 install -r $BUILD_DIR/_deps/benchmark-src/requirements.txt
pip3 install --user -r $BUILD_DIR/_deps/benchmark-src/requirements.txt

# Create temporary directory for benchmark results (json)
cd $BASE_DIR
mkdir $BENCH_RESULTS_DIR

# Build and run bench in current branch
echo -e "\nConfiguring and building $BENCH_TARGET in current feature branch..\n"
rm -rf $BUILD_DIR
cmake --preset bench > /dev/null && cmake --build --preset bench --target $BENCH_TARGET
cd build-bench
BRANCH_RESULTS="$BENCH_RESULTS_DIR/results_branch.json"
echo -e "\nRunning $BENCH_TARGET in feature branch.."
bin/$BENCH_TARGET --benchmark_format=json > $BRANCH_RESULTS

# Checkout baseline branch, run benchmarks, save results in json format
echo -e "\nConfiguring and building $BENCH_TARGET in $BASELINE_BRANCH branch..\n"
git checkout master > /dev/null
Expand All @@ -33,19 +42,12 @@ BASELINE_RESULTS="$BENCH_RESULTS_DIR/results_baseline.json"
echo -e "\nRunning $BENCH_TARGET in master.."
bin/$BENCH_TARGET --benchmark_format=json > $BASELINE_RESULTS

# Checkout working branch (-), run benchmarks, save results in json format
echo -e "\nConfiguring and building $BENCH_TARGET in current feature branch..\n"
git checkout -
rm -rf $BUILD_DIR
cmake --preset bench > /dev/null && cmake --build --preset bench --target $BENCH_TARGET
cd build-bench
BRANCH_RESULTS="$BENCH_RESULTS_DIR/results_branch.json"
echo -e "\nRunning $BENCH_TARGET in feature branch.."
bin/$BENCH_TARGET --benchmark_format=json > $BRANCH_RESULTS

# Call compare.py on the results (json) to get high level statistics.
# See docs at https://github.com/google/benchmark/blob/main/docs/tools.md for more details.
$BENCH_TOOLS_DIR/compare.py benchmarks $BASELINE_RESULTS $BRANCH_RESULTS

# Return to branch from which the script was called
git checkout -

# Delete the temporary results directory and its contents
rm -r $BENCH_RESULTS_DIR
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools"

# Install requirements (numpy + scipy) for comparison script if necessary.
# Note: By default, installation will occur in $HOME/.local/bin.
pip3 install -r $BUILD_DIR/_deps/benchmark-src/requirements.txt
pip3 install --user -r $BUILD_DIR/_deps/benchmark-src/requirements.txt

# Create temporary directory for honk_bench results (json)
cd $BASE_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools"

# Install requirements (numpy + scipy) for comparison script if necessary.
# Note: By default, installation will occur in $HOME/.local/bin.
pip3 install -r $BUILD_DIR/_deps/benchmark-src/requirements.txt
pip3 install --user -r $BUILD_DIR/_deps/benchmark-src/requirements.txt

# Create temporary directory for honk_bench results (json)
cd $BASE_DIR
Expand Down

0 comments on commit a6a1f17

Please # to comment.