pset: remove one more intermediate-zero check from the blinding logic

This commit is contained in:
Andrew Poelstra 2021-10-01 18:12:36 +00:00
parent 9eb285c19d
commit a67a2df330

View file

@ -311,8 +311,17 @@ bool ComputeAndAddToScalarOffset(uint256& a, CAmount value, const uint256& asset
if (a.IsNull()) {
a = scalar;
} else {
// If we have a, then add the scalar to it.
if (secp256k1_ec_privkey_tweak_add(secp256k1_blind_context, a.begin(), scalar.begin()) != 1) return false;
uint256 scalar_negated = scalar;
if (secp256k1_ec_seckey_negate(secp256k1_blind_context, scalar_negated.begin()) != 1) {
return false;
}
// Special-case zero, which would otherwise cause `secp256k1_ec_privkey_tweak_add` to fail
if (scalar_negated == a) {
a = uint256{};
} else {
// If we have a, then add the scalar to it.
if (secp256k1_ec_privkey_tweak_add(secp256k1_blind_context, a.begin(), scalar.begin()) != 1) return false;
}
}
return true;
}