Update secp256k1 dependency

Update our `rust-secp256k1` dependency to the latest version.

Requires doing:

- Add a new variant to `Error` for the case where parity of the internal
  key is an invalid value (not 0 or 1).
- Use non-deprecated const
This commit is contained in:
Tobin Harding 2022-03-11 09:41:32 +11:00
parent 337caad880
commit d68531d815
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
3 changed files with 8 additions and 4 deletions

View File

@ -36,7 +36,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies] [dependencies]
bech32 = { version = "0.8.1", default-features = false } bech32 = { version = "0.8.1", default-features = false }
bitcoin_hashes = { version = "0.10.0", default-features = false } bitcoin_hashes = { version = "0.10.0", default-features = false }
secp256k1 = { version = "0.21.2", default-features = false } secp256k1 = { version = "0.22.0", default-features = false }
core2 = { version = "0.3.0", optional = true, default-features = false } core2 = { version = "0.3.0", optional = true, default-features = false }
base64-compat = { version = "1.0.0", optional = true } base64-compat = { version = "1.0.0", optional = true }
@ -47,7 +47,7 @@ hashbrown = { version = "0.8", optional = true }
[dev-dependencies] [dev-dependencies]
serde_json = "<1.0.45" serde_json = "<1.0.45"
serde_test = "1" serde_test = "1"
secp256k1 = { version = "0.21.2", features = [ "recovery", "rand-std" ] } secp256k1 = { version = "0.22.0", features = [ "recovery", "rand-std" ] }
bincode = "1.3.1" bincode = "1.3.1"
# We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0 # We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0
ryu = "<1.0.5" ryu = "<1.0.5"

View File

@ -174,7 +174,7 @@ impl TweakedPublicKey {
/// the y-coordinate is represented by only a single bit, as x determines /// the y-coordinate is represented by only a single bit, as x determines
/// it up to one bit. /// it up to one bit.
#[inline] #[inline]
pub fn serialize(&self) -> [u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE] { pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] {
self.0.serialize() self.0.serialize()
} }
} }

View File

@ -682,7 +682,8 @@ impl ControlBlock {
{ {
return Err(TaprootError::InvalidControlBlockSize(sl.len())); return Err(TaprootError::InvalidControlBlockSize(sl.len()));
} }
let output_key_parity = secp256k1::Parity::from((sl[0] & 1) as i32); let output_key_parity = secp256k1::Parity::from_i32((sl[0] & 1) as i32)
.map_err(TaprootError::InvalidParity)?;
let leaf_version = LeafVersion::from_consensus(sl[0] & TAPROOT_LEAF_MASK)?; let leaf_version = LeafVersion::from_consensus(sl[0] & TAPROOT_LEAF_MASK)?;
let internal_key = UntweakedPublicKey::from_slice(&sl[1..TAPROOT_CONTROL_BASE_SIZE]) let internal_key = UntweakedPublicKey::from_slice(&sl[1..TAPROOT_CONTROL_BASE_SIZE])
.map_err(TaprootError::InvalidInternalKey)?; .map_err(TaprootError::InvalidInternalKey)?;
@ -970,6 +971,8 @@ pub enum TaprootError {
InvalidControlBlockSize(usize), InvalidControlBlockSize(usize),
/// Invalid taproot internal key /// Invalid taproot internal key
InvalidInternalKey(secp256k1::Error), InvalidInternalKey(secp256k1::Error),
/// Invalid parity for internal key
InvalidParity(secp256k1::InvalidParityValue),
/// Empty TapTree /// Empty TapTree
EmptyTree, EmptyTree,
} }
@ -999,6 +1002,7 @@ impl fmt::Display for TaprootError {
), ),
// TODO: add source when in MSRV // TODO: add source when in MSRV
TaprootError::InvalidInternalKey(e) => write!(f, "Invalid Internal XOnly key : {}", e), TaprootError::InvalidInternalKey(e) => write!(f, "Invalid Internal XOnly key : {}", e),
TaprootError::InvalidParity(e) => write!(f, "Invalid parity value for internal key: {}", e),
TaprootError::EmptyTree => write!(f, "Taproot Tree must contain at least one script"), TaprootError::EmptyTree => write!(f, "Taproot Tree must contain at least one script"),
} }
} }