Skip to content

Commit 4b3dd11

Browse files
authored
feat: merge-train/barretenberg (#16588)
BEGIN_COMMIT_OVERRIDE fix(bb): debug preset is actually debug (#16577) chore: audit PointTable relation in the ECCVM. (#16592) feat(bb): runtime stack traces in debug mode (#16590) END_COMMIT_OVERRIDE
2 parents 9a983b2 + ce4cd28 commit 4b3dd11

File tree

11 files changed

+106
-81
lines changed

11 files changed

+106
-81
lines changed

barretenberg/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ If you are in a scenario where you have a failing call to check_circuit and wish
326326

327327
Usage instructions:
328328

329-
- On ubuntu (or our mainframe accounts) use `sudo apt-get install libdw-dev libelf-dev libbackward-cpp-dev` to support trace printing
329+
- On ubuntu (or our mainframe accounts) use `sudo apt-get install libdw-dev libelf-dev` to support trace printing
330330
- Use `cmake --preset debug-fast-circuit-check-traces` and `cmake --build --preset debug-fast-circuit-check-traces` to enable the backward-cpp dependency through the CHECK_CIRCUIT_STACKTRACES CMake variable.
331331
- Run any case where you have a failing check_circuit call, you will now have a stack trace illuminating where this constraint was added in code.
332332

barretenberg/cpp/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OF
3030
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)
3131
# Note: Must do 'sudo apt-get install libdw-dev' or equivalent
3232
option(CHECK_CIRCUIT_STACKTRACES "Enable (slow) stack traces for check circuit" OFF)
33+
option(ENABLE_STACKTRACES "Enable stack traces on assertion" OFF)
3334
option(ENABLE_TRACY "Enable low-medium overhead profiling for memory and performance with tracy" OFF)
3435
option(ENABLE_PIC "Builds with position independent code" OFF)
3536
option(SYNTAX_ONLY "only check syntax (-fsyntax-only)" OFF)
@@ -44,7 +45,9 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "a
4445
endif()
4546

4647
if(CHECK_CIRCUIT_STACKTRACES)
47-
add_compile_options(-DCHECK_CIRCUIT_STACKTRACES)
48+
add_compile_options(-DCHECK_CIRCUIT_STACKTRACES -DSTACKTRACES)
49+
elseif(ENABLE_STACKTRACES)
50+
add_compile_options(-DSTACKTRACES)
4851
endif()
4952

5053
if(ENABLE_TRACY OR ENABLE_TRACY_TIME_INSTRUMENTED)

barretenberg/cpp/CMakePresets.json

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@
119119
"inherits": "clang20",
120120
"binaryDir": "build-debug",
121121
"environment": {
122-
"CMAKE_BUILD_TYPE": "Debug",
123122
"CFLAGS": "-gdwarf-4",
124123
"CXXFLAGS": "-gdwarf-4",
125124
"LDFLAGS": "-gdwarf-4"
126125
},
127126
"cacheVariables": {
127+
"CMAKE_BUILD_TYPE": "Debug",
128128
"ENABLE_ASAN": "OFF",
129-
"DISABLE_ASM": "ON"
129+
"DISABLE_ASM": "ON",
130+
"ENABLE_STACKTRACES": "ON"
130131
}
131132
},
132133
{
@@ -163,12 +164,12 @@
163164
"binaryDir": "build-tracy-time-sampled",
164165
"inherits": "clang20",
165166
"environment": {
166-
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
167167
"CFLAGS": "-g -fno-omit-frame-pointer",
168168
"CXXFLAGS": "-g -fno-omit-frame-pointer",
169169
"LDFLAGS": "-g -fno-omit-frame-pointer -rdynamic"
170170
},
171171
"cacheVariables": {
172+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
172173
"ENABLE_TRACY": "ON"
173174
}
174175
},
@@ -190,10 +191,12 @@
190191
"inherits": "debug",
191192
"binaryDir": "build-debug-fast",
192193
"environment": {
193-
"CMAKE_BUILD_TYPE": "Debug",
194194
"CFLAGS": "-O2 -gdwarf",
195195
"CXXFLAGS": "-O2 -gdwarf-4",
196196
"LDFLAGS": "-O2 -gdwarf-4"
197+
},
198+
"cacheVariables": {
199+
"ENABLE_STACKTRACES": "ON"
197200
}
198201
},
199202
{
@@ -207,13 +210,25 @@
207210
}
208211
},
209212
{
210-
"name": "debug-no-avm",
213+
"name": "debug-fast-no-avm",
211214
"displayName": "Optimized debug build with Clang-20 (no AVM)",
212215
"description": "Build with globally installed Clang-20 in debug mode excluding the Aztec VM",
216+
"inherits": "debug-fast",
217+
"binaryDir": "build-debug-fast-no-avm",
218+
"cacheVariables": {
219+
"DISABLE_AZTEC_VM": "ON",
220+
"ENABLE_STACKTRACES": "ON"
221+
}
222+
},
223+
{
224+
"name": "debug-no-avm",
225+
"displayName": "Debug build with Clang-20 (no AVM)",
226+
"description": "Build with globally installed Clang-20 in debug mode excluding the Aztec VM",
213227
"inherits": "debug",
214228
"binaryDir": "build-debug-no-avm",
215229
"cacheVariables": {
216-
"DISABLE_AZTEC_VM": "ON"
230+
"DISABLE_AZTEC_VM": "ON",
231+
"ENABLE_STACKTRACES": "ON"
217232
}
218233
},
219234
{
@@ -235,7 +250,8 @@
235250
"cacheVariables": {
236251
"ENABLE_ASAN": "ON",
237252
"DISABLE_AZTEC_VM": "ON",
238-
"DISABLE_ASM": "ON"
253+
"DISABLE_ASM": "ON",
254+
"ENABLE_STACKTRACES": "OFF"
239255
}
240256
},
241257
{
@@ -244,12 +260,10 @@
244260
"description": "Build with address sanitizer on clang20 with debugging information",
245261
"inherits": "debug",
246262
"binaryDir": "build-asan",
247-
"environment": {
248-
"CMAKE_BUILD_TYPE": "Debug"
249-
},
250263
"cacheVariables": {
251264
"ENABLE_ASAN": "ON",
252-
"DISABLE_ASM": "ON"
265+
"DISABLE_ASM": "ON",
266+
"ENABLE_STACKTRACES": "OFF"
253267
}
254268
},
255269
{
@@ -279,9 +293,7 @@
279293
"binaryDir": "build-fuzzing",
280294
"cacheVariables": {
281295
"FUZZING": "ON",
282-
"DISABLE_AZTEC_VM": "ON"
283-
},
284-
"environment": {
296+
"DISABLE_AZTEC_VM": "ON",
285297
"CMAKE_BUILD_TYPE": "RelWithAssert"
286298
}
287299
},
@@ -294,9 +306,7 @@
294306
"cacheVariables": {
295307
"FUZZING": "ON",
296308
"DISABLE_AZTEC_VM": "ON",
297-
"DISABLE_ASM": "ON"
298-
},
299-
"environment": {
309+
"DISABLE_ASM": "ON",
300310
"CMAKE_BUILD_TYPE": "RelWithAssert"
301311
}
302312
},
@@ -311,9 +321,7 @@
311321
"FUZZING_SHOW_INFORMATION": "ON",
312322
"DISABLE_AZTEC_VM": "ON",
313323
"ENABLE_ASAN": "ON",
314-
"DISABLE_ASM": "ON"
315-
},
316-
"environment": {
324+
"DISABLE_ASM": "ON",
317325
"CMAKE_BUILD_TYPE": "RelWithAssert"
318326
}
319327
},
@@ -326,11 +334,11 @@
326334
"cacheVariables": {
327335
"FUZZING": "ON",
328336
"DISABLE_ASM": "ON",
329-
"DISABLE_AZTEC_VM": "ON"
337+
"DISABLE_AZTEC_VM": "ON",
338+
"CMAKE_BUILD_TYPE": "RelWithAssert"
330339
},
331340
"environment": {
332-
"CXXFLAGS": "-fprofile-instr-generate -fcoverage-mapping",
333-
"CMAKE_BUILD_TYPE": "RelWithAssert"
341+
"CXXFLAGS": "-fprofile-instr-generate -fcoverage-mapping"
334342
}
335343
},
336344
{
@@ -446,10 +454,8 @@
446454
"description": "Build for pthread enabled WASM",
447455
"inherits": "wasm",
448456
"binaryDir": "build-wasm-threads",
449-
"environment": {
450-
"CMAKE_BUILD_TYPE": "Release"
451-
},
452457
"cacheVariables": {
458+
"CMAKE_BUILD_TYPE": "Release",
453459
"MULTITHREADING": "ON"
454460
}
455461
},
@@ -459,10 +465,8 @@
459465
"binaryDir": "build-wasm-threads-dbg",
460466
"description": "Build with wasi-sdk to create debug wasm",
461467
"inherits": "wasm",
462-
"environment": {
463-
"CMAKE_BUILD_TYPE": "Debug"
464-
},
465468
"cacheVariables": {
469+
"CMAKE_BUILD_TYPE": "Debug",
466470
"MULTITHREADING": "ON"
467471
}
468472
},
@@ -517,6 +521,11 @@
517521
"inherits": "default",
518522
"configurePreset": "clang20-no-avm"
519523
},
524+
{
525+
"name": "debug-fast-no-avm",
526+
"inherits": "default",
527+
"configurePreset": "debug-fast-no-avm"
528+
},
520529
{
521530
"name": "debug-no-avm",
522531
"inherits": "default",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if(CHECK_CIRCUIT_STACKTRACES)
1+
if(CHECK_CIRCUIT_STACKTRACES OR ENABLE_STACKTRACES)
22
include(FetchContent)
33

44
# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
@@ -8,4 +8,4 @@ if(CHECK_CIRCUIT_STACKTRACES)
88
SYSTEM # optional, the Backward include directory will be treated as system directory
99
)
1010
FetchContent_MakeAvailable(backward)
11-
endif()
11+
endif()

barretenberg/cpp/cmake/module.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function(barretenberg_module MODULE_NAME)
5757
${TBB_IMPORTED_TARGETS}
5858
)
5959

60-
if(CHECK_CIRCUIT_STACKTRACES)
60+
if(CHECK_CIRCUIT_STACKTRACES OR ENABLE_STACKTRACES)
6161
target_link_libraries(
6262
${MODULE_NAME}_objects
6363
PUBLIC
@@ -108,7 +108,7 @@ function(barretenberg_module MODULE_NAME)
108108
)
109109
list(APPEND exe_targets ${MODULE_NAME}_tests)
110110

111-
if(CHECK_CIRCUIT_STACKTRACES)
111+
if(CHECK_CIRCUIT_STACKTRACES OR ENABLE_STACKTRACES)
112112
target_link_libraries(
113113
${MODULE_NAME}_test_objects
114114
PUBLIC
@@ -236,7 +236,7 @@ function(barretenberg_module MODULE_NAME)
236236
${TRACY_LIBS}
237237
${TBB_IMPORTED_TARGETS}
238238
)
239-
if(CHECK_CIRCUIT_STACKTRACES)
239+
if(CHECK_CIRCUIT_STACKTRACES OR ENABLE_STACKTRACES)
240240
target_link_libraries(
241241
${BENCHMARK_NAME}_bench_objects
242242
PUBLIC

barretenberg/cpp/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ if(WASM)
252252
DEPENDS ${CMAKE_BINARY_DIR}/bin/barretenberg.wasm.gz
253253
)
254254

255-
if(CHECK_CIRCUIT_STACKTRACES)
255+
if(CHECK_CIRCUIT_STACKTRACES OR ENABLE_STACKTRACES)
256256
target_link_libraries(
257257
barretenberg.wasm
258258
PUBLIC

barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (NOT(FUZZING))
2323
bb-cli-lib
2424
tracy_mem
2525
)
26-
if(CHECK_CIRCUIT_STACKTRACES)
26+
if(CHECK_CIRCUIT_STACKTRACES OR ENABLE_STACKTRACES)
2727
target_link_libraries(
2828
bb
2929
PUBLIC

barretenberg/cpp/src/barretenberg/env/throw_or_abort_impl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "barretenberg/common/log.hpp"
22
#include <stdexcept>
3+
#ifdef STACKTRACES
4+
#include <backward.hpp>
5+
#endif
36

47
inline void abort_with_message [[noreturn]] (std::string const& err)
58
{
@@ -10,6 +13,13 @@ inline void abort_with_message [[noreturn]] (std::string const& err)
1013
// Native implementation of throw_or_abort
1114
extern "C" void throw_or_abort_impl [[noreturn]] (const char* err)
1215
{
16+
17+
#ifdef STACKTRACES
18+
// Use backward library to print stack trace
19+
backward::StackTrace trace;
20+
trace.load_here(32);
21+
backward::Printer{}.print(trace);
22+
#endif
1323
#ifndef BB_NO_EXCEPTIONS
1424
throw std::runtime_error(err);
1525
#else

barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation_impl.hpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@ void ECCVMPointTableRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
5757
* In the table, the point associated with `pc = 1` is labelled P.
5858
* the point associated with `pc = 0` is labelled Q.
5959
*
60-
* | precompute_pc | precompute_point_transition | precompute_round | Tx | Ty | Dx | Dy |
61-
* | -------- | ----------------------- | ----------- | ----- | ----- | ---- | ---- |
62-
* | 1 | 0 | 0 |15P.x | 15P.y | 2P.x | 2P.y |
63-
* | 1 | 0 | 1 |13P.x | 13P.y | 2P.x | 2P.y |
64-
* | 1 | 0 | 2 |11P.x | 11P.y | 2P.x | 2P.y |
65-
* | 1 | 0 | 3 | 9P.x | 9P.y | 2P.x | 2P.y |
66-
* | 1 | 0 | 4 | 7P.x | 7P.y | 2P.x | 2P.y |
67-
* | 1 | 0 | 5 | 5P.x | 5P.y | 2P.x | 2P.y |
68-
* | 1 | 0 | 6 | 3P.x | 3P.y | 2P.x | 2P.y |
69-
* | 1 | 1 | 7 | P.x | P.y | 2P.x | 2P.y |
70-
* | 0 | 0 | 0 |15Q.x | 15Q.y | 2Q.x | 2Q.y |
71-
* | 0 | 0 | 1 |13Q.x | 13Q.y | 2Q.x | 2Q.y |
72-
* | 0 | 0 | 2 |11Q.x | 11Q.y | 2Q.x | 2Q.y |
73-
* | 0 | 0 | 3 | 9Q.x | 9Q.y | 2Q.x | 2Q.y |
74-
* | 0 | 0 | 4 | 7Q.x | 7Q.y | 2Q.x | 2Q.y |
75-
* | 0 | 0 | 5 | 5Q.x | 5Q.y | 2Q.x | 2Q.y |
76-
* | 0 | 0 | 6 | 3Q.x | 3Q.y | 2Q.x | 2Q.y |
77-
* | 0 | 1 | 7 | Q.x | Q.y | 2Q.x | 2Q.y |
60+
* | precompute_pc | precompute_point_transition | precompute_round | Tx | Ty | Dx | Dy |
61+
* | ------------- | ---------------------------- | ------------------- | ----- | ----- | ---- | ---- |
62+
* | 1 | 0 | 0 | 15P.x | 15P.y | 2P.x | 2P.y |
63+
* | 1 | 0 | 1 | 13P.x | 13P.y | 2P.x | 2P.y |
64+
* | 1 | 0 | 2 | 11P.x | 11P.y | 2P.x | 2P.y |
65+
* | 1 | 0 | 3 | 9P.x | 9P.y | 2P.x | 2P.y |
66+
* | 1 | 0 | 4 | 7P.x | 7P.y | 2P.x | 2P.y |
67+
* | 1 | 0 | 5 | 5P.x | 5P.y | 2P.x | 2P.y |
68+
* | 1 | 0 | 6 | 3P.x | 3P.y | 2P.x | 2P.y |
69+
* | 1 | 1 | 7 | P.x | P.y | 2P.x | 2P.y |
70+
* | 0 | 0 | 0 | 15Q.x | 15Q.y | 2Q.x | 2Q.y |
71+
* | 0 | 0 | 1 | 13Q.x | 13Q.y | 2Q.x | 2Q.y |
72+
* | 0 | 0 | 2 | 11Q.x | 11Q.y | 2Q.x | 2Q.y |
73+
* | 0 | 0 | 3 | 9Q.x | 9Q.y | 2Q.x | 2Q.y |
74+
* | 0 | 0 | 4 | 7Q.x | 7Q.y | 2Q.x | 2Q.y |
75+
* | 0 | 0 | 5 | 5Q.x | 5Q.y | 2Q.x | 2Q.y |
76+
* | 0 | 0 | 6 | 3Q.x | 3Q.y | 2Q.x | 2Q.y |
77+
* | 0 | 1 | 7 | Q.x | Q.y | 2Q.x | 2Q.y |
7878
*
7979
* We apply the following relations to constrain the above table:
8080
*
@@ -84,9 +84,12 @@ void ECCVMPointTableRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
8484
*
8585
* The relations that constrain `precompute_point_transition` and `precompute_pc` are in `ecc_wnaf_relation.hpp`
8686
*
87-
* When precompute_point_transition = 1, we use a strict lookup protocol in `ecc_set_relation.hpp` to validate (pc,
88-
* Tx, Ty) belong to the set of points present in our transcript columns.
89-
* ("strict" lookup protocol = every item in the table must be read from once, and only once)
87+
* When precompute_point_transition = 1, the next row corresponds to the beginning of the processing of a new point.
88+
* We use a multiset-equality check, `ecc_set_relation.hpp` to validate (pc, Tx, Ty, scalar-multiplier) is the same
89+
* as something derived from the transcript columns. In other words, the multiset equality check allows the tables
90+
* to communicate, and in particular validates that we are populating our PointTable with precomputed values that
91+
* indeed arise from the Transcript columns. (Formerly, we referred to this as a "strict" lookup protocol = every
92+
* item in the table must be read from once, and only once)
9093
*
9194
* For every row, we use a lookup protocol in `ecc_lookup_relation.hpp` to write the following tuples into a lookup
9295
* table:
@@ -102,15 +105,15 @@ void ECCVMPointTableRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
102105
* negative values produces the WNAF slice values that correspond to the multipliers for (Tx, Ty) and (Tx, -Ty):
103106
*
104107
* | Tx | Ty | x = 15 - precompute_round | 2x - 15 | y = precompute_round | 2y - 15 |
105-
* | ----- | ----- | -------------------- | ------- | --------------- | ------- |
106-
* | 15P.x | 15P.y | 15 | 15 | 0 | -15 |
107-
* | 13P.x | 13P.y | 14 | 13 | 1 | -13 |
108-
* | 11P.x | 11P.y | 13 | 11 | 2 | -11 |
109-
* | 9P.x | 9P.y | 12 | 9 | 3 | -9 |
110-
* | 7P.x | 7P.y | 11 | 7 | 4 | -7 |
111-
* | 5P.x | 5P.y | 10 | 5 | 5 | -5 |
112-
* | 3P.x | 3P.y | 9 | 3 | 6 | -3 |
113-
* | P.x | P.y | 8 | 1 | 7 | -1 |
108+
* | ----- | ----- | -------------------- | ------- | --------------- | ------- |
109+
* | 15P.x | 15P.y | 15 | 15 | 0 | -15 |
110+
* | 13P.x | 13P.y | 14 | 13 | 1 | -13 |
111+
* | 11P.x | 11P.y | 13 | 11 | 2 | -11 |
112+
* | 9P.x | 9P.y | 12 | 9 | 3 | -9 |
113+
* | 7P.x | 7P.y | 11 | 7 | 4 | -7 |
114+
* | 5P.x | 5P.y | 10 | 5 | 5 | -5 |
115+
* | 3P.x | 3P.y | 9 | 3 | 6 | -3 |
116+
* | P.x | P.y | 8 | 1 | 7 | -1 |
114117
*/
115118

116119
/**
@@ -161,9 +164,11 @@ void ECCVMPointTableRelationImpl<FF>::accumulate(ContainerOverSubrelations& accu
161164
* (x_3 + x_2 + x_1) * (x_2 - x_1)^2 - (y_2 - y_1)^2 = 0
162165
* (y_3 + y_1) * (x_2 - x_1) + (x_3 - x_1) * (y_2 - y_1) = 0
163166
*
164-
* We don't need to check for incomplete point addition edge case (x_1 == x_2)
165-
* TODO explain why (computing simple point multiples cannot trigger the edge cases, but need to serve a proof of
166-
* this...)
167+
* We don't need to check for incomplete point addition edge case (x_1 == x_2); the only cases this would correspond
168+
* to are y2 == y1 or y2 == -y1. Both of these cases may be ruled out as follows.
169+
* 1. y2 == y1. Then 2P == kP, where k∈{1, ..., 13}, which of course cannot happen because the order r of E(Fₚ)
170+
* is a large prime and P is already assumed to not be the neutral element.
171+
* 2. y2 == -y1. Again, then -2P == kP, k∈{1, ..., 13}, and we get the same contradiction.
167172
*/
168173
const auto& x1 = Tx_shift;
169174
const auto& y1 = Ty_shift;

0 commit comments

Comments
 (0)