From 027322ab1b40b44c837a3ba48108d8d2a2d730dc Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Wed, 31 Jan 2024 19:46:23 +0700 Subject: [PATCH] Migrate from tuple to array --- README.md | 29 ++- cp0.json | 532 ++++++++++++++++++++++++++++++++++++++++------------ schema.json | 22 --- 3 files changed, 433 insertions(+), 150 deletions(-) diff --git a/README.md b/README.md index 9a741c1..123399e 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Based on [instructions.csv](https://github.com/ton-community/ton-docs/blob/main/ | value_flow.inputs | Incoming values constraints. Input is unconstrained if absent. | value_flow.inputs.stack | Defines how current stack is used by instruction. Instruction must not operate on stack entries other than defined here. Required. | value_flow.inputs.stack[i] | Stack entry or group of stack entries. -| value_flow.inputs.stack[i].type | Type of stack entry. Can be one of "simple", "const", "conditional", "tuple". Required. +| value_flow.inputs.stack[i].type | Type of stack entry. Can be one of "simple", "const", "conditional", "array". Required. | value_flow.inputs.stack[i].* | Properties for stack entries of each type are described below. | value_flow.outputs | Outgoing values constraints. Output is unconstrained if absent. Identical to value_flow.inputs. @@ -237,6 +237,7 @@ Specifies a constant value on stack. `value_type` is either `Integer` or `Null`, } ] ``` +_Stack notation: `0 or c -1`_ ```json [ { @@ -260,17 +261,33 @@ Specifies a constant value on stack. `value_type` is either `Integer` or `Null`, } ] ``` +_Stack notation: `x or null x`_ + Depending on `value` of variable specified in `name`, put values specified in corresponding arm of `match`. If `else` arm is not present, then input for this conditional may be only of specified values. -#### Tuple +#### Array ```json { - "type": "tuple", - "name": "x", - "length_var": "n" + "type": "array", + "name": "key_message_pairs", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "pk", + "value_types": ["Slice"] + }, + { + "type": "simple", + "name": "msg", + "value_types": ["Slice"] + } + ] } ``` -Specifies a bunch of stack entries with length from variable `length_var`, usually noted as `x_1 ... x_n`. Used in tuple and continuation arguments operations. +_Stack notation: `pk_1 msg_1 ... pk_n msg_n`_ + +Specifies a bunch of stack entries with length from variable `length_var`, usually noted as `x_1 ... x_n`. Each part of array, such as `x_i` or `x_i y_i` is described in `array_entry`. Used in tuple, continuation arguments and crypto operations. #### Notes 1. Each variable name is unique across `operands` and `stack` sections of each instruction. Assumed that variables are immutable, so if variable `x` is defined both in inputs and outputs, it goes to output without any modification. diff --git a/cp0.json b/cp0.json index f44fcc7..f98ae65 100644 --- a/cp0.json +++ b/cp0.json @@ -1358,9 +1358,15 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "n" + "type": "array", + "name": "tuple_elements", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] } ] }, @@ -1454,9 +1460,15 @@ "outputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "n" + "type": "array", + "name": "tuple_elements", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] } ] } @@ -1498,9 +1510,15 @@ "outputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "k" + "type": "array", + "name": "tuple_elements", + "length_var": "k", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] } ] } @@ -1542,9 +1560,15 @@ "outputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "m" + "type": "array", + "name": "tuple_elements", + "length_var": "m", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -1713,9 +1737,15 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "n" + "type": "array", + "name": "tuple_elements", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -1808,9 +1838,15 @@ "outputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "n" + "type": "array", + "name": "tuple_elements", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] } ] } @@ -1849,9 +1885,15 @@ "outputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "n" + "type": "array", + "name": "tuple_elements", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] } ] } @@ -1890,9 +1932,15 @@ "outputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "m" + "type": "array", + "name": "tuple_elements", + "length_var": "m", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -23257,9 +23305,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23301,9 +23355,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23345,9 +23405,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23389,9 +23455,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] } ] }, @@ -23580,9 +23652,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23616,9 +23694,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23662,9 +23746,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23703,9 +23793,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -23749,9 +23845,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "p", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -25388,9 +25490,15 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "r" + "type": "array", + "name": "args", + "length_var": "r", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -25473,9 +25581,15 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "r" + "type": "array", + "name": "args", + "length_var": "r", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -25601,9 +25715,15 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "r" + "type": "array", + "name": "args", + "length_var": "r", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -25667,9 +25787,15 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "x", - "length_var": "r" + "type": "array", + "name": "args", + "length_var": "r", + "array_entry": [ + { + "type": "simple", + "name": "x" + } + ] }, { "type": "simple", @@ -27350,9 +27476,15 @@ "inputs": { "stack": [ { - "type": "tuple", + "type": "array", "name": "args", - "length_var": "p" + "length_var": "r", + "array_entry": [ + { + "type": "simple", + "name": "arg" + } + ] }, { "type": "simple", @@ -37635,9 +37767,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37676,9 +37815,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37722,9 +37868,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37768,9 +37921,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37809,9 +37969,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37855,9 +38022,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37896,9 +38070,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37942,9 +38123,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -37988,9 +38176,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38029,9 +38224,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38080,9 +38282,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38126,9 +38335,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38172,9 +38388,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38218,9 +38441,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38264,9 +38494,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38310,9 +38547,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38356,9 +38600,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38402,9 +38653,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38448,9 +38706,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -38494,9 +38759,16 @@ "value_types": ["Builder"] }, { - "type": "tuple", - "name": "s", - "length_var": "n" + "type": "array", + "name": "input_parts", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "s", + "value_types": ["Slice", "Builder"] + } + ] }, { "type": "simple", @@ -39402,9 +39674,18 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "sig", - "length_var": "n" + "type": "array", + "name": "signatures", + "length_var": "n", + "array_entry":[ + { + "type": "simple", + "name": "sig", + "value_types": [ + "Slice" + ] + } + ] }, { "type": "simple", @@ -39443,9 +39724,16 @@ "inputs": { "stack": [ { - "type": "tuple", - "name": "pk", - "length_var": "n" + "type": "array", + "name": "public_keys", + "length_var": "n", + "array_entry": [ + { + "type": "simple", + "name": "pk", + "value_types": ["Slice"] + } + ] }, { "type": "simple", diff --git a/schema.json b/schema.json index 4a7cb22..defa595 100644 --- a/schema.json +++ b/schema.json @@ -243,28 +243,6 @@ } } }, - { - "type": "object", - "additionalProperties": false, - "required": [ - "type", - "name", - "length_var" - ], - "properties": { - "type": { - "const": "tuple" - }, - "name": { - "name": "Variable name", - "type": "string" - }, - "length_var": { - "name": "Variable which contains tuple length", - "type": "string" - } - } - }, { "type": "object", "additionalProperties": false,