diff --git a/Arduino/scr.sh b/Arduino/scr.sh new file mode 100644 index 000000000..43eb76f3a --- /dev/null +++ b/Arduino/scr.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +rm -rf verify/mycache + +ROOT="$(git rev-parse --show-toplevel)" + +cp "${ROOT}/vendor/nim/lib/nimbase.h" "Arduino/verify" + +nim c -r \ + --cpu:esp \ + -d:release \ + -d:danger \ + --opt:size \ + --verbosity:3 \ + --os:standalone \ + --noMain:on \ + --deadCodeElim:on \ + --d:CTT_32=1 \ + --d:CTT_ASM=false \ + --nimcache:Arduino/verify/mycache \ + --lib:"${ROOT}/vendor/nim/lib/" "${ROOT}/contracts/cosmos/verifier/verifier-constantine/lib/nim/verify/verify.nim" + +rm "${ROOT}/verify/@" +rm Arduino/verify/@ + +cp -r "${ROOT}/Arduino/verify/mycache/." "${ROOT}/Arduino/verify" diff --git a/Arduino/verify/import.hh b/Arduino/verify/import.hh new file mode 100644 index 000000000..37d6fcca8 --- /dev/null +++ b/Arduino/verify/import.hh @@ -0,0 +1,27 @@ +#include +#include +#include +const uint32_t ROOT_LENGTH = 32; +const uint32_t VERIFICATION_KEY_LENGTH = 640; +const uint32_t PROOF_LENGTH = 256; + +extern "C" { +bool makePairsAndVerify(std::array *vk, + std::array *prf, + std::array *currentHeaderHash, + std::array *newOptimisticHeader, + std::array *newFinalizedHeader, + std::array *newExecutionStateRoot, + std::array *currentSlot, + std::array *domain); +} + +std::array vkey = { 23, 14, 17, 42, 185, 164, 205, 1, 195, 107, 171, 71, 64, 46, 252, 207, 233, 238, 75, 26, 225, 17, 222, 60, 207, 94, 92, 15, 152, 2, 235, 6, 30, 139, 14, 214, 223, 44, 75, 49, 54, 176, 41, 90, 23, 66, 228, 60, 120, 2, 126, 203, 170, 53, 127, 17, 146, 101, 59, 78, 218, 81, 70, 6, 224, 39, 103, 0, 74, 163, 104, 212, 12, 80, 4, 180, 153, 193, 41, 121, 104, 119, 103, 167, 254, 129, 4, 245, 126, 30, 115, 6, 90, 118, 243, 42, 88, 62, 102, 201, 100, 28, 210, 51, 27, 159, 235, 14, 105, 41, 0, 200, 191, 106, 23, 217, 230, 36, 64, 114, 191, 133, 13, 1, 47, 144, 202, 41, 54, 145, 20, 235, 167, 131, 110, 143, 205, 16, 96, 55, 239, 135, 252, 114, 36, 250, 52, 248, 199, 18, 198, 164, 218, 225, 83, 161, 169, 138, 117, 21, 52, 72, 248, 169, 122, 13, 36, 24, 168, 117, 136, 211, 252, 64, 182, 185, 249, 202, 91, 35, 140, 89, 89, 45, 244, 198, 204, 171, 3, 231, 194, 42, 38, 32, 188, 2, 209, 181, 131, 142, 114, 1, 123, 73, 53, 25, 235, 220, 223, 26, 129, 151, 71, 38, 184, 251, 59, 80, 150, 175, 65, 56, 87, 25, 64, 97, 76, 168, 125, 115, 180, 175, 196, 216, 2, 88, 90, 221, 67, 96, 134, 47, 160, 82, 252, 80, 233, 9, 107, 123, 234, 58, 131, 240, 254, 20, 246, 233, 107, 136, 157, 250, 157, 97, 120, 155, 158, 245, 151, 210, 127, 254, 254, 125, 27, 35, 98, 26, 158, 255, 6, 66, 158, 174, 235, 126, 253, 40, 238, 86, 24, 199, 86, 91, 9, 100, 187, 60, 125, 50, 34, 249, 87, 220, 118, 16, 53, 51, 190, 53, 249, 85, 130, 100, 253, 147, 230, 160, 164, 13, 38, 32, 188, 2, 209, 181, 131, 142, 114, 1, 123, 73, 53, 25, 235, 220, 223, 26, 129, 151, 71, 38, 184, 251, 59, 80, 150, 175, 65, 56, 87, 25, 64, 97, 76, 168, 125, 115, 180, 175, 196, 216, 2, 88, 90, 221, 67, 96, 134, 47, 160, 82, 252, 80, 233, 9, 107, 123, 234, 58, 131, 240, 254, 20, 246, 233, 107, 136, 157, 250, 157, 97, 120, 155, 158, 245, 151, 210, 127, 254, 254, 125, 27, 35, 98, 26, 158, 255, 6, 66, 158, 174, 235, 126, 253, 40, 238, 86, 24, 199, 86, 91, 9, 100, 187, 60, 125, 50, 34, 249, 87, 220, 118, 16, 53, 51, 190, 53, 249, 85, 130, 100, 253, 147, 230, 160, 164, 13, 111, 184, 203, 90, 60, 233, 99, 208, 105, 198, 17, 27, 170, 63, 164, 235, 89, 138, 44, 71, 77, 86, 250, 114, 158, 185, 210, 144, 64, 123, 239, 15, 222, 231, 138, 155, 249, 201, 152, 185, 180, 32, 216, 18, 207, 224, 200, 78, 1, 247, 107, 24, 113, 8, 25, 234, 251, 192, 200, 141, 43, 46, 140, 23, 164, 85, 253, 109, 87, 59, 29, 233, 190, 58, 38, 152, 86, 64, 105, 96, 128, 159, 187, 178, 215, 58, 254, 153, 85, 233, 92, 71, 19, 51, 251, 33, 186, 68, 84, 84, 140, 220, 78, 252, 153, 242, 177, 175, 140, 197, 148, 55, 7, 168, 10, 217, 103, 64, 0, 103, 105, 55, 253, 67, 105, 214, 53, 1, 233, 8, 55, 162, 182, 137, 134, 184, 120, 76, 43, 200, 104, 163, 181, 240, 252, 165, 124, 79, 220, 228, 61, 80, 175, 50, 53, 146, 249, 235, 55, 0, 135, 66, 42, 148, 149, 40, 192, 246, 199, 22, 166, 43, 56, 111, 130, 160, 181, 83, 4, 152, 147, 169, 193, 149, 171, 188, 60, 231, 177, 95, 116, 14}; +std::array proof = {30, 31, 60, 34, 210, 253, 202, 188, 172, 17, 13, 195, 160, 133, 195, 248, 167, 90, 22, 66, 237, 150, 134, 176, 188, 178, 113, 59, 77, 148, 207, 34, 236, 137, 248, 203, 253, 208, 212, 7, 153, 35, 45, 200, 105, 130, 55, 66, 21, 185, 243, 136, 230, 181, 65, 75, 81, 83, 236, 151, 236, 15, 247, 8, 192, 84, 28, 96, 230, 70, 19, 21, 108, 148, 41, 240, 197, 112, 162, 142, 198, 76, 121, 146, 156, 117, 91, 38, 239, 62, 181, 132, 131, 15, 112, 44, 152, 62, 117, 248, 197, 213, 8, 253, 161, 126, 171, 180, 6, 182, 12, 41, 6, 137, 255, 36, 235, 125, 235, 130, 73, 73, 5, 15, 159, 85, 72, 0, 24, 147, 115, 166, 1, 111, 86, 222, 208, 66, 124, 179, 64, 133, 168, 0, 122, 2, 52, 2, 103, 239, 45, 102, 77, 120, 140, 250, 114, 194, 220, 34, 46, 134, 1, 15, 77, 68, 140, 70, 203, 189, 192, 83, 142, 113, 147, 85, 78, 88, 99, 134, 116, 58, 141, 228, 135, 41, 16, 245, 187, 58, 51, 17, 52, 178, 184, 140, 13, 86, 10, 222, 152, 56, 100, 66, 57, 4, 217, 71, 104, 236, 245, 106, 25, 236, 242, 212, 229, 88, 130, 153, 210, 139, 151, 28, 232, 226, 187, 1, 140, 2, 100, 48, 119, 51, 37, 67, 186, 178, 240, 243, 197, 100, 124, 10, 53, 52, 100, 176, 24, 95, 238, 38, 227, 183, 133, 24}; +std::array currentHeader = {76, 231, 107, 116, 120, 203, 14, 238, 74, 50, 199, 242, 91, 181, 97, 202, 29, 15, 68, 77, 23, 22, 200, 246, 242, 96, 144, 14, 244, 95, 55, 210}; +std::array newOptimisticHeader = {224, 132, 253, 242, 42, 114, 188, 147, 160, 185, 117, 205, 215, 245, 192, 90, 14, 9, 0, 34, 219, 97, 218, 241, 110, 95, 76, 216, 87, 111, 211, 171}; +std::array newFinalizedHeader = {136, 59, 86, 215, 36, 97, 240, 88, 164, 76, 237, 14, 37, 50, 111, 115, 134, 120, 129, 207, 42, 6, 20, 39, 143, 233, 102, 217, 21, 236, 105, 23}; +std::array newExecutionStateRoot = {100, 107, 155, 135, 186, 7, 66, 136, 107, 248, 51, 46, 14, 126, 245, 198, 197, 223, 2, 219, 5, 34, 196, 6, 33, 240, 220, 87, 150, 72, 208, 3}; + +std::array domain = {7, 0, 0, 0, 98, 137, 65, 239, 33, 209, 254, 140, 113, 52, 114, 10, 221, 16, 187, 145, 227, 176, 44, 0, 126, 0, 70, 210, 71, 44, 102, 149}; +std::array new_slot = {109, 150, 85, 0, 0, 0, 0, 0}; diff --git a/Arduino/verify/nimbase.h b/Arduino/verify/nimbase.h new file mode 100644 index 000000000..a83bd3006 --- /dev/null +++ b/Arduino/verify/nimbase.h @@ -0,0 +1,602 @@ +/* + + Nim's Runtime Library + (c) Copyright 2015 Andreas Rumpf + + See the file "copying.txt", included in this + distribution, for details about the copyright. +*/ + +/* compiler symbols: +__BORLANDC__ +_MSC_VER +__WATCOMC__ +__LCC__ +__GNUC__ +__DMC__ +__POCC__ +__TINYC__ +__clang__ +__AVR__ +*/ + + +#ifndef NIMBASE_H +#define NIMBASE_H + +/*------------ declaring a custom attribute to support using LLVM's Address Sanitizer ------------ */ + +/* + This definition exists to provide support for using the LLVM ASAN (Address SANitizer) tooling with Nim. This + should only be used to mark implementations of the GC system that raise false flags with the ASAN tooling, or + for functions that are hot and need to be disabled for performance reasons. Based on the official ASAN + documentation, both the clang and gcc compilers are supported. In addition to that, a check is performed to + verify that the necessary attribute is supported by the compiler. + + To flag a proc as ignored, append the following code pragma to the proc declaration: + {.codegenDecl: "CLANG_NO_SANITIZE_ADDRESS $# $#$#".} + + For further information, please refer to the official documentation: + https://github.com/google/sanitizers/wiki/AddressSanitizer + */ +#define CLANG_NO_SANITIZE_ADDRESS +#if defined(__clang__) +# if __has_attribute(no_sanitize_address) +# undef CLANG_NO_SANITIZE_ADDRESS +# define CLANG_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) +# endif +#endif + + +/* ------------ ignore typical warnings in Nim-generated files ------------- */ +#if defined(__GNUC__) || defined(__clang__) +# pragma GCC diagnostic ignored "-Wpragmas" +# pragma GCC diagnostic ignored "-Wwritable-strings" +# pragma GCC diagnostic ignored "-Winvalid-noreturn" +# pragma GCC diagnostic ignored "-Wformat" +# pragma GCC diagnostic ignored "-Wlogical-not-parentheses" +# pragma GCC diagnostic ignored "-Wlogical-op-parentheses" +# pragma GCC diagnostic ignored "-Wshadow" +# pragma GCC diagnostic ignored "-Wunused-function" +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Winvalid-offsetof" +# pragma GCC diagnostic ignored "-Wtautological-compare" +# pragma GCC diagnostic ignored "-Wswitch-bool" +# pragma GCC diagnostic ignored "-Wmacro-redefined" +# pragma GCC diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers" +# pragma GCC diagnostic ignored "-Wpointer-bool-conversion" +# pragma GCC diagnostic ignored "-Wconstant-conversion" +#endif + +#if defined(_MSC_VER) +# pragma warning(disable: 4005 4100 4101 4189 4191 4200 4244 4293 4296 4309) +# pragma warning(disable: 4310 4365 4456 4477 4514 4574 4611 4668 4702 4706) +# pragma warning(disable: 4710 4711 4774 4800 4809 4820 4996 4090 4297) +#endif +/* ------------------------------------------------------------------------- */ + +#if defined(__GNUC__) && !defined(__ZEPHYR__) +/* Zephyr does some magic in it's headers that override the GCC stdlib. This breaks that. */ +# define _GNU_SOURCE 1 +#endif + +#if defined(__TINYC__) +/*# define __GNUC__ 3 +# define GCC_MAJOR 4 +# define __GNUC_MINOR__ 4 +# define __GNUC_PATCHLEVEL__ 5 */ +# define __DECLSPEC_SUPPORTED 1 +#endif + +/* calling convention mess ----------------------------------------------- */ +#if defined(__GNUC__) || defined(__LCC__) || defined(__POCC__) \ + || defined(__TINYC__) + /* these should support C99's inline */ + /* the test for __POCC__ has to come before the test for _MSC_VER, + because PellesC defines _MSC_VER too. This is brain-dead. */ +# define N_INLINE(rettype, name) inline rettype name +#elif defined(__BORLANDC__) || defined(_MSC_VER) +/* Borland's compiler is really STRANGE here; note that the __fastcall + keyword cannot be before the return type, but __inline cannot be after + the return type, so we do not handle this mess in the code generator + but rather here. */ +# define N_INLINE(rettype, name) __inline rettype name +#elif defined(__DMC__) +# define N_INLINE(rettype, name) inline rettype name +#elif defined(__WATCOMC__) +# define N_INLINE(rettype, name) __inline rettype name +#else /* others are less picky: */ +# define N_INLINE(rettype, name) rettype __inline name +#endif + +#define N_INLINE_PTR(rettype, name) rettype (*name) + +#if defined(__POCC__) +# define NIM_CONST /* PCC is really picky with const modifiers */ +# undef _MSC_VER /* Yeah, right PCC defines _MSC_VER even if it is + not that compatible. Well done. */ +#elif defined(__cplusplus) +# define NIM_CONST /* C++ is picky with const modifiers */ +#else +# define NIM_CONST const +#endif + +/* + NIM_THREADVAR declaration based on + http://stackoverflow.com/questions/18298280/how-to-declare-a-variable-as-thread-local-portably +*/ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__ +# define NIM_THREADVAR _Thread_local +#elif defined _WIN32 && ( \ + defined _MSC_VER || \ + defined __ICL || \ + defined __DMC__ || \ + defined __BORLANDC__ ) +# define NIM_THREADVAR __declspec(thread) +#elif defined(__TINYC__) || defined(__GENODE__) +# define NIM_THREADVAR +/* note that ICC (linux) and Clang are covered by __GNUC__ */ +#elif defined __GNUC__ || \ + defined __SUNPRO_C || \ + defined __xlC__ +# define NIM_THREADVAR __thread +#else +# error "Cannot define NIM_THREADVAR" +#endif + +#if defined(__cplusplus) + #define NIM_THREAD_LOCAL thread_local +#endif + +/* --------------- how int64 constants should be declared: ----------- */ +#if defined(__GNUC__) || defined(__LCC__) || \ + defined(__POCC__) || defined(__DMC__) || defined(_MSC_VER) +# define IL64(x) x##LL +#else /* works only without LL */ +# define IL64(x) ((NI64)x) +#endif + +/* ---------------- casting without correct aliasing rules ----------- */ + +#if defined(__GNUC__) +# define NIM_CAST(type, ptr) (((union{type __x__;}*)(ptr))->__x__) +#else +# define NIM_CAST(type, ptr) ((type)(ptr)) +#endif + + +/* ------------------------------------------------------------------- */ +#ifdef __cplusplus +# define NIM_EXTERNC extern "C" +#else +# define NIM_EXTERNC +#endif + +#if defined(WIN32) || defined(_WIN32) /* only Windows has this mess... */ +# define N_LIB_PRIVATE +# define N_CDECL(rettype, name) rettype __cdecl name +# define N_STDCALL(rettype, name) rettype __stdcall name +# define N_SYSCALL(rettype, name) rettype __syscall name +# define N_FASTCALL(rettype, name) rettype __fastcall name +# define N_THISCALL(rettype, name) rettype __thiscall name +# define N_SAFECALL(rettype, name) rettype __stdcall name +/* function pointers with calling convention: */ +# define N_CDECL_PTR(rettype, name) rettype (__cdecl *name) +# define N_STDCALL_PTR(rettype, name) rettype (__stdcall *name) +# define N_SYSCALL_PTR(rettype, name) rettype (__syscall *name) +# define N_FASTCALL_PTR(rettype, name) rettype (__fastcall *name) +# define N_THISCALL_PTR(rettype, name) rettype (__thiscall *name) +# define N_SAFECALL_PTR(rettype, name) rettype (__stdcall *name) + +# ifdef __cplusplus +# define N_LIB_EXPORT NIM_EXTERNC __declspec(dllexport) +# else +# define N_LIB_EXPORT NIM_EXTERNC __declspec(dllexport) +# endif +# define N_LIB_EXPORT_VAR __declspec(dllexport) +# define N_LIB_IMPORT extern __declspec(dllimport) +#else +# define N_LIB_PRIVATE __attribute__((visibility("hidden"))) +# if defined(__GNUC__) +# define N_CDECL(rettype, name) rettype name +# define N_STDCALL(rettype, name) rettype name +# define N_SYSCALL(rettype, name) rettype name +# define N_FASTCALL(rettype, name) __attribute__((fastcall)) rettype name +# define N_SAFECALL(rettype, name) rettype name +/* function pointers with calling convention: */ +# define N_CDECL_PTR(rettype, name) rettype (*name) +# define N_STDCALL_PTR(rettype, name) rettype (*name) +# define N_SYSCALL_PTR(rettype, name) rettype (*name) +# define N_FASTCALL_PTR(rettype, name) __attribute__((fastcall)) rettype (*name) +# define N_SAFECALL_PTR(rettype, name) rettype (*name) +# else +# define N_CDECL(rettype, name) rettype name +# define N_STDCALL(rettype, name) rettype name +# define N_SYSCALL(rettype, name) rettype name +# define N_FASTCALL(rettype, name) rettype name +# define N_SAFECALL(rettype, name) rettype name +/* function pointers with calling convention: */ +# define N_CDECL_PTR(rettype, name) rettype (*name) +# define N_STDCALL_PTR(rettype, name) rettype (*name) +# define N_SYSCALL_PTR(rettype, name) rettype (*name) +# define N_FASTCALL_PTR(rettype, name) rettype (*name) +# define N_SAFECALL_PTR(rettype, name) rettype (*name) +# endif +# define N_LIB_EXPORT NIM_EXTERNC __attribute__((visibility("default"))) +# define N_LIB_EXPORT_VAR __attribute__((visibility("default"))) +# define N_LIB_IMPORT extern +#endif + +#define N_NOCONV(rettype, name) rettype name +/* specify no calling convention */ +#define N_NOCONV_PTR(rettype, name) rettype (*name) + +#if defined(__GNUC__) || defined(__ICC__) +# define N_NOINLINE(rettype, name) rettype __attribute__((__noinline__)) name +#elif defined(_MSC_VER) +# define N_NOINLINE(rettype, name) __declspec(noinline) rettype name +#else +# define N_NOINLINE(rettype, name) rettype name +#endif + +#define N_NOINLINE_PTR(rettype, name) rettype (*name) + +#if defined(__BORLANDC__) || defined(__WATCOMC__) || \ + defined(__POCC__) || defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) +/* these compilers have a fastcall so use it: */ +# ifdef __TINYC__ +# define N_NIMCALL(rettype, name) rettype __attribute((__fastcall)) name +# define N_NIMCALL_PTR(rettype, name) rettype (__attribute((__fastcall)) *name) +# define N_RAW_NIMCALL __attribute((__fastcall)) +# else +# define N_NIMCALL(rettype, name) rettype __fastcall name +# define N_NIMCALL_PTR(rettype, name) rettype (__fastcall *name) +# define N_RAW_NIMCALL __fastcall +# endif +#else +# define N_NIMCALL(rettype, name) rettype name /* no modifier */ +# define N_NIMCALL_PTR(rettype, name) rettype (*name) +# define N_RAW_NIMCALL +#endif + +#define N_CLOSURE(rettype, name) N_NIMCALL(rettype, name) +#define N_CLOSURE_PTR(rettype, name) N_NIMCALL_PTR(rettype, name) + +/* ----------------------------------------------------------------------- */ + +#define COMMA , + +#include +#include + +// define NIM_STATIC_ASSERT +// example use case: CT sizeof for importc types verification +// where we have {.completeStruct.} (or lack of {.incompleteStruct.}) +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) +#define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg) +#elif defined(__cplusplus) +#define NIM_STATIC_ASSERT(x, msg) static_assert((x), msg) +#else +#define NIM_STATIC_ASSERT(x, msg) typedef int NIM_STATIC_ASSERT_AUX[(x) ? 1 : -1]; +// On failure, your C compiler will say something like: +// "error: 'NIM_STATIC_ASSERT_AUX' declared as an array with a negative size" +// we could use a better fallback to also show line number, using: +// http://www.pixelbeat.org/programming/gcc/static_assert.html +#endif + +/* C99 compiler? */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) +# define HAVE_STDINT_H +#endif + +/* Known compiler with stdint.h that doesn't fit the general pattern? */ +#if defined(__LCC__) || defined(__DMC__) || defined(__POCC__) || \ + defined(__AVR__) || (defined(__cplusplus) && (__cplusplus < 201103)) +# define HAVE_STDINT_H +#endif + +#if (!defined(HAVE_STDINT_H) && defined(__cplusplus) && (__cplusplus >= 201103)) +# define HAVE_CSTDINT +#endif + + +/* wrap all Nim typedefs into namespace Nim */ +#ifdef USE_NIM_NAMESPACE +#ifdef HAVE_CSTDINT +#include +#else +#include +#endif +namespace USE_NIM_NAMESPACE { +#endif + +// preexisting check, seems paranoid, maybe remove +#if defined(NIM_TRUE) || defined(NIM_FALSE) || defined(NIM_BOOL) +#error "nim reserved preprocessor macros clash" +#endif + +/* bool types (C++ has it): */ +#ifdef __cplusplus +#define NIM_BOOL bool +#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +// see #13798: to avoid conflicts for code emitting `#include ` +#define NIM_BOOL _Bool +#else +typedef unsigned char NIM_BOOL; // best effort +#endif + +NIM_STATIC_ASSERT(sizeof(NIM_BOOL) == 1, ""); // check whether really needed +NIM_STATIC_ASSERT(CHAR_BIT == 8, ""); + // fail fast for (rare) environments where this doesn't hold, as some implicit + // assumptions would need revisiting (e.g. `uint8` or https://github.com/nim-lang/Nim/pull/18505) + +#define NIM_TRUE true +#define NIM_FALSE false + +#ifdef __cplusplus +# if __cplusplus >= 201103L +# /* nullptr is more type safe (less implicit conversions than 0) */ +# define NIM_NIL nullptr +# else +# // both `((void*)0)` and `NULL` would cause codegen to emit +# // error: assigning to 'Foo *' from incompatible type 'void *' +# // but codegen could be fixed if need. See also potential caveat regarding +# // NULL. +# // However, `0` causes other issues, see #13798 +# define NIM_NIL 0 +# endif +#else +# include +# define NIM_NIL ((void*)0) /* C's NULL is fucked up in some C compilers, so + the generated code does not rely on it anymore */ +#endif + +#if defined(__BORLANDC__) || defined(__DMC__) \ + || defined(__WATCOMC__) || defined(_MSC_VER) +typedef signed char NI8; +typedef signed short int NI16; +typedef signed int NI32; +typedef __int64 NI64; +/* XXX: Float128? */ +typedef unsigned char NU8; +typedef unsigned short int NU16; +typedef unsigned int NU32; +typedef unsigned __int64 NU64; +#elif defined(HAVE_STDINT_H) +#ifndef USE_NIM_NAMESPACE +# include +#endif +typedef int8_t NI8; +typedef int16_t NI16; +typedef int32_t NI32; +typedef int64_t NI64; +typedef uint8_t NU8; +typedef uint16_t NU16; +typedef uint32_t NU32; +typedef uint64_t NU64; +#elif defined(HAVE_CSTDINT) +#ifndef USE_NIM_NAMESPACE +# include +#endif +typedef std::int8_t NI8; +typedef std::int16_t NI16; +typedef std::int32_t NI32; +typedef std::int64_t NI64; +typedef std::uint8_t NU8; +typedef std::uint16_t NU16; +typedef std::uint32_t NU32; +typedef std::uint64_t NU64; +#else +/* Unknown compiler/version, do our best */ +#ifdef __INT8_TYPE__ +typedef __INT8_TYPE__ NI8; +#else +typedef signed char NI8; +#endif +#ifdef __INT16_TYPE__ +typedef __INT16_TYPE__ NI16; +#else +typedef signed short int NI16; +#endif +#ifdef __INT32_TYPE__ +typedef __INT32_TYPE__ NI32; +#else +typedef signed int NI32; +#endif +#ifdef __INT64_TYPE__ +typedef __INT64_TYPE__ NI64; +#else +typedef long long int NI64; +#endif +/* XXX: Float128? */ +#ifdef __UINT8_TYPE__ +typedef __UINT8_TYPE__ NU8; +#else +typedef unsigned char NU8; +#endif +#ifdef __UINT16_TYPE__ +typedef __UINT16_TYPE__ NU16; +#else +typedef unsigned short int NU16; +#endif +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ NU32; +#else +typedef unsigned int NU32; +#endif +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ NU64; +#else +typedef unsigned long long int NU64; +#endif +#endif + +#ifdef NIM_INTBITS +# if NIM_INTBITS == 64 +typedef NI64 NI; +typedef NU64 NU; +# elif NIM_INTBITS == 32 +typedef NI32 NI; +typedef NU32 NU; +# elif NIM_INTBITS == 16 +typedef NI16 NI; +typedef NU16 NU; +# elif NIM_INTBITS == 8 +typedef NI8 NI; +typedef NU8 NU; +# else +# error "invalid bit width for int" +# endif +#endif + +// for now there isn't an easy way for C code to reach the program result +// when hot code reloading is ON - users will have to: +// load the nimhcr.dll, get the hcrGetGlobal proc from there and use it +#ifndef NIM_HOT_CODE_RELOADING +extern NI nim_program_result; +#endif + +typedef float NF32; +typedef double NF64; +typedef double NF; + +typedef char NIM_CHAR; +typedef char* NCSTRING; + +#ifdef NIM_BIG_ENDIAN +# define NIM_IMAN 1 +#else +# define NIM_IMAN 0 +#endif + +#define NIM_STRLIT_FLAG ((NU)(1) << ((NIM_INTBITS) - 2)) /* This has to be the same as system.strlitFlag! */ + +#define STRING_LITERAL(name, str, length) \ + static const struct { \ + TGenericSeq Sup; \ + NIM_CHAR data[(length) + 1]; \ + } name = {{length, (NI) ((NU)length | NIM_STRLIT_FLAG)}, str} + +/* declared size of a sequence/variable length array: */ +#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) +# define SEQ_DECL_SIZE /* empty is correct! */ +#else +# define SEQ_DECL_SIZE 1000000 +#endif + +#define ALLOC_0(size) calloc(1, size) +#define DL_ALLOC_0(size) dlcalloc(1, size) + +#define paramCount() cmdCount + +// NAN definition copied from math.h included in the Windows SDK version 10.0.14393.0 +#ifndef NAN +# ifndef _HUGE_ENUF +# define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow +# endif +# define NAN_INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF)) +# define NAN ((float)(NAN_INFINITY * 0.0F)) +#endif + +#ifndef INF +# ifdef INFINITY +# define INF INFINITY +# elif defined(HUGE_VAL) +# define INF HUGE_VAL +# elif defined(_MSC_VER) +# include +# define INF (DBL_MAX+DBL_MAX) +# else +# define INF (1.0 / 0.0) +# endif +#endif + +typedef struct TFrame_ TFrame; +struct TFrame_ { + TFrame* prev; + NCSTRING procname; + NI line; + NCSTRING filename; + NI16 len; + NI16 calldepth; + NI frameMsgLen; +}; + +#define NIM_POSIX_INIT __attribute__((constructor)) + +#ifdef __GNUC__ +# define NIM_LIKELY(x) __builtin_expect(x, 1) +# define NIM_UNLIKELY(x) __builtin_expect(x, 0) +/* We need the following for the posix wrapper. In particular it will give us + POSIX_SPAWN_USEVFORK: */ +# ifndef _GNU_SOURCE +# define _GNU_SOURCE +# endif +#else +# define NIM_LIKELY(x) (x) +# define NIM_UNLIKELY(x) (x) +#endif + +#if 0 // defined(__GNUC__) || defined(__clang__) +// not needed anymore because the stack marking cares about +// interior pointers now +static inline void GCGuard (void *ptr) { asm volatile ("" :: "X" (ptr)); } +# define GC_GUARD __attribute__ ((cleanup(GCGuard))) +#else +# define GC_GUARD +#endif + +// Test to see if Nim and the C compiler agree on the size of a pointer. +NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, ""); + +#ifdef USE_NIM_NAMESPACE +} +#endif + +#if defined(_MSC_VER) +# define NIM_ALIGN(x) __declspec(align(x)) +# define NIM_ALIGNOF(x) __alignof(x) +#else +# define NIM_ALIGN(x) __attribute__((aligned(x))) +# define NIM_ALIGNOF(x) __alignof__(x) +#endif + +/* ---------------- platform specific includes ----------------------- */ + +/* VxWorks related includes */ +#if defined(__VXWORKS__) +# include +# include +# include +#elif defined(__FreeBSD__) +# include +#endif + +/* these exist to make the codegen logic simpler */ +#define nimModInt(a, b, res) (((*res) = (a) % (b)), 0) +#define nimModInt64(a, b, res) (((*res) = (a) % (b)), 0) + +#if (!defined(_MSC_VER) || defined(__clang__)) && !defined(NIM_EmulateOverflowChecks) + /* these exist because we cannot have .compilerProcs that are importc'ed + by a different name */ + + #define nimAddInt64(a, b, res) __builtin_saddll_overflow(a, b, (long long int*)res) + #define nimSubInt64(a, b, res) __builtin_ssubll_overflow(a, b, (long long int*)res) + #define nimMulInt64(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res) + + #if NIM_INTBITS == 32 + #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res) + #define nimSubInt(a, b, res) __builtin_ssub_overflow(a, b, res) + #define nimMulInt(a, b, res) __builtin_smul_overflow(a, b, res) + #else + /* map it to the 'long long' variant */ + #define nimAddInt(a, b, res) __builtin_saddll_overflow(a, b, (long long int*)res) + #define nimSubInt(a, b, res) __builtin_ssubll_overflow(a, b, (long long int*)res) + #define nimMulInt(a, b, res) __builtin_smulll_overflow(a, b, (long long int*)res) + #endif +#endif + +#define NIM_NOALIAS __restrict +/* __restrict is said to work for all the C(++) compilers out there that we support */ + +#endif /* NIMBASE_H */ diff --git a/Arduino/verify/verify.ino b/Arduino/verify/verify.ino new file mode 100644 index 000000000..78d29263c --- /dev/null +++ b/Arduino/verify/verify.ino @@ -0,0 +1,45 @@ +#include "import.hh" + +bool isTrue; +int LoopCounter = 0; +void setup() { + Serial.begin(9600); + Serial.printf("TESTING"); + + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + delay(2000); + + isTrue = makePairsAndVerify(&vkey, + &proof, + ¤tHeader, + &newOptimisticHeader, + &newFinalizedHeader, + &newExecutionStateRoot, + &new_slot, + &domain); + Serial.printf("End of Setup"); + + +} + + +void loop() { + Serial.println("Looping"); + LoopCounter++; + + Serial.print("LoopCounter value = "); + Serial.println(LoopCounter); + Serial.println("Print 1 if function returns "); + if(isTrue) + { + printf("1"); + } + + digitalWrite(LED_BUILTIN, LOW); + delay(2000); + + digitalWrite(LED_BUILTIN, HIGH); + delay(2000); + +}