From d0063ba690fb06211f79edb26c0bac9d3ed39e00 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 4 Jun 2025 09:55:35 +0200 Subject: [PATCH] Fix decoding of verify proof input --- server/lib/directory.ml | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/server/lib/directory.ml b/server/lib/directory.ml index 730bea1..9a88a4f 100644 --- a/server/lib/directory.ml +++ b/server/lib/directory.ml @@ -194,6 +194,29 @@ module Encoding = struct | _ -> None) (fun () -> `Uncommitted); ] + + let verify_input = + let commitment = + union + [ + case + (merge_objs commitment_with_hash unit) + (function + | Some c -> Some (c, ()) + | None -> None) + (fun (c, ()) -> Some c); + case unit + (function + | None -> Some () + | Some _ -> None) + (fun () -> None); + ] in + conv (fun x -> (x, ())) fst + @@ merge_objs + (obj3 (req "hash" hash) + (req "proof" any_ezjson_value) + (dft "commitment" commitment None)) + unit end module Arg = struct @@ -351,14 +374,7 @@ module Verify_notarization = struct post_service ~section ~name:"Verify notarization" ~errors:[err_502; err_400; err_422] ~descr:"Verify a notarization proof for a given hash" - ~input: - Json_encoding.( - merge_objs - (obj3 (req "hash" Encoding.hash) - (req "proof" any_ezjson_value) - (opt "commitment" - (merge_objs Encoding.commitment_with_hash unit))) - unit) + ~input:Encoding.verify_input ~output:Json_encoding.(obj1 (req "notarized" Encoding.timestamp)) ~params:[Param.block] Path.(root // "notarize" // "verify") @@ -386,7 +402,10 @@ module Verify_notarization = struct EndianBytes.BigEndian.set_int64 buf 68 number_of_ticks ; Commitment_hash.hash_bytes buf - let handler state params _ ((hash, proof, commitment), ()) = + let handler state params _ + ( hash, + proof, + (commitment : Rollup_node_client.commitment_with_hash option) ) = let*? hash = Encoding.parse_hex hash in let block = Option.bind (Req.find_param Param.block params) Arg.block_id_of_string @@ -394,7 +413,7 @@ module Verify_notarization = struct let*? () = match commitment with | None -> Lwt.return_ok () - | Some (Rollup_node_client.{ commitment; hash }, ()) -> + | Some { commitment; hash } -> let (State_hash.V proof_state_hash) = state_hash_of_proof proof in let (State_hash.V state_hash) = commitment.compressed_state in let*? () = -- GitLab