Skip to content

Commit 61b6bdf

Browse files
authored
feat: merge-train/barretenberg (#22300)
BEGIN_COMMIT_OVERRIDE chore: upgrade uintx assert to run in release (#22289) chore: Fix log statement in ECDSA test (#22285) fix: avoid oob access in RAM / ROM and enable soft-fail (#22301) fix: restore test execution in ci-barretenberg CI modes (#22303) fix: minor fixes pt. 5 (#22306) chore: comment about standard behavior for de bruijn (#22310) fix: null socket on bb process exit/error in native_socket.ts (#22309) END_COMMIT_OVERRIDE
2 parents 30c2854 + 29f4aca commit 61b6bdf

19 files changed

Lines changed: 193 additions & 18 deletions

File tree

.github/ci3_labels_to_env.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ function main {
5757
fi
5858
fi
5959
fi
60+
elif has_label "ci-skip"; then
61+
echo "WARNING: Skipping CI due to the ci-skipok label! Make sure this is intended!" >&2
62+
ci_mode="skip"
6063
elif has_label "ci-release-pr"; then
6164
ci_mode="release-pr"
6265
elif has_label "ci-full"; then
@@ -73,9 +76,6 @@ function main {
7376
ci_mode="barretenberg"
7477
elif [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then
7578
ci_mode="release"
76-
elif has_label "ci-skip"; then
77-
echo "WARNING: Skipping CI due to the ci-skipok label! Make sure this is intended!" >&2
78-
ci_mode="skip"
7979
else
8080
ci_mode="fast"
8181
fi

barretenberg/cpp/src/barretenberg/bbapi/bbapi.test.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "barretenberg/bbapi/bbapi.hpp"
22
#include "barretenberg/api/file_io.hpp"
33
#include "barretenberg/bbapi/bbapi_shared.hpp"
4+
#include "barretenberg/chonk/private_execution_steps.hpp"
45
#include "barretenberg/common/serialize.hpp"
56
#include "barretenberg/common/utils.hpp"
67
#include "barretenberg/serialize/test_helper.hpp"
@@ -113,3 +114,73 @@ TEST(BBApiInputValidation, VkWithCorrectSizeAccepted)
113114
std::vector<uint8_t> good_vk(expected_size, 0);
114115
EXPECT_NO_THROW(bbapi::validate_vk_size<VK>(good_vk));
115116
}
117+
118+
// Helper: pack a vector of PrivateExecutionStepRaw into a byte buffer via msgpack.
119+
namespace {
120+
std::vector<uint8_t> pack_steps(const std::vector<PrivateExecutionStepRaw>& steps)
121+
{
122+
std::stringstream ss;
123+
msgpack::pack(ss, steps);
124+
const std::string s = ss.str();
125+
return { s.begin(), s.end() };
126+
}
127+
} // namespace
128+
129+
TEST(BBApiInputValidation, MsgpackParseUncompressedAcceptsCleanInput)
130+
{
131+
PrivateExecutionStepRaw step{
132+
.bytecode = { 0xCA, 0xFE }, .witness = { 0xBE, 0xEF }, .vk = {}, .function_name = "test_fn"
133+
};
134+
135+
auto buf = pack_steps({ step });
136+
auto result = PrivateExecutionStepRaw::parse_uncompressed(buf);
137+
138+
ASSERT_EQ(result.size(), 1);
139+
EXPECT_EQ(result[0].bytecode, step.bytecode);
140+
EXPECT_EQ(result[0].witness, step.witness);
141+
EXPECT_EQ(result[0].function_name, "test_fn");
142+
}
143+
144+
TEST(BBApiInputValidation, MsgpackParseUncompressedRejectsTrailingData)
145+
{
146+
PrivateExecutionStepRaw step{ .bytecode = {}, .witness = {}, .vk = {}, .function_name = "x" };
147+
148+
auto buf = pack_steps({ step });
149+
buf.push_back(0x00);
150+
151+
EXPECT_THROW(PrivateExecutionStepRaw::parse_uncompressed(buf), std::invalid_argument);
152+
}
153+
154+
TEST(BBApiInputValidation, MsgpackLoadAcceptsCleanFile)
155+
{
156+
PrivateExecutionStepRaw step{ .bytecode = { 1, 2, 3 }, .witness = { 4, 5 }, .vk = {}, .function_name = "file_fn" };
157+
158+
auto buf = pack_steps({ step });
159+
160+
auto tmp = std::filesystem::temp_directory_path() / "bb_test_clean.msgpack";
161+
std::ofstream out(tmp, std::ios::binary);
162+
out.write(reinterpret_cast<const char*>(buf.data()), static_cast<std::streamsize>(buf.size()));
163+
out.close();
164+
165+
auto result = PrivateExecutionStepRaw::load(tmp);
166+
std::filesystem::remove(tmp);
167+
168+
ASSERT_EQ(result.size(), 1);
169+
EXPECT_EQ(result[0].function_name, "file_fn");
170+
}
171+
172+
TEST(BBApiInputValidation, MsgpackLoadRejectsTrailingData)
173+
{
174+
PrivateExecutionStepRaw step{ .bytecode = {}, .witness = {}, .vk = {}, .function_name = "x" };
175+
176+
auto buf = pack_steps({ step });
177+
buf.push_back(0x00);
178+
179+
auto tmp = std::filesystem::temp_directory_path() / "bb_test_tailed.msgpack";
180+
std::ofstream out(tmp, std::ios::binary);
181+
out.write(reinterpret_cast<const char*>(buf.data()), static_cast<std::streamsize>(buf.size()));
182+
out.close();
183+
184+
EXPECT_THROW(PrivateExecutionStepRaw::load(tmp), std::invalid_argument);
185+
std::filesystem::remove(tmp);
186+
}

barretenberg/cpp/src/barretenberg/chonk/private_execution_steps.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ template <typename T> T unpack_from_file(const std::filesystem::path& filename)
8686
T result;
8787
std::string encoded_data(fsize, '\0');
8888
fin.read(encoded_data.data(), static_cast<std::streamsize>(fsize));
89-
msgpack::unpack(encoded_data.data(), fsize).get().convert(result);
89+
std::size_t offset = 0;
90+
msgpack::unpack(encoded_data.data(), fsize, offset).get().convert(result);
91+
if (offset != fsize) {
92+
THROW std::invalid_argument("msgpack input has trailing data (" + std::to_string(fsize - offset) +
93+
" extra bytes)");
94+
}
9095
return result;
9196
}
9297

@@ -121,7 +126,12 @@ std::vector<PrivateExecutionStepRaw> PrivateExecutionStepRaw::parse_uncompressed
121126
{
122127
std::vector<PrivateExecutionStepRaw> raw_steps;
123128
// Read with msgpack
124-
msgpack::unpack(reinterpret_cast<const char*>(buf.data()), buf.size()).get().convert(raw_steps);
129+
std::size_t offset = 0;
130+
msgpack::unpack(reinterpret_cast<const char*>(buf.data()), buf.size(), offset).get().convert(raw_steps);
131+
if (offset != buf.size()) {
132+
THROW std::invalid_argument("msgpack input has trailing data (" + std::to_string(buf.size() - offset) +
133+
" extra bytes)");
134+
}
125135
// Unlike load_and_decompress, we don't need to decompress the bytecode and witness fields
126136
return raw_steps;
127137
}

barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <limits>
1313
namespace bb::numeric {
1414

15+
// De Bruijn MSB. Returns 0 for input 0 (by convention; many callers rely on this).
1516
// from http://supertech.csail.mit.edu/papers/debruijn.pdf
1617
constexpr inline uint32_t get_msb32(const uint32_t in)
1718
{

barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ template <class base_uint>
1313
std::pair<uintx<base_uint>, uintx<base_uint>> uintx<base_uint>::divmod_base(const uintx& b) const
1414

1515
{
16-
BB_ASSERT_DEBUG(b != 0);
16+
BB_ASSERT(b != 0);
1717
if (*this == 0) {
1818
return { uintx(0), uintx(0) };
1919
}

barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ template <typename Fr> class Polynomial {
106106
*/
107107
static Polynomial shiftable(size_t virtual_size)
108108
{
109+
BB_ASSERT_GTE(virtual_size, NUM_ZERO_ROWS, "shiftable virtual_size must be >= NUM_ZERO_ROWS");
109110
return Polynomial(
110111
/*actual size*/ virtual_size - NUM_ZERO_ROWS, virtual_size, /*shiftable offset*/ NUM_ZERO_ROWS);
111112
}
@@ -114,6 +115,7 @@ template <typename Fr> class Polynomial {
114115
*/
115116
static Polynomial shiftable(size_t size, size_t virtual_size)
116117
{
118+
BB_ASSERT_GTE(size, NUM_ZERO_ROWS, "shiftable size must be >= NUM_ZERO_ROWS");
117119
return Polynomial(/*actual size*/ size - NUM_ZERO_ROWS, virtual_size, /*shiftable offset*/ NUM_ZERO_ROWS);
118120
}
119121
// Allow polynomials to be entirely reset/dormant

barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
#include <math.h>
1313
#include <memory.h>
1414
#include <memory>
15+
#include <mutex>
1516

1617
namespace bb::polynomial_arithmetic {
1718

1819
namespace {
1920

2021
template <typename Fr> std::shared_ptr<Fr[]> get_scratch_space(const size_t num_elements)
2122
{
23+
static std::mutex scratch_mutex;
24+
std::lock_guard lock(scratch_mutex);
2225
static std::shared_ptr<Fr[]> working_memory = nullptr;
2326
static size_t current_size = 0;
2427
if (num_elements > current_size) {
@@ -52,6 +55,8 @@ void scale_by_generator(Fr* coeffs,
5255
const Fr& generator_shift,
5356
const size_t generator_size)
5457
{
58+
BB_ASSERT(generator_size % domain.num_threads == 0,
59+
"generator_size must be divisible by num_threads to avoid silently skipping elements");
5560
parallel_for(domain.num_threads, [&](size_t j) {
5661
Fr thread_shift = generator_shift.pow(static_cast<uint64_t>(j * (generator_size / domain.num_threads)));
5762
Fr work_generator = generator_start * thread_shift;

barretenberg/cpp/src/barretenberg/polynomials/row_disabling_polynomial.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ template <typename FF> struct RowDisablingPolynomial {
170170
* @param log_circuit_size
171171
* @return FF
172172
*/
173-
static FF evaluate_at_challenge(std::vector<FF> multivariate_challenge, const size_t log_circuit_size)
173+
static FF evaluate_at_challenge(std::span<const FF> multivariate_challenge, const size_t log_circuit_size)
174174
{
175175
FF evaluation_at_multivariate_challenge{ 1 };
176176

@@ -188,7 +188,7 @@ template <typename FF> struct RowDisablingPolynomial {
188188
* @param padding_indicator_array An array with first log_n entries equal to 1, and the remaining entries are 0.
189189
* @return FF
190190
*/
191-
static FF evaluate_at_challenge(std::span<FF> multivariate_challenge,
191+
static FF evaluate_at_challenge(std::span<const FF> multivariate_challenge,
192192
const std::vector<FF>& padding_indicator_array)
193193
{
194194
FF evaluation_at_multivariate_challenge{ 1 };

barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ template <class Curve> class EcdsaTests : public ::testing::Test {
6363

6464
if (random_signature) {
6565
// Logging in case of random signature
66-
info("The private key used generate this signature is: ", private_key);
66+
info("The private key used generate this signature is: ", account.private_key);
6767
}
6868

6969
return { account, signature };

barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ void field_t<Builder>::evaluate_linear_identity(
11021102
Builder* ctx = validate_context(a.context, b.context, c.context, d.context);
11031103

11041104
if (a.is_constant() && b.is_constant() && c.is_constant() && d.is_constant()) {
1105-
BB_ASSERT_EQ(a.get_value() + b.get_value() + c.get_value() + d.get_value(), 0);
1105+
BB_ASSERT_EQ(a.get_value() + b.get_value() + c.get_value() + d.get_value(), 0, msg);
11061106
return;
11071107
}
11081108

@@ -1136,7 +1136,7 @@ void field_t<Builder>::evaluate_polynomial_identity(
11361136
const field_t& a, const field_t& b, const field_t& c, const field_t& d, const std::string& msg)
11371137
{
11381138
if (a.is_constant() && b.is_constant() && c.is_constant() && d.is_constant()) {
1139-
BB_ASSERT((a.get_value() * b.get_value() + c.get_value() + d.get_value()).is_zero());
1139+
BB_ASSERT((a.get_value() * b.get_value() + c.get_value() + d.get_value()).is_zero(), msg);
11401140
return;
11411141
}
11421142

0 commit comments

Comments
 (0)