fix timestamp compare

This commit is contained in:
swrup 2026-02-27 22:44:49 +01:00
parent 26f01efec0
commit 9c87aa63ea
6 changed files with 15 additions and 22 deletions

View file

@ -83,7 +83,7 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date =
| None -> denom_l | None -> denom_l
| Some timestamp -> | Some timestamp ->
List.filter List.filter
(fun v -> Timestamp.geq v.Denomination.stamp_start timestamp) (fun v -> Timestamp.compare timestamp v.Denomination.stamp_start <= 0)
denom_l denom_l
in in
let* denominations = Denomination.make_denom_group_sorted denom_l in let* denominations = Denomination.make_denom_group_sorted denom_l in

View file

@ -122,7 +122,7 @@ module Auditors = struct
Logs.info (fun m -> m "enabled auditor"); Logs.info (fun m -> m "enabled auditor");
() ()
| Some 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" Error "replay detected on enable-auditor"
else else
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
@ -157,7 +157,7 @@ module Auditors_disable = struct
match opt with match opt with
| None -> Error "auditor not found" | None -> Error "auditor not found"
| Some auditor -> ( | 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" Error "replay detected on disable-auditor"
else else
match auditor.is_active with match auditor.is_active with
@ -384,7 +384,7 @@ module Wire = struct
Logs.info (fun m -> m "added wire method"); Logs.info (fun m -> m "added wire method");
() ()
| Some (wire, _is_active, last_change) -> | 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" Error "replay detected on enable-wire"
else else
let+ () = let+ () =
@ -423,7 +423,7 @@ module Wire_disable = struct
match opt with match opt with
| None -> Error "wire not found" | None -> Error "wire not found"
| Some (wire, _is_active, last_change) -> | 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" Error "replay detected on disable-wire"
else else
let+ () = let+ () =

View file

@ -19,4 +19,5 @@ let verify_exchange_signing_key_validity ~key sk =
} }
let is_valid_at ~timestamp 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

View file

@ -97,10 +97,6 @@ module Timestamp = struct
let never = uint64_max let never = uint64_max
let zero = 0L let zero = 0L
let compare = Int64.unsigned_compare 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 equal a b = compare a b = 0
let min a b = if compare a b < 0 then a else b 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 let max a b = if compare a b > 0 then a else b

View file

@ -37,10 +37,6 @@ module Timestamp : sig
val never : t val never : t
val zero : t val zero : t
val compare : t -> t -> int 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 equal : t -> t -> bool
val min : t -> t -> t val min : t -> t -> t
val max : t -> t -> t val max : t -> t -> t

View file

@ -36,6 +36,12 @@ let keys content =
in in
(*Fmt.pr "OK wire_fees@.";*) (*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 = List.map SignKey.to_signkey v.signkeys in
let* () = let* () =
sk_l sk_l
@ -80,13 +86,7 @@ let keys content =
if last_issue_date = v.list_issue_date then Ok () if last_issue_date = v.list_issue_date then Ok ()
else Fmt.error "list_issue_date is wrong" else Fmt.error "list_issue_date is wrong"
in in
(*Fmt.pr "OK denominations@.";*) 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@.";*)
let* () = let* () =
(* TODO O(n^2) *) (* TODO O(n^2) *)
@ -124,7 +124,7 @@ let keys content =
denom_hash= dn.h_pub; denom_hash= dn.h_pub;
}) })
in in
(*Fmt.pr "OK auditors@.";*) Fmt.pr "OK auditors@.";
Ok () Ok ()