glow icon indicating copy to clipboard operation
glow copied to clipboard

Systematic support for call-by-value vs call-by-reference in EVM backend

Open kwannoel opened this issue 3 years ago • 36 comments

In GitLab by @fahree on Dec 15, 2020, 01:25

Description

We would like to support boxed types in addition the current support for unboxed types.

Example builtin non-immediate types:

  • Signature (65 bytes, r, s, v fields)

And then at some point we need to handle strings: immediate, non-immediate? A new kind of "indirect" values?

  • a ByteString has a length + an offset in memory.

What we need

  • Notion of immediate vs non-immediate types.
  • Provide the proper interface for marshaling values to the EVM. Type descriptors with methods for storing / loading etc...

Patches for gerbil-ethereum

Tracked here.

Patches for Glow

Type descriptors (See: https://gitlab.com/mukn/glow/-/merge_requests/158)

  • [ ] boxed/unboxed type descriptor
  • [ ] size descriptors
  • [ ] descriptors for conversion between objects, bytes.

Refactor current handling

Consensus code generator handles variables in the following way:

  1. Get type via lookup-type:
    (def type (lookup-type (.@ self program) argument-name))
    
  2. Get length via param-length:
    (def len (and type (param-length type)))
    
  3. Get static offset via lookup-variable-offset.
  4. Use mloadat / mstoreat to handle the variable's loading / storing.

Once EVM type descriptor interface is stabilized, we should use its methods instead. In consensus code generator:

  • [ ] Update define-small-functions to use EVM type descriptor methods.
  • [ ] Update compile-consensus-statement to use EVM type descriptor methods.
  • [ ] Update load-immediate-variable to use EVM type descriptor methods.
  • [ ] Update add-local-variable-to-frame to use EVM type descriptor methods.
  • [ ] Update add-temporary-variable-offset to use EVM type descriptor methods.
  • [ ] Update trivial-expression to use EVM type descriptor methods.
  • [ ] Update setup-tail-call to use EVM type descriptor methods.
  • [ ] Update compute-variable-offsets to use EVM type descriptor methods.

TODO how to integrate with EVM type descriptor methods? TODO any other areas we need to handle?

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @fahree on Dec 15, 2020, 01:44

  • [ ] In Ethereum types, have a notion of immediate vs non-immediate type
  • [ ] Immediate types are stored directly on the stack, e.g. integers less than 256 bits, objects that fit in 256 bits in general
  • [ ] Non-immediate objects are stored in memory, and only their 16- or 24-bit offset in passed on the EVM stack.
  • [ ] We want type descriptors, etc., to convert between objects and bytes, to generate the proper EVM code, etc.

Example builtin non-immediate types:

  • Signature (65 bytes, r, s, v fields)

And then at some point we need to handle strings: immediate, non-immediate? A new kind of "indirect" values?

  • a ByteString has a length + an offset in memory.

Methods?

  • [ ] Hashing
  • [ ] get to stack, store from stack, copy, etc., on the EVM backend.

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @fahree on Dec 15, 2020, 03:50

assigned to @fahree

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @fahree on Dec 15, 2020, 03:50

assigned to @AlexKnauth and @Akaa

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 10, 2021, 20:55

assigned to @kwanzknoel

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 11, 2021, 01:33

marked this issue as related to #68

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 11, 2021, 01:33

marked this issue as related to #115

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 11, 2021, 01:47

Note: as mentioned by @fahree, until we have user-defined data structures, the only data structure in need of references is Signature.

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 11, 2021, 16:34

Type descriptors are similar to typeclasses in Haskell.

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 11, 2021, 20:47

EVM backends and other similar backends define a predicate: immediate?. This enables us to discriminate between immediate and non-immediate entities, i.e. whether an entity can be represented in a way that fits into a single stack entry / register (depending on VM).

We will choose an indirect type representation for those which cannot fit.

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on May 11, 2021, 20:48

Task prerequisites: understanding of EVM, glow type descriptors, glow consensus code gen.

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 03:55

marked this issue as related to #191

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 16:25

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 16:31

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 19:03

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:10

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:12

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:13

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:15

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:17

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:17

marked the task boxed? method to discriminate between the two. as completed

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:52

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 2, 2021, 21:54

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 25, 2021, 01:51

marked the task boxed? method to discriminate between the two. as incomplete

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 25, 2021, 03:17

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 25, 2021, 03:18

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jun 25, 2021, 03:18

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jul 7, 2021, 03:11

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jul 7, 2021, 03:21

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jul 7, 2021, 04:04

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel

In GitLab by @kwanzknoel on Jul 7, 2021, 04:17

changed the description

kwannoel avatar Sep 22 '21 04:09 kwannoel