simplicity icon indicating copy to clipboard operation
simplicity copied to clipboard

Not WASM compatible

Open uncomputable opened this issue 1 year ago • 7 comments
trafficstars

The current C code cannot be compiled for WASM, which prevents Simplicity to be run in the browser. rust-simplicity depends on C FFI, so it has the same problem. For comparison, libsecp can be compiled.

We have to remove incompatible standard library headers. So far it looks like these headers cause problems:

  • stdio.h
  • assert.h

uncomputable avatar Nov 26 '23 16:11 uncomputable

I was able to replace stdio.h with stddef.h in #207. Assertions are still a problem. Maybe we can define our own assertions like libsecp. We still have to tell the compiler that certain paths are unreachable, or it will fire errors.

uncomputable avatar Nov 26 '23 16:11 uncomputable

Standard assertions don't cause paths to be unreachable. It should be fine to replace C assertions with our own.

The bigger issue will be eliminating calls to malloc which is far easier in libsecp than in simplicity.

apoelstra avatar Nov 27 '23 14:11 apoelstra

the use of stdio.h is probably a holdover from when I was using the FILE interface. Please make a PR to replace it with stddef.h

roconnor-blockstream avatar Nov 27 '23 15:11 roconnor-blockstream

As far as the C FFI goes, jets are not allowed to do malloc, so there should be no problem with compling the jets to WASM?

roconnor-blockstream avatar Nov 27 '23 15:11 roconnor-blockstream

Great observation @roconnor-blockstream. Depending how stupid our compiler is, we may need to do some preprocessor hacking to just cut out all the non-jet C code. (I think right now we build the entire C/ tree of the simplicity lib.)

apoelstra avatar Nov 27 '23 17:11 apoelstra

I intended to have the C Makefile produce a static library for the jets, but I didn't have any actual consumers for such an artefact so I haven't bothered implementing it.

roconnor-blockstream avatar Jan 09 '24 22:01 roconnor-blockstream

I added a separate jet target to the Makefile: #215

uncomputable avatar Jan 14 '24 11:01 uncomputable

Fixed by #222

uncomputable avatar May 10 '24 13:05 uncomputable