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

feat(wasm): add beerus-web wasm library #756

Merged
merged 61 commits into from
Sep 25, 2024
Merged

feat(wasm): add beerus-web wasm library #756

merged 61 commits into from
Sep 25, 2024

Conversation

src/client.rs Outdated Show resolved Hide resolved
@sergey-melnychuk
Copy link
Collaborator Author

sergey-melnychuk commented Sep 9, 2024

Current problem is that blocking IO must be called from single-threaded JS runtime, which in practice is impossible.

There are two strategies:

  • a major refactoring of blockifier + cairo-vm + cairo-lang-* crates, which is already in progress. Next step in this direction is a significant hint executor refactoring (avoid shared mutable state)
  • using tools like asyncify to hack into the wasm runtime internals and do manual stack unwinding in async calls, in order to make them behave like non-async ones.

I am currently pursuing both approaches simultaneously to investigate the best way to proceed, but just one of them to work should be enough.

@sergey-melnychuk
Copy link
Collaborator Author

sergey-melnychuk commented Sep 21, 2024

At this point the blocking IO is no longer an issue - the easiest way to make it work was to run beerus in a web worker, and inject blocking http call through JavaScript function.

Currently the problem is with parsing Sierra program from Felt252: the root cause is that size_of<usize> is 4 (bytes) in wasm runtime (as opposed to 8 in x86_64), thus trying to parse a usize from u64 fails.

Some extra juggling with dependencies and features was necessary to ensure that the same codebase can compile to both x86_64 and wasm32 target architecture. See commits in beerus-wasm in sequencer, cairo-vm and cairo repositories (links in a PR description).

@sergey-melnychuk
Copy link
Collaborator Author

Screenshot 2024-09-24 at 13 21 41

@sergey-melnychuk
Copy link
Collaborator Author

The PR is ready for review. @LKozlowski @ICavlek PTAL.

Copy link
Contributor

@ICavlek ICavlek left a comment

Choose a reason for hiding this comment

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

I have added couple of comments, but in general excellent job :) I have managed to run it from my side and I had no issues :)

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
tests/common/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ICavlek ICavlek left a comment

Choose a reason for hiding this comment

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

LGTM, please also check the package-lock.json, license value

web/etc/proxy/package-lock.json Outdated Show resolved Hide resolved
Copy link
Contributor

@LKozlowski LKozlowski left a comment

Choose a reason for hiding this comment

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

I went through the PR commit by commit and got the general idea behind that PR. It's a huge PR and as you said there are still a lot of rough edges that need to be polished in the future, but as for the general it seems very easy to follow. I haven't found anything particularly odd that needs to be fixed now. I mostly checked the rust code and skimmed through JS, as I assume this is just for demo purposes for now and will be heavily changed in the future. I think we should merge it as soon as possible and set up a job that will test the wasm code regularly.
The most important thing is that it is working, and the details of it can be ironed out very easily.

@sergey-melnychuk sergey-melnychuk merged commit def9de8 into main Sep 25, 2024
7 checks passed
@sergey-melnychuk sergey-melnychuk deleted the sm/full-wasm branch September 25, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(wasm): beerus demo page feat: compile to wasm32-unknown-unknown target
3 participants