Skip to content

Commit a1d2a40

Browse files
authored
feat: merge-train/barretenberg (#17149)
BEGIN_COMMIT_OVERRIDE chore(bb): allow disabling asserts in tests (#17148) chore: expanded bigfield tests (veridise report) (#16802) END_COMMIT_OVERRIDE
2 parents 65107c5 + 2afd00f commit a1d2a40

File tree

11 files changed

+1842
-370
lines changed

11 files changed

+1842
-370
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "barretenberg/common/assert.hpp"
2+
#include "barretenberg/common/throw_or_abort.hpp"
3+
4+
namespace bb {
5+
AssertMode& get_assert_mode()
6+
{
7+
static AssertMode current_mode = AssertMode::ABORT;
8+
return current_mode;
9+
}
10+
11+
void assert_failure(std::string const& err)
12+
{
13+
if (get_assert_mode() == AssertMode::WARN) {
14+
info("NOT FOR PROD - assert as warning: ", err);
15+
return;
16+
}
17+
throw_or_abort(err);
18+
}
19+
} // namespace bb

barretenberg/cpp/src/barretenberg/common/assert.hpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
#pragma once
22

3-
#include "barretenberg/common/throw_or_abort.hpp"
3+
#include <cstdint>
44
#include <sstream>
55

6+
namespace bb {
7+
enum class AssertMode : std::uint8_t { ABORT, WARN };
8+
AssertMode& get_assert_mode();
9+
void assert_failure(std::string const& err);
10+
11+
// NOTE do not use in threaded contexts!
12+
struct AssertGuard {
13+
AssertGuard(AssertMode mode)
14+
: previous_mode(get_assert_mode())
15+
{
16+
get_assert_mode() = mode;
17+
}
18+
~AssertGuard() { get_assert_mode() = (previous_mode); }
19+
AssertMode previous_mode;
20+
};
21+
} // namespace bb
22+
23+
// NOTE do not use in threaded contexts!
24+
#define BB_DISABLE_ASSERTS() bb::AssertGuard __bb_assert_guard(bb::AssertMode::WARN)
25+
626
// NOLINTBEGIN
727
// Compiler should optimize this out in release builds, without triggering unused-variable warnings.
828
#define DONT_EVALUATE(expression) \
@@ -42,7 +62,7 @@
4262
if (!(expression)) { \
4363
info("Assertion failed: (" #expression ")"); \
4464
__VA_OPT__(info("Reason : ", __VA_ARGS__);) \
45-
throw_or_abort(""); \
65+
bb::assert_failure(""); \
4666
} \
4767
} while (0)
4868

@@ -52,7 +72,7 @@
5272
std::ostringstream oss; \
5373
oss << "Assertion failed: (" #expression ")"; \
5474
__VA_OPT__(oss << " | Reason: " << __VA_ARGS__;) \
55-
throw_or_abort(oss.str()); \
75+
bb::assert_failure(oss.str()); \
5676
} \
5777
} while (0)
5878

@@ -66,7 +86,7 @@
6686
oss << " Actual : " << _actual << "\n"; \
6787
oss << " Expected: " << _expected; \
6888
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
69-
throw_or_abort(oss.str()); \
89+
bb::assert_failure(oss.str()); \
7090
} \
7191
} while (0)
7292

@@ -80,7 +100,7 @@
80100
oss << " Actual : " << _actual << "\n"; \
81101
oss << " Not expected: " << _expected; \
82102
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
83-
throw_or_abort(oss.str()); \
103+
bb::assert_failure(oss.str()); \
84104
} \
85105
} while (0)
86106

@@ -94,7 +114,7 @@
94114
oss << " Left : " << _left << "\n"; \
95115
oss << " Right : " << _right; \
96116
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
97-
throw_or_abort(oss.str()); \
117+
bb::assert_failure(oss.str()); \
98118
} \
99119
} while (0)
100120

@@ -108,7 +128,7 @@
108128
oss << " Left : " << _left << "\n"; \
109129
oss << " Right : " << _right; \
110130
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
111-
throw_or_abort(oss.str()); \
131+
bb::assert_failure(oss.str()); \
112132
} \
113133
} while (0)
114134

@@ -122,7 +142,7 @@
122142
oss << " Left : " << _left << "\n"; \
123143
oss << " Right : " << _right; \
124144
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
125-
throw_or_abort(oss.str()); \
145+
bb::assert_failure(oss.str()); \
126146
} \
127147
} while (0)
128148

@@ -136,7 +156,7 @@
136156
oss << " Left : " << _left << "\n"; \
137157
oss << " Right : " << _right; \
138158
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
139-
throw_or_abort(oss.str()); \
159+
bb::assert_failure(oss.str()); \
140160
} \
141161
} while (0)
142162
#endif // __wasm__

barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,9 @@ template <typename Builder, typename T> class bigfield {
939939

940940
static_assert(PROHIBITED_LIMB_BITS < MAXIMUM_LIMB_SIZE_THAT_WOULDNT_OVERFLOW);
941941

942+
// For testing purposes only
943+
friend class bigfield_test_access;
944+
942945
private:
943946
/**
944947
* @brief Get the witness indices of the (normalized) binary basis limbs
@@ -1123,6 +1126,31 @@ template <typename Builder, typename T> class bigfield {
11231126

11241127
}; // namespace stdlib
11251128

1129+
// NOTE: For testing private functions in bigfield
1130+
class bigfield_test_access {
1131+
public:
1132+
template <typename bigfield>
1133+
static void unsafe_evaluate_multiply_add(const bigfield& input_left,
1134+
const bigfield& input_to_mul,
1135+
const std::vector<bigfield>& to_add,
1136+
const bigfield& input_quotient,
1137+
const std::vector<bigfield>& input_remainders)
1138+
{
1139+
bigfield::unsafe_evaluate_multiply_add(input_left, input_to_mul, to_add, input_quotient, input_remainders);
1140+
}
1141+
1142+
template <typename bigfield>
1143+
static void unsafe_evaluate_multiple_multiply_add(const std::vector<bigfield>& input_left,
1144+
const std::vector<bigfield>& input_right,
1145+
const std::vector<bigfield>& to_add,
1146+
const bigfield& input_quotient,
1147+
const std::vector<bigfield>& input_remainders)
1148+
{
1149+
bigfield::unsafe_evaluate_multiple_multiply_add(
1150+
input_left, input_right, to_add, input_quotient, input_remainders);
1151+
}
1152+
};
1153+
11261154
template <typename C, typename T> inline std::ostream& operator<<(std::ostream& os, bigfield<T, C> const& v)
11271155
{
11281156
return os << v.get_value();

0 commit comments

Comments
 (0)