Skip to content

Flatten return tuples of storage variables - #191

Open
langfield wants to merge 14 commits into
masterfrom
langfield/flattening
Open

Flatten return tuples of storage variables#191
langfield wants to merge 14 commits into
masterfrom
langfield/flattening

Conversation

@langfield

Copy link
Copy Markdown
Contributor

In this commit, we add a function `userAnnotatedSources` which replaces
`isStandardSource`. It generates a list of all the user annotated
ScopedFunctions. This list is used to filter modules for solving. This
requires a slight refactor within `FunctionAnalysis.hs`.

* Add `extern_remove_dirty` test.

The basic idea is this:
1. Find all wrapper functions.
2. Compute their respective set of reachable functions.
3. Mark them all as 'don't check' unless they are referenced from a
   different source as well.
@langfield
langfield force-pushed the langfield/flattening branch 3 times, most recently from 85082ea to 21c0aec Compare March 26, 2023 12:24
Don't verify `@external`-generated wrapper functions
* Use `ssh-agent` to clone with specific private key
* Set `0o400` permissions on private key file
* Add `mathsat` to list of solvers used in tests
Add mathsat installation to Github actions workflow
…ted-specs

Add FAQ about commenting-out annotations
…eadme-additions

Add `README.md` section on details of `CairoSemanticsL`
@langfield
langfield force-pushed the langfield/flattening branch from 21c0aec to c3e0670 Compare March 28, 2023 15:33
* Update a storage var test for the new syntax.
* Update `display.sh` and `oneoff.sh` testing scripts.
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.
We put `dropMain` in `SW/ScopedName.hs`
@langfield

Copy link
Copy Markdown
Contributor Author

There may be an infinite loop or something here. CI tests never finish and it can't be the SMT queries because they have a timeout.

@langfield
langfield force-pushed the langfield/flattening branch from c3e0670 to 5233a9b Compare March 28, 2023 15:53
@langfield
langfield force-pushed the master branch 2 times, most recently from 9f9928b to 3397b7c Compare March 31, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants