essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 5 forks source link

Type safety in solutions (and OOB problems) #807

Open mohammadfawaz opened 4 months ago

mohammadfawaz commented 4 months ago

Type safety in general is a bit shaky at the moment. I'm mostly referring to proposed solutions here.

Here are some examples:

  1. I can go out OOB with tuples in storage with no issues.
    • This is also likely the case with decision variables?
  2. I can store an int at a b256 without issues.
  3. etc.

I believe that every decision variable and every state mutation must satisfy some additional constraints, enforced by the compiler, that make sure that the proposed values do not violate the rules of the type.

otrho commented 4 months ago

We already add constraints for enum variants and I was considering it for bools too.

For (2), storing a smaller type in a bigger one, how could we constrain it?

mohammadfawaz commented 18 hours ago

Update: we don't have any checks currently and we should add all of them for all types, where possible. Not sure how we do this for dynamic arrays though.. maybe a constraint that uses the len intrinsic (which we want to add)

otrho commented 16 hours ago

Absolutely -- we'd use len().