From 0a7058cbda228c9baf378d69c906596e204d804f Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 29 Aug 2023 15:41:34 +0100 Subject: [PATCH] fix: Truncate SRS size to the amount of points that we have downloaded (#1862) related to #1861 # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --- .../cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp index 808bb5a0f01..be827610303 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp @@ -62,8 +62,15 @@ inline std::vector get_g1_data(const std::file vinfo("using cached crs at: ", path); auto data = read_file(path / "g1.dat"); auto points = std::vector(num_points); + + auto size_of_points_in_bytes = num_points * 64; + if (data.size() < size_of_points_in_bytes) { + vinfo("data is smaller than expected!", data.size(), size_of_points_in_bytes); + } + size_t actual_buffer_size = std::min(data.size(), size_of_points_in_bytes); + barretenberg::srs::IO::read_affine_elements_from_buffer( - points.data(), (char*)data.data(), num_points * 64); + points.data(), (char*)data.data(), actual_buffer_size); return points; }