Closed tomusdrw closed 3 weeks ago
Example Rust version of this API can be found here: https://github.com/FluffyLabs/pvm-shell/blob/main/src/lib.rs#L54
I think we might consider changing it to something like:
const pointer = newPvm(program, registers, gas);
const gasLeft = getGasLeft(pointer);
We should also consider returning pointers to WASM memory for getRegisters
and especially getPageDump
to avoid passing too much data between WASM and the browser.
This is pretty cool!
I would be interested in officially adding my PolkaVM to it.
API-wise, maybe you could also take a look at my API for inspiration.
Few notes:
resetJam
and resetGeneric
, or something like that?). Otherwise there's no clean way to differentiate between a JAM program blob and a raw PVM code blob, since neither have e.g. any magic bytes to easily check which one is which. (You could try to parse both and see whichever parses without error, but that's a little janky.).wasm
blob without the rest of the .wasm
.wasm
blob where the "code" section can be changed and the rest of the sections are mostly hardcoded.wasm
blob, but simplified; it's essentially a superset of a JAM program blob, it's general purpose, and designed to support things like e.g. debug info and other use cases with minimum extra complexity (e.g. our upcoming smart contracts will probably just use this)Hey @koute! Thanks for the write-up.
It would be great to support PolkaVM and all of the other possible use cases you've mentioned. Let me address some things specifically.
I've updated the interface code to encompass the different blob kinds. The API currently is well suited for wasm_bindgen-like output, I think it is going to become a bit more raw (i.e. passing pointers instead of Uint8Array
) to make it easier for other implementations. I'm planning to get in touch with teams writing the JAM PVM in Go to figure out what output they can provide.
3. Supporting debug info would be amazing, I'd say that if the tool proves to be useful we would be happy to take a shot at implementing that support. We lack a bit of knowledge and experience on this one though, so any pointers would be great.
In general the easiest thing here would most likely be to piggyback on PolkaVM's crates compiled to WASM (at very least until I can get the PolkaVM program blob format somewhat standardized like it is for WASM).
The main two types of interest are ProgramBlob
and ProgramParts
. These are, essentially, mostly equivalent, except a ProgramParts
is just a ProgramBlob
split into parts.
So, the bare minimum to do to be able to load PolkaVM blobs would be something like this:
#[wasm_bindgen]
pub fn polkavm_to_code_blob(raw_blob: Vec<u8>) -> Vec<u8> {
let parts = polkavm::ProgramParts::from_bytes(&raw_blob).unwrap();
return parts.code_and_jump_table.to_vec();
}
This will give you a raw PVM code blob which you can already ingest.
Now, to get debug info working you'd have to use ProgramBlob::parse
or ProgramBlob::from_parts
to create a ProgramBlob
, keep the ProgramBlob
around, and then you can use get_debug_line_program
. You give the function a program counter/byte offset into the code, and it will return you an iterator which produces FrameInfo
structs, which in turn tell you the function name and/or the source path/line of where the given piece of code comes from. (So if you'd display the source code side-by-side you can use this to make a source-level debugger.)
Currently the debug info support is limited to being able to extract the locations of the code in the original sources, but I'm also planning to add support for getting backtraces and also for reading/writing to local variables, etc. (Basically I want to support full blown rich debugging experience.)
It's now possible to load wasm-bindgen compatible WASM blob (either via URL pointing to the metadata JSON or via direct upload of WASM file) #94.
We've also added PolkaVM to the dropdown list as one of the default choices: #99. PolkaVM is compiled from https://github.com/tomusdrw/polkavm/blob/master/pvm-shell/src/lib.rs The original, koute's polkaVM, is a submodule in that repo and we just plug it into the pvm-shell API.
I've extracted support for debug symbols to a separate issue #100
We would love to support other PVM implementations than typeberry.
If you'd like to be listed in the select box on the PVM disassembler page, please add a comment in this issue.
The idea is to compile the PVM to WASM (if possible) and expose a common interface that is yet to be fully defined (we are open for discussion).
The proposed interface for now is:
I imagine that the teams will provide an URL for the
JSON
file with metadata. That file will be fetched by the UI at start to decouple deployment process of PVM implementations and the UI.