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

add C example, handwritten example, and generic tester #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

poemm
Copy link

@poemm poemm commented Feb 10, 2019

No description provided.


i64 reverse_bytes(i64 a){
i64 b = 0;
b += (a & 0xff00000000000000)>>56;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace += with |= and magic happens: https://godbolt.org/z/GYL1L0
Unfortunately, wasm does not have bswap support.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

But Wasm has no bswap opcode. I would have to look at the output wasm, but don't think there is a difference since addition + and or | both use the ALU in one cycle.


// call function based on selector value
switch (*selector) {
case 0x1a029399:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, why are the selector values here different from those in the example pseudo-code for this repository?

Copy link
Author

@poemm poemm Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you are referring to the wrc20 spec https://gist.github.com/axic/16158c5c88fbc7b1d09dfa8c658bc363 where the selector has value 0x9993021a. The selector here is reversed because callDataCopy() puts the call data into wasm memory, and Wasm reverses the bytes when it loads/stores memory to the stack. I could have also done reverse_bytes() on selector and used the same selector byte-ordering as the wrc20 spec.

@poemm
Copy link
Author

poemm commented May 30, 2019

Please do not merge yet. I am not sure that people want source code in this repo. It may be better to just have a spec, a tester, and links to implementations. Any thoughts?

In this PR, wrc20.c, the tester, and the handwritten examples now live in the C_ewasm_contracts repo. So I think that this PR should be closed, and another one opened with just the tester.

.PHONY: all

#LLVM_BUILD_DIR=/path/to/llvm-build
LLVM_BUILD_DIR=/home/user/repos/benchmarking/wasmception/build/llvm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the upstream LLVM has wasm target enabled by default. How do you want to handle the LLVM installation?

Copy link
Author

@poemm poemm May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is old and outdated. I don't want this repo to include the wrc20.c code anymore. I think that this PR should be closed, but am waiting for feedback before I close.

This is a great question which I need advice for in the current wrc20.c repo https://github.com/poemm/C_ewasm_contracts . It is good that newer version of ubuntu have LLVM 8+ by default. But getting LLVM 8+ may be a challenge for some users. The linked repo gives instructions in the README and compilation commands in the Makefile, but, in my experience, I have had to restart the compilation several times before it finished. Maybe this conversation should be moved to that repo, but I am happy to continue here.

@jwasinger
Copy link

jwasinger commented Jun 1, 2019

and another one opened with just the tester.

Ideally we can ditch testeth and use Javascript-based Truffle tests. E.g. https://github.com/ewasm/wrc20-examples/pull/8/files#diff-80cadf6d11da55ac0a9b807c2c51bcc0

These are much more concise and human-readable than state tests.

Current limitations of Truffle revolve around solc's argument packing (default to 256 bit), differing function selector than specified in the WRC20 Challenge (doesn't include the result of the function signature when calculating the hash for the selector).

Here's what I've done so far to the C contract to reflect the issues I just mentioned: https://github.com/ewasm/wrc20-examples/pull/8/files#diff-cce65dd672810c34ebe43a8482583861

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

Successfully merging this pull request may close these issues.

3 participants