static int test(char *buf, unsigned lineno) { char *last; char *c; uint32_t in[MAX_LENGTH_CANON]; size_t in_len; uint32_t out[MAX_LENGTH_CANON]; size_t out_len; uint32_t *tmp; size_t norm_len; int ret; c = strtok_r(buf, ";", &last); if (c == NULL) return 0; in_len = parse_vector(c, in); if (strtok_r(NULL, ";", &last) == NULL) return 0; if (strtok_r(NULL, ";", &last) == NULL) return 0; c = strtok_r(NULL, ";", &last); if (c == NULL) return 0; out_len = parse_vector(c, out); if (strtok_r(NULL, ";", &last) == NULL) return 0; c = last; norm_len = MAX_LENGTH_CANON; tmp = malloc(norm_len * sizeof(uint32_t)); if (tmp == NULL && norm_len != 0) err(1, "malloc"); ret = _wind_stringprep_normalize(in, in_len, tmp, &norm_len); if (ret) { printf("wind_stringprep_normalize %s failed\n", c); free(tmp); return 1; } if (out_len != norm_len) { printf("%u: wrong out len (%s)\n", lineno, c); dump_vector("Expected", out, out_len); dump_vector("Received", tmp, norm_len); free(tmp); return 1; } if (memcmp(out, tmp, out_len * sizeof(uint32_t)) != 0) { printf("%u: wrong out data (%s)\n", lineno, c); dump_vector("Expected", out, out_len); dump_vector("Received", tmp, norm_len); free(tmp); return 1; } free(tmp); return 0; }
void output_hist(ndim_histogram * h) { unsigned int i; long value; for (i = 0; i < h->size; i++) { value = ndim_histogram_get(h, i); if (value == 0) continue; dump_vector(get_lower_corner_for_index(h, i)); printf(".."); dump_vector(get_upper_corner_for_index(h, i)); printf("\t%lu\n", value); } }
/// /// Debug tools: print the content of a 2d map to stdout. /// void Utils::dump_map(const std::map<int, std::vector<int> >& map) { for ( std::map<int,std::vector<int> >::const_iterator it = map.begin(); it != map.end(); it++) { cout << "Key: " << it->first << endl; cout << "Values" << endl; dump_vector(it->second); } }
static void dump_data(void *pointer, tag_t *tag) { union_t u; u.v = pointer; switch (tag->type) { case type_char: printf("%d", *u.c); break; case type_uchar: printf("%x", *u.uc); break; case type_short: printf("%d", *u.s); break; case type_ushort: printf("%x", *u.us); break; case type_int: printf("%d", *u.i); break; case type_uint: printf("%x", *u.ui); break; case type_long: printf("%ld", *u.l); break; case type_ulong: printf("%lx", *u.ul); break; case type_float: printf("%f", *u.f); break; case type_double: printf("%f", *u.d); break; default: if (tag->type & type_pointer) printf("%p", u.p); else if (tag->type & type_vector) dump_vector(pointer, tag); else dump_record(pointer, tag); break; } }
void dump_matrix (double **m, int nr, int nc) { int i; for (i=0; i < nr; i++) dump_vector(m[i], nc); fprintf(stderr, "\n"); }
void Verifier::create_commitment_query() { cout << "LOG: Verifier is creating commitment queries." << endl; #if NONINTERACTIVE == 1 create_noninteractive_query(); #else string commitment_str = "fX_commitment_query"; vector < uint32_t >::const_iterator it = commitment_query_sizes.begin(); for (uint32_t i = 0; i < commitment_query_sizes.size(); i++) { v->create_commitment_query(commitment_query_sizes[i], f_commitment_ptrs[i], f_consistency_ptrs[i], prime); commitment_str[1] = '0' + (i + 1); bool prover_using_gpu = true; #if USE_GPU == 0 prover_using_gpu = false; #endif if (prover_using_gpu == false) { dump_vector_interleaved(expansion_factor * (commitment_query_sizes[i]), f_commitment_ptrs[i], const_cast<char *>(commitment_str.c_str())); } else { dump_vector(expansion_factor * (commitment_query_sizes[i]), f_commitment_ptrs[i], const_cast<char *>(commitment_str.c_str())); } send_file(const_cast<char *>(commitment_str.c_str())); } #endif }
static void RLE_demonstration(int rows, int cols) { int matrix[rows][cols]; int vector[rows*cols]; /* Set matrix */ for (RLE rle = RLE_init(rows, cols); !RLE_finished(&rle); RLE_next(&rle)) { #ifdef RLE_DUMP_REQUIRED RLE_dump("Set Matrix", &rle); #endif RC rc = RLE_position(&rle); matrix[rc.row][rc.col] = RLE_sequence(&rle); } dump_matrix("Matrix", rows, cols, matrix); /* Convert matrix to vector */ for (RLE rle = RLE_init(rows, cols); !RLE_finished(&rle); RLE_next(&rle)) { #ifdef RLE_DUMP_REQUIRED RLE_dump("Get Matrix", &rle); #endif RC rc = RLE_position(&rle); vector[RLE_sequence(&rle)] = matrix[rc.row][rc.col]; } dump_vector("Vector", rows, cols, vector); }
void pbqp_dump_node(FILE *file, pbqp_node_t *node) { if (node) { fprintf(file, "\tc<sub>%u</sub> = ", node->index); dump_vector(file, node->costs); fputs("<br>\n", file); } }
void ZComputationVerifier::create_input() { // as many computations as inputs for (int k=0; k<batch_size; k++) { int input_size = size_input; //v->get_random_vec(size_input, input, num_bits_in_input); //v->add_sign(size_input, input); input_creator->create_input(input_q, input_size); snprintf(scratch_str, BUFLEN-1, "input1_q_b_%d", k); dump_vector(input_size, input_q, scratch_str); send_file(scratch_str); convert_to_z(input_size, input, input_q, prime); snprintf(scratch_str, BUFLEN-1, "input1_b_%d", k); dump_vector(size_input, input, scratch_str); send_file(scratch_str); } }
void MatrixCubicVerifier::create_input() { // as many computations as inputs for (int k=0; k<batch_size; k++) { v->get_random_vec_priv(size_input, A, num_bits_in_input); v->add_sign(size_input, A); snprintf(scratch_str, BUFLEN-1, "input1_b_%d", k); dump_vector(size_input, A, scratch_str); send_file(scratch_str); } }
//Refer to apps_sfdl_gen/cql_rw_si_cons.h for constants to use when generating input. // this name stands for cql read/write select insert. void cql_rw_siVerifierInpGenHw::create_input(mpq_t* input_q, int num_inputs) { srand(time(NULL)); mpq_t* full_db_handle; int num_ints = sizeof(Student_handle_t) / sizeof(uint64_t); alloc_init_vec(&full_db_handle, num_ints); Student_handle_t handle; if (generate_states) { // SIZE should be a power of 2. int number_of_rows = SIZE - 1; // get the full handle of a DB. handle = create_db(number_of_rows, ("prover_1_" + shared_bstore_file_name).c_str()); uint64_t* input_ptr = (uint64_t*)&handle; for(int i = 0; i < num_ints; i++) { mpq_set_ui(full_db_handle[i], input_ptr[i], 1); } dump_vector(num_ints, full_db_handle, "db_handle", FOLDER_PERSIST_STATE); } else { // import the root hash from a place. load_vector(num_ints, full_db_handle, "db_handle", FOLDER_PERSIST_STATE); uint64_t* input_ptr = (uint64_t*)&handle; for(int i = 0; i < num_ints; i++) { input_ptr[i] = mpz_get_ui(mpq_numref(full_db_handle[i])); } } struct In input; Student_handle_t empty_handle; memset(&input, 0, sizeof(input)); // get a succinct handle of a DB using hashput. char db_file_path[BUFLEN]; snprintf(db_file_path, BUFLEN - 1, "%s/block_stores/prover_1_%s", FOLDER_STATE, shared_bstore_file_name.c_str()); HashBlockStore* bs = new ConfigurableBlockStore(db_file_path); hashput2(bs, &(input.db_handle), &handle); delete bs; // assign it to input_q uint64_t* input_ptr = (uint64_t*)&input.db_handle; int number_of_hash_elements = sizeof(hash_t) / sizeof(uint64_t); for(int i = 0; i < number_of_hash_elements; i++) { mpq_set_ui(input_q[i], input_ptr[i], 1); } for (int i = number_of_hash_elements; i < num_inputs; i++) { mpq_set_ui(input_q[i], rand(), 1); } clear_del_vec(full_db_handle, num_ints); }
void dct(int flag, int n) { double* in = malloc( n * sizeof(double)); double* out = malloc( n * sizeof(double)); // fftw_plan plan = fftw_plan_r2r_1d(n, in, out, flag, FFTW_ESTIMATE); for( int k = 0; k < n; k++) { // Init input vector for( int i = 0; i < n; i++) in[i] = 0; in[k] = 1; // Perform DFT fftw_execute(plan); // Print results dump_vector(n, in ); dump_vector(n, out); printf("\n"); } // free(in); free(out); fftw_destroy_plan(plan); }
static void test_8x8(void) { int vector[8*8]; int matrix[8][8] = { { 1, 2, 6, 7, 15, 16, 28, 29 }, { 3, 5, 8, 14, 17, 27, 30, 43 }, { 4, 9, 13, 18, 26, 31, 42, 44 }, { 10, 12, 19, 25, 32, 41, 45, 54 }, { 11, 20, 24, 33, 40, 46, 53, 55 }, { 21, 23, 34, 39, 47, 52, 56, 61 }, { 22, 35, 38, 48, 51, 57, 60, 62 }, { 36, 37, 49, 50, 58, 59, 63, 64 }, }; printf("\nTest 8x8\n\n"); print_info(8, 8); dump_matrix("Matrix", 8, 8, matrix); zigzag(8, 8, matrix, vector); dump_vector("Vector", 8, 8, vector); }
void dump(const mcmc ** chains, const unsigned int n_beta, const unsigned long iter, FILE * acceptance_file, FILE ** probabilities_file) { unsigned int i; if (iter % PRINT_PROB_INTERVAL == 0) { if (dumpflag) { report(chains, n_beta); dumpflag = 0; for (i = 0; i < n_beta; i++) { fflush(probabilities_file[i]); } } fprintf(acceptance_file, "%lu", iter); for (i = 0; i < n_beta; i++) { fprintf(acceptance_file, "\t%lu", get_params_accepts_global( chains[i])); } fprintf(acceptance_file, "\n"); fflush(acceptance_file); IFDEBUG { debug("dumping distribution"); dump_ul("iteration", iter); dump_ul("acceptance rate: accepts", get_params_accepts_global(chains[0])); dump_ul("acceptance rate: rejects", get_params_rejects_global(chains[0])); dump_mcmc(chains[0]); } else { printf("iteration: %lu, a/r: %.3f(%lu/%lu), v:", iter, (double) get_params_accepts_global(chains[0]) / (double) (get_params_accepts_global(chains[0]) + get_params_rejects_global(chains[0])), get_params_accepts_global(chains[0]), get_params_rejects_global(chains[0])); dump_vector(get_params(chains[0])); printf(" [%d/%lu ticks]\r", get_duration(), get_ticks_per_second()); fflush(stdout); } }
static void test_9x6(void) { enum { rows = 9 }; enum { cols = 6 }; int vector[rows * cols]; int matrix[rows][cols] = { { 1, 2, 6, 7, 15, 16, }, { 3, 5, 8, 14, 17, 27, }, { 4, 9, 13, 18, 26, 28, }, { 10, 12, 19, 25, 29, 39, }, { 11, 20, 24, 30, 38, 40, }, { 21, 23, 31, 37, 41, 48, }, { 22, 32, 36, 42, 47, 49, }, { 33, 35, 43, 46, 50, 53, }, { 34, 44, 45, 51, 52, 54, }, }; printf("\nTest 9x6\n\n"); print_info(rows, cols); dump_matrix("Matrix", rows, cols, matrix); zigzag(rows, cols, matrix, vector); dump_vector("Vector", rows, cols, vector); }
/* Compute the pseudoinverse of A and store it in A_plus A+ = VS+U* A m x n V m x m S n x n U m x n */ int pseudoinverse(gsl_matrix *A, gsl_matrix *A_plus) { int rc; double temp; int m = (int)(A->size1); int n = (int)(A->size2); gsl_vector *workspace = gsl_vector_alloc(n); gsl_matrix *V = gsl_matrix_alloc(n, n); gsl_matrix *S = gsl_matrix_alloc(n, n); gsl_matrix *U_times_S_plus_trans = gsl_matrix_alloc(m, n); gsl_vector *singular_values = gsl_vector_alloc(n); int i; double tolerance = 0; rc = gsl_linalg_SV_decomp(A, V, singular_values, workspace); // NOTE: this does a thin SVD // Now A = U dump_matrix(A, "U.dat"); dump_matrix(V, "V.dat"); dump_vector(singular_values, "S.dat"); if (rc) { // ERROR return rc; } // compute tolerace as MAX(SIZE(A)) * NORM(A) * EPS(class(A)) // singular values within tolerance of 0 are considered to be 0 tolerance = MAX(m,n) * gsl_vector_get(singular_values, 0) * DBL_EPSILON; //printf("tolerance = %g\n", tolerance); // compute S+ // by taking reciprocal of nonzero entries for (i = 0 ; i < n ; i++) { temp = gsl_vector_get(singular_values, i); if (temp < tolerance) { break; // singular values are non-negative and form a non-increasing sequence } gsl_matrix_set(S, i, i, 1 / temp); } // now S = S+* // compute US+* rc = gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, A, S, 0.0, U_times_S_plus_trans); // now A = US+* if (rc) { // ERROR return rc; } // compute VS+U rc = gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, V, U_times_S_plus_trans, 0.0, A_plus); // now A_plus = VS+U if (rc) { // ERROR return rc; } // cleanup gsl_vector_free(workspace); gsl_matrix_free(V); gsl_matrix_free(S); gsl_matrix_free(U_times_S_plus_trans); gsl_vector_free(singular_values); return 0; }
void dump_node(int indent, Node *node) { switch (node->kind) { case NODE_ROOT: case NODE_DECLN: case NODE_COMPOUND_STMT: indented_puts(indent, kind_label(node->kind)); dump_vector(indent + 1, node->children); break; case NODE_PTR: case NODE_RETURN: indented_puts(indent, kind_label(node->kind)); if (node->param) dump_node(indent + 1, node->param); break; case NODE_FUNC: indented_puts(indent, kind_label(node->kind)); dump_nodes(indent + 1, 3, node->type, node->spec, node->stmts); break; case NODE_PARAM_DECL: indented_puts(indent, kind_label(node->kind)); dump_node(indent + 1, node->type); if (node->spec) dump_node(indent + 1, node->spec); break; case NODE_FUNC_DECL: case NODE_VAR_DECL: indented_puts(indent, kind_label(node->kind)); dump_nodes(indent + 1, 2, node->type, node->spec); break; case NODE_FUNCALL: case NODE_FUNC_SPEC: indented_puts(indent, kind_label(node->kind)); dump_node(indent + 1, node->func); dump_vector(indent + 1, node->params); break; case NODE_TYPE: indented_printf(indent, "%s", kind_label(node->kind)); print_types(node); printf("\n"); if (node->fields) dump_vector(indent + 1, node->fields); break; case NODE_FIELD: indented_printf(indent, "%s\n", kind_label(node->kind)); dump_node(indent + 1, node->field_type); dump_vector(indent + 1, node->fields); break; case NODE_IDENTIFIER: case NODE_SPEC: case NODE_STRING: case NODE_DEFINED: indented_printf(indent, "%s id=%s\n", kind_label(node->kind), node->id); break; case NODE_INTEGER: indented_printf(indent, "%s ival=%d\n", kind_label(node->kind), node->ival); break; case NODE_BINOP: indented_printf(indent, "%s '%c'\n", kind_label(node->kind), node->op); dump_node(indent + 1, node->lhs); dump_node(indent + 1, node->rhs); break; case NODE_UNARY: if ((int)node->op >= 256) { indented_printf(indent, "%s token %d\n", kind_label(node->kind), (int)node->op); } else { indented_printf(indent, "%s %c\n", kind_label(node->kind), node->op); } if (node->lhs) dump_node(indent + 1, node->lhs); if (node->rhs) dump_node(indent + 1, node->rhs); break; case NODE_IF: indented_puts(indent, kind_label(node->kind)); dump_node(indent + 1, node->cond); dump_node(indent + 1, node->if_stmt); if (node->else_stmt) dump_node(indent + 1, node->else_stmt); break; case NODE_ARRAY_SPEC: indented_puts(indent, kind_label(node->kind)); dump_node(indent + 1, node->lhs); dump_node(indent + 1, node->rhs); break; default: indented_puts(indent, kind_label(node->kind)); break; } }
void MatrixCubicVerifier::create_plain_queries() { uint32_t m2 = input_size*input_size; // keeps track of #filled coins int f1_con_filled = -1; for (int rho=0; rho<num_repetitions; rho++) { if (rho == 0) m_plainq.begin_with_init(); else m_plainq.begin_with_history(); int query_id = 1; for (int i=0; i<NUM_REPS_LIN; i++) { v->create_lin_test_queries(hadamard_code_size, f1_q1, f1_q2, f1_q3, f1_consistency, f1_con_filled, f_con_coins, prime); f1_con_filled += 3; //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(hadamard_code_size, f1_q1, scratch_str); //send_file(scratch_str); //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(hadamard_code_size, f1_q2, scratch_str); //send_file(scratch_str); query_id++; //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(hadamard_code_size, f1_q3, scratch_str); //send_file(scratch_str); // use one of the linearity queries as self correction queries if (i == 0) { for (int i=0; i<hadamard_code_size; i++) mpz_set(f1_q4[i], f1_q1[i]); } } // f1_q1 = q3 // f1_q2 = q4 // f2_q1 = q1 // f2_q2 = q2 mpz_set_ui(f_con_coins[f1_con_filled+1], 0); mpz_set_ui(f_con_coins[f1_con_filled+2], 0); f1_con_filled += 2; query_id += 2; v->create_corr_test_queries_vproduct(input_size, f2_q1, f2_q2, f1_q1, f1_q4, f1_consistency, f1_con_filled, f_con_coins, prime); f1_con_filled += 1; //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(hadamard_code_size, f1_q1, scratch_str); //send_file(scratch_str); m_plainq.end(); // compute answers to f1(q1) and f1(q2) locally now itself if (rho == 0) m_runtests.begin_with_init(); else m_runtests.begin_with_history(); for (int b=0; b<batch_size; b++) { mpz_set_ui(a1, 0); mpz_set_ui(a2, 0); snprintf(scratch_str, BUFLEN-1, "input1_b_%d", b); load_vector(2*input_size*input_size, A, scratch_str); //snprintf(scratch_str, BUFLEN-1, "input1_b_%d", b); //load_vector(input_size*input_size, B, scratch_str); int index; mpz_set_ui(a3, 0); for (int k=0; k<input_size; k++) { // dot product of k^th row of A with k^th row of f2_q1 //\sum_{j=1}{m}{A[k][j] \cdot f2_q1[k][j]} mpz_set_ui(a1, 0); mpz_set_ui(a2, 0); for (int j=0; j<input_size; j++) { index = j*input_size+k; mpz_mul(temp, A[index], f2_q1[index]); mpz_add(a1, a1, temp); } for (int i=0; i<input_size; i++) { index = k*input_size+i; mpz_mul(temp, B[index], f2_q2[index]); mpz_add(a2, a2, temp); } mpz_mul(temp, a1, a2); mpz_add(a3, a3, temp); mpz_mod(a3, a3, prime); } snprintf(scratch_str, BUFLEN-1, "corr_answer_b_%d_r_%d", b, rho); dump_scalar(a3, scratch_str); } m_runtests.end(); // circuit test m_plainq.begin_with_history(); v->get_random_vec_pub(input_size*input_size, gamma, prime); for (int i=0; i<hadamard_code_size; i++) mpz_set_ui(f1_q1[i], 0); int index, index2; for (int i=0; i<input_size; i++) { for (int j=0; j<input_size; j++) { // add gamma[i*input_size+j] to all the cells in query index2 = i*input_size+j; for (int k=0; k<input_size; k++) { index = index2 * input_size+k; mpz_add(f1_q1[index], f1_q1[index], gamma[index2]); } } } for (int i=0; i<input_size*input_size*input_size; i++) mpz_mod(f1_q1[i], f1_q1[i], prime); v->create_ckt_test_queries(hadamard_code_size, f1_q1, f1_q3, f1_q4, f1_consistency, f1_con_filled, f_con_coins, prime); //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(hadamard_code_size, f1_q3, scratch_str); //send_file(scratch_str); f1_con_filled += 1; m_plainq.end(); m_runtests.begin_with_history(); // finally compute c for (int i=0; i<batch_size; i++) { snprintf(scratch_str, BUFLEN-1, "output_b_%d", i); load_vector(input_size*input_size, C, scratch_str); int c_index = i * num_repetitions + rho; mpz_set_ui(c_values[c_index], 0); for (int j=0; j<input_size*input_size; j++) { mpz_neg(temp, gamma[j]); mpz_mul(temp, temp, C[j]); mpz_add(c_values[c_index], c_values[c_index], temp); } } m_runtests.end(); } dump_vector(hadamard_code_size, f1_consistency, (char *)"f1_consistency_query"); send_file((char *)"f1_consistency_query"); }
void ZComputationVerifier::create_plain_queries() { clear_vec(size_f1_vec*expansion_factor, f1_commitment); clear_vec(size_f2_vec*expansion_factor, f2_commitment); m_plainq.begin_with_init(); // keeps track of #filled coins int f_con_filled = -1; int query_id; for (int rho=0; rho<num_repetitions; rho++) { if (rho == 0) m_plainq.begin_with_init(); else m_plainq.begin_with_history(); // create linearity test queries query_id = 1; for (int i=0; i<NUM_REPS_LIN; i++) { v->create_lin_test_queries(size_f1_vec, f1_q1, f1_q2, f1_q3, f1_consistency, f_con_filled, f_con_coins, prime); f_con_filled += 3; v->create_lin_test_queries(size_f2_vec, f2_q1, f2_q2, f2_q3, f2_consistency, f_con_filled, f_con_coins, prime); f_con_filled += 3; //TODO: can be folded into a function /* snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q1, scratch_str); send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q2, scratch_str); send_file(scratch_str); // don't dump, but increment query_id query_id++; //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(size_f1_vec, f1_q3, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q1, scratch_str); send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q2, scratch_str); send_file(scratch_str); query_id++; //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); //dump_vector(size_f2_vec, f2_q3, scratch_str); //send_file(scratch_str); */ // use one of the linearity queries as self correction queries if (i == 0) { for (int i=0; i<size_f1_vec; i++) mpz_set(f1_q4[i], f1_q1[i]); for (int i=0; i<size_f2_vec; i++) mpz_set(f2_q4[i], f2_q1[i]); } } for (int i=0; i<n+1; i++) { mpz_set_ui(eval_poly_A[i], 0); mpz_set_ui(eval_poly_B[i], 0); mpz_set_ui(eval_poly_C[i], 0); } // create zquad correction queries: create q9, q10, q11, and q12 v->create_div_corr_test_queries(n, size_f1_vec, size_f2_vec, f1_q1, f1_q2, f1_q3, f2_q1, f_con_coins, f_con_filled, f1_consistency, f_con_coins, f_con_filled+3, f2_consistency, f1_q4, f2_q4, d_star[rho], num_aij, num_bij, num_cij, set_v, poly_A, poly_B, poly_C, eval_poly_A, eval_poly_B, eval_poly_C, prime); f_con_filled += 4; int base = rho * (1 + size_input + size_output); mpz_set(A_tau_io[base+0], eval_poly_A[0]); mpz_set(B_tau_io[base+0], eval_poly_B[0]); mpz_set(C_tau_io[base+0], eval_poly_C[0]); for (int i=0; i<size_input+size_output; i++) { mpz_set(A_tau_io[base+1+i], eval_poly_A[1+n_prime+i]); mpz_set(B_tau_io[base+1+i], eval_poly_B[1+n_prime+i]); mpz_set(C_tau_io[base+1+i], eval_poly_C[1+n_prime+i]); } /* snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q1, scratch_str); send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q2, scratch_str); send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q3, scratch_str); send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q1, scratch_str); send_file(scratch_str); */ } dump_vector(size_f1_vec, f1_consistency, (char *)"f1_consistency_query"); send_file((char *)"f1_consistency_query"); dump_vector(size_f2_vec, f2_consistency, (char *)"f2_consistency_query"); send_file((char *)"f2_consistency_query"); m_plainq.end(); // cleanup time clear_vec(n+1, eval_poly_A); clear_vec(n+1, eval_poly_B); clear_vec(n+1, eval_poly_C); clear_vec(size_f1_vec, f1_consistency); clear_vec(size_f2_vec, f2_consistency); for (int i=0; i<num_aij; i++) clear_scalar(poly_A[i].coefficient); for (int i=0; i<num_bij; i++) clear_scalar(poly_B[i].coefficient); for (int i=0; i<num_cij; i++) clear_scalar(poly_C[i].coefficient); free(poly_A); free(poly_B); free(poly_C); clear_vec(size_f1_vec, f1_q1); clear_vec(size_f1_vec, f1_q2); clear_vec(size_f1_vec, f1_q3); clear_vec(size_f1_vec, f1_q4); clear_vec(size_f2_vec, f2_q1); clear_vec(size_f2_vec, f2_q2); clear_vec(size_f2_vec, f2_q3); clear_vec(size_f2_vec, f2_q4); // Ginger's codebase did some run test part of work in plain query // creation; so the base class calls with history; m_runtests.reset(); }
int main() { int i,j,pn=0; std::vector<int> output_l, output_a, output_b; for(j=0;polygon[j] != -2;pn++) { float avgx=0, avgy=0; for(i=0;polygon[j+i+1]!=-1;i++) { int p0 = polygon[j+i], p1 = polygon[j+i+1]; float x0 = vertex[p0*2]*xscale, y0 = vertex[p0*2+1]*yscale, x1 = vertex[p1*2]*xscale, y1 = vertex[p1*2+1]*yscale, dx = x1-x0, dy = y1-y0; avgx += x0; avgy += y0; float norm = sqrt(dx*dx + dy*dy); // L(x,y) is the half-plane normal = line segment vector (dx,dy) rotated // 90 degrees left (on a left-handed coordinate system) float Lx = dy; float Ly = -dx; float angle = round(angle_quantum*atan2(Ly, Lx)/M_PI); //if(angle<0) angle += 2*angle_quantum; // positive angles only? no need // todo: quantize Lx,Ly // just use sin/cos? 64 angles? float Lx2 = cos(M_PI*angle/angle_quantum); float Ly2 = sin(M_PI*angle/angle_quantum); // calculate B based on center of segment so any angle errors are // propagated equally through the segment float B = Lx2*(x0+x1)/2+Ly2*(y0+y1)/2; float B2 = ceil(offset_quantum*B/offset_max); // hmm, we need to slightly inflate this away from the polygon centroid but how? // round B2 such that ((x0+x1)/2, (y0+y1)/2) is in the interior float B2scaled = offset_max*B2/offset_quantum; if(Lx2*(x0+x1)/2 + Ly2*(y0+y1)/2 < B2scaled) { B2--; } if(B2 == offset_quantum) B2--; B2scaled = offset_max*B2/offset_quantum; float ax = avgx/(1+i); float ay = avgy/(1+i); printf("// polygon %d segment %d (%d-%d): L=(%g,%g) B=%g check(%g,%g)=%g\n", pn, i, p0,p1, Lx,Ly,B, ax/xscale,ay/yscale, ax*Lx+ay*Ly-B); //printf("a=%g,(%g,%g)->(%g,%g),%g,\n", angle, Lx/norm,Ly/norm, Lx2,Ly2,B); printf("// %d,%d,\n", (int)angle, (int)B2); int aa = (int) angle; int bb = (int) B2; // -32 to 31 int e1 = aa, e2 = -bb; output_a.push_back(e1); output_b.push_back(e2); printf("%g,%g,%g,\n", Lx2,Ly2,B2scaled); } output_l.push_back(output_a.size()); printf("-99,\n"); j += i+2; } printf("-98\n"); printf("// anglescale = %g ^-1 = %g\n", M_PI/angle_quantum, angle_quantum/M_PI); printf("// offsetscale = %g ^-1 = %g\n", offset_max/offset_quantum, offset_quantum/offset_max); dump_vector(output_l, "length", 50); dump_vector(output_a, "a", 79); dump_vector(output_b, "b", 79); printf("// total length=%d\n", output_a.size()); }
void PolyEvalD3Prover::deduce_queries() { int f_con_filled = -1; load_vector(num_coefficients, coefficients, (char *)"coefficients"); for (int rho=0; rho<num_repetitions; rho++) { if (rho == 0) m_plainq.begin_with_init(); else m_plainq.begin_with_history(); int query_id = 1; for (int i=0; i<NUM_REPS_LIN; i++) { v->create_lin_test_queries(size_f1_vec, f1_q1, f1_q2, f1_q3, NULL, f_con_filled, NULL, prime); f_con_filled += 3; v->create_lin_test_queries(size_f2_vec, f2_q1, f2_q2, f2_q3, NULL, f_con_filled, NULL, prime); f_con_filled += 3; v->create_lin_test_queries(size_f3_vec, f3_q1, f3_q2, f3_q3, NULL, f_con_filled, NULL, prime); f_con_filled += 3; //TODO: can be folded into a function snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q1, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q2, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q3, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q1, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q2, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q3, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f3_vec, f3_q1, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f3_vec, f3_q2, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f3_vec, f3_q3, scratch_str); //send_file(scratch_str); // use one of the linearity queries as self correction queries if (i == 0) { for (int i=0; i<size_f1_vec; i++) { mpz_set(f1_q4[i], f1_q1[i]); mpz_set(f1_q5[i], f1_q2[i]); } for (int i=0; i<size_f2_vec; i++) mpz_set(f2_q4[i], f2_q1[i]); for (int i=0; i<size_f3_vec; i++) mpz_set(f3_q4[i], f3_q1[i]); } } v->create_corr_test_queries_reuse(size_f1_vec, f1_q4, size_f1_vec, f1_q5, f2_q1, f2_q4, NULL, NULL, NULL, f_con_filled, NULL, f_con_filled, NULL, f_con_filled, NULL, prime, false); f_con_filled += 1; snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q1, scratch_str); //send_file(scratch_str); v->create_corr_test_queries_reuse(size_f1_vec, f1_q4, size_f2_vec, f2_q4, f3_q1, f3_q4, NULL, NULL, NULL, f_con_filled, NULL, f_con_filled, NULL, f_con_filled, NULL, prime, false); f_con_filled += 1; snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f3_vec, f3_q1, scratch_str); //send_file(scratch_str); // circuit test v->get_random_vec_pub(size_f1_vec+1, alpha, prime); // formulate a; a = -\alpha_0 \cdot degree-2 coefficients mpz_neg(neg, alpha[0]); // set the query to zero first for (int i=0; i<size_f3_vec; i++) { mpz_set_ui(f3_q1[i], 0); } int index_coefficients = 0; int index_query = 0; for (int i=0; i<size_f1_vec; i++) { for (int j=0; j<=i; j++) { for (int k=0; k<=j; k++) { index_query = (i*size_f1_vec+j)*size_f1_vec+k; mpz_mul(f3_q1[index_query], neg, coefficients[index_coefficients]); mpz_mod(f3_q1[index_query], f3_q1[index_query], prime); index_coefficients++; } } } int offset = (size_f3_vec + 3*size_f2_vec + 2*size_f1_vec)/6; // quadratic part of circuit test query for (int i=0; i<size_f2_vec; i++) { mpz_set_ui(f2_q1[i], 0); } int index; int k = 0; for (int i=0; i<size_f1_vec; i++) { for (int j=0; j<=i; j++) { index = size_f1_vec*i + j; mpz_mul(f2_q1[index], neg, coefficients[offset+k]); mpz_mod(f2_q1[index], f2_q1[index], prime); k++; } } offset += (size_f1_vec * size_f1_vec + size_f1_vec)/2; // formulate b; b = -\alpha_0 \cdot degree-1 coefficients + [\alpha_1, // \alpha_2, ... , \alpha_{size_f1_vec+1}] for (int i=0; i<size_f1_vec; i++) { mpz_mul(f1_q2[i], neg, coefficients[offset+i]); mpz_add(f1_q2[i], alpha[i+1], f1_q2[i]); mpz_mod(f1_q2[i], f1_q2[i], prime); } v->create_ckt_test_queries(size_f1_vec, f1_q2, f1_q3, f1_q4, NULL, f_con_filled, NULL, prime); f_con_filled += 1; v->create_ckt_test_queries(size_f2_vec, f2_q1, f2_q3, f2_q4, NULL, f_con_filled, NULL, prime); f_con_filled += 1; v->create_ckt_test_queries(size_f3_vec, f3_q1, f3_q3, f3_q4, NULL, f_con_filled, NULL, prime); f_con_filled += 1; snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f1_vec, f1_q3, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f2_vec, f2_q3, scratch_str); //send_file(scratch_str); snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho); dump_vector(size_f3_vec, f3_q3, scratch_str); //send_file(scratch_str); m_plainq.end(); } }
//PROVER's CODE void PolyEvalD3Prover:: prover_computation_commitment() { load_vector(expansion_factor*m, f1_commitment, (char *)"f1_commitment_query", FOLDER_WWW_DOWNLOAD); load_vector(expansion_factor*size_f2_vec, f2_commitment, (char *)"f2_commitment_query", FOLDER_WWW_DOWNLOAD); load_vector(expansion_factor*size_f3_vec, f3_commitment, (char *)"f3_commitment_query", FOLDER_WWW_DOWNLOAD); m_computation.begin_with_init(); //for (int k=0; k<INNER_LOOP_SMALL; k++) load_vector(num_coefficients, coefficients, (char *)"coefficients", FOLDER_WWW_DOWNLOAD); m_computation.end(); for (int i=batch_start; i<=batch_end; i++) { m_computation.begin_with_history(); //for (int k=0; k<INNER_LOOP_SMALL; k++) { snprintf(scratch_str, BUFLEN-1, "input_b_%d", i); load_vector(m, variables, scratch_str, FOLDER_WWW_DOWNLOAD); for (int j=0; j<expansion_factor; j++) mpz_set_ui(output[j], 0); computation_polyeval(output[0]); // start saving the state snprintf(scratch_str, BUFLEN-1, "output_b_%d", i); dump_scalar(output[0], scratch_str, FOLDER_WWW_DOWNLOAD); } m_computation.end(); computation_assignment(output[0]); snprintf(scratch_str, BUFLEN-1, "f1_assignment_vector_b_%d", i); dump_vector(m, F1, scratch_str, FOLDER_WWW_DOWNLOAD); snprintf(scratch_str, BUFLEN-1, "f2_assignment_vector_b_%d", i); dump_vector(size_f2_vec, F2, scratch_str, FOLDER_WWW_DOWNLOAD); snprintf(scratch_str, BUFLEN-1, "f3_assignment_vector_b_%d", i); dump_vector(size_f3_vec, F3, scratch_str, FOLDER_WWW_DOWNLOAD); } for (int i=batch_start; i<=batch_end; i++) { if (i == 0) m_answer_queries.begin_with_init(); else m_answer_queries.begin_with_history(); snprintf(scratch_str, BUFLEN-1, "f1_assignment_vector_b_%d", i); load_vector(m, F1, scratch_str, FOLDER_WWW_DOWNLOAD); snprintf(scratch_str, BUFLEN-1, "f2_assignment_vector_b_%d", i); load_vector(size_f2_vec, F2, scratch_str, FOLDER_WWW_DOWNLOAD); snprintf(scratch_str, BUFLEN-1, "f3_assignment_vector_b_%d", i); load_vector(size_f3_vec, F3, scratch_str, FOLDER_WWW_DOWNLOAD); v->dot_product_enc(m, f1_commitment, F1, dotp[0], dotp[1]); v->dot_product_enc(size_f2_vec, f2_commitment, F2, output[0], output[1]); v->add_enc(dotp[0], dotp[1], dotp[0], dotp[1], output[0], output[1]); v->dot_product_enc(size_f3_vec, f3_commitment, F3, output[0], output[1]); v->add_enc(dotp[0], dotp[1], dotp[0], dotp[1], output[0], output[1]); snprintf(scratch_str, BUFLEN-1, "f_commitment_answer_b_%d", i); dump_vector(expansion_factor, dotp, scratch_str, FOLDER_WWW_DOWNLOAD); m_answer_queries.end(); } }