diff --git a/zebra-chain/src/commitments/sapling.rs b/zebra-chain/src/commitments/sapling.rs index b56e1e2a7..11cc6fa2a 100644 --- a/zebra-chain/src/commitments/sapling.rs +++ b/zebra-chain/src/commitments/sapling.rs @@ -316,13 +316,12 @@ impl ValueCommitment { /// Generate a new _ValueCommitment_. /// /// https://zips.z.cash/protocol/protocol.pdf#concretehomomorphiccommit - // TODO: accept an Amount instead? #[allow(non_snake_case)] - pub fn new(csprng: &mut T, value_bytes: [u8; 32]) -> Self + pub fn new(csprng: &mut T, value: Amount) -> Self where T: RngCore + CryptoRng, { - let v = jubjub::Fr::from_bytes(&value_bytes).unwrap(); + let v = jubjub::Fr::from(value); let rcv = generate_trapdoor(csprng); let V = find_group_hash(*b"Zcash_cv", b"v"); diff --git a/zebra-chain/src/types/amount.rs b/zebra-chain/src/types/amount.rs index 7efe87405..3747a05e6 100644 --- a/zebra-chain/src/types/amount.rs +++ b/zebra-chain/src/types/amount.rs @@ -132,6 +132,16 @@ impl From> for u64 { } } +impl From> for jubjub::Fr { + fn from(a: Amount) -> jubjub::Fr { + if a.0 < 0 { + jubjub::Fr::from(a.0.abs() as u64).neg() + } else { + jubjub::Fr::from(a.0 as u64) + } + } +} + impl TryFrom for Amount where C: AmountConstraint,