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

Build without warnings #17

Merged
merged 3 commits into from Jun 20, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cargo/config
@@ -0,0 +1,3 @@
[alias]
tr = "test --release"
bs = "build --tests --features strict"
4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -39,3 +39,7 @@ debug = true # Debug symbols are required for profiling. Remove for production!
# TODO: Make sure it doesn't hurt wasm
[build]
rustflags = ["-C target-cpu=native"]

[features]
# Treat warnings as a build error.
strict = []
3 changes: 2 additions & 1 deletion src/fibonacci.rs
Expand Up @@ -672,7 +672,8 @@ pub fn fib_proof(witness: FieldElement) -> Channel {
}
0
};
proof.write(&pow_find_nonce(12).to_be_bytes());
let nonce = pow_find_nonce(12);
proof.write(&nonce.to_be_bytes());

let num_queries = 20;
let mut query_indices = Vec::with_capacity(num_queries + 3);
Expand Down
32 changes: 19 additions & 13 deletions src/field.rs
Expand Up @@ -110,21 +110,27 @@ impl FieldElement {
}

pub fn invert_batch(to_be_inverted: &[FieldElement]) -> Vec<FieldElement> {
let mut res = Vec::with_capacity(to_be_inverted.len());
for item in to_be_inverted.iter() {
res.push(item.clone())
}
let n = to_be_inverted.len();
let mut inverses = cumulative_product(to_be_inverted);

for x in 1..res.len() {
res[x] *= res[x - 1].clone();
}
let mut inv = res[res.len() - 1].inv().unwrap(); //TODO: Enforce check to prevent uninvertable elements
for x in (1..res.len()).rev() {
res[x] = &res[x - 1] * &inv;
inv *= to_be_inverted[x].clone();
// TODO: Enforce check to prevent uninvertable elements.
let mut inverse = inverses[n - 1].inv().unwrap();
for i in (1..n).rev() {
inverses[i] = &inverses[i - 1] * &inverse;
inverse *= &to_be_inverted[i];
}
res[0] = inv;
res.to_vec()
inverses[0] = inverse;
inverses
}

fn cumulative_product(elements: &[FieldElement]) -> Vec<FieldElement> {
elements
.iter()
.scan(FieldElement::ONE, |running_product, x| {
*running_product *= x;
Some(running_product.clone())
})
.collect()
}

impl From<U256> for FieldElement {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
@@ -1,5 +1,6 @@
// TODO: #![deny(warnings, missing_docs)]
// TODO: #![deny(missing_docs)]
#![warn(clippy::all)]
#![cfg_attr(feature = "strict", deny(warnings))]

pub mod binops;
pub mod channel;
Expand Down
3 changes: 1 addition & 2 deletions src/polynomial.rs
@@ -1,6 +1,4 @@
use crate::field::FieldElement;
use crate::u256h;
use hex_literal::*;

pub fn eval_poly(x: FieldElement, coefficients: &[FieldElement]) -> FieldElement {
let mut b = FieldElement::ZERO;
Expand All @@ -15,6 +13,7 @@ mod tests {
use super::*;
use crate::u256::*;
use crate::u256h;
use hex_literal::*;

#[test]
fn poly_eval_test() {
Expand Down