diff --git a/src/circuit/ecc.rs b/src/circuit/ecc.rs index c05e6ca..71f1caa 100644 --- a/src/circuit/ecc.rs +++ b/src/circuit/ecc.rs @@ -32,8 +32,8 @@ use super::boolean::Boolean; #[derive(Clone)] pub struct EdwardsPoint { - pub x: AllocatedNum, - pub y: AllocatedNum + x: AllocatedNum, + y: AllocatedNum } /// Perform a fixed-base scalar multiplication with @@ -84,6 +84,14 @@ pub fn fixed_base_multiplication( } impl EdwardsPoint { + pub fn get_x(&self) -> &AllocatedNum { + &self.x + } + + pub fn get_y(&self) -> &AllocatedNum { + &self.y + } + pub fn assert_not_small_order( &self, mut cs: CS, @@ -183,12 +191,6 @@ impl EdwardsPoint { ) } - /// This extracts the x-coordinate, which is an injective - /// encoding for elements of the prime order subgroup. - pub fn into_num(&self) -> AllocatedNum { - self.x.clone() - } - /// Returns `self` if condition is true, and the neutral /// element (0, 1) otherwise. pub fn conditionally_select( diff --git a/src/circuit/mod.rs b/src/circuit/mod.rs index e461257..fa7df72 100644 --- a/src/circuit/mod.rs +++ b/src/circuit/mod.rs @@ -229,7 +229,7 @@ impl<'a, E: JubjubEngine> Circuit for Spend<'a, E> { let mut position_bits = vec![]; // Injective encoding. - let mut cur = cm.x.clone(); + let mut cur = cm.get_x().clone(); for (i, e) in self.auth_path.into_iter().enumerate() { let cs = &mut cs.namespace(|| format!("merkle tree hash {}", i)); @@ -268,7 +268,7 @@ impl<'a, E: JubjubEngine> Circuit for Spend<'a, E> { pedersen_hash::Personalization::MerkleTree(i), &preimage, self.params - )?.x; // Injective encoding + )?.get_x().clone(); // Injective encoding } assert_eq!(position_bits.len(), tree_depth); @@ -473,7 +473,7 @@ impl<'a, E: JubjubEngine> Circuit for Output<'a, E> { // since we know it is prime order, and we know that // the x-coordinate is an injective encoding for // prime-order elements. - cm.x.inputize(cs.namespace(|| "commitment"))?; + cm.get_x().inputize(cs.namespace(|| "commitment"))?; Ok(()) } diff --git a/src/circuit/pedersen_hash.rs b/src/circuit/pedersen_hash.rs index 8b3d715..407ef93 100644 --- a/src/circuit/pedersen_hash.rs +++ b/src/circuit/pedersen_hash.rs @@ -176,8 +176,8 @@ mod test { params ).into_xy(); - assert_eq!(res.x.get_value().unwrap(), expected.0); - assert_eq!(res.y.get_value().unwrap(), expected.1); + assert_eq!(res.get_x().get_value().unwrap(), expected.0); + assert_eq!(res.get_y().get_value().unwrap(), expected.1); // Test against the output of a different personalization let unexpected = ::pedersen_hash::pedersen_hash::( @@ -186,8 +186,8 @@ mod test { params ).into_xy(); - assert!(res.x.get_value().unwrap() != unexpected.0); - assert!(res.y.get_value().unwrap() != unexpected.1); + assert!(res.get_x().get_value().unwrap() != unexpected.0); + assert!(res.get_y().get_value().unwrap() != unexpected.1); } } }