Rename into_ -> to_ where &self is used.

This commit is contained in:
Jack Grigg
2019-08-02 12:00:15 +01:00
parent 91541675e2
commit fe93f2ff6b
17 changed files with 70 additions and 70 deletions

View File

@@ -50,7 +50,7 @@ fn main() {
nsk: nsk.clone(),
};
let viewing_key = proof_generation_key.into_viewing_key(jubjub_params);
let viewing_key = proof_generation_key.to_viewing_key(jubjub_params);
let payment_address;
@@ -61,7 +61,7 @@ fn main() {
Diversifier(d)
};
if let Some(p) = viewing_key.into_payment_address(diversifier, jubjub_params) {
if let Some(p) = viewing_key.to_payment_address(diversifier, jubjub_params) {
payment_address = p;
break;
}

View File

@@ -121,9 +121,9 @@ impl<E: JubjubEngine> EdwardsPoint<E> {
{
let mut tmp = vec![];
let x = self.x.into_bits_le_strict(cs.namespace(|| "unpack x"))?;
let x = self.x.to_bits_le_strict(cs.namespace(|| "unpack x"))?;
let y = self.y.into_bits_le_strict(cs.namespace(|| "unpack y"))?;
let y = self.y.to_bits_le_strict(cs.namespace(|| "unpack y"))?;
tmp.extend(y);
tmp.push(x[0].clone());
@@ -141,7 +141,7 @@ impl<E: JubjubEngine> EdwardsPoint<E> {
where
CS: ConstraintSystem<E>,
{
let p = p.map(|p| p.into_xy());
let p = p.map(|p| p.to_xy());
// Allocate x
let x = AllocatedNum::alloc(cs.namespace(|| "x"), || Ok(p.get()?.0))?;
@@ -688,8 +688,8 @@ mod test {
let mut cs = TestConstraintSystem::<Bls12>::new();
let p = montgomery::Point::<Bls12, _>::rand(rng, params);
let (u, v) = edwards::Point::from_montgomery(&p, params).into_xy();
let (x, y) = p.into_xy().unwrap();
let (u, v) = edwards::Point::from_montgomery(&p, params).to_xy();
let (x, y) = p.to_xy().unwrap();
let numx = AllocatedNum::alloc(cs.namespace(|| "mont x"), || Ok(x)).unwrap();
let numy = AllocatedNum::alloc(cs.namespace(|| "mont y"), || Ok(y)).unwrap();
@@ -728,7 +728,7 @@ mod test {
let mut cs = TestConstraintSystem::<Bls12>::new();
let q = EdwardsPoint::witness(&mut cs, Some(p.clone()), &params).unwrap();
let p = p.into_xy();
let p = p.to_xy();
assert!(cs.is_satisfied());
assert_eq!(q.x.get_value().unwrap(), p.0);
@@ -737,7 +737,7 @@ mod test {
for _ in 0..100 {
let p = edwards::Point::<Bls12, _>::rand(rng, &params);
let (x, y) = p.into_xy();
let (x, y) = p.to_xy();
let mut cs = TestConstraintSystem::<Bls12>::new();
let numx = AllocatedNum::alloc(cs.namespace(|| "x"), || Ok(x)).unwrap();
@@ -779,7 +779,7 @@ mod test {
let p = params.generator(FixedGenerators::NoteCommitmentRandomness);
let s = Fs::random(rng);
let q = p.mul(s, params);
let (x1, y1) = q.into_xy();
let (x1, y1) = q.to_xy();
let mut s_bits = BitIterator::new(s.into_repr()).collect::<Vec<_>>();
s_bits.reverse();
@@ -823,8 +823,8 @@ mod test {
let s = Fs::random(rng);
let q = p.mul(s, params);
let (x0, y0) = p.into_xy();
let (x1, y1) = q.into_xy();
let (x0, y0) = p.to_xy();
let (x1, y1) = q.to_xy();
let num_x0 = AllocatedNum::alloc(cs.namespace(|| "x0"), || Ok(x0)).unwrap();
let num_y0 = AllocatedNum::alloc(cs.namespace(|| "y0"), || Ok(y0)).unwrap();
@@ -873,7 +873,7 @@ mod test {
let p = edwards::Point::<Bls12, _>::rand(rng, params);
let (x0, y0) = p.into_xy();
let (x0, y0) = p.to_xy();
let num_x0 = AllocatedNum::alloc(cs.namespace(|| "x0"), || Ok(x0)).unwrap();
let num_y0 = AllocatedNum::alloc(cs.namespace(|| "y0"), || Ok(y0)).unwrap();
@@ -941,9 +941,9 @@ mod test {
let p3 = p1.add(&p2, params);
let (x0, y0) = p1.into_xy();
let (x1, y1) = p2.into_xy();
let (x2, y2) = p3.into_xy();
let (x0, y0) = p1.to_xy();
let (x1, y1) = p2.to_xy();
let (x2, y2) = p3.to_xy();
let mut cs = TestConstraintSystem::<Bls12>::new();
@@ -1002,8 +1002,8 @@ mod test {
let p1 = edwards::Point::<Bls12, _>::rand(rng, params);
let p2 = p1.double(params);
let (x0, y0) = p1.into_xy();
let (x1, y1) = p2.into_xy();
let (x0, y0) = p1.to_xy();
let (x1, y1) = p2.to_xy();
let mut cs = TestConstraintSystem::<Bls12>::new();
@@ -1053,9 +1053,9 @@ mod test {
let p3 = p1.add(&p2, params);
let (x0, y0) = p1.into_xy().unwrap();
let (x1, y1) = p2.into_xy().unwrap();
let (x2, y2) = p3.into_xy().unwrap();
let (x0, y0) = p1.to_xy().unwrap();
let (x1, y1) = p2.to_xy().unwrap();
let (x2, y2) = p3.to_xy().unwrap();
let mut cs = TestConstraintSystem::<Bls12>::new();

View File

@@ -189,7 +189,7 @@ mod test {
input.clone().into_iter(),
params,
)
.into_xy();
.to_xy();
assert_eq!(res.get_x().get_value().unwrap(), expected.0);
assert_eq!(res.get_y().get_value().unwrap(), expected.1);
@@ -200,7 +200,7 @@ mod test {
input.into_iter(),
params,
)
.into_xy();
.to_xy();
assert!(res.get_x().get_value().unwrap() != unexpected.0);
assert!(res.get_y().get_value().unwrap() != unexpected.1);

View File

@@ -336,8 +336,8 @@ impl<'a, E: JubjubEngine> Circuit<E> for Spend<'a, E> {
// they will be unable to find an authentication path in the
// tree with high probability.
let mut preimage = vec![];
preimage.extend(xl.into_bits_le(cs.namespace(|| "xl into bits"))?);
preimage.extend(xr.into_bits_le(cs.namespace(|| "xr into bits"))?);
preimage.extend(xl.to_bits_le(cs.namespace(|| "xl into bits"))?);
preimage.extend(xr.to_bits_le(cs.namespace(|| "xr into bits"))?);
// Compute the new subtree value
cur = pedersen_hash::pedersen_hash(
@@ -464,7 +464,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for Output<'a, E> {
// they would like.
{
// Just grab pk_d from the witness
let pk_d = self.payment_address.as_ref().map(|e| e.pk_d.into_xy());
let pk_d = self.payment_address.as_ref().map(|e| e.pk_d.to_xy());
// Witness the y-coordinate, encoded as little
// endian bits (to match the representation)
@@ -567,7 +567,7 @@ fn test_input_circuit_with_bls12_381() {
nsk: nsk.clone(),
};
let viewing_key = proof_generation_key.into_viewing_key(params);
let viewing_key = proof_generation_key.to_viewing_key(params);
let payment_address;
@@ -578,7 +578,7 @@ fn test_input_circuit_with_bls12_381() {
Diversifier(d)
};
if let Some(p) = viewing_key.into_payment_address(diversifier, params) {
if let Some(p) = viewing_key.to_payment_address(diversifier, params) {
payment_address = p;
break;
}
@@ -590,8 +590,8 @@ fn test_input_circuit_with_bls12_381() {
let ar = fs::Fs::random(rng);
{
let rk = viewing_key.rk(ar, params).into_xy();
let expected_value_cm = value_commitment.cm(params).into_xy();
let rk = viewing_key.rk(ar, params).to_xy();
let expected_value_cm = value_commitment.cm(params).to_xy();
let note = Note {
value: value_commitment.value,
g_d: g_d.clone(),
@@ -626,7 +626,7 @@ fn test_input_circuit_with_bls12_381() {
.chain(rhs.into_iter().take(Fr::NUM_BITS as usize)),
params,
)
.into_xy()
.to_xy()
.0;
if b {
@@ -714,7 +714,7 @@ fn test_output_circuit_with_bls12_381() {
nsk: nsk.clone(),
};
let viewing_key = proof_generation_key.into_viewing_key(params);
let viewing_key = proof_generation_key.to_viewing_key(params);
let payment_address;
@@ -725,7 +725,7 @@ fn test_output_circuit_with_bls12_381() {
Diversifier(d)
};
if let Some(p) = viewing_key.into_payment_address(diversifier, params) {
if let Some(p) = viewing_key.to_payment_address(diversifier, params) {
payment_address = p;
break;
}
@@ -759,13 +759,13 @@ fn test_output_circuit_with_bls12_381() {
.expect("should be valid")
.cm(params);
let expected_value_cm = value_commitment.cm(params).into_xy();
let expected_value_cm = value_commitment.cm(params).to_xy();
let expected_epk = payment_address
.g_d(params)
.expect("should be valid")
.mul(esk, params);
let expected_epk_xy = expected_epk.into_xy();
let expected_epk_xy = expected_epk.to_xy();
assert_eq!(cs.num_inputs(), 6);
assert_eq!(cs.get_input(0, "ONE"), Fr::one());

View File

@@ -79,10 +79,10 @@ impl SaplingProvingContext {
};
// Construct the viewing key
let viewing_key = proof_generation_key.into_viewing_key(params);
let viewing_key = proof_generation_key.to_viewing_key(params);
// Construct the payment address with the viewing key / diversifier
let payment_address = match viewing_key.into_payment_address(diversifier, params) {
let payment_address = match viewing_key.to_payment_address(diversifier, params) {
Some(p) => p,
None => return Err(()),
};
@@ -130,12 +130,12 @@ impl SaplingProvingContext {
// Construct public input for circuit
let mut public_input = [Fr::zero(); 7];
{
let (x, y) = rk.0.into_xy();
let (x, y) = rk.0.to_xy();
public_input[0] = x;
public_input[1] = y;
}
{
let (x, y) = value_commitment.cm(params).into_xy();
let (x, y) = value_commitment.cm(params).to_xy();
public_input[2] = x;
public_input[3] = y;
}

View File

@@ -82,12 +82,12 @@ impl SaplingVerificationContext {
// Construct public input for circuit
let mut public_input = [Fr::zero(); 7];
{
let (x, y) = rk.0.into_xy();
let (x, y) = rk.0.to_xy();
public_input[0] = x;
public_input[1] = y;
}
{
let (x, y) = cv.into_xy();
let (x, y) = cv.to_xy();
public_input[2] = x;
public_input[3] = y;
}
@@ -146,12 +146,12 @@ impl SaplingVerificationContext {
// Construct public input for circuit
let mut public_input = [Fr::zero(); 5];
{
let (x, y) = cv.into_xy();
let (x, y) = cv.to_xy();
public_input[0] = x;
public_input[1] = y;
}
{
let (x, y) = epk.into_xy();
let (x, y) = epk.to_xy();
public_input[2] = x;
public_input[3] = y;
}