You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1006 B

5 years ago
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. #include "utils.h"
  5. #include "circom.h"
  6. #include "calcwit.h"
  7. auto j = R"(
  8. {
  9. "in": "314"
  10. }
  11. )"_json;
  12. typedef void (*ItFunc)(int idx, json val);
  13. void iterateArr(int o, Circom_Sizes sizes, json jarr, ItFunc f) {
  14. if (!jarr.is_array()) {
  15. assert((sizes[0] == 1)&&(sizes[1] == 0));
  16. f(o, jarr);
  17. } else {
  18. int n = sizes[0] / sizes[1];
  19. for (int i=0; i<n; i++) {
  20. iterateArr(o + i*sizes[1], sizes+1, jarr[i], f);
  21. }
  22. }
  23. }
  24. void itFunc(int o, json v) {
  25. std::cout << o << " <-- " << v << '\n';
  26. }
  27. int main(int argc, char **argv) {
  28. Circom_CalcWit *ctx = new Circom_CalcWit(&_circuit);
  29. for (json::iterator it = j.begin(); it != j.end(); ++it) {
  30. // std::cout << it.key() << " => " << it.value() << '\n';
  31. u64 h = fnv1a(it.key());
  32. int o = ctx->getSignalOffset(0, h);
  33. Circom_Sizes sizes = ctx->getSignalSizes(0, h);
  34. iterateArr(o, sizes, it.value(), itFunc);
  35. }
  36. }