ewasm / testnet

Testnet planning & documentation
64 stars 19 forks source link

Nim contracts on eWASM #122

Open 0zAND1z opened 5 years ago

0zAND1z commented 5 years ago

Objective: Develop a detailed pipeline for Contracts in Nim based on the eWASM Specs

People involved: @kggp1995, @AchalaSB and others from eWASM & status.im team

Goal(s):

  1. Develop a proper emscripten-based transpiler that can convert a .nim program (contract) to WASM executable along with other supporting files

Detailed Workflow (Proposed/Expected):

  1. Writing contracts in Nim as per the eWASM Specs
  2. Compiling contracts using emscripten and generating .wasm, .js, .html & other files.
  3. Generating .wast from .wasm using wabt
  4. Getting Hex code for the contracts
  5. Deploy WASM "Bytecode" & generate new contract address
  6. Testing wast code in eWASM testnet
  7. Extending wast file conversion which contains gas usage and metering information
0zAND1z commented 5 years ago

@achalaSB can explain the processes in detail, perhaps?

Also if @lrettig , @axic or someone can confirm the flow's alignment - that'll be great.

axic commented 5 years ago

I'm sure you are aware of https://github.com/status-im/nim-eth-contracts ? It does some of these steps already.

0zAND1z commented 5 years ago

Yes, but unfortunately it does not support an emscripten-based pipeline, yet.

axic commented 5 years ago

Why the need for emscripten?

0zAND1z commented 5 years ago

Our perspective was to have the emscripten transpile any LLVM-IR compatible contracts to WASM.

So does that make sense to have a single transpiler that could handle all these languages (c/c++/rust to begin with)? OR would it make sense to allow the clang toolchain take care of it?

AchalaSB commented 5 years ago

Hey, Im working on deploying Nim contract in testnet using Clang. Facing some issues in unicode.nim Here's my code

import unittest

import leypa_nim_packagespkg/submodule 
proc mains() {.exportwasm.} =
 test "correct welcome" : check getWelcomeMessage() == "Hello, World!"
 #echo getWelcomeMessage() == "Hello, World!"

Here is my log

nimble test
  Executing task test in /home/achala/Codes/kip-gitlab/leypa-nim-packages/leypa_nim_packages.nimble
  Verifying dependencies for leypa_nim_packages@0.0.1
  Compiling /home/achala/Codes/kip-gitlab/leypa-nim-packages/tests/test1.nim (from package leypa_nim_packages) using c backend
Hint: used config file '/home/achala/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
Hint: used config file '/home/achala/Codes/kip-gitlab/leypa-nim-packages/tests/config.nims' [Conf]
Hint: system [Processing]
Hint: test1 [Processing]
Hint: unittest [Processing]
Hint: macros [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: algorithm [Processing]
Hint: unicode [Processing]
../../../../.choosenim/toolchains/nim-0.19.0/lib/pure/unicode.nim(252, 3) Error: type mismatch: got <seq[char]> but expected'string'
       Tip: 4 messages have been suppressed, use --verbose to show them.
     Error: nimble.nim(1106)         nimble
        ... nimble.nim(1097)         doAction
        ... nimble.nim(1006)         test
        ... nimble.nim(544)          execBackend
        ... tools.nim(28)            doCmd
        ... Execution failed with exit code 1
        ... Command: "/home/achala/.nimble/bin/nim" c --noNimblePath "-r" "--path:."  "/home/achala/Codes/kip-gitlab/leypa-nim-packages/tests/test1.nim"
0zAND1z commented 5 years ago

@AchalaSB , can you describe the pipeline for Nim Contract in detail?

That should help here. TIA!

AchalaSB commented 5 years ago

Here's Detailed workflow of Nim contarcts:

  1. Writing contracts in Nim as per the eWASM Specs
  2. Compiling contracts using clang and generating .wasm file i.e using wasm32-unknown-unknown (clang >= 6.0)
  3. Generating .wast from .wasm using wabt (wasm2wat conversion)
  4. Testing wast code in eWASM testnet & generate new contract address
  5. Getting Hex code for the contracts
  6. Getting new wast file which contains gas usage and metering information
AchalaSB commented 5 years ago

@axic I have compiled the Nim contract using emscripten but the generated wasm file is not according to the eWASM spec, couldn't deploy in testnet. How can I get the required wasm file?

axic commented 5 years ago

Does it have the proper imports and exports?

You could run wasm-chisel on it to clean some of that up. You need to install it via Rust's cargo: cargo install chisel.