From 9c87aa63eade4898bd8d0dbed8523c10dea08583 Mon Sep 17 00:00:00 2001 From: swrup Date: Fri, 27 Feb 2026 22:44:49 +0100 Subject: [PATCH] fix timestamp compare --- src/http_info.ml | 2 +- src/http_management.ml | 8 ++++---- src/signkey.ml | 3 ++- src/time.ml | 4 ---- src/time.mli | 4 ---- test/validate_response.ml | 16 ++++++++-------- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/http_info.ml b/src/http_info.ml index 97b80e03..ad4fc4e7 100644 --- a/src/http_info.ml +++ b/src/http_info.ml @@ -83,7 +83,7 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date = | None -> denom_l | Some timestamp -> List.filter - (fun v -> Timestamp.geq v.Denomination.stamp_start timestamp) + (fun v -> Timestamp.compare timestamp v.Denomination.stamp_start <= 0) denom_l in let* denominations = Denomination.make_denom_group_sorted denom_l in diff --git a/src/http_management.ml b/src/http_management.ml index f1b67201..04fc9a51 100644 --- a/src/http_management.ml +++ b/src/http_management.ml @@ -122,7 +122,7 @@ module Auditors = struct Logs.info (fun m -> m "enabled auditor"); () | Some auditor -> - if Timestamp.geq auditor.last_change validity_start then + if Timestamp.compare validity_start auditor.last_change <= 0 then Error "replay detected on enable-auditor" else let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in @@ -157,7 +157,7 @@ module Auditors_disable = struct match opt with | None -> Error "auditor not found" | Some auditor -> ( - if Timestamp.geq auditor.last_change validity_end then + if Timestamp.compare validity_end auditor.last_change <= 0 then Error "replay detected on disable-auditor" else match auditor.is_active with @@ -384,7 +384,7 @@ module Wire = struct Logs.info (fun m -> m "added wire method"); () | Some (wire, _is_active, last_change) -> - if Timestamp.geq last_change validity_start then + if Timestamp.compare validity_start last_change <= 0 then Error "replay detected on enable-wire" else let+ () = @@ -423,7 +423,7 @@ module Wire_disable = struct match opt with | None -> Error "wire not found" | Some (wire, _is_active, last_change) -> - if Timestamp.geq last_change validity_end then + if Timestamp.compare validity_end last_change <= 0 then Error "replay detected on disable-wire" else let+ () = diff --git a/src/signkey.ml b/src/signkey.ml index 78e4ea46..2f0763be 100644 --- a/src/signkey.ml +++ b/src/signkey.ml @@ -19,4 +19,5 @@ let verify_exchange_signing_key_validity ~key sk = } let is_valid_at ~timestamp sk = - Timestamp.geq sk.stamp_start timestamp && Timestamp.lt timestamp sk.stamp_end + Timestamp.compare sk.stamp_start timestamp <= 0 + && Timestamp.compare timestamp sk.stamp_end < 0 diff --git a/src/time.ml b/src/time.ml index b05cf5fb..634a9dff 100644 --- a/src/time.ml +++ b/src/time.ml @@ -97,10 +97,6 @@ module Timestamp = struct let never = uint64_max let zero = 0L let compare = Int64.unsigned_compare - let gt a b = compare a b > 0 - let geq a b = compare a b >= 0 - let lt a b = compare a b < 0 - let leq a b = compare a b <= 0 let equal a b = compare a b = 0 let min a b = if compare a b < 0 then a else b let max a b = if compare a b > 0 then a else b diff --git a/src/time.mli b/src/time.mli index dc4bd841..a7c038b3 100644 --- a/src/time.mli +++ b/src/time.mli @@ -37,10 +37,6 @@ module Timestamp : sig val never : t val zero : t val compare : t -> t -> int - val gt : t -> t -> bool - val geq : t -> t -> bool - val lt : t -> t -> bool - val leq : t -> t -> bool val equal : t -> t -> bool val min : t -> t -> t val max : t -> t -> t diff --git a/test/validate_response.ml b/test/validate_response.ml index 6248acee..aebda500 100644 --- a/test/validate_response.ml +++ b/test/validate_response.ml @@ -36,6 +36,12 @@ let keys content = in (*Fmt.pr "OK wire_fees@.";*) + let* () = + v.global_fees + |> list_iter (GlobalFees.verify_global_fees ~key:v.master_public_key) + in + (*Fmt.pr "OK global_fees@.";*) + let sk_l = List.map SignKey.to_signkey v.signkeys in let* () = sk_l @@ -80,13 +86,7 @@ let keys content = if last_issue_date = v.list_issue_date then Ok () else Fmt.error "list_issue_date is wrong" in - (*Fmt.pr "OK denominations@.";*) - - let* () = - v.global_fees - |> list_iter (GlobalFees.verify_global_fees ~key:v.master_public_key) - in - (*Fmt.pr "OK global_fees@.";*) + Fmt.pr "OK denominations@."; let* () = (* TODO O(n^2) *) @@ -124,7 +124,7 @@ let keys content = denom_hash= dn.h_pub; }) in - (*Fmt.pr "OK auditors@.";*) + Fmt.pr "OK auditors@."; Ok ()