From 048e36584ef4a7a09d8c2246fc738c8b32d77881 Mon Sep 17 00:00:00 2001 From: Joe Polny Date: Fri, 16 Jun 2023 08:39:21 -0400 Subject: [PATCH 1/5] No Length in Dynamic Arrays of Static Types --- ARCs/arc-draft_rm_dynamic_len.md | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ARCs/arc-draft_rm_dynamic_len.md diff --git a/ARCs/arc-draft_rm_dynamic_len.md b/ARCs/arc-draft_rm_dynamic_len.md new file mode 100644 index 000000000..19e32b651 --- /dev/null +++ b/ARCs/arc-draft_rm_dynamic_len.md @@ -0,0 +1,44 @@ +--- +arc: +title: No Length in Dynamic Arrays of Static Types +description: Remove the length prefix in dynamic arrays if the type is static +author: Joe Polny (@joe-p) +discussions-to: +status: Draft +type: Standards Track +category: ARC +created: 2023-07-16 +requires: 4 +--- +## Abstract +According to [ARC-0004](./arc-0004.md), all dynamic arrays must be prefixed with their element length encoded as a uint16. This information is not necessary when the element type is static and thus it should be removed for simplicity sake. The exception is if the array is encoded inside of a tuple. + +## Motivation +ABI-compliant contracts freuquently work with `string` types but all of the AVM opcodes expect regular byteslices, wihch means extra opcodes are needed when using a `string` with opcodes, which is quite common. + +## Specification +The key words "**MUST**", "**MUST NOT**", "**REQUIRED**", "**SHALL**", "**SHALL NOT**", "**SHOULD**", "**SHOULD NOT**", "**RECOMMENDED**", "**MAY**", and "**OPTIONAL**" in this document are to be interpreted as described in RFC-2119. + +If encoding a dynamic array, `x`, of type `T[]`, and the element type `T` is static, the array is encoded by simply concatenating all values of `x` together. If the array is inside of a tuple, the number of elements in `x` must be encoded as `uint16` and prefixed to the array, as per [ARC-0004](./arc-0004.md). + +## Rationale +This will reduce the amount of bytes required when encoding dynamic arrays and make it easier to work with `byte[]` and `string` types in the AVM. + +## Backwards Compatibility +This change is not backwards compatible with [ARC-0004](./arc-0004.md). + +## Test Cases +N/A + +## Reference Implementation +`[1, 2, 3]` encoded as `uint8[]` + +[ARC-0004](./arc-0004.md): `0x 0003 01 02 03` + +This ARC: `0x 01 02 03` + +## Security Considerations +None + +## Copyright +Copyright and related rights waived via CCO. From f88259539213fa707b40ab50f1f7b45dd323cc59 Mon Sep 17 00:00:00 2001 From: Joe Polny <50534337+joe-p@users.noreply.github.com> Date: Fri, 16 Jun 2023 08:41:38 -0400 Subject: [PATCH 2/5] Add discussion link --- ARCs/arc-draft_rm_dynamic_len.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ARCs/arc-draft_rm_dynamic_len.md b/ARCs/arc-draft_rm_dynamic_len.md index 19e32b651..d3054cea3 100644 --- a/ARCs/arc-draft_rm_dynamic_len.md +++ b/ARCs/arc-draft_rm_dynamic_len.md @@ -3,7 +3,7 @@ arc: title: No Length in Dynamic Arrays of Static Types description: Remove the length prefix in dynamic arrays if the type is static author: Joe Polny (@joe-p) -discussions-to: +discussions-to: https://github.com/algorandfoundation/ARCs/issues/214 status: Draft type: Standards Track category: ARC From e8d36a1279871429b1d39165a3f7d05b7a554cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane?= Date: Fri, 16 Jun 2023 14:47:04 +0200 Subject: [PATCH 3/5] Assign ARC number --- ARCs/{arc-draft_rm_dynamic_len.md => arc-0043.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ARCs/{arc-draft_rm_dynamic_len.md => arc-0043.md} (98%) diff --git a/ARCs/arc-draft_rm_dynamic_len.md b/ARCs/arc-0043.md similarity index 98% rename from ARCs/arc-draft_rm_dynamic_len.md rename to ARCs/arc-0043.md index d3054cea3..830462f7f 100644 --- a/ARCs/arc-draft_rm_dynamic_len.md +++ b/ARCs/arc-0043.md @@ -1,5 +1,5 @@ --- -arc: +arc: 43 title: No Length in Dynamic Arrays of Static Types description: Remove the length prefix in dynamic arrays if the type is static author: Joe Polny (@joe-p) From 69e8445593951c580f45ac06689351ccf03664fa Mon Sep 17 00:00:00 2001 From: Joe Polny <50534337+joe-p@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:00:57 -0400 Subject: [PATCH 4/5] add clarity to spec --- ARCs/arc-0043.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ARCs/arc-0043.md b/ARCs/arc-0043.md index 830462f7f..177c72bfc 100644 --- a/ARCs/arc-0043.md +++ b/ARCs/arc-0043.md @@ -19,7 +19,7 @@ ABI-compliant contracts freuquently work with `string` types but all of the AVM ## Specification The key words "**MUST**", "**MUST NOT**", "**REQUIRED**", "**SHALL**", "**SHALL NOT**", "**SHOULD**", "**SHOULD NOT**", "**RECOMMENDED**", "**MAY**", and "**OPTIONAL**" in this document are to be interpreted as described in RFC-2119. -If encoding a dynamic array, `x`, of type `T[]`, and the element type `T` is static, the array is encoded by simply concatenating all values of `x` together. If the array is inside of a tuple, the number of elements in `x` must be encoded as `uint16` and prefixed to the array, as per [ARC-0004](./arc-0004.md). +If encoding a dynamic array, `x`, of type `T[]`, and the element type `T` is static, the array is encoded by simply concatenating all values of `x` together. If the array is inside of a tuple or array, the number of elements in `x` must be encoded as `uint16` and prefixed to the array, as per [ARC-0004](./arc-0004.md). ## Rationale This will reduce the amount of bytes required when encoding dynamic arrays and make it easier to work with `byte[]` and `string` types in the AVM. From f5d27103e9f18e5e6fe104ed9d615dbdfeeacbcc Mon Sep 17 00:00:00 2001 From: Joe Polny <50534337+joe-p@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:27:52 -0400 Subject: [PATCH 5/5] further clarity --- ARCs/arc-0043.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ARCs/arc-0043.md b/ARCs/arc-0043.md index 177c72bfc..5d85b70c3 100644 --- a/ARCs/arc-0043.md +++ b/ARCs/arc-0043.md @@ -11,7 +11,7 @@ created: 2023-07-16 requires: 4 --- ## Abstract -According to [ARC-0004](./arc-0004.md), all dynamic arrays must be prefixed with their element length encoded as a uint16. This information is not necessary when the element type is static and thus it should be removed for simplicity sake. The exception is if the array is encoded inside of a tuple. +According to [ARC-0004](./arc-0004.md), all dynamic arrays must be prefixed with their element length encoded as a uint16. This information is not necessary when the element type is static and thus it should be removed for simplicity sake. The exception is if the array is encoded inside of a tuple or array. ## Motivation ABI-compliant contracts freuquently work with `string` types but all of the AVM opcodes expect regular byteslices, wihch means extra opcodes are needed when using a `string` with opcodes, which is quite common.