1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

merge dev

This commit is contained in:
schaeff 2019-01-21 14:21:03 +01:00
commit ef5e8fff6c
4 changed files with 39 additions and 62 deletions

23
Cargo.lock generated
View file

@ -309,6 +309,16 @@ dependencies = [
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-bigint"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.39"
@ -795,7 +805,7 @@ dependencies = [
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
"zokrates_core 0.3.3",
"zokrates_field 0.3.0",
"zokrates_field 0.3.1",
"zokrates_fs_resolver 0.3.2",
]
@ -822,19 +832,21 @@ dependencies = [
"serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"zokrates_field 0.3.0",
"zokrates_field 0.3.1",
]
[[package]]
name = "zokrates_field"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
"num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -886,6 +898,7 @@ dependencies = [
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
"checksum num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1"
"checksum num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57450397855d951f1a41305e54851b1a7b8f5d2e349543a02a2effe25459f718"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"

View file

@ -1,6 +1,6 @@
[package]
name = "zokrates_field"
version = "0.3.0"
version = "0.3.1"
authors = ["Guillaume Ballet <gballet@gmail.com>"]
edition = "2018"
@ -8,6 +8,11 @@ edition = "2018"
serde = "1.0"
serde_derive = "1.0"
lazy_static = "0.1.*"
num = {version = "0.1.36", default-features = false}
num-bigint = {version = "0.1.36", default-features = false}
bincode = "0.8.0"
bincode = "0.8.0"
serde_json = "1.0"
num-traits = "0.2"
num-integer = "0.1"
[dependencies.num-bigint]
version = "0.2"
features = ["serde"]

View file

@ -4,10 +4,11 @@
// @author Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>
// @date 2017
use num::{Integer, Num, One, Zero};
use lazy_static::lazy_static;
use num_bigint::{BigInt, BigUint, Sign, ToBigInt};
use serde::de::{Deserialize, Deserializer, Visitor};
use serde::{Serialize, Serializer};
use num_integer::Integer;
use num_traits::{Num, One, Zero};
use serde_derive::{Deserialize, Serialize};
use std::convert::From;
use std::fmt;
use std::fmt::{Debug, Display};
@ -71,7 +72,7 @@ pub trait Field:
fn get_required_bits() -> usize;
}
#[derive(PartialEq, PartialOrd, Clone, Eq, Ord, Hash)]
#[derive(PartialEq, PartialOrd, Clone, Eq, Ord, Hash, Serialize, Deserialize)]
pub struct FieldPrime {
value: BigInt,
}
@ -323,49 +324,6 @@ impl<'a> Pow<&'a FieldPrime> for FieldPrime {
}
}
// custom serde serialization
impl Serialize for FieldPrime {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
// serializer.serialize_bytes(&(*self.value.to_biguint().to_bytes_le().as_slice()))
serializer.serialize_bytes(&(*self.into_byte_vector().as_slice()))
}
}
// custom serde deserialization
struct FieldPrimeVisitor;
impl FieldPrimeVisitor {
fn new() -> Self {
FieldPrimeVisitor {}
}
}
impl<'de> Visitor<'de> for FieldPrimeVisitor {
type Value = FieldPrime;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("struct FieldPrime")
}
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E> {
let val = BigUint::from_bytes_le(v).to_bigint().unwrap();
Ok(FieldPrime { value: val })
}
}
impl<'de> Deserialize<'de> for FieldPrime {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_bytes(FieldPrimeVisitor::new())
}
}
/// Calculates the gcd using an iterative implementation of the extended euclidian algorithm.
/// Returning `(d, s, t)` so that `d = s * a + t * b`
///
@ -633,6 +591,13 @@ mod tests {
assert_eq!(FieldPrime::from("11"), deserialized);
}
#[test]
fn serde_json_ser_deser() {
let serialized = serde_json::to_string(&FieldPrime::from("11")).unwrap();
let deserialized = serde_json::from_str(&serialized).unwrap();
assert_eq!(FieldPrime::from("11"), deserialized);
}
#[test]
fn bytes_ser_deser() {
let fp = FieldPrime::from("101");

View file

@ -1,7 +1 @@
#[macro_use]
extern crate lazy_static;
extern crate num;
extern crate num_bigint;
extern crate serde;
pub mod field;