Giter VIP home page Giter VIP logo

witnesscalc's People

Contributors

demonsh avatar mmilenkovic avatar nixw4 avatar obrezhniev avatar olomix avatar rauljareno avatar yushihang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

witnesscalc's Issues

Invalid witness generated on Android

Hello,

I am trying to generate a witness of the following circuit on android.
I am using the feature/arm-asm branch, and in order to compile it I change the code in the src/auth.cpp file:

namespace CIRCUIT_NAME {
	// add the code from the cpp compiled poc.circom circuit (from poc_cpp/poc.cpp)
}

Then, I execute

./build_gmp.sh android
make -j 8 android

and I copy the generated package_android/bin/auth executable together with the .dat file generated from circom (poc_cpp/poc.dat) as auth.dat to a physical android device.

Please let me know if I am doing something incorrectly up to now.

Then, if I execute ./auth poc.json w.wtns on android, it calculates a witness, but when I try to verify a proof, generated from this witness file, the proof is not valid.
I viewed the w.wtns file, and it looks like it is mostly empty to me.

Please, let me know if I have made a mistake somewhere, or this is a bug in the witness calculator.

It is probably worth mentioning that this specific circuit did not work for the circom generated c++ witness calculator up until very recently, but there the witness generation crashed without generating a witness file, while witnesscalc generates an invalid witness file.

witness generation for a circuit

Hi,

Can you please specify how to use this repo for witness generation of a circuit. After compilation, should I expect some final binary which is to be used for witness generation?

Thanks

Cannot determine how to define 32-bit word, bug?

hi, trying to compile for ios_x86_64 on m2 using the feature/arm_asm branch.
following the steps in readme. when running ./build_gmp.sh ios_x86_64 it breaks at:

...
checking for assembler local label prefix... L
checking for assembler byte directive... .byte
checking how to define a 32-bit word... configure: error: cannot determine how to define a 32-bit word

if ignored, it then causes compilation in xcode to fail with a
nasm: fatal: unrecognised output format 'macho64 --prefix _' - use -hf for a list

any ideas where this may be coming from?

full output Building for ios x86_64 x86_64-apple-darwin checking build system type... aarch64-apple-darwin21.6.0 checking host system type... x86_64-apple-darwin checking for a BSD-compatible install... /usr/local/bin/ginstall -c checking whether build environment is sane... yes checking for x86_64-apple-darwin-strip... no checking for strip... strip checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p checking for gawk... no checking for mawk... no checking for nawk... no checking for awk... awk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether to enable maintainer-specific portions of Makefiles... no checking ABI=64 checking whether /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang is gcc... yes checking compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -O3 -g3 -fembed-bitcode ... yes checking for x86_64-apple-darwin-gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang accepts -g... yes checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang option to accept ISO C89... none needed checking whether /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang understands -c and -o together... rm: conftest.dSYM: is a directory yes checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang option to accept ISO C99... none needed checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp checking build system compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang... rm: conftest.dSYM: is a directory rm: conftest.dSYM: is a directory no checking build system compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -O3 -g3 -fembed-bitcode ... rm: conftest.dSYM: is a directory rm: conftest.dSYM: is a directory no checking build system compiler cc... rm: conftest.dSYM: is a directory rm: conftest.dSYM: is a directory yes checking for build system preprocessor... rm: conftest.dSYM: is a directory cc -E checking for build system executable suffix... rm: conftest.dSYM: is a directory

checking whether build system compiler is ANSI... rm: conftest.dSYM: is a directory
yes
checking for build system compiler math library... rm: conftest.dSYM: is a directory
-lm
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
using ABI="64"
CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
CFLAGS="-arch x86_64 -miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -O3 -g3 -fembed-bitcode"
CPPFLAGS=""
MPN_PATH="generic"
checking whether assembler supports --noexecstack option... rm: conftest.dSYM: is a directory
no
checking for x86_64-apple-darwin-ar... no
checking for ar... ar
configure: WARNING: using cross tools not prefixed with host triplet
checking for BSD- or MS-compatible name lister (nm)... no
checking for x86_64-apple-darwin-dumpbin... no
checking for x86_64-apple-darwin-link... no
checking for dumpbin... no
checking for link... link -dump
checking the name lister (nm) interface... rm: conftest.dSYM: is a directory
BSD nm
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... (cached) BSD nm
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin21.6.0 file names to x86_64-apple-darwin format... func_convert_file_noop
checking how to convert aarch64-apple-darwin21.6.0 file names to toolchain format... func_convert_file_noop
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for x86_64-apple-darwin-objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for x86_64-apple-darwin-dlltool... dlltool
checking how to associate runtime and link libraries... printf %s\n
checking for x86_64-apple-darwin-ar... ar
checking for archiver @file support... rm: conftest.dSYM: is a directory
no
checking for x86_64-apple-darwin-strip... strip
checking for x86_64-apple-darwin-ranlib... no
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang object... rm: conftest.dSYM: is a directory
ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for x86_64-apple-darwin-mt... no
checking for mt... no
checking if : is a manifest tool... no
checking for x86_64-apple-darwin-dsymutil... no
checking for dsymutil... dsymutil
checking for x86_64-apple-darwin-nmedit... no
checking for nmedit... nmedit
checking for x86_64-apple-darwin-lipo... no
checking for lipo... lipo
checking for x86_64-apple-darwin-otool... no
checking for otool... otool
checking for x86_64-apple-darwin-otool64... no
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang supports -fno-rtti -fno-exceptions... yes
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang option to produce PIC... -fno-common -DPIC
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang PIC flag -fno-common -DPIC works... yes
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang static flag -static works... no
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang supports -c -o file.o... yes
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang supports -c -o file.o... (cached) yes
checking whether the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -E
checking whether the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... no
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ option to produce PIC... -DPIC
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ PIC flag -DPIC works... yes
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ static flag works... yes
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ supports -c -o file.o... yes
checking if /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ supports -c -o file.o... (cached) yes
checking whether the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... no
checking dynamic linker characteristics... darwin dyld
checking how to hardcode library paths into programs... immediate
checking for ANSI C header files... (cached) yes
checking whether time.h and sys/time.h may both be included... yes
checking fcntl.h usability... yes
checking fcntl.h presence... no
configure: WARNING: fcntl.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: fcntl.h: proceeding with the compiler's result
checking for fcntl.h... yes
checking float.h usability... yes
checking float.h presence... yes
checking for float.h... yes
checking invent.h usability... no
checking invent.h presence... no
checking for invent.h... no
checking langinfo.h usability... yes
checking langinfo.h presence... yes
checking for langinfo.h... yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking nl_types.h usability... yes
checking nl_types.h presence... no
configure: WARNING: nl_types.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: nl_types.h: proceeding with the compiler's result
checking for nl_types.h... yes
checking sys/attributes.h usability... no
checking sys/attributes.h presence... no
checking for sys/attributes.h... no
checking sys/iograph.h usability... no
checking sys/iograph.h presence... no
checking for sys/iograph.h... no
checking sys/mman.h usability... yes
checking sys/mman.h presence... no
configure: WARNING: sys/mman.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: sys/mman.h: proceeding with the compiler's result
checking for sys/mman.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... no
configure: WARNING: sys/param.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: sys/param.h: proceeding with the compiler's result
checking for sys/param.h... yes
checking sys/processor.h usability... no
checking sys/processor.h presence... no
checking for sys/processor.h... no
checking sys/pstat.h usability... no
checking sys/pstat.h presence... no
checking for sys/pstat.h... no
checking sys/sysinfo.h usability... no
checking sys/sysinfo.h presence... no
checking for sys/sysinfo.h... no
checking sys/syssgi.h usability... no
checking sys/syssgi.h presence... no
checking for sys/syssgi.h... no
checking sys/systemcfg.h usability... no
checking sys/systemcfg.h presence... no
checking for sys/systemcfg.h... no
checking sys/time.h usability... yes
checking sys/time.h presence... no
configure: WARNING: sys/time.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: sys/time.h: proceeding with the compiler's result
checking for sys/time.h... yes
checking sys/times.h usability... yes
checking sys/times.h presence... yes
checking for sys/times.h... yes
checking for sys/resource.h... yes
checking for sys/sysctl.h... yes
checking for machine/hal_sysinfo.h... no
checking whether fgetc is declared... yes
checking whether fscanf is declared... yes
checking whether optarg is declared... yes
checking whether ungetc is declared... yes
checking whether vfprintf is declared... yes
checking whether sys_errlist is declared... yes
checking whether sys_nerr is declared... yes
checking return type of signal handlers... void
checking for intmax_t... yes
checking for long double... yes
checking for long long... yes
checking for ptrdiff_t... yes
checking for quad_t... yes
checking for uint_least32_t... yes
checking for intptr_t... yes
checking for working volatile... yes
checking for C/C++ restrict keyword... __restrict
checking whether gcc attribute ((const)) works... yes
checking whether gcc attribute ((malloc)) works... yes
checking whether gcc attribute ((mode (XX))) works... yes
checking whether gcc attribute ((noreturn)) works... yes
checking whether gcc hidden aliases work... no
checking for inline... inline
checking for working alloca.h... yes
checking for alloca (via gmp-impl.h)... yes
checking how to allocate temporary memory... alloca
checking whether byte ordering is bigendian... no
checking format of `double' floating point... rm: conftest.dSYM: is a directory
IEEE little endian
checking for alarm... yes
checking for attr_get... no
checking for clock... yes
checking for cputime... no
checking for getpagesize... yes
checking for getrusage... yes
checking for gettimeofday... yes
checking for getsysinfo... no
checking for localeconv... yes
checking for memset... yes
checking for mmap... yes
checking for mprotect... yes
checking for nl_langinfo... yes
checking for obstack_vprintf... no
checking for popen... yes
checking for processor_info... yes
checking for pstat_getprocessor... no
checking for raise... yes
checking for read_real_time... no
checking for sigaction... yes
checking for sigaltstack... yes
checking for sigstack... no
checking for syssgi... no
checking for strchr... yes
checking for strerror... yes
checking for strnlen... yes
checking for strtol... yes
checking for strtoul... yes
checking for sysconf... yes
checking for sysctl... yes
checking for sysctlbyname... yes
checking for times... yes
checking for library containing clock_gettime... none required
checking for vsnprintf... yes
checking whether vsnprintf works... probably
configure: WARNING: cannot check for properly working vsnprintf when cross compiling, will assume it's ok
checking whether sscanf needs writable input... no
checking for struct pst_processor.psp_iticksperclktick... no
checking for suitable m4... m4
checking if m4wrap produces spurious output... no
checking how to switch to text section... .text
checking how to switch to data section... .data
checking for assembler label suffix... :
checking for assembler global directive... .globl
checking for assembler global directive attribute...
checking if globals are prefixed by underscore... yes
checking how to switch to read-only data section... .section __TEXT,__const
checking for assembler .type directive...
checking for assembler .size directive...
checking for assembler local label prefix... L
checking for assembler byte directive... .byte
checking how to define a 32-bit word... configure: error: cannot determine how to define a 32-bit word

Potential memory errors in Circom_Circuit* loadCircuit(const void *buffer, unsigned long buffer_size)

memcpy((void *)(circuit->InputHashMap), (void *)bdata, dsize);

memcpy((void *)(circuit->witness2SignalList), (void *)(bdata+inisize), dsize);

memcpy((void *)(circuit->circuitConstants), (void *)(bdata+inisize), dsize);

memcpy((void *)index, (void *)(bdata+inisize), dsize);

memcpy((void *)dataiomap, (void *)(bdata+inisize), buffer_size-inisize);

In Circom_Circuit* loadCircuit(const void *buffer, unsigned long buffer_size), if the length of the passed buffer_size does not meet the requirements, it may lead to memory errors triggered by the memcpy in the code.

Circom_Circuit* loadCircuit(const void *buffer, unsigned long buffer_size) {
    if (buffer_size % sizeof(u32) != 0) {
      throw std::runtime_error("Invalid circuit file: wrong buffer_size");
    }

    Circom_Circuit *circuit = new Circom_Circuit;

    u8* bdata = (u8*)buffer;

    circuit->InputHashMap = new HashSignalInfo[get_size_of_input_hashmap()];
    uint dsize = get_size_of_input_hashmap()*sizeof(HashSignalInfo);
    if (buffer_size < dsize) {
        //Add this code snippet to prevent potential memory errors.
        throw std::runtime_error("Invalid circuit file: buffer_size <= dsize");
    }
    memcpy((void *)(circuit->InputHashMap), (void *)bdata, dsize);

    circuit->witness2SignalList = new u64[get_size_of_witness()];
    uint inisize = dsize;
    dsize = get_size_of_witness()*sizeof(u64);
    if (buffer_size < dsize + inisize) {
        //Add this code snippet to prevent potential memory errors.
        throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize (1)");
    }
    memcpy((void *)(circuit->witness2SignalList), (void *)(bdata+inisize), dsize);

    circuit->circuitConstants = new FrElement[get_size_of_constants()];
    if (get_size_of_constants()>0) {
      inisize += dsize;
      dsize = get_size_of_constants()*sizeof(FrElement);
        if (buffer_size < dsize + inisize) {
            //Add this code snippet to prevent potential memory errors.
            throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize (2)");
        }
      memcpy((void *)(circuit->circuitConstants), (void *)(bdata+inisize), dsize);
    }

    std::map<u32,IODefPair> templateInsId2IOSignalInfo1;
    if (get_size_of_io_map()>0) {
      u32 index[get_size_of_io_map()];
      inisize += dsize;
      dsize = get_size_of_io_map()*sizeof(u32);
        if (buffer_size < dsize + inisize) {
            //Add this code snippet to prevent potential memory errors.
            throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize (3)");
        }
      memcpy((void *)index, (void *)(bdata+inisize), dsize);
      inisize += dsize;
      if (inisize % sizeof(u32) != 0) {
        throw std::runtime_error("Invalid circuit file: wrong inisize");
      }
        
      if (buffer_size <= inisize) {
          //Add this code snippet to prevent potential memory errors.
        throw std::runtime_error("Invalid circuit file: buffer_size <= inisize");
      }
      u32 dataiomap[(buffer_size-inisize)/sizeof(u32)];
      memcpy((void *)dataiomap, (void *)(bdata+inisize), buffer_size-inisize);
      u32* pu32 = dataiomap;

      for (int i = 0; i < get_size_of_io_map(); i++) {
    u32 n = *pu32;
    IODefPair p;
    p.len = n;
    IODef defs[n];
    pu32 += 1;
    for (u32 j = 0; j <n; j++){
      defs[j].offset=*pu32;
      u32 len = *(pu32+1);
      defs[j].len = len;
      defs[j].lengths = new u32[len];
      memcpy((void *)defs[j].lengths,(void *)(pu32+2),len*sizeof(u32));
      pu32 += len + 2;
    }
    p.defs = (IODef*)calloc(10, sizeof(IODef));
    for (u32 j = 0; j < p.len; j++){
      p.defs[j] = defs[j];
    }
    templateInsId2IOSignalInfo1[index[i]] = p;
      }
    }
    circuit->templateInsId2IOSignalInfo = move(templateInsId2IOSignalInfo1);

    return circuit;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.