walleth / KWRC20

Kotlin implementation for the WRC20 (WASM + ERC20) challenge
5 stars 1 forks source link

Get rid of Konan_* imports #1

Open ligi opened 6 years ago

ligi commented 6 years ago

currently the import section looks like this:

  (import "env" "Konan_abort" (func $Konan_abort (type 3)))
  (import "env" "Konan_date_now" (func $Konan_date_now (type 3)))
  (import "env" "Konan_heap_grow" (func $Konan_heap_grow (type 1)))
  (import "env" "Konan_heap_lower" (func $Konan_heap_lower (type 4)))
  (import "env" "Konan_heap_upper" (func $Konan_heap_upper (type 4)))
  (import "env" "Konan_js_allocateArena" (func $Konan_js_allocateArena (type 4))
)
  (import "env" "Konan_js_arg_size" (func $Konan_js_arg_size (type 1)))
  (import "env" "Konan_js_fetch_arg" (func $Konan_js_fetch_arg (type 0)))
  (import "env" "abort" (func $abort (type 5)))
  (import "env" "callDataCopy" (func $callDataCopy (type 7)))
  (import "env" "finish" (func $finish (type 6)))
  (import "env" "getCallDataSize" (func $getCallDataSize (type 4)))
  (import "env" "getTxOrigin" (func $getTxOrigin (type 1)))
  (import "env" "revert" (func $revert (type 6)))
  (import "env" "storageLoad" (func $storageLoad (type 6)))
  (import "env" "storageStore" (func $storageStore (type 6)))
  (import "env" "write" (func $write (type 2)))
  (import "env" "memory" (memory (;0;) 17))

Create this file by building via ./gradlew wat

These Konan_ imports need to vanish - so it can be used in the eWasm context. The import section must look like this (taken from https://github.com/lrettig/wrc20-challenge/blob/master/build/main.wat):

 (import "ethereum" "getCallDataSize" (func $~lib/ethereum/getCallDataSize (result i32)))
 (import "ethereum" "revert" (func $~lib/ethereum/revert (param i32 i32)))
 (import "ethereum" "callDataCopy" (func $~lib/ethereum/callDataCopy (param i32 i32 i32)))
 (import "ethereum" "storageLoad" (func $~lib/ethereum/storageLoad (param i32 i32)))
 (import "ethereum" "return" (func $~lib/ethereum/finish (param i32 i32)))
 (import "ethereum" "getCaller" (func $~lib/ethereum/getCaller (param i32)))
 (import "ethereum" "storageStore" (func $~lib/ethereum/storageStore (param i32 i32)))

Also we must find a way to change the module source from "env" to "etheruem" - but this is the easier part as far as I see, I have seen this just being replaced in build-scripts. But it would be nicer if we could specify it when declaring the import in eei.kt like this:

@SymbolName("getCallDataSize")
external fun eei_getCallDataSize(): Int

Perhaps there is a way to also specify the module there.

gballet commented 6 years ago

@ligi another thing that I would like to know is how to select what is the module name for each symbol, because 1) the module that should be included is called "ethereum" and 2) even if we can't get rid of all the Konan_ symbols then they will be provided by an auxiliary module that won't provide functions like getTxOrigin.

gballet commented 6 years ago

As an intermediate solution, it would be possible to have: