From ced738f852b641b3804f4292fe4f37fd4d8fbe87 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 22:59:26 -0700 Subject: [PATCH] use from y coordinate from snarkos --- Cargo.lock | 75 ++++++++++--------- .../src/value/group/targets/edwards_bls12.rs | 45 ++++++----- compiler/tests/group/mod.rs | 46 ++++++------ 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71b34d3eeb..0192e3c510 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,7 +128,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -220,9 +220,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.13" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" +checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" dependencies = [ "num-integer", "num-traits", @@ -420,7 +420,7 @@ checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -438,7 +438,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -449,9 +449,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "encoding_rs" @@ -503,7 +503,7 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "synstructure", ] @@ -677,9 +677,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.3" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -738,9 +738,9 @@ checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" [[package]] name = "hashbrown" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" dependencies = [ "autocfg", ] @@ -846,9 +846,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" +checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9" dependencies = [ "autocfg", "hashbrown", @@ -1411,7 +1411,7 @@ dependencies = [ "pest_meta", "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1442,7 +1442,7 @@ checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1805,7 +1805,7 @@ checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1873,14 +1873,14 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" +checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "snarkos-algorithms" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "blake2", "derivative", @@ -1900,7 +1900,7 @@ dependencies = [ [[package]] name = "snarkos-curves" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "derivative", "rand", @@ -1915,17 +1915,17 @@ dependencies = [ [[package]] name = "snarkos-derives" version = "0.1.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] name = "snarkos-dpc" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "blake2", "derivative", @@ -1946,7 +1946,7 @@ dependencies = [ [[package]] name = "snarkos-errors" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "base58", "bech32", @@ -1954,12 +1954,13 @@ dependencies = [ "hex", "jsonrpc-core", "thiserror", + "toml", ] [[package]] name = "snarkos-gadgets" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "derivative", "digest 0.8.1", @@ -1974,7 +1975,7 @@ dependencies = [ [[package]] name = "snarkos-models" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "bincode", "derivative", @@ -1990,7 +1991,7 @@ dependencies = [ [[package]] name = "snarkos-objects" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "base58", "bech32", @@ -2011,7 +2012,7 @@ dependencies = [ [[package]] name = "snarkos-parameters" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "hex", "snarkos-algorithms", @@ -2023,12 +2024,12 @@ dependencies = [ [[package]] name = "snarkos-profiler" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" [[package]] name = "snarkos-utilities" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "bincode", "rand", @@ -2073,9 +2074,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", @@ -2090,7 +2091,7 @@ checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "unicode-xid 0.2.1", ] @@ -2143,7 +2144,7 @@ checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -2406,7 +2407,7 @@ dependencies = [ "log", "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "wasm-bindgen-shared", ] @@ -2440,7 +2441,7 @@ checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index a53be4e1f7..a6e20a4769 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -188,31 +188,30 @@ impl EdwardsGroupType { pub fn edwards_affine_from_y_str( y_string: String, y_span: Span, - _greatest: Option, - _element_span: Span, + greatest: Option, + element_span: Span, ) -> Result { - let _y = Fq::from_str(&y_string).map_err(|_| GroupError::y_invalid(y_string, y_span))?; + let y = Fq::from_str(&y_string).map_err(|_| GroupError::y_invalid(y_string, y_span))?; - unimplemented!("recover from_y_coordinate not implemented for Edwards Affine") - // match greatest { - // // Sign provided - // Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)), - // // Sign inferred - // None => { - // // Attempt to recover with a sign_low bit. - // if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) { - // return Ok(element); - // } - // - // // Attempt to recover with a sign_high bit. - // if let Some(element) = EdwardsAffine::from_y_coordinate(y, true) { - // return Ok(element); - // } - // - // // Otherwise return error. - // Err(GroupError::y_recover(element_span)) - // } - // } + match greatest { + // Sign provided + Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)), + // Sign inferred + None => { + // Attempt to recover with a sign_low bit. + if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) { + return Ok(element); + } + + // Attempt to recover with a sign_high bit. + if let Some(element) = EdwardsAffine::from_y_coordinate(y, true) { + return Ok(element); + } + + // Otherwise return error. + Err(GroupError::y_recover(element_span)) + } + } } pub fn edwards_affine_from_pair( diff --git a/compiler/tests/group/mod.rs b/compiler/tests/group/mod.rs index eebdd96bb2..676059271f 100644 --- a/compiler/tests/group/mod.rs +++ b/compiler/tests/group/mod.rs @@ -66,29 +66,29 @@ fn test_x_sign_inferred() { assert_satisfied(program); } -// #[test] -// fn test_y_sign_high() { -// let bytes = include_bytes!("y_sign_high.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } -// -// #[test] -// fn test_y_sign_low() { -// let bytes = include_bytes!("y_sign_low.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } -// -// #[test] -// fn test_y_sign_inferred() { -// let bytes = include_bytes!("y_sign_inferred.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } +#[test] +fn test_y_sign_high() { + let bytes = include_bytes!("y_sign_high.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_y_sign_low() { + let bytes = include_bytes!("y_sign_low.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_y_sign_inferred() { + let bytes = include_bytes!("y_sign_inferred.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} #[test] fn test_double_high() {