From a2f21247a5681b49269b191fef951d70f48016d8 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 3 Feb 2022 13:15:37 +0100 Subject: [PATCH 1/6] Proto/Michelson: deprecate annotation on parameter toplevel constructor --- src/proto_alpha/lib_protocol/script_ir_translator.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index fd4782c37a1b..f6806f9b93f9 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -5056,7 +5056,7 @@ and parse_view_name ctxt : Script.node -> (Script_string.t * context) tzresult = and parse_toplevel : context -> legacy:bool -> Script.expr -> (toplevel * context) tzresult = - fun ctxt ~legacy:_ toplevel -> + fun ctxt ~legacy toplevel -> record_trace (Ill_typed_contract (toplevel, [])) @@ match root toplevel with @@ -5120,14 +5120,15 @@ and parse_toplevel : views ) -> let maybe_root_name = (* root name can be attached to either the parameter - primitive or the toplevel constructor *) + primitive or the toplevel constructor (legacy only) *) Script_ir_annot.extract_field_annot p >>? fun (p, root_name) -> match root_name with | Some _ -> ok (p, pannot, root_name) | None -> ( match pannot with | [single] - when Compare.Int.(String.length single > 0) + when legacy + && Compare.Int.(String.length single > 0) && Compare.Char.(single.[0] = '%') -> parse_field_annot ploc [single] >>? fun pannot -> ok (p, [], pannot) -- GitLab From 18b5bf140b6975581b055e59f091a92f2b18eaa3 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 3 Feb 2022 13:18:53 +0100 Subject: [PATCH 2/6] Proto/Doc: add entry to changelog --- docs/protocols/alpha.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index d35c510ad77d..c6a15a2d78d8 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -97,6 +97,11 @@ Michelson - Field annotations are ignored and not propagated on comparable types and on regular pairs (MR :gl:`!4175`) +- Annotating the parameter toplevel constructor to designate the root entrypoint + is now forbidden. Put the annotation on the parameter type instead. + E.g. replace ``parameter %a int;`` by ``parameter (int %a);`` + (MR :gl:`!4366`) + Internal -------- -- GitLab From aba36e76eb4d478d5e2b01fd184a81dbec36c8ab Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 3 Feb 2022 13:23:29 +0100 Subject: [PATCH 3/6] Proto/Doc: do not use it in the documentation --- docs/alpha/michelson.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/alpha/michelson.rst b/docs/alpha/michelson.rst index ee1702794cbd..f9ae7bc60a0e 100644 --- a/docs/alpha/michelson.rst +++ b/docs/alpha/michelson.rst @@ -3336,7 +3336,7 @@ name the root of the type. The conventional name for that is ``root``. Let us recapitulate this by tweaking the names of the previous example. -``parameter %root (or (or (nat %A) (bool %B)) (or (unit %default) string))`` +``parameter (or %root (or (nat %A) (bool %B)) (or (unit %default) string))`` The input values will be wrapped as in the following examples. -- GitLab From cb327f2b67740a81044d4647775a6ea260c46ac0 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 3 Feb 2022 16:38:52 +0100 Subject: [PATCH 4/6] Tests/Python: adapt tests 1/3 --- .../tests_alpha/test_contract_annotations.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests_python/tests_alpha/test_contract_annotations.py b/tests_python/tests_alpha/test_contract_annotations.py index c34dcc016ee1..b1f67007c914 100644 --- a/tests_python/tests_alpha/test_contract_annotations.py +++ b/tests_python/tests_alpha/test_contract_annotations.py @@ -51,14 +51,34 @@ class TestAnnotations: 'unexpected annotation', ) - def test_field_annotation_in_root_alphabetic(self, client): + def test_field_annotation_in_root_alphabetic_legacy(self, client): client.typecheck( - 'parameter %r unit; storage unit; code {FAILWITH}', file=False + 'parameter %r unit; storage unit; code {FAILWITH}', + file=False, + legacy=True, ) - def test_field_annotation_in_root_numeral(self, client): + def test_field_annotation_in_root_numeral_legacy(self, client): client.typecheck( - 'parameter %1 unit; storage unit; code {FAILWITH}', file=False + 'parameter %1 unit; storage unit; code {FAILWITH}', + file=False, + legacy=True, + ) + + def test_field_annotation_in_root_alphabetic(self, client): + assert_typecheck_failure( + client, + 'parameter %r unit; storage unit; code {FAILWITH}', + 'unexpected annotation', + file=False, + ) + + def test_field_annotation_in_root_numeral(self, client): + assert_typecheck_failure( + client, + 'parameter %1 unit; storage unit; code {FAILWITH}', + 'unexpected annotation', + file=False, ) def test_field_annotation_in_root_invalid_character(self, client): -- GitLab From c469d13bc14a65fc376eebda63f5bf0af33c3419 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 3 Feb 2022 16:41:42 +0100 Subject: [PATCH 5/6] Tests/Python: adapt tests 2/3 --- .../ill_typed/create_contract_rootname.tz | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests_python/contracts_alpha/ill_typed/create_contract_rootname.tz diff --git a/tests_python/contracts_alpha/ill_typed/create_contract_rootname.tz b/tests_python/contracts_alpha/ill_typed/create_contract_rootname.tz new file mode 100644 index 000000000000..b85b4cf8bb41 --- /dev/null +++ b/tests_python/contracts_alpha/ill_typed/create_contract_rootname.tz @@ -0,0 +1,15 @@ +# this contract creates a contract +parameter unit; +storage (option address); +code { DROP; + UNIT; # starting storage for contract + AMOUNT; # Push the starting balance + NONE key_hash; # No delegate + CREATE_CONTRACT # Create the contract + { parameter %root unit ; + storage unit ; + code + { CDR; + NIL operation; + PAIR; } }; + DIP {SOME;NIL operation}; CONS ; PAIR} # Ending calling convention stuff -- GitLab From 295506aa9f0f247df97eebd5a52acc3f4a7cf20f Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 3 Feb 2022 16:41:26 +0100 Subject: [PATCH 6/6] Tests/Python: adapt tests 3/3 --- .../contracts_alpha/opcodes/create_contract_rootname.tz | 2 +- ...ion::test_contract_hash[client_regtest_custom_scrubber0].out | 2 +- ...ck::test_typecheck[opcodes--create_contract_rootname.tz].out | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests_python/contracts_alpha/opcodes/create_contract_rootname.tz b/tests_python/contracts_alpha/opcodes/create_contract_rootname.tz index b85b4cf8bb41..85fb97922fe7 100644 --- a/tests_python/contracts_alpha/opcodes/create_contract_rootname.tz +++ b/tests_python/contracts_alpha/opcodes/create_contract_rootname.tz @@ -6,7 +6,7 @@ code { DROP; AMOUNT; # Push the starting balance NONE key_hash; # No delegate CREATE_CONTRACT # Create the contract - { parameter %root unit ; + { parameter (unit %root) ; storage unit ; code { CDR; diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out index e1fbc7c9c83c..f6457c33156e 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out @@ -151,7 +151,7 @@ expruYk7GXYQ7bKbUcqcHDKs97USVBrxAkzSo2Bkj5AXVjSawDkNAS [CONTRACT_PATH]/opcodes/c expruMW9W9kkb2JaQWzKVThky4ULQ6ckgLzE2xD49XUp5E1iwWfUbe [CONTRACT_PATH]/opcodes/contains_all.tz exprvDvotLP1G2qjPJiqz2RvVUm8wJ2cEuFvKtm7YUNW3w6krDponF [CONTRACT_PATH]/opcodes/contract.tz exprvNrgGoLvfEaXw6QmjQrkXESpWo72JHR4G4mhTJy7Y266YXa3fe [CONTRACT_PATH]/opcodes/create_contract.tz -exprv8no3WSXCsf89WYazUNurLm8hwZRwTWYBQrzihscQcR6M1uKEu [CONTRACT_PATH]/opcodes/create_contract_rootname.tz +exprttdxhC3YwJ9SGJNTDMQRpyWX1KwqAUuPbkQHX3uMPHNt3GKkZK [CONTRACT_PATH]/opcodes/create_contract_rootname.tz exprttdxhC3YwJ9SGJNTDMQRpyWX1KwqAUuPbkQHX3uMPHNt3GKkZK [CONTRACT_PATH]/opcodes/create_contract_rootname_alt.tz expruxUAUoijmC6A4rZK9XHcQL4WmgreJwT17hrgpuYkg1VeELBdbF [CONTRACT_PATH]/opcodes/create_contract_with_view.tz exprteqmco8PDGH1PnTGgF5jPjBPCYyZfyvER2ULtv2y3MRgGdcP8T [CONTRACT_PATH]/opcodes/diff_timestamps.tz diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--create_contract_rootname.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--create_contract_rootname.tz].out index b1c8f67e84df..fef637c9b41a 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--create_contract_rootname.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--create_contract_rootname.tz].out @@ -14,7 +14,7 @@ Gas remaining: 1039988.704 units remaining NONE key_hash /* [ option key_hash : mutez : unit ] */ ; CREATE_CONTRACT - { parameter %root unit ; + { parameter (unit %root) ; storage unit ; code { CDR ; NIL operation ; PAIR } } /* [ operation : address ] */ ; -- GitLab