DE-labtory / koa

The koa is a high-level language that has more expressions than the bitcoin script and is simpler and easy to analyze
Apache License 2.0
74 stars 18 forks source link

Feature/func jumper #325

Closed hihiboss closed 5 years ago

hihiboss commented 5 years ago

resolved: #279

details:

  1. Define FuncMap which has the location(program counter) of each function.
  2. Implemented Function Jumper!

Compile Flow

  1. expect function jumper to calculate function jumper size. (expectFuncJmpr())
  2. compile each function updating FuncMap. (compileFunction())
  3. generate function jumper with updated FuncMap. (generateFuncJmpr())

Function Jumper Logic

  1. push the location of REVERT. this location is used to exit the program.
  2. load function selector of call function. (LoadFunc)
  3. duplicate call function selector.
  4. push the function selector of function being compiled.
  5. compare call function selector with the selector being compiled.
  6. push the location(program counter) to jump.
  7. repeat 3~6 for each function.
  8. add logic to revert (nothing corresponding to call function selector or program finished).

Reference

  1. https://blog.zeppelin.solutions/deconstructing-a-solidity-contract-part-iii-the-function-selector-6a9b6886ea49
  2. 305