diff --git a/src/proto_alpha/lib_dac/RPC.ml b/src/proto_alpha/lib_dac/RPC.ml index 3dea7ef5a3b265ad4f08c3bae020e5171350c88c..d652ac7a6fb006da2868c95781bf32606bfdbb08 100644 --- a/src/proto_alpha/lib_dac/RPC.ml +++ b/src/proto_alpha/lib_dac/RPC.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Trili Tech *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -55,6 +56,10 @@ let () = module Registration = struct let register0_noctxt ~chunked s f dir = RPC_directory.register ~chunked dir s (fun _rpc_ctxt q i -> f q i) + + (* A variant of [register0_noctxt] accepting one argument in the path *) + let register1_noctxt ~chunked s f dir = + RPC_directory.register ~chunked dir s (fun (_rpc_ctxt, p) q i -> f p q i) end module DAC = struct @@ -109,6 +114,15 @@ module DAC = struct ~query:external_message_query ~output:Data_encoding.bool RPC_path.(open_root / "verify_signature") + + let retrieve_preimage = + RPC_service.get_service + ~description: + "Retrieves a page by its page hash and returns its contents" + ~query:RPC_query.empty + ~output:(Data_encoding.bytes Hex) + RPC_path.( + open_root / "preimage" /: Protocol.Sc_rollup_reveal_hash.rpc_arg) end let handle_serialize_dac_store_preimage cctxt dac_sk_uris reveal_data_dir @@ -158,6 +172,10 @@ module DAC = struct | Some (External_message.Dac_message {root_hash; signature; witnesses}) -> Signatures.verify ~public_keys_opt root_hash signature witnesses + let handle_retrieve_preimage reveal_data_dir hash = + let page_store = Page_store.Filesystem.init reveal_data_dir in + Page_store.Filesystem.load page_store ~hash + let register_serialize_dac_store_preimage cctxt dac_sk_uris reveal_data_dir = Registration.register0_noctxt ~chunked:false @@ -178,10 +196,17 @@ module DAC = struct public_keys_opt external_message) + let register_retrieve_preimage reveal_data_dir = + Registration.register1_noctxt + ~chunked:false + S.retrieve_preimage + (fun hash () () -> handle_retrieve_preimage reveal_data_dir hash) + let register reveal_data_dir cctxt dac_public_keys_opt dac_sk_uris = (RPC_directory.empty : unit RPC_directory.t) |> register_serialize_dac_store_preimage cctxt dac_sk_uris reveal_data_dir |> register_verify_external_message_signature dac_public_keys_opt + |> register_retrieve_preimage reveal_data_dir end let rpc_services ~reveal_data_dir cctxt dac_public_keys_opt dac_sk_uris diff --git a/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.ml b/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.ml index e186bdc52c326fc4ddf28ce6ca8db188fe41d467..07274ade850615c9fe43618c17a2b9d3988f4b90 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.ml @@ -3,6 +3,7 @@ (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs *) (* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -107,3 +108,17 @@ let of_hex hex = let open Option_syntax in let* hash = Hex.to_bytes (`Hex hex) in Data_encoding.Binary.of_bytes_opt encoding hash + +let rpc_arg = + let construct = to_hex in + let destruct hash = + match of_hex hash with + | None -> Error "Cannot parse reveal hash" + | Some reveal_hash -> Ok reveal_hash + in + RPC_arg.make + ~descr:"A reveal hash" + ~name:"reveal_hash" + ~destruct + ~construct + () diff --git a/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.mli b/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.mli index ecfca6ef42345f003bb9b22e39bab6fd47b9db7c..399efacbe1a3901e8e75b14dcc58c15298573347 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_reveal_hash.mli @@ -3,6 +3,7 @@ (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs *) (* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -78,3 +79,5 @@ val scheme_of_hash : t -> supported_hashes val of_hex : string -> t option val to_hex : t -> string + +val rpc_arg : t RPC_arg.t diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index 86ed2497e20315ab84853eae07977d46a9040a44..bbc2ff08a2b235cddd08bba23656c0fbd41d8c12 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -912,6 +913,9 @@ module Dac = struct match Hex.of_string external_msg with `Hex s -> s ); ] in - make ~query_string GET ["verify_signature"] @@ JSON.as_bool + make ~query_string GET ["verify_signature"] JSON.as_bool + + let dac_retrieve_preimage page_hash = + make GET ["preimage"; page_hash] JSON.as_string end end diff --git a/tezt/lib_tezos/rollup.mli b/tezt/lib_tezos/rollup.mli index 0e7d13eb965a212edca25c9360f4f53f3b29f922..510d14f232269d4f8891d2af6d7f5335c0919c4d 100644 --- a/tezt/lib_tezos/rollup.mli +++ b/tezt/lib_tezos/rollup.mli @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -406,20 +407,24 @@ end module Dac : sig module RPC : sig (** [dac_store_preimage ~payload ~pagination_scheme] posts a [payload] to - dac/store_preimage using a given [pagination_scheme]. It returnst the + dac/store_preimage using a given [pagination_scheme]. It returns the base58 encoded root page hash, and the raw bytes that can be used as contents of a rollup message to trigger the request of - the payload in a Wasm rollup. *) + the payload in a WASM rollup. *) val dac_store_preimage : payload:string -> pagination_scheme:string -> (Dac_node.t, string * string) RPC_core.t - (** [dac_verify_signature data] requests the dal node to verify + (** [dac_verify_signature data] requests the DAL node to verify the signature of the external message [data] via the plugin/dac/verify_signature endpoint. The DAC committee - of the dal node must be the same that was used to produce the + of the DAL node must be the same that was used to produce the [data]. *) val dac_verify_signature : string -> (Dac_node.t, bool) RPC_core.t + + (** [dac_retrieve_preimage page_hash] retrieves a [payload] in the + dac/store_preimage from the base58 provided encoded page_hash *) + val dac_retrieve_preimage : string -> (Dac_node.t, string) RPC_core.t end end diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index aa4cd0c3532595940dba01c53598ea13cf8d59d8..33a80b7f1d42d55062a09988ad7f0a9cfb091322 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -384,6 +385,43 @@ let test_dac_node_handles_dac_store_preimage_hash_chain_V0 _protocol dac_node check_preimage payload recovered_preimage ; unit +let test_dac_node_handles_dac_retrieve_preimage_merkle_V0 _protocol dac_node + sc_rollup_node _sc_rollup_address _node _client pvm_name = + let payload = "test" in + let* actual_rh, _l1_operation = + RPC.call + dac_node + (Rollup.Dac.RPC.dac_store_preimage + ~payload + ~pagination_scheme:"Merkle_tree_V0") + in + (* Expected reveal hash equals to the result of + [Tezos_dac_alpha.Dac_pages_encoding.Merkle_tree.V0.serialize_payload "test"]. + *) + let expected_rh = + "00a3703854279d2f377d689163d1ec911a840d84b56c4c6f6cafdf0610394df7c6" + in + check_valid_root_hash expected_rh actual_rh ; + let filename = + Filename.concat + (Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) pvm_name) + actual_rh + in + let cin = open_in filename in + let recovered_payload = really_input_string cin (in_channel_length cin) in + let () = close_in cin in + let recovered_preimage = Hex.of_string recovered_payload in + let* preimage = + RPC.call dac_node (Rollup.Dac.RPC.dac_retrieve_preimage expected_rh) + in + Check.( + (preimage = Hex.show recovered_preimage) + string + ~error_msg: + "Returned page does not match the expected one (Current: %L <> \ + Expected: %R)") ; + unit + let test_rollup_arith_uses_reveals protocol dac_node sc_rollup_node sc_rollup_address _node client _pvm_name = let* genesis_info = @@ -550,6 +588,11 @@ let register ~protocols = "dac_reveals_data_hash_chain_v0" test_dac_node_handles_dac_store_preimage_hash_chain_V0 protocols ; + scenario_with_all_nodes + ~tags:["dac"; "dac_node"] + "dac_retrieve_preimage" + test_dac_node_handles_dac_retrieve_preimage_merkle_V0 + protocols ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] "dac_rollup_arith_uses_reveals" diff --git a/tezt/tests/expected/dac.ml/Alpha- Testing DAC rollup and node with L1 (dac_retrieve_preimage).out b/tezt/tests/expected/dac.ml/Alpha- Testing DAC rollup and node with L1 (dac_retrieve_preimage).out new file mode 100644 index 0000000000000000000000000000000000000000..77ef864f3b14bf6f0bac64c864aefd118d625321 --- /dev/null +++ b/tezt/tests/expected/dac.ml/Alpha- Testing DAC rollup and node with L1 (dac_retrieve_preimage).out @@ -0,0 +1,34 @@ + +./octez-client --wait none originate smart rollup from '[PUBLIC_KEY_HASH]' of kind arith of type string with kernel --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 2748.229 units (will add 100 for safety) +Estimated storage: 6552 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000633 + Expected counter: 1 + Gas limit: 2849 + Storage limit: 6572 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000633 + payload fees(the block proposer) ....... +ꜩ0.000633 + Smart rollup origination: + Kind: arith + Parameter type: string + Kernel Blake2B hash: '0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8' + This smart rollup origination was successfully applied + Consumed gas: 2748.229 + Storage size: 6552 bytes + Address: [SMART_ROLLUP_HASH] + Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.638 + storage fees ........................... +ꜩ1.638 +