onlydustxyz / starklings

An interactive tutorial to get you up and running with Starknet
309 stars 83 forks source link

Showcase felts and field operations #226

Closed bal7hazar closed 2 years ago

bal7hazar commented 2 years ago

Fix #135

bal7hazar commented 2 years ago

Note: I created 2 new exercises for felt operations, one very basic which is relevant to do after seeing the syntax exercises, then another one more tricky (got from cairo doc) and showing how operations are easier to implement in high-level syntax than low-level, which is more relevant to do after doing registers exercises.

This is the first time that exercises from a single theme are splitted across the synoptic, so feel free to blame me and I'll find another order. Another possibility is to push the second exercise into registers and leave a single exercise in operations theme.

Here is the synoptic proposition (see --> <-- for new exercises)

exercises
    syntax/
      - syntax01
      - syntax02
      - syntax03
      - syntax04
      - syntax05
    operations/
  --> - felt01 <--
    strings/
      - strings00
      - strings01
    storage/
      - storage01
      - storage02
      - storage03
    implicit_arguments/
      - implicit_arguments01
      - implicit_arguments02
      - implicit_arguments03
    recursions/
      - recursion01
      - array01
      - array02
      - array03
      - array04
      - struct01
      - collatz_sequence
    registers/
      - registers00
      - registers01
      - registers02
      - registers03
    operations/
  --> - felt02 <--
    revoked_references/
      - revoked_references01
    builtins/
      - bitwise
    tricks/
      - no_conditionals
      - assert_bool
      - inline_if
    hints/
      - hints00
      - hints01

EDIT @ b6e7a1c

After the first review, we decided to apply the 2nd scenario and not split the theme across the synoptic, here the new synoptic:

exercises/
    syntax/
      - syntax01
      - syntax02
      - syntax03
      - syntax04
      - syntax05
    operations/
      - operations00 <--
    strings/
      - strings00
      - strings01
    storage/
      - storage01
      - storage02
      - storage03
    implicit_arguments/
      - implicit_arguments01
      - implicit_arguments02
      - implicit_arguments03
    recursions/
      - recursion01
      - array01
      - array02
      - array03
      - array04
      - struct01
      - collatz_sequence
    registers/
      - registers00
      - registers01
      - registers02
      - registers03
      - registers04 <--
    revoked_references/
      - revoked_references01
    builtins/
      - bitwise
    tricks/
      - no_conditionals
      - assert_bool
      - inline_if
    hints/
      - hints00
      - hints01
bal7hazar commented 2 years ago

I feel those exercises are more about the syntax than field operations. But I still like them so we can keep them but add a preliminary exercise showing what makes algebraic operations different for felts. In particular: To show that MAX_FELT + 1 = 0 (because of modular arithmetic), you could ask the exefcise solver to find a number x such that x + 1 < x (verify this in your test) You could find the same kind of examples to:

  • Show that divisions are not like in the integers 5/2 is not 2.5;
  • Show that negative numbers can still be handled in some way.
  • more examples can be found here

I added 3 new exercises: