mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
summing two sum_commits rolls the switch commit hashes up (#634)
This commit is contained in:
parent
911aadf8b4
commit
6b0f1fc20e
1 changed files with 16 additions and 1 deletions
|
@ -847,6 +847,7 @@ impl ops::Add for SumCommit {
|
||||||
type Output = SumCommit;
|
type Output = SumCommit;
|
||||||
|
|
||||||
fn add(self, other: SumCommit) -> SumCommit {
|
fn add(self, other: SumCommit) -> SumCommit {
|
||||||
|
// Build a new commitment by summing the two commitments.
|
||||||
let secp = static_secp_instance();
|
let secp = static_secp_instance();
|
||||||
let sum = match secp.lock().unwrap().commit_sum(
|
let sum = match secp.lock().unwrap().commit_sum(
|
||||||
vec![
|
vec![
|
||||||
|
@ -858,10 +859,24 @@ impl ops::Add for SumCommit {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => Commitment::from_vec(vec![1; 33]),
|
Err(_) => Commitment::from_vec(vec![1; 33]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Now build a new switch_commit_hash by concatenating the two switch_commit_hash value
|
||||||
|
// and hashing the result.
|
||||||
|
let mut bytes = self.switch_commit_hash.0.to_vec();
|
||||||
|
bytes.extend(other.switch_commit_hash.0.iter().cloned());
|
||||||
|
let key = SwitchCommitHashKey::zero();
|
||||||
|
let hash = blake2b(SWITCH_COMMIT_HASH_SIZE, &key.0, &bytes);
|
||||||
|
let hash = hash.as_bytes();
|
||||||
|
let mut h = [0; SWITCH_COMMIT_HASH_SIZE];
|
||||||
|
for i in 0..SWITCH_COMMIT_HASH_SIZE {
|
||||||
|
h[i] = hash[i];
|
||||||
|
}
|
||||||
|
let switch_commit_hash_sum = SwitchCommitHash(h);
|
||||||
|
|
||||||
SumCommit {
|
SumCommit {
|
||||||
features: self.features | other.features,
|
features: self.features | other.features,
|
||||||
commit: sum,
|
commit: sum,
|
||||||
switch_commit_hash: SwitchCommitHash::zero(),
|
switch_commit_hash: switch_commit_hash_sum,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue