summing two sum_commits rolls the switch commit hashes up (#634)

This commit is contained in:
AntiochP 2018-01-18 17:25:10 -05:00 committed by GitHub
parent 911aadf8b4
commit 6b0f1fc20e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
} }
} }
} }