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 polkatool jam-service support #176

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

Conversation

sourabhniyogi
Copy link

@sourabhniyogi sourabhniyogi commented Sep 24, 2024

This WIP PR sets up:

  1. a Rust-based JAM service (named "jam-service-fib") with refine/accumulate/on_transfer/is_authorized entrypoints, use the polka_import macros for import/export/write.
  • Therefine (entry point 5) imports a 12-byte segment with [n, fib(n), f(n-1)] and exports the next segment in the same way [n+1, fib(n+1), fib(n)].
  • The accumulate (entry point 10) reads a 12-byte segment and writes to service storage key "0"
  • The is_authorized (entry point 0) and on_transfer (entry point 15) are just stubs right now
  1. polkatool jam_service [binary] to run @koute recommended code/approach to be "JAM-ready". By "JAM-ready" we mean having the "0/5/10/15" entry points for is_authorized/refine/accumulate/transfer.

Rather than hand assemble PVM byte code like this using @koute's assembler we would much rather use Rust. The sample code includes a first attempt to get at 23 functions from GP Appendix B and teases a few others.

Rather than hand assemble
https://gist.github.com/sourabhniyogi/5e44600216af117169384a51ab389c8d
we would like to demonstrate how a JAM service written in Rust using
#[polkavm_import(index = 0)]
can be compiled into JAM-ready PVM and include "ecalli {0..22}" calls;  By "JAM-ready" we mean the "0/5/10/15" entry points for is_authorized/refine/accumulate/transfer.

TODO: (1) Get toolchain instructions sufficient to get above Rust compiled into PVM with
 (a) ecalli 16/17/3 in place of import/export (refine) + write (accumulate)
 (b) entrypoints 0/5/10/15 going into is_authorized/refine/accumulate/on_transfer
(2) get polkatool to output .pvm byte code with (1b) streamlined
@sourabhniyogi
Copy link
Author

sourabhniyogi commented Sep 25, 2024

@koute Thank you for your super friendly and critically useful hints!

Based on your advice, we successfully built a "polkatool jam-service" to take a "cargo build" compiled Rust JAM Service like jam-service-fib and generated a code blob with 4 entry points that can be disassembled with polkadot.

We added a README showing the steps and the disassembly. We will build a small battery of actually useful services to test this out further, covering many of the other host functions.

To make these JAM Services into JAM-ready toplevel service blobs (as defined in equation 241 in A.7 in GP v0.3.8) we will prepend a header in polkatool jam-service.

@sourabhniyogi sourabhniyogi changed the title JAM Service Example: fibonacci add polkatool jam_service support Sep 25, 2024
Sample execution: (after cargo build of jam-service-fib)
./target/release/polkatool jam-service ~/polkavm/guest-programs/jam-service-fib/target/riscv32ema-unknown-none-elf/release/jam-service-fib
@sourabhniyogi sourabhniyogi changed the title add polkatool jam_service support add polkatool jam-service support Sep 26, 2024
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.

1 participant