Skip to content

Commit

Permalink
Reworking hash concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer committed May 22, 2024
1 parent 7966aeb commit 0b44ee9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions crates/core/src/address/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ pub enum Discriminant {
IbcToken = 13,
/// MASP raw address.
Masp = 14,
/// Replay protection
ReplayProtection = 15,
/// Temporary storage address.
TempStorage = 16,
TempStorage = 15,
/// Replay protection
ReplayProtection = 16,
}

/// Raw address representation.
Expand Down
10 changes: 4 additions & 6 deletions crates/core/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Types for working with 32 bytes hashes.

use std::fmt::{self, Display};
use std::ops::Add;
use std::str::FromStr;

use arse_merkle_tree::traits::Hasher;
Expand Down Expand Up @@ -155,12 +154,11 @@ impl Hash {
pub const fn as_ptr(&self) -> *const u8 {
self.0.as_ptr()
}
}

impl<'a> Add<&'a Hash> for Hash {
type Output = Self;

fn add(self, rhs: &'a Hash) -> Self::Output {
/// Given hashes A and B, compute Sha256(A||B),
/// but if one value is the zero hash, the other
/// value is returned.
pub fn concat(self, rhs: &Hash) -> Self {
let mut hasher = Sha256::default();
if self.is_zero() {
*rhs
Expand Down
2 changes: 1 addition & 1 deletion crates/state/src/wl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ where
batch,
&replay_protection::current_key(hash),
)?;
acc = acc + hash;
acc = acc.concat(hash);
Ok::<_, Error>(acc)
})?;
self.write(&replay_prot_key, new_commitment)?;
Expand Down

0 comments on commit 0b44ee9

Please sign in to comment.