diff --git a/goas/atomic_asset_transfer/common/src/lib.rs b/goas/atomic_asset_transfer/common/src/lib.rs index e351dcd..59c1901 100644 --- a/goas/atomic_asset_transfer/common/src/lib.rs +++ b/goas/atomic_asset_transfer/common/src/lib.rs @@ -1,6 +1,6 @@ pub mod mmr; -use cl::{balance::Unit, merkle, NoteCommitment}; +use cl::{balance::Unit, NoteCommitment}; use ed25519_dalek::{ ed25519::{signature::SignerMut, SignatureBytes}, Signature, SigningKey, VerifyingKey, PUBLIC_KEY_LENGTH, @@ -12,11 +12,6 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::collections::BTreeMap; -// TODO: sparse merkle tree -pub const MAX_BALANCES: usize = 1 << 8; -pub const MAX_TXS: usize = 1 << 8; -pub const MAX_EVENTS: usize = 1 << 8; - // state of the zone #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] pub struct StateCommitment(pub [u8; 32]); @@ -105,14 +100,15 @@ impl StateWitness { } pub fn balances_root(&self) -> [u8; 32] { - let balance_bytes = Vec::from_iter(self.balances.iter().map(|(owner, balance)| { - let mut bytes: Vec = vec![]; - bytes.extend(owner); - bytes.extend(balance.to_le_bytes()); - bytes - })); - let balance_merkle_leaves = cl::merkle::padded_leaves(&balance_bytes); - merkle::root::(balance_merkle_leaves) + let mut hasher = Sha256::new(); + hasher.update(b"NOMOS_BALANCES_ROOT"); + + for (k, v) in self.balances.iter() { + hasher.update(k); + hasher.update(&v.to_le_bytes()); + } + + hasher.finalize().into() } pub fn total_balance(&self) -> u64 {