From 70dae32bf6b0b2823deae9405e209406a7f898ad Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 15 Jun 2022 13:54:18 +0200 Subject: [PATCH 1/6] Michelson_sampler: extract functions from address --- .../lib_benchmark/michelson_samplers.ml | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index e78124e1a27d..c5a8618bdaea 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -490,31 +490,34 @@ end) val stack : ('a, 'b) Script_typed_ir.stack_ty -> ('a * 'b) sampler end = struct + let implicit = Crypto_samplers.pkh + + let originated rng_state = + (* For a description of the format, see + tezos-codec describe alpha.contract binary encoding *) + let string = + "\001" ^ Base_samplers.uniform_string ~nbytes:20 rng_state ^ "\000" + in + Data_encoding.Binary.of_string_exn + Alpha_context.Contract.originated_encoding + string + + let entrypoint rng_state = + Alpha_context.Entrypoint.of_string_strict_exn + @@ Base_samplers.string ~size:{min = 1; max = 31} rng_state + let address rng_state = if Base_samplers.uniform_bool rng_state then - let contract = - Alpha_context.Contract.Implicit (Crypto_samplers.pkh rng_state) + let destination = + Alpha_context.Destination.Contract (Implicit (implicit rng_state)) in - { - destination = Contract contract; - entrypoint = Alpha_context.Entrypoint.default; - } + {destination; entrypoint = Alpha_context.Entrypoint.default} else - (* For a description of the format, see - tezos-codec describe alpha.contract binary encoding *) - let string = - "\001" ^ Base_samplers.uniform_string ~nbytes:20 rng_state ^ "\000" - in - let contract = - Data_encoding.Binary.of_string_exn - Alpha_context.Contract.encoding - string - in - let ep = - Alpha_context.Entrypoint.of_string_strict_exn - @@ Base_samplers.string ~size:{min = 1; max = 31} rng_state + let destination = + Alpha_context.Destination.Contract (Originated (originated rng_state)) in - {destination = Contract contract; entrypoint = ep} + let entrypoint = entrypoint rng_state in + {destination; entrypoint} let tx_rollup_l2_address rng_state = let seed = -- GitLab From 6fa1044b08791c48b6737d48873001fbc7bd019d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 15 Jun 2022 13:56:08 +0200 Subject: [PATCH 2/6] Michelson_sampler: use address directly rather than value address_t --- src/proto_alpha/lib_benchmark/michelson_samplers.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index c5a8618bdaea..15e9ad3b34b0 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -686,7 +686,7 @@ end) arg Script_typed_ir.typed_contract sampler = fun arg_ty -> let open M in - let* address = value address_t in + let* address = address in return (Typed_contract {arg_ty; address}) and generate_operation : Script_typed_ir.operation sampler = -- GitLab From d4d2016c317e60af00dbfeafc7257738bc49427f Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 15 Jun 2022 13:56:54 +0200 Subject: [PATCH 3/6] Michelson_sampler: generate_contract is not mutually recursive with value anymore --- .../lib_benchmark/michelson_samplers.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 15e9ad3b34b0..97cd8a4352d6 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -519,6 +519,15 @@ end) let entrypoint = entrypoint rng_state in {destination; entrypoint} + let generate_contract : + type arg argc. + (arg, argc) Script_typed_ir.ty -> + arg Script_typed_ir.typed_contract sampler = + fun arg_ty -> + let open M in + let* address = address in + return (Typed_contract {arg_ty; address}) + let tx_rollup_l2_address rng_state = let seed = Bytes.init 32 (fun _ -> char_of_int @@ Random.State.int rng_state 255) @@ -680,15 +689,6 @@ end) e ; fail_sampling "raise_if_error" - and generate_contract : - type arg argc. - (arg, argc) Script_typed_ir.ty -> - arg Script_typed_ir.typed_contract sampler = - fun arg_ty -> - let open M in - let* address = address in - return (Typed_contract {arg_ty; address}) - and generate_operation : Script_typed_ir.operation sampler = fun rng_state -> let transfer = generate_transfer_tokens rng_state in -- GitLab From 133b3eede56c78297c15fdecb0a315ae4bc96063 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 15 Jun 2022 13:50:58 +0200 Subject: [PATCH 4/6] Michelson_sampler: generate well-typed contracts Only generate typed implicit contracts when the argument type is unit --- .../lib_benchmark/michelson_samplers.ml | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 97cd8a4352d6..0818ed013241 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -519,15 +519,38 @@ end) let entrypoint = entrypoint rng_state in {destination; entrypoint} - let generate_contract : + let generate_originated_contract : type arg argc. (arg, argc) Script_typed_ir.ty -> arg Script_typed_ir.typed_contract sampler = fun arg_ty -> let open M in - let* address = address in + let* c = originated in + let* entrypoint = entrypoint in + let destination = Alpha_context.Destination.Contract (Originated c) in + let address = {destination; entrypoint} in return (Typed_contract {arg_ty; address}) + let generate_contract : + type arg argc. + (arg, argc) Script_typed_ir.ty -> + arg Script_typed_ir.typed_contract sampler = + fun arg_ty -> + let open M in + match arg_ty with + | Unit_t -> + let* b = Base_samplers.uniform_bool in + if b then + let* pkh = implicit in + let destination = + Alpha_context.Destination.Contract (Implicit pkh) + in + let entrypoint = Alpha_context.Entrypoint.default in + let address = {destination; entrypoint} in + return (Typed_contract {arg_ty; address}) + else generate_originated_contract arg_ty + | _ -> generate_originated_contract arg_ty + let tx_rollup_l2_address rng_state = let seed = Bytes.init 32 (fun _ -> char_of_int @@ Random.State.int rng_state 255) -- GitLab From 4a3a38952833cd48e005b0195457e98f3d34a152 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 15 Jun 2022 15:39:25 +0200 Subject: [PATCH 5/6] Michelson_sampler: also generate tx rollup typed contracts --- src/proto_alpha/lib_benchmark/michelson_samplers.ml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 0818ed013241..58360e35d33a 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -502,6 +502,10 @@ end) Alpha_context.Contract.originated_encoding string + let tx_rollup rng_state = + let string = Base_samplers.uniform_string ~nbytes:20 rng_state in + Data_encoding.Binary.of_string_exn Alpha_context.Tx_rollup.encoding string + let entrypoint rng_state = Alpha_context.Entrypoint.of_string_strict_exn @@ Base_samplers.string ~size:{min = 1; max = 31} rng_state @@ -549,6 +553,15 @@ end) let address = {destination; entrypoint} in return (Typed_contract {arg_ty; address}) else generate_originated_contract arg_ty + | Pair_t (Ticket_t _, Tx_rollup_l2_address_t, _, _) -> + let* b = Base_samplers.uniform_bool in + if b then + let* tx_rollup = tx_rollup in + let destination = Alpha_context.Destination.Tx_rollup tx_rollup in + let entrypoint = Alpha_context.Tx_rollup.deposit_entrypoint in + let address = {destination; entrypoint} in + return (Typed_contract {arg_ty; address}) + else generate_originated_contract arg_ty | _ -> generate_originated_contract arg_ty let tx_rollup_l2_address rng_state = -- GitLab From da522fec6a54bb947dc86d6d46e19b53d06ef4f4 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 1 Jul 2022 14:44:42 +0200 Subject: [PATCH 6/6] Michelson_sampler: also generate sc_rollup typed contracts --- .../lib_benchmark/michelson_samplers.ml | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 58360e35d33a..e45390cbba73 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -506,6 +506,12 @@ end) let string = Base_samplers.uniform_string ~nbytes:20 rng_state in Data_encoding.Binary.of_string_exn Alpha_context.Tx_rollup.encoding string + let sc_rollup rng_state = + let string = Base_samplers.uniform_string ~nbytes:20 rng_state in + Data_encoding.Binary.of_string_exn + Alpha_context.Sc_rollup.Address.encoding + string + let entrypoint rng_state = Alpha_context.Entrypoint.of_string_strict_exn @@ Base_samplers.string ~size:{min = 1; max = 31} rng_state @@ -535,6 +541,28 @@ end) let address = {destination; entrypoint} in return (Typed_contract {arg_ty; address}) + let generate_sc_rollup_contract : + type arg argc. + (arg, argc) Script_typed_ir.ty -> + arg Script_typed_ir.typed_contract sampler = + fun arg_ty -> + let open M in + let* ru = sc_rollup in + let* entrypoint = entrypoint in + let destination = Alpha_context.Destination.Sc_rollup ru in + let address = {destination; entrypoint} in + return (Typed_contract {arg_ty; address}) + + let generate_any_type_contract : + type arg argc. + (arg, argc) Script_typed_ir.ty -> + arg Script_typed_ir.typed_contract sampler = + fun arg_ty -> + let open M in + let* b = Base_samplers.uniform_bool in + if b then generate_originated_contract arg_ty + else generate_sc_rollup_contract arg_ty + let generate_contract : type arg argc. (arg, argc) Script_typed_ir.ty -> @@ -552,7 +580,7 @@ end) let entrypoint = Alpha_context.Entrypoint.default in let address = {destination; entrypoint} in return (Typed_contract {arg_ty; address}) - else generate_originated_contract arg_ty + else generate_any_type_contract arg_ty | Pair_t (Ticket_t _, Tx_rollup_l2_address_t, _, _) -> let* b = Base_samplers.uniform_bool in if b then @@ -561,8 +589,8 @@ end) let entrypoint = Alpha_context.Tx_rollup.deposit_entrypoint in let address = {destination; entrypoint} in return (Typed_contract {arg_ty; address}) - else generate_originated_contract arg_ty - | _ -> generate_originated_contract arg_ty + else generate_any_type_contract arg_ty + | _ -> generate_any_type_contract arg_ty let tx_rollup_l2_address rng_state = let seed = -- GitLab