From ca1caf2e617433b836be9ba30f814880b9cdedcd Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 20:27:50 -0800 Subject: [PATCH 01/13] Add bytes_unpack test for CameLIGO --- src/test/contracts/bytes_unpack.mligo | 11 +++++++++++ src/test/integration_tests.ml | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/contracts/bytes_unpack.mligo diff --git a/src/test/contracts/bytes_unpack.mligo b/src/test/contracts/bytes_unpack.mligo new file mode 100644 index 000000000..e33f09b47 --- /dev/null +++ b/src/test/contracts/bytes_unpack.mligo @@ -0,0 +1,11 @@ +let id_string (p: string) : string option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): string option) + +let id_int (p: int) : int option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): int option) + +let id_address (p: address) : address option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): address option) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 394bcc4f0..83647bb12 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1968,6 +1968,16 @@ let bytes_unpack () : unit result = let%bind () = expect_eq program "id_address" (e_address addr) (e_some (e_address addr)) in ok () +let bytes_unpack_mligo () : unit result = + let%bind program = mtype_file "./contracts/bytes_unpack.mligo" in + let%bind () = expect_eq program "id_string" (e_string "teststring") (e_some (e_string "teststring")) in + let%bind () = expect_eq program "id_int" (e_int 42) (e_some (e_int 42)) in + let open Proto_alpha_utils.Memory_proto_alpha in + let addr = Protocol.Alpha_context.Contract.to_b58check @@ + (List.nth dummy_environment.identities 0).implicit_contract in + let%bind () = expect_eq program "id_address" (e_address addr) (e_some (e_address addr)) in + ok () + let empty_case () : unit result = let%bind program = type_file "./contracts/empty_case.ligo" in let%bind () = @@ -2012,6 +2022,7 @@ let empty_case_religo () : unit result = let main = test_suite "Integration (End to End)" [ test "bytes unpack" bytes_unpack ; + test "bytes unpack (mligo)" bytes_unpack ; test "key hash" key_hash ; test "chain id" chain_id ; test "type alias" type_alias ; From 4ee3a29a349f2094cb75b32788f533d863fcad4a Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 20:59:26 -0800 Subject: [PATCH 02/13] Enable CameLIGO bytes_unpack test and add one for ReasonLIGO --- src/test/contracts/bytes_unpack.religo | 14 ++++++++++++++ src/test/integration_tests.ml | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/bytes_unpack.religo diff --git a/src/test/contracts/bytes_unpack.religo b/src/test/contracts/bytes_unpack.religo new file mode 100644 index 000000000..86b291ecc --- /dev/null +++ b/src/test/contracts/bytes_unpack.religo @@ -0,0 +1,14 @@ +let id_string = (p: string) : option(string) => { + let packed : bytes = Bytes.pack(p); + ((Bytes.unpack(packed)): option(string)); +}; + +let id_int = (p: int) : option(int) => { + let packed: bytes = Bytes.pack(p); + ((Bytes.unpack(packed)): option(int)); +}; + +let id_address = (p: address) : option(address) => { + let packed: bytes = Bytes.pack(p); + ((Bytes.unpack(packed)): option(address)); +}; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 83647bb12..375f59423 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1978,6 +1978,16 @@ let bytes_unpack_mligo () : unit result = let%bind () = expect_eq program "id_address" (e_address addr) (e_some (e_address addr)) in ok () +let bytes_unpack_religo () : unit result = + let%bind program = retype_file "./contracts/bytes_unpack.religo" in + let%bind () = expect_eq program "id_string" (e_string "teststring") (e_some (e_string "teststring")) in + let%bind () = expect_eq program "id_int" (e_int 42) (e_some (e_int 42)) in + let open Proto_alpha_utils.Memory_proto_alpha in + let addr = Protocol.Alpha_context.Contract.to_b58check @@ + (List.nth dummy_environment.identities 0).implicit_contract in + let%bind () = expect_eq program "id_address" (e_address addr) (e_some (e_address addr)) in + ok () + let empty_case () : unit result = let%bind program = type_file "./contracts/empty_case.ligo" in let%bind () = @@ -2022,7 +2032,8 @@ let empty_case_religo () : unit result = let main = test_suite "Integration (End to End)" [ test "bytes unpack" bytes_unpack ; - test "bytes unpack (mligo)" bytes_unpack ; + test "bytes unpack (mligo)" bytes_unpack_mligo ; + test "bytes unpack (religo)" bytes_unpack_religo ; test "key hash" key_hash ; test "chain id" chain_id ; test "type alias" type_alias ; From 4fcfa3df8f3fb49292e41d02e177098747d043ff Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 21:37:29 -0800 Subject: [PATCH 03/13] Add CameLIGO key_hash test --- src/test/contracts/key_hash.mligo | 5 +++++ src/test/integration_tests.ml | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/test/contracts/key_hash.mligo diff --git a/src/test/contracts/key_hash.mligo b/src/test/contracts/key_hash.mligo new file mode 100644 index 000000000..830ea3496 --- /dev/null +++ b/src/test/contracts/key_hash.mligo @@ -0,0 +1,5 @@ +let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash = + let kh2 : key_hash = Crypto.hash_key k2 in + if kh1 = kh2 + then (true, kh2) + else (false, kh2) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 375f59423..98074e608 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1901,6 +1901,17 @@ let key_hash () : unit result = let%bind () = expect_eq program "check_hash_key" make_input make_expected in ok () +let key_hash_mligo () : unit result = + let open Tezos_crypto in + let (raw_pkh,raw_pk,_) = Signature.generate_key () in + let pkh_str = Signature.Public_key_hash.to_b58check raw_pkh in + let pk_str = Signature.Public_key.to_b58check raw_pk in + let%bind program = mtype_file "./contracts/key_hash.mligo" in + let make_input = e_pair (e_key_hash pkh_str) (e_key pk_str) in + let make_expected = e_pair (e_bool true) (e_key_hash pkh_str) in + let%bind () = expect_eq program "check_hash_key" make_input make_expected in + ok () + let curry () : unit result = let%bind program = mtype_file "./contracts/curry.mligo" in let%bind () = @@ -2035,6 +2046,7 @@ let main = test_suite "Integration (End to End)" [ test "bytes unpack (mligo)" bytes_unpack_mligo ; test "bytes unpack (religo)" bytes_unpack_religo ; test "key hash" key_hash ; + test "key hash (mligo)" key_hash_mligo ; test "chain id" chain_id ; test "type alias" type_alias ; test "function" function_ ; From 411c17eb99043d3665ceffbeeed6e08020bb4199 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 21:45:40 -0800 Subject: [PATCH 04/13] Add ReasonLIGO version of key_hash test --- src/test/contracts/key_hash.religo | 10 ++++++++++ src/test/integration_tests.ml | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/contracts/key_hash.religo diff --git a/src/test/contracts/key_hash.religo b/src/test/contracts/key_hash.religo new file mode 100644 index 000000000..f3b8e8976 --- /dev/null +++ b/src/test/contracts/key_hash.religo @@ -0,0 +1,10 @@ +let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { + let kh1, k2 = kh1_k2; + let kh2 : key_hash = Crypto.hash_key(k2); + if (kh1 == kh2) { + (true, kh2); + } + else { + (false, kh2); + } +}; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 98074e608..7d5b909c5 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1912,6 +1912,17 @@ let key_hash_mligo () : unit result = let%bind () = expect_eq program "check_hash_key" make_input make_expected in ok () +let key_hash_religo () : unit result = + let open Tezos_crypto in + let (raw_pkh,raw_pk,_) = Signature.generate_key () in + let pkh_str = Signature.Public_key_hash.to_b58check raw_pkh in + let pk_str = Signature.Public_key.to_b58check raw_pk in + let%bind program = retype_file "./contracts/key_hash.religo" in + let make_input = e_pair (e_key_hash pkh_str) (e_key pk_str) in + let make_expected = e_pair (e_bool true) (e_key_hash pkh_str) in + let%bind () = expect_eq program "check_hash_key" make_input make_expected in + ok () + let curry () : unit result = let%bind program = mtype_file "./contracts/curry.mligo" in let%bind () = @@ -2047,6 +2058,7 @@ let main = test_suite "Integration (End to End)" [ test "bytes unpack (religo)" bytes_unpack_religo ; test "key hash" key_hash ; test "key hash (mligo)" key_hash_mligo ; + test "key hash (religo)" key_hash_religo ; test "chain id" chain_id ; test "type alias" type_alias ; test "function" function_ ; From 96bcbf572aa1d5393e77bc718a8484c80e3d3566 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 21:50:45 -0800 Subject: [PATCH 05/13] Add rough draft documentation for hashing keys and pack/unpack operations --- .../docs/language-basics/tezos-specific.md | 80 +++++++++++++++++++ gitlab-pages/website/sidebars.json | 3 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 gitlab-pages/docs/language-basics/tezos-specific.md diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md new file mode 100644 index 000000000..ff1cf6644 --- /dev/null +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -0,0 +1,80 @@ +--- +id: tezos-specific +title: Tezos Domain-Specific Operations +--- + +LIGO is a language for writing Tezos smart contracts. It would be a little odd if +it didn't have any Tezos specific functions. This page will tell you about them. + +## Pack and Unpack + +Michelson provides the `PACK` and `UNPACK` instructions for data serialization. +`PACK` converts Michelson data structures to a binary format, and `UNPACK` +reverses it. This functionality can be accessed from within LIGO. + +> ⚠️ There should be a message here about the dangers of using `UNPACK` on untrusted +data, perhaps about executable code? + + + + +```pascaligo +function id_string (const p : string) : option(string) is block { + const packed : bytes = bytes_pack(p) ; +} with (bytes_unpack(packed): option(string)) +``` + + +```cameligo +let id_string (p: string) : string option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): string option) +``` + + +```reasonligo +let id_string = (p: string) : option(string) => { + let packed : bytes = Bytes.pack(p); + ((Bytes.unpack(packed)): option(string)); +}; +``` + + + +## Hashing Keys + + + + +```pascaligo +function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is block { + var ret : bool := False ; + var kh2 : key_hash := crypto_hash_key(k2) ; + if kh1 = kh2 then ret := True else skip; +} with (ret, kh2) +``` + + +```cameligo +let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash = + let kh2 : key_hash = Crypto.hash_key k2 in + if kh1 = kh2 + then (true, kh2) + else (false, kh2) +``` + + +```reasonligo +let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { + let kh1, k2 = kh1_k2; + let kh2 : key_hash = Crypto.hash_key(k2); + if (kh1 == kh2) { + (true, kh2); + } + else { + (false, kh2); + } +}; +``` + + diff --git a/gitlab-pages/website/sidebars.json b/gitlab-pages/website/sidebars.json index 00fe28d25..674fa7cb2 100644 --- a/gitlab-pages/website/sidebars.json +++ b/gitlab-pages/website/sidebars.json @@ -11,7 +11,8 @@ "language-basics/loops", "language-basics/unit-option-pattern-matching", "language-basics/maps-records", - "language-basics/sets-lists-touples" + "language-basics/sets-lists-touples", + "language-basics/tezos-specific" ], "Advanced": [ "advanced/timestamps-addresses", From eb4336b0e7337e55bec3595602981b8e2be54cb7 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 17 Jan 2020 01:50:06 -0800 Subject: [PATCH 06/13] Add PascaLIGO CHECK_SIGNATURE test to suite --- src/test/contracts/check_signature.ligo | 2 ++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/contracts/check_signature.ligo diff --git a/src/test/contracts/check_signature.ligo b/src/test/contracts/check_signature.ligo new file mode 100644 index 000000000..231b726ea --- /dev/null +++ b/src/test/contracts/check_signature.ligo @@ -0,0 +1,2 @@ +function check_signature (const pk: key; const signed: signature; const msg: bytes) : bool is + crypto_check(pk, signed, msg) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 7d5b909c5..3daec1887 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1923,6 +1923,19 @@ let key_hash_religo () : unit result = let%bind () = expect_eq program "check_hash_key" make_input make_expected in ok () +let check_signature () : unit result = + let open Tezos_crypto in + let (_, raw_pk, sk) = Signature.generate_key () in + let pk_str = Signature.Public_key.to_b58check raw_pk in + let signed = Signature.sign sk (Bytes.of_string "hello world") in + let%bind program = type_file "./contracts/check_signature.ligo" in + let make_input = e_tuple [e_key pk_str ; + e_signature (Signature.to_b58check signed) ; + e_bytes_ofbytes (Bytes.of_string "hello world")] in + let make_expected = e_bool true in + let%bind () = expect_eq program "check_signature" make_input make_expected in + ok () + let curry () : unit result = let%bind program = mtype_file "./contracts/curry.mligo" in let%bind () = @@ -2059,6 +2072,7 @@ let main = test_suite "Integration (End to End)" [ test "key hash" key_hash ; test "key hash (mligo)" key_hash_mligo ; test "key hash (religo)" key_hash_religo ; + test "check signature" check_signature ; test "chain id" chain_id ; test "type alias" type_alias ; test "function" function_ ; From eea8e30e87c79ba29f852295cfd9b17ca891cc0f Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 17 Jan 2020 01:53:22 -0800 Subject: [PATCH 07/13] Add CameLIGO CHECK_SIGNATURE test to suite --- src/test/contracts/check_signature.mligo | 2 ++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/contracts/check_signature.mligo diff --git a/src/test/contracts/check_signature.mligo b/src/test/contracts/check_signature.mligo new file mode 100644 index 000000000..ecd56eb4b --- /dev/null +++ b/src/test/contracts/check_signature.mligo @@ -0,0 +1,2 @@ +let check_signature (pk, signed, msg: key * signature * bytes) : bool = + Crypto.check pk signed msg diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 3daec1887..1eec89aaa 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1936,6 +1936,19 @@ let check_signature () : unit result = let%bind () = expect_eq program "check_signature" make_input make_expected in ok () +let check_signature_mligo () : unit result = + let open Tezos_crypto in + let (_, raw_pk, sk) = Signature.generate_key () in + let pk_str = Signature.Public_key.to_b58check raw_pk in + let signed = Signature.sign sk (Bytes.of_string "hello world") in + let%bind program = mtype_file "./contracts/check_signature.mligo" in + let make_input = e_tuple [e_key pk_str ; + e_signature (Signature.to_b58check signed) ; + e_bytes_ofbytes (Bytes.of_string "hello world")] in + let make_expected = e_bool true in + let%bind () = expect_eq program "check_signature" make_input make_expected in + ok () + let curry () : unit result = let%bind program = mtype_file "./contracts/curry.mligo" in let%bind () = @@ -2073,6 +2086,7 @@ let main = test_suite "Integration (End to End)" [ test "key hash (mligo)" key_hash_mligo ; test "key hash (religo)" key_hash_religo ; test "check signature" check_signature ; + test "check signature (mligo)" check_signature_mligo ; test "chain id" chain_id ; test "type alias" type_alias ; test "function" function_ ; From d6000be3699cdf377d1b1cbe0bf03ea33fc94112 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 17 Jan 2020 01:57:07 -0800 Subject: [PATCH 08/13] Add ReasonLIGO CHECK_SIGNATURE test to suite --- src/test/contracts/check_signature.religo | 4 ++++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/contracts/check_signature.religo diff --git a/src/test/contracts/check_signature.religo b/src/test/contracts/check_signature.religo new file mode 100644 index 000000000..9d2f266ce --- /dev/null +++ b/src/test/contracts/check_signature.religo @@ -0,0 +1,4 @@ +let check_signature = (param: (key, signature, bytes)) : bool => { + let pk, signed, msg = param; + Crypto.check(pk, signed, msg); +}; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 1eec89aaa..fe74e6e09 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1949,6 +1949,19 @@ let check_signature_mligo () : unit result = let%bind () = expect_eq program "check_signature" make_input make_expected in ok () +let check_signature_religo () : unit result = + let open Tezos_crypto in + let (_, raw_pk, sk) = Signature.generate_key () in + let pk_str = Signature.Public_key.to_b58check raw_pk in + let signed = Signature.sign sk (Bytes.of_string "hello world") in + let%bind program = retype_file "./contracts/check_signature.religo" in + let make_input = e_tuple [e_key pk_str ; + e_signature (Signature.to_b58check signed) ; + e_bytes_ofbytes (Bytes.of_string "hello world")] in + let make_expected = e_bool true in + let%bind () = expect_eq program "check_signature" make_input make_expected in + ok () + let curry () : unit result = let%bind program = mtype_file "./contracts/curry.mligo" in let%bind () = @@ -2087,6 +2100,7 @@ let main = test_suite "Integration (End to End)" [ test "key hash (religo)" key_hash_religo ; test "check signature" check_signature ; test "check signature (mligo)" check_signature_mligo ; + test "check signature (religo)" check_signature_religo ; test "chain id" chain_id ; test "type alias" type_alias ; test "function" function_ ; From 1d485b0242713832d79da8b1e046d60b87462e52 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 17 Jan 2020 02:08:07 -0800 Subject: [PATCH 09/13] Add signature checking to tezos specific functions page --- .../docs/language-basics/tezos-specific.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index ff1cf6644..1d28fe322 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -78,3 +78,37 @@ let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { ``` + +## Checking Signatures + +> ⚠️ There is no way to *generate* a signed message in LIGO. This is because that +would require storing a private key on chain, at which point it isn't very private +anymore. + + + + +```pascaligo +function check_signature + (const pk: key; + const signed: signature; + const msg: bytes) : bool + is crypto_check(pk, signed, msg) +``` + + +```cameligo +let check_signature (pk, signed, msg: key * signature * bytes) : bool = + Crypto.check pk signed msg +``` + + +```reasonligo +let check_signature = (param: (key, signature, bytes)) : bool => { + let pk, signed, msg = param; + Crypto.check(pk, signed, msg); +}; +``` + + + From dea98d408c8c54f8a90ff459c42a6f181e3c4136 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 17 Jan 2020 23:19:49 -0800 Subject: [PATCH 10/13] Fill in empty sections of Tezos-specific function page --- .../docs/language-basics/tezos-specific.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index 1d28fe322..4d7ea1f0b 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -12,8 +12,7 @@ Michelson provides the `PACK` and `UNPACK` instructions for data serialization. `PACK` converts Michelson data structures to a binary format, and `UNPACK` reverses it. This functionality can be accessed from within LIGO. -> ⚠️ There should be a message here about the dangers of using `UNPACK` on untrusted -data, perhaps about executable code? +> ⚠️ An `UNPACK` isn't *quite* an `eval`, but it should be kept in mind that if you're deserializing untrusted input certain types could be problematic. If you deserialize an `operation` from an untrusted source and then execute it, [you are running eval on user input](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html). @@ -43,6 +42,11 @@ let id_string = (p: string) : option(string) => { ## Hashing Keys +It's often desirable to hash a public key. In Michelson, certain data structures +such as maps will not allow the use of the `key` type. Even if this weren't the case +hashes are much smaller than keys, and storage on blockchains comes at a cost premium. +You can hash keys with the `key_hash` type and associated built in function. + @@ -81,9 +85,12 @@ let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { ## Checking Signatures -> ⚠️ There is no way to *generate* a signed message in LIGO. This is because that -would require storing a private key on chain, at which point it isn't very private -anymore. +Sometimes a contract will want to check that a message has been signed by a +particular key. For example, a point-of-sale system might want a customer to +sign a transaction so it can be processed asynchronously. You can do this in LIGO +using the `key` and `signature` types. + +> ⚠️ There is no way to *generate* a signed message in LIGO. This is because that would require storing a private key on chain, at which point it isn't very private anymore. From dd44c0d62141fa24e1ae488755226fb50decb3ad Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 21 Jan 2020 02:45:38 -0800 Subject: [PATCH 11/13] Add self_address docs, fix warning for PACK and UNPACK --- .../docs/language-basics/tezos-specific.md | 27 ++++++++++++++++++- src/test/md_file_tests.ml | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index 4d7ea1f0b..8aa60fb5d 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -12,7 +12,7 @@ Michelson provides the `PACK` and `UNPACK` instructions for data serialization. `PACK` converts Michelson data structures to a binary format, and `UNPACK` reverses it. This functionality can be accessed from within LIGO. -> ⚠️ An `UNPACK` isn't *quite* an `eval`, but it should be kept in mind that if you're deserializing untrusted input certain types could be problematic. If you deserialize an `operation` from an untrusted source and then execute it, [you are running eval on user input](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html). +> ⚠️ `PACK` and `UNPACK` are features of Michelson that are intended to be used by people that really know what they're doing. There are several failure cases (such as `UNPACK`ing a lambda from an untrusted source), most of which are beyond the scope of this document. Don't use these functions without doing your homework first. @@ -119,3 +119,28 @@ let check_signature = (param: (key, signature, bytes)) : bool => { +## Getting The Contract's Own Address + +Often you want to get the address of the contract being executed. You can do it with +`self_address`. + +> ⚠️ Due to limitations in Michelson, self_address is only allowed in top-level expressions. Using it in a function will cause an error. + + + + +```pascaligo +const current_addr : address = self_address; +``` + + +```cameligo +let current_addr : address = Current.self_address +``` + + +```reasonligo +let current_addr : address = Current.self_address; +``` + + diff --git a/src/test/md_file_tests.ml b/src/test/md_file_tests.ml index 0401648d0..a201b6dd4 100644 --- a/src/test/md_file_tests.ml +++ b/src/test/md_file_tests.ml @@ -104,6 +104,7 @@ let md_files = [ "/gitlab-pages/docs/language-basics/operators.md"; "/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md"; "/gitlab-pages/docs/language-basics/loops.md"; + "/gitlab-pages/docs/language-basics/tezos-specific.md"; "/gitlab-pages/docs/contributors/big-picture/back-end.md"; "/gitlab-pages/docs/contributors/big-picture/vendors.md"; "/gitlab-pages/docs/contributors/big-picture/front-end.md"; From c811f0058e0464fab8250a29138acf6969d882a4 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 21 Jan 2020 03:13:57 -0800 Subject: [PATCH 12/13] Change 'touples' to 'tuples' in docs --- .../{sets-lists-touples.md => sets-lists-tuples.md} | 2 +- gitlab-pages/website/sidebars.json | 2 +- src/test/md_file_tests.ml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename gitlab-pages/docs/language-basics/{sets-lists-touples.md => sets-lists-tuples.md} (99%) diff --git a/gitlab-pages/docs/language-basics/sets-lists-touples.md b/gitlab-pages/docs/language-basics/sets-lists-tuples.md similarity index 99% rename from gitlab-pages/docs/language-basics/sets-lists-touples.md rename to gitlab-pages/docs/language-basics/sets-lists-tuples.md index 321470da7..65cb1343e 100644 --- a/gitlab-pages/docs/language-basics/sets-lists-touples.md +++ b/gitlab-pages/docs/language-basics/sets-lists-tuples.md @@ -1,5 +1,5 @@ --- -id: sets-lists-touples +id: sets-lists-tuples title: Sets, Lists, Tuples --- diff --git a/gitlab-pages/website/sidebars.json b/gitlab-pages/website/sidebars.json index 674fa7cb2..717fa03ec 100644 --- a/gitlab-pages/website/sidebars.json +++ b/gitlab-pages/website/sidebars.json @@ -11,7 +11,7 @@ "language-basics/loops", "language-basics/unit-option-pattern-matching", "language-basics/maps-records", - "language-basics/sets-lists-touples", + "language-basics/sets-lists-tuples", "language-basics/tezos-specific" ], "Advanced": [ diff --git a/src/test/md_file_tests.ml b/src/test/md_file_tests.ml index a201b6dd4..86aefeb89 100644 --- a/src/test/md_file_tests.ml +++ b/src/test/md_file_tests.ml @@ -100,7 +100,7 @@ let md_files = [ "/gitlab-pages/docs/language-basics/strings.md"; "/gitlab-pages/docs/language-basics/maps-records.md"; "/gitlab-pages/docs/language-basics/variables-and-constants.md"; - "/gitlab-pages/docs/language-basics/sets-lists-touples.md"; + "/gitlab-pages/docs/language-basics/sets-lists-tuples.md"; "/gitlab-pages/docs/language-basics/operators.md"; "/gitlab-pages/docs/language-basics/unit-option-pattern-matching.md"; "/gitlab-pages/docs/language-basics/loops.md"; From f39e006cf900def606f56c952bcbf27b4500accb Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 21 Jan 2020 14:08:26 -0800 Subject: [PATCH 13/13] Change warning about top level use of self_address in docs --- gitlab-pages/docs/language-basics/tezos-specific.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index 8aa60fb5d..2e40d786a 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -124,7 +124,7 @@ let check_signature = (param: (key, signature, bytes)) : bool => { Often you want to get the address of the contract being executed. You can do it with `self_address`. -> ⚠️ Due to limitations in Michelson, self_address is only allowed in top-level expressions. Using it in a function will cause an error. +> ⚠️ Due to limitations in Michelson, self_address in a contract is only allowed at the entry-point level. Using it in a utility function will cause an error.