Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nim contracts on eWASM #122

Open
0zAND1z opened this issue Nov 17, 2018 · 10 comments
Open

Nim contracts on eWASM #122

0zAND1z opened this issue Nov 17, 2018 · 10 comments

Comments

@0zAND1z
Copy link

0zAND1z commented Nov 17, 2018

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 0zAND1z mentioned this issue Nov 17, 2018
3 tasks
@0zAND1z
Copy link
Author

0zAND1z commented Nov 17, 2018

@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
Copy link
Member

axic commented Nov 17, 2018

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

@0zAND1z
Copy link
Author

0zAND1z commented Nov 17, 2018

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

@axic
Copy link
Member

axic commented Nov 17, 2018

Why the need for emscripten?

@0zAND1z
Copy link
Author

0zAND1z commented Nov 17, 2018

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
Copy link

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
Copy link
Author

0zAND1z commented Nov 25, 2018

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

That should help here. TIA!

@AchalaSB
Copy link

AchalaSB commented Nov 26, 2018

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
Copy link

AchalaSB commented Dec 6, 2018

@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
Copy link
Member

axic commented Dec 7, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants