Skip to content

Commit 258db35

Browse files
committed
feat(noise): add 10s clock skew tolerance to signature verification
`SignatureNoiseMessage` verification now accepts messages whose `valid_from`/`not_valid_after` bounds fall within a 10-second leeway. This prevents false negatives when the local machine clock is a few seconds ahead or behind (e.g., minor NTP drift).
1 parent 5faf119 commit 258db35

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

sv2/noise-sv2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "noise_sv2"
3-
version = "1.4.0"
3+
version = "1.4.1"
44
authors = ["The Stratum V2 Developers"]
55
edition = "2021"
66
readme = "README.md"

sv2/noise-sv2/src/signature_message.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl SignatureNoiseMessage {
8181
self.verify_with_now(pk, authority_pk, now)
8282
}
8383

84-
/// Verifies the validity and authenticity of the `SignatureNoiseMessage` at a given timestamp.
84+
/// Verifies the validity and authenticity of the `SignatureNoiseMessage` at a given timestamp
85+
/// with 10 seconds of tolerance.
8586
///
8687
/// See [`Self::verify`] for more details.
8788
///
@@ -94,8 +95,14 @@ impl SignatureNoiseMessage {
9495
authority_pk: &Option<XOnlyPublicKey>,
9596
now: u32,
9697
) -> bool {
98+
// Allow the local clock to drift up to 10 seconds ahead or behind.
99+
// See https://github.com/stratum-mining/stratum/issues/2015
100+
const TIME_LEEWAY: u32 = 10;
101+
97102
if let Some(authority_pk) = authority_pk {
98-
if self.valid_from <= now && self.not_valid_after >= now {
103+
if self.valid_from.saturating_sub(TIME_LEEWAY) <= now
104+
&& self.not_valid_after.saturating_add(TIME_LEEWAY) >= now
105+
{
99106
let secp = Secp256k1::verification_only();
100107
let (m, s) = self.split();
101108
// m = SHA-256(version || valid_from || not_valid_after || server_static_key)

0 commit comments

Comments
 (0)