NilFoundation / zkLLVM

Zero-Knowledge Proof Systems Circuit Compiler
https://docs.nil.foundation/zkllvm
295 stars 48 forks source link

"Unhandled constant expression: getelementptr" in ops with pointers on self #338

Open BoogerWooger opened 1 year ago

BoogerWooger commented 1 year ago

in case like:

struct lumpinfo_s                                                                                                                      
{                                                                                                                                      
    lumpinfo_s * next;
    lumpinfo_s * prev;                                                                                                                 
    int     data1;
};                                                                                                                                     

lumpinfo_s first;                                                                                                                      

[[circuit]] int list_demo(__zkllvm_field_pallas_base unused) {
    // ...
    first.next = first.prev = &first;
   // ...
}

example: memory.cpp.zip

error in assigner(backtrace):

D _Z9list_demou26__zkllvm_field_pallas_base:
D       entry: 
D                 store ptr @first, ptr getelementptr inbounds (%struct.lumpinfo_s, ptr @first, i32 0, i32 1), align 8, !tbaa !3
UNREACHABLE at /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/parser.hpp:637
        Unhandled constant expression: getelementptr
 #0 0x00007f2bdfd55450 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (.localalias) /home/boogerwooger/tmp/zkLLVM/libs/circifier/llvm/lib/Support/Unix/Signals.inc:567:22
 #1 0x00007f2bdfd5581b PrintStackTraceSignalHandler(void*) /home/boogerwooger/tmp/zkLLVM/libs/circifier/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x00007f2bdfd530fe llvm::sys::RunSignalHandlers() (.localalias) /home/boogerwooger/tmp/zkLLVM/libs/circifier/llvm/lib/Support/Signals.cpp:104:20
 #3 0x00007f2bdfd54d84 SignalHandler(int) /home/boogerwooger/tmp/zkLLVM/libs/circifier/llvm/lib/Support/Unix/Signals.inc:412:1
 #4 0x00007f2bdf8be420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #5 0x00007f2bdf3ad00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #6 0x00007f2bdf38c859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #7 0x000055d6bf41a863 nil::blueprint::unreachable(char const*, char const*, unsigned int) /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/asserts.hpp:44:93
 #8 0x000055d6bf41a910 nil::blueprint::unreachable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, unsigned int) /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/asserts.hpp:50:100
 #9 0x000055d6bf41a948 nil::blueprint::assert_check(bool, char const*, char const*, unsigned int, char const*) /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/asserts.hpp:54:119
#10 0x000055d6bf4c5979 nil::blueprint::parser<nil::crypto3::algebra::fields::pallas_base_field, nil::crypto3::zk::snark::plonk_arithmetization_params<15ul, 1ul, 5ul, 35ul>, true>::put_constant(llvm::Constant*, nil::blueprint::stack_frame<nil::crypto3::zk::snark::plonk_variable<nil::crypto3::algebra::fields::detail::element_fp<nil::crypto3::algebra::fields::params<nil::crypto3::algebra::fields::pallas_base_field> > > >&) /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/parser.hpp:639:74
#11 0x000055d6bf49c5d3 nil::blueprint::parser<nil::crypto3::algebra::fields::pallas_base_field, nil::crypto3::zk::snark::plonk_arithmetization_params<15ul, 1ul, 5ul, 35ul>, true>::handle_instruction(llvm::Instruction const*) /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/parser.hpp:668:29
#12 0x000055d6bf477493 nil::blueprint::parser<nil::crypto3::algebra::fields::pallas_base_field, nil::crypto3::zk::snark::plonk_arithmetization_params<15ul, 1ul, 5ul, 35ul>, true>::evaluate(llvm::Module const&, boost::json::array const&) /home/boogerwooger/tmp/zkLLVM/libs/assigner/include/nil/blueprint/parser.hpp:1285:31
#13 0x000055d6bf45994d int curve_dependent_main<nil::crypto3::algebra::curves::pallas, true>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, long, bool, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/boogerwooger/tmp/zkLLVM/bin/assigner/src/main.cpp:157:9
#14 0x000055d6bf41bc48 main /home/boogerwooger/tmp/zkLLVM/bin/assigner/src/main.cpp:319:84
#15 0x00007f2bdf38e083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#16 0x000055d6bf40948e _start (/home/boogerwooger/tmp/zkLLVM/build/bin/assigner/assigner+0x3448e)
Aborted
dkales commented 12 months ago

we also had a similar issue in that the MLIR to LLVM toolchain outputs mallocs with constexpr operands

they look like

%15 = call ptr @malloc(i64 add (i64 ptrtoint (ptr getelementptr (i32, ptr null, i32 10) to i64), i64 16))

and try to calculate the size of the allocation by gep offset to null.

ATM this has 2 blockers: