New storage format in compiled output#63
Open
ElijahVlasov wants to merge 1 commit intoElijahVlasov/flatteningfrom
Open
New storage format in compiled output#63ElijahVlasov wants to merge 1 commit intoElijahVlasov/flatteningfrom
ElijahVlasov wants to merge 1 commit intoElijahVlasov/flatteningfrom
Conversation
28c0254 to
770918f
Compare
c7d844b to
0047423
Compare
0047423 to
db75277
Compare
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 8, 2023
Warning: remove tracing code Warning: finish revising this commit messsage This commit makes changes to match the new `spec.json` format output by `horus-compile` in the following PR: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we change implicitly change the `FromJSON` of `FuncSpec`/`Storage`, and define `ScopedNameWithIdxArg` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, instead we parse a value of type `S +type Storage' = Map ScopedNameWithIdxArg [([Expr TFelt], Expr TFelt)] ``` ..... finish this later Miscellaneous changes ===================== * Update `display.sh` and `oneoff.sh` testing scripts. * Uncomment the command that cleans up temp files in `oneoff.sh`. * Add `FromJSON` instance for `ScopedNameWithIdxArg` * Add flattening example `ab.cairo` We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps.
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 8, 2023
Warning: remove tracing code This commit makes changes to match the new `spec.json` format output by `horus-compile` in the following PR: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we change implicitly change the `FromJSON` of `FuncSpec`/`Storage`, and define `ScopedNameWithIdxArg` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `Storage'`: ``` +type Storage' = Map ScopedNameWithIdxArg [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `storage'ToStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps. Miscellaneous changes ===================== * Update `display.sh` and `oneoff.sh` testing scripts. * Uncomment the command that cleans up temp files in `oneoff.sh`. * Add `FromJSON` instance for `ScopedNameWithIdxArg` * Add flattening example `ab.cairo`
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 8, 2023
This commit makes changes to match the new `spec.json` format in: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we change implicitly change the `FromJSON` of `FuncSpec`/`Storage`, and define `ScopedNameWithIdxArg` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `Storage'`: ``` +type Storage' = Map ScopedNameWithIdxArg [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `storage'ToStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps. Miscellaneous changes ===================== * Update `display.sh` and `oneoff.sh` testing scripts. * Uncomment the command that cleans up temp files in `oneoff.sh`. * Add `FromJSON` instance for `ScopedNameWithIdxArg` * Add flattening example `ab.cairo`
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 8, 2023
This commit makes changes to match the new `spec.json` format in: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we change implicitly change the `FromJSON` of `FuncSpec`/`Storage`, and define `ScopedNameWithIdxArg` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `Storage'`: ``` +type Storage' = Map ScopedNameWithIdxArg [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `storage'ToStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps. Miscellaneous changes ===================== * Add flattening example `ab.cairo`
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 8, 2023
This commit makes changes to match the new `spec.json` format in: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we implicitly change the `FromJSON` instance of `FuncSpec`/`Storage`, and define `ScopedNameWithIdxArg` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `Storage'`: ``` +type Storage' = Map ScopedNameWithIdxArg [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `storage'ToStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps.
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 8, 2023
This commit makes changes to match the new `spec.json` format in: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we implicitly change the `FromJSON` instance of `FuncSpec`/`Storage`, and define `StorageUpdateKey` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `IndexedStorage`: ``` +type IndexedStorage = Map StorageUpdateKey [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `unindexStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps.
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 26, 2023
This commit makes changes to match the new `spec.json` format in: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we implicitly change the `FromJSON` instance of `FuncSpec`/`Storage`, and define `StorageUpdateKey` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `IndexedStorage`: ``` +type IndexedStorage = Map StorageUpdateKey [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `unindexStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps.
langfield
added a commit
to NethermindEth/horus-checker
that referenced
this pull request
Mar 28, 2023
This commit makes changes to match the new `spec.json` format in: NethermindEth/horus-compile#63 In particular, return types of storage variables which are `struct`s are flattened (deeply) into a tuple, and internally, we use an extra argument to index into this tuple. Parsing the new JSON format =========================== For example, the keys in the `storage_update` object in the `spec.json` file have been modified as follows: ```diff - "__main__.complex_var_1.s.x": [ + "__main__.complex_var_1 0": [ ``` The relevants bits of the source file are: ```cairo struct Point { x: felt, y: felt, } @storage_var func complex_var_1(arg: Uint256) -> (s: Point) { } ``` Note that instead of using dot-accessor notation, we use an index `0` to indicate the first member of the return tuple of `complex_var_1()`, which is identified with the field `x` of `Point`. In order to parse this index argument from the key in the JSON, as seen in the diff above, we implicitly change the `FromJSON` instance of `FuncSpec`/`Storage`, and define `StorageUpdateKey` which is basically `"__main__.complex_var_1 0"`, as is obvious from its name. So instead of parsing a value of type `Storage` from the JSON, we parse a value of type `IndexedStorage`: ``` +type IndexedStorage = Map StorageUpdateKey [([Expr TFelt], Expr TFelt)] ``` and then convert it to a map of type `Storage` with a `unindexStorage` function. Standard specs for `<storage>.read()` and `<storage>.write()` ============================================================= We refactor `storageVarsSpecs` heavily, folding over the `ContractDefinition` field: ```diff + , cd_storageVars :: Map ScopedName (Arity, Coarity) ``` which now includes the arity and coarity of each storage variable. In order to manage this, we add helper functions: ```diff +mkReadSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] +mkWriteSpecs :: ScopedName -> (Int, Int) -> [(ScopedName, FuncSpec)] ``` which basically construct a separate `FuncSpec` for each element of the flattened return tuple. We use a `mergeFuncSpecs` function to nicely take the conjunction of the preconditions and postconditions, and take the union of the `Storage` maps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"storage_variables"field in the spec json contains storage variables with [arity, coarity] tuplestorage_name n ...args...wherenis the deep index of the member