Closed HarryR closed 5 years ago
This seems to originate from different build flags being used to compile ethsnarks versus the host program.
For example:
In stub_genkeys
(gdb) ptype pb
type = class libsnark::protoboard<libff::Fp_model<4, (libff::bigint<4> const&)(&libff::alt_bn128_modulus_r)> >
[with FieldT = libff::Fp_model<4, (libff::bigint<4> const&)(&libff::alt_bn128_modulus_r)>] {
private:
FieldT constant_term;
libsnark::r1cs_variable_assignment values;
libsnark::var_index_t next_free_var;
libsnark::lc_index_t next_free_lc;
std::__debug::vector<FieldT, std::allocator<FieldT> > lc_values;
libsnark::r1cs_constraint_system<FieldT> constraint_system;
vs
In stub_genkeys_from_pb
:
(gdb) ptype pb
type = class libsnark::protoboard<libff::Fp_model<4, (libff::bigint<4> const&)(&libff::alt_bn128_modulus_r)> >
[with FieldT = libff::Fp_model<4, (libff::bigint<4> const&)(&libff::alt_bn128_modulus_r)>] {
private:
FieldT constant_term;
libsnark::r1cs_variable_assignment values;
libsnark::var_index_t next_free_var;
libsnark::lc_index_t next_free_lc;
std::vector<FieldT, std::allocator<FieldT> > lc_values;
libsnark::r1cs_constraint_system<FieldT> constraint_system;
This explains the difference in offsets, in stub_genkeys
(a template, defined in a header) the std::vector
type has debug information, meaning ProtoboardT has different sizes, hence the different offsets and the crash.
This is probably caused by the -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
flags on compile:
The fix should be to:
This was causing crashes in ethsnarks-miximus and other projects, but only with GCC on Linux, it doesn't seem to be a problem with clang++ on OSX.
The pointer to
pb.constraint_system.constraints
seems to differ across calls.Then in
stub_genkeys_from_pb
it crashes in the copy constructor forlibsnark::r1cs_constraint_system
during call toget_constraint_system
.Backtrace from GDB:
GDB shows
&pb.constraint_system.constraints
instub_genkeys_from_pb
differs from the address instub_genkeys
. Instub_genkeys
the address is correct (0x7fffffffdd70
), but one level down instub_genkeys_from_pb
the address is incorrect (0x7fffffffddb0
).