Skip to content

Commit 5f050a7

Browse files
committed
f - Restrict timestamps to 35 bits
1 parent f805e2b commit 5f050a7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightning-invoice/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ mod sync;
8585

8686
pub use de::{ParseError, ParseOrSemanticError};
8787

88+
/// The number of bits used to represent timestamps as defined in BOLT 11.
89+
const TIMESTAMP_BITS: usize = 35;
90+
8891
/// The maximum timestamp that can be represented as a [`Duration`] since the UNIX epoch while
8992
/// allowing for adding an expiry without overflowing.
90-
const MAX_TIMESTAMP: u64 = core::i64::MAX as u64;
93+
const MAX_TIMESTAMP: u64 = core::u64::MAX >> (64 - TIMESTAMP_BITS);
9194

9295
/// The maximum expiry allowed, represented as a [`Duration`] since the invoice timestamp.
93-
const MAX_EXPIRY_TIME: u64 = (core::i64::MAX) as u64 + 1;
96+
const MAX_EXPIRY_TIME: u64 = core::u64::MAX - MAX_TIMESTAMP;
9497

9598
/// Assert that the maximum expiry represented as a [`Duration`] since the UNIX epoch does not
9699
/// exceed [`u64::MAX`].

0 commit comments

Comments
 (0)