Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
  • Loading branch information
conradoplg and jvff authored Jun 21, 2021
1 parent 403df0b commit dd2cf2d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 51 deletions.
24 changes: 5 additions & 19 deletions zebra-chain/src/orchard/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,11 @@ impl NoteCommitment {
let psi_bytes: [u8; 32] = psi.into();

// g*d || pk*d || I2LEBSP_64(v) || I2LEBSP_l^Orchard_Base(ρ) || I2LEBSP_l^Orchard_base(ψ)
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&g_d_bytes[..])
.expect("must work for small slices"),
);
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&pk_d_bytes[..])
.expect("must work for small slices"),
);
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&v_bytes[..]).expect("must work for small slices"),
);
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&rho_bytes[..])
.expect("must work for small slices"),
);
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&psi_bytes[..])
.expect("must work for small slices"),
);
s.extend(g_d_bytes);
s.extend(pk_d_bytes);
s.extend(v_bytes);
s.extend(rho_bytes);
s.extend(psi_bytes);

let rcm = CommitmentRandomness(generate_trapdoor(csprng));

Expand Down
10 changes: 2 additions & 8 deletions zebra-chain/src/orchard/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,8 @@ impl From<FullViewingKey> for IncomingViewingKey {
fn from(fvk: FullViewingKey) -> Self {
let mut M: BitVec<Lsb0, u8> = BitVec::new();

M.append(
&mut BitVec::<Lsb0, u8>::from_slice(&<[u8; 32]>::from(fvk.spend_validating_key)[..])
.expect("must work for small slices"),
);
M.append(
&mut BitVec::<Lsb0, u8>::from_slice(&<[u8; 32]>::from(fvk.nullifier_deriving_key)[..])
.expect("must work for small slices"),
);
M.extend(<[u8; 32]>::from(fvk.spend_validating_key));
M.extend(<[u8; 32]>::from(fvk.nullifier_deriving_key));

// Commit^ivk_rivk
let commit_x = sinsemilla_short_commit(
Expand Down
10 changes: 3 additions & 7 deletions zebra-chain/src/orchard/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ fn merkle_crh_orchard(layer: u8, left: [u8; 32], right: [u8; 32]) -> [u8; 32] {
let mut s = bitvec![Lsb0, u8;];

// Prefix: l = I2LEBSP_10(MerkleDepth^Orchard − 1 − layer)
s.extend_from_bitslice(&BitSlice::<Lsb0, _>::from_element(&layer)[0..10]);
s.extend_from_bitslice(
&BitSlice::<Lsb0, _>::from_slice(&left).expect("must work for small slices")[0..255],
);
s.extend_from_bitslice(
&BitSlice::<Lsb0, _>::from_slice(&right).expect("must work for small slices")[0..255],
);
s.extend_from_bitslice(&BitArray::<Lsb0, _>::from([layer, 0])[0..10]);
s.extend_from_bitslice(&BitArray::<Lsb0, _>::from(left)[0..255]);
s.extend_from_bitslice(&BitArray::<Lsb0, _>::from(right)[0..255]);

sinsemilla_hash(b"z.cash:Orchard-MerkleCRH", &s).to_bytes()
}
Expand Down
14 changes: 3 additions & 11 deletions zebra-chain/src/sapling/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,9 @@ impl NoteCommitment {
let pk_d_bytes = <[u8; 32]>::from(transmission_key);
let v_bytes = value.to_bytes();

s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&g_d_bytes[..])
.expect("must work for small slices"),
);
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&pk_d_bytes[..])
.expect("must work for small slices"),
);
s.append(
&mut BitVec::<Lsb0, u8>::from_slice(&v_bytes[..]).expect("must work for small slices"),
);
s.extend(g_d_bytes);
s.extend(pk_d_bytes);
s.extend(v_bytes);

let rcm = CommitmentRandomness(generate_trapdoor(csprng));

Expand Down
8 changes: 2 additions & 6 deletions zebra-chain/src/sapling/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ fn merkle_crh_sapling(layer: u8, left: [u8; 32], right: [u8; 32]) -> [u8; 32] {

// Prefix: l = I2LEBSP_6(MerkleDepth^Sapling − 1 − layer)
s.extend_from_bitslice(&BitSlice::<Lsb0, _>::from_element(&layer)[0..6]);
s.extend_from_bitslice(
&BitSlice::<Lsb0, _>::from_slice(&left).expect("must work for small slices")[0..255],
);
s.extend_from_bitslice(
&BitSlice::<Lsb0, _>::from_slice(&right).expect("must work for small slices")[0..255],
);
s.extend_from_bitslice(&BitArray::<Lsb0, _>::from(left)[0..255]);
s.extend_from_bitslice(&BitArray::<Lsb0, _>::from(right)[0..255]);

pedersen_hash(*b"Zcash_PH", &s).to_bytes()
}
Expand Down

0 comments on commit dd2cf2d

Please sign in to comment.