Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed divisions #336

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,8 @@ namespace nil {
std::size_t id1 = s_indices[j][0] < s_indices[j][1] ? 1 : 0;
Q[j][0] -= combined_U[p];
Q[j][1] -= combined_U[p];
Q[j][0] /= denominators[p].evaluate(s[j][id0]);
Q[j][1] /= denominators[p].evaluate(s[j][id1]);
Q[j][0] *= denominators[p].evaluate(s[j][id0]).inversed();
Q[j][1] *= denominators[p].evaluate(s[j][id1]).inversed();
y[j][0] += Q[j][0];
y[j][1] += Q[j][1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ namespace nil {
return element_kc(this->g.doubled(), this->h.doubled());
}

void mixed_add(const element_kc &other) {
g.mixed_add(other.g);
h.mixed_add(other.h);
}

void double_inplace() {
g.double_inplace();
h.double_inplace();
}
element_kc& operator+=(const element_kc &other) {
g += other.g;
h += other.h;
return *this;
}

element_kc to_projective() {
return element_kc(this->g.to_projective(), this->h.to_projective());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace nil {
auto reduced_g = reduce_dfs_polynomial_domain(g, basic_domain->m);
auto reduced_h = reduce_dfs_polynomial_domain(h, basic_domain->m);
for( std::size_t j = 0; j < preprocessed_data.common_data.desc.usable_rows_amount; j++){
current_poly[j] = (previous_poly[j] * reduced_g[j]) / reduced_h[j];
current_poly[j] = (previous_poly[j] * reduced_g[j]) * reduced_h[j].inversed();
}
commitment_scheme.append_to_batch(PERMUTATION_BATCH, current_poly);
auto par = lookup_alphas[i] * (previous_poly * g - current_poly * h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace nil {
nom *= g_v[i][j - 1];
denom *= h_v[i][j - 1];
}
V_P[j] = V_P[j - 1] * nom / denom;
V_P[j] = V_P[j - 1] * nom * denom.inversed();
}

// 4. Compute and add commitment to $V_P$ to $\text{transcript}$.
Expand Down Expand Up @@ -198,7 +198,7 @@ namespace nil {
auto reduced_g = reduce_dfs_polynomial_domain(g, basic_domain->m);
auto reduced_h = reduce_dfs_polynomial_domain(h, basic_domain->m);
for(std::size_t j = 0; j < preprocessed_data.common_data.desc.usable_rows_amount; j++){
current_poly[j] = (previous_poly[j] * reduced_g[j]) / reduced_h[j];
current_poly[j] = (previous_poly[j] * reduced_g[j]) * reduced_h[j].inversed();
}
commitment_scheme.append_to_batch(PERMUTATION_BATCH, current_poly);
auto part = permutation_alphas[i] * (previous_poly * g - current_poly * h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace nil {
auto omega = common_data.basic_domain->get_domain_element(1);
auto challenge = proof.eval_proof.challenge;
auto numerator = challenge.pow(table_description.rows_amount) - FieldType::value_type::one();
numerator /= typename FieldType::value_type(table_description.rows_amount);
numerator *= typename FieldType::value_type(table_description.rows_amount).inversed();

// If public input sizes are set, all of them should be set.
if(constraint_system.public_input_sizes_num() != 0 && constraint_system.public_input_sizes_num() != table_description.public_input_columns){
Expand All @@ -165,7 +165,7 @@ namespace nil {
max_size = std::min(max_size, constraint_system.public_input_size(i));
auto omega_pow = FieldType::value_type::one();
for( std::size_t j = 0; j < max_size; ++j ){
value += (public_input[i][j] * omega_pow) / (challenge - omega_pow);
value += (public_input[i][j] * omega_pow) * (challenge - omega_pow).inversed();
omega_pow = omega_pow * omega;
}
value *= numerator;
Expand Down