diff --git a/README.md b/README.md index af480d1..d219e66 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,10 @@ However, nothing can stop you from just copying `cp0.json` (and `schema.json` if | value_flow | Information related to usage of stack and registers by instruction. Required. | value_flow.doc_stack | Free-form description of stack inputs and outputs. Usually the form is `[inputs] - [outputs]` where `[inputs]` are consumed stack values and `outputs` are produced stack values (top of stack is the last value). Required. | value_flow.inputs | Incoming values constraints. Required. +| value_flow.inputs.registers | Defines how registers is used by instruction. Instruction must not operate on registers other than defined here. Required. +| value_flow.inputs.registers[i] | Register which is access by instruction. +| value_flow.inputs.registers[i].type | Type of register: "constant", "variable", "special". Required. +| value_flow.inputs.registers[i].* | Properties for registers of each type are described below. | value_flow.inputs.stack | Defines how current stack is used by instruction. Instruction must not operate on stack entries other than defined here. Optional, input stack is unconstrained if absent. | 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", "array". Required. @@ -350,6 +354,40 @@ Specifies a bunch of stack entries with length from variable `length_var`, usual 1. Each variable name is unique across `operands`, `value_flow`, and `control_flow` 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. 2. Value flow describes only `cc` stack usage before the actual jump or call. Subsequent continuations may have a separate stack, so this will be defined in control flow section of this spec. +### Register Specification and Examples +#### constant +```json +{ + "type": "constant", + "index": 0 +} +``` +Represents `c{index}` register. + +#### variable +```json +{ + "type": "variable", + "var_name": "i" +} +``` +Represents `c{{var_name}}` register. Its number is taken from variable `var_name`, defined in stack inputs or operands. + +#### special +```json +{ + "type": "special", + "name": "gas" +} +``` +```json +{ + "type": "special", + "name": "cstate" +} +``` +Represents gas registers (used by app_gas instructions) and cstate (used by COMMIT instruction). + ### Continuations Specification and Examples Each object represents a continuation, which can be constructed in several ways: * from a variable (operand or stack) diff --git a/cp0.json b/cp0.json index ed26c5a..5560742 100644 --- a/cp0.json +++ b/cp0.json @@ -21357,7 +21357,10 @@ { "type": "constant", "index": 0 } ] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 0 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21387,8 +21390,17 @@ }, "value_flow": { "doc_stack": "", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [ + { "type": "variable", "var_name": "i" }, + { "type": "constant", "index": 1 } + ] + }, + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 1 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21418,8 +21430,21 @@ }, "value_flow": { "doc_stack": "", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [ + { "type": "variable", "var_name": "i" }, + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } + ] + }, + "outputs": { + "stack": [], + "registers": [ + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } + ] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21444,7 +21469,8 @@ "inputs": { "stack": [ { "type": "simple", "name": "i", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "variable", "var_name": "i" }] }, "outputs": { "stack": [{ "type": "simple", "name": "x" }] } }, @@ -21474,7 +21500,10 @@ { "type": "simple", "name": "i", "value_types": ["Integer"] } ] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "variable", "var_name": "i" }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21633,9 +21662,13 @@ "inputs": { "stack": [ { "type": "simple", "name": "c", "value_types": ["Continuation"] } - ] + ], + "registers": [{ "type": "constant", "index": 0 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 0 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21665,9 +21698,13 @@ "inputs": { "stack": [ { "type": "simple", "name": "c", "value_types": ["Continuation"] } - ] + ], + "registers": [{ "type": "constant", "index": 1 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 1 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21692,9 +21729,16 @@ "inputs": { "stack": [ { "type": "simple", "name": "c", "value_types": ["Continuation"] } + ], + "registers": [ + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } ] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 1 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21719,7 +21763,8 @@ "inputs": { "stack": [ { "type": "simple", "name": "c", "value_types": ["Continuation"] } - ] + ], + "registers": [{ "type": "constant", "index": 0 }] }, "outputs": { "stack": [ @@ -21750,7 +21795,8 @@ "inputs": { "stack": [ { "type": "simple", "name": "c", "value_types": ["Continuation"] } - ] + ], + "registers": [{ "type": "constant", "index": 1 }] }, "outputs": { "stack": [ @@ -21778,8 +21824,20 @@ }, "value_flow": { "doc_stack": "-", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [ + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } + ] + }, + "outputs": { + "stack": [], + "registers": [ + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } + ] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21870,8 +21928,14 @@ }, "value_flow": { "doc_stack": "-", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 0 }] + }, + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 1 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -21893,8 +21957,20 @@ }, "value_flow": { "doc_stack": "-", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [ + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } + ] + }, + "outputs": { + "stack": [], + "registers": [ + { "type": "constant", "index": 0 }, + { "type": "constant", "index": 1 } + ] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -22060,7 +22136,10 @@ }, "value_flow": { "doc_stack": " - n c", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 3 }] + }, "outputs": { "stack": [ { "type": "simple", "name": "n", "value_types": ["Integer"] }, @@ -29762,8 +29841,14 @@ }, "value_flow": { "doc_stack": "-", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [{ "type": "special", "name": "gas" }] + }, + "outputs": { + "stack": [], + "registers": [{ "type": "special", "name": "gas" }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -29788,9 +29873,13 @@ "inputs": { "stack": [ { "type": "simple", "name": "g", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "special", "name": "gas" }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "special", "name": "gas" }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -29816,7 +29905,8 @@ "outputs": { "stack": [ { "type": "simple", "name": "g_c", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "special", "name": "gas" }] } }, "control_flow": { "branches": [], "nobranch": true } @@ -29839,8 +29929,17 @@ }, "value_flow": { "doc_stack": "-", - "inputs": { "stack": [] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [], + "registers": [ + { "type": "constant", "index": 4 }, + { "type": "constant", "index": 5 } + ] + }, + "outputs": { + "stack": [], + "registers": [{ "type": "special", "name": "cstate" }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -29862,11 +29961,15 @@ }, "value_flow": { "doc_stack": "- x", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [ { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] } }, "control_flow": { "branches": [], "nobranch": true } @@ -29892,12 +29995,14 @@ "inputs": { "stack": [ { "type": "simple", "name": "y", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, "outputs": { "stack": [ { "type": "simple", "name": "z", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] } }, "control_flow": { "branches": [], "nobranch": true } @@ -29923,9 +30028,13 @@ "inputs": { "stack": [ { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -29950,9 +30059,13 @@ "inputs": { "stack": [ { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -29982,7 +30095,10 @@ }, "value_flow": { "doc_stack": " - x", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [ { "type": "simple", "name": "x", "value_types": ["Integer"] } @@ -30009,7 +30125,10 @@ }, "value_flow": { "doc_stack": " - D 32", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [ { "type": "simple", "name": "x", "value_types": ["Slice", "Null"] }, @@ -30040,7 +30159,8 @@ "inputs": { "stack": [ { "type": "simple", "name": "i", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, "outputs": { "stack": [ @@ -30084,7 +30204,8 @@ "inputs": { "stack": [ { "type": "simple", "name": "i", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, "outputs": { "stack": [ @@ -30112,7 +30233,10 @@ }, "value_flow": { "doc_stack": "- t", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [{ "type": "simple", "name": "t", "value_types": ["Tuple"] }] } @@ -30137,7 +30261,10 @@ }, "value_flow": { "doc_stack": "- t", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [{ "type": "simple", "name": "t", "value_types": ["Tuple"] }] } @@ -30162,7 +30289,10 @@ }, "value_flow": { "doc_stack": "- i", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [ { "type": "simple", "name": "i", "value_types": ["Integer"] } @@ -30192,7 +30322,8 @@ "inputs": { "stack": [ { "type": "simple", "name": "k", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, "outputs": { "stack": [{ "type": "simple", "name": "x" }] } }, @@ -30225,7 +30356,10 @@ }, "value_flow": { "doc_stack": " - x", - "inputs": { "stack": [] }, + "inputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + }, "outputs": { "stack": [{ "type": "simple", "name": "x" }] } }, "control_flow": { "branches": [], "nobranch": true } @@ -30252,9 +30386,13 @@ "stack": [ { "type": "simple", "name": "x" }, { "type": "simple", "name": "k", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 7 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -30285,8 +30423,14 @@ }, "value_flow": { "doc_stack": "x - ", - "inputs": { "stack": [{ "type": "simple", "name": "x" }] }, - "outputs": { "stack": [] } + "inputs": { + "stack": [{ "type": "simple", "name": "x" }], + "registers": [{ "type": "constant", "index": 7 }] + }, + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 7 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33425,9 +33569,13 @@ "stack": [ { "type": "simple", "name": "c", "value_types": ["Cell"] }, { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 5 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33453,9 +33601,13 @@ "stack": [ { "type": "simple", "name": "x", "value_types": ["Integer"] }, { "type": "simple", "name": "y", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 5 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33482,9 +33634,13 @@ { "type": "simple", "name": "x", "value_types": ["Integer"] }, { "type": "simple", "name": "D", "value_types": ["Cell", "Null"] }, { "type": "simple", "name": "y", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 5 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33507,9 +33663,13 @@ "value_flow": { "doc_stack": "c - ", "inputs": { - "stack": [{ "type": "simple", "name": "c", "value_types": ["Cell"] }] + "stack": [{ "type": "simple", "name": "c", "value_types": ["Cell"] }], + "registers": [{ "type": "constant", "index": 5 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 5 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33535,9 +33695,13 @@ "stack": [ { "type": "simple", "name": "c", "value_types": ["Cell"] }, { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 5 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33563,9 +33727,13 @@ "stack": [ { "type": "simple", "name": "h", "value_types": ["Integer"] }, { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] }, - "outputs": { "stack": [] } + "outputs": { + "stack": [], + "registers": [{ "type": "constant", "index": 5 }] + } }, "control_flow": { "branches": [], "nobranch": true } }, @@ -33591,12 +33759,14 @@ "stack": [ { "type": "simple", "name": "c", "value_types": ["Cell"] }, { "type": "simple", "name": "x", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] }, "outputs": { "stack": [ { "type": "simple", "name": "fee", "value_types": ["Integer"] } - ] + ], + "registers": [{ "type": "constant", "index": 5 }] } }, "control_flow": { "branches": [], "nobranch": true } diff --git a/schema.json b/schema.json index 7003d79..452e748 100644 --- a/schema.json +++ b/schema.json @@ -61,12 +61,54 @@ "values": { "type": "object", "additionalProperties": false, + "required": ["registers"], "properties": { "stack": { "$ref": "#/definitions/stack" + }, + "registers": { + "type": "array", + "title": "Register values", + "items": { + "$ref": "#/definitions/register_flow" + }, + "additionalItems": false } } }, + "register_flow": { + "title": "Register", + "description": "Represents read/write access to a register", + "oneOf": [ + { + "type": "object", + "additionalProperties": false, + "required": ["type", "index"], + "properties": { + "type": { "const": "constant" }, + "index": { "type": "number" } + } + }, + { + "type": "object", + "additionalProperties": false, + "required": ["type", "var_name"], + "properties": { + "type": { "const": "variable" }, + "var_name": { "$ref": "#/definitions/var_name" } + } + }, + { + "type": "object", + "additionalProperties": false, + "required": ["type", "name"], + "properties": { + "type": { "const": "special" }, + "name": { "enum": ["gas", "cstate"] } + } + } + ] + }, "stack": { "type": "array", "title": "Stack values",