Skip to content

wasm and clvm_tools-js integration #108

@ChiaMineJP

Description

@ChiaMineJP

@richardkiss
I've just confirmed that the wasm of clvm_rs can be successfully integrated into clvm_tools-js!
clvm_tools-js#clvm_rs

# Terminal
git clone https://github.com/Chia-Mine/clvm_tools-js
cd clvm_tools-js
git checkout clvm_rs
npm install
npm run build
node .dist/npm/bin/cli.js brun --experiment-backend rust --time "(+ 1 (q . 3))" "2"

However, I'm aware that current wasm API is not fully aligned with Python's clvm_rs API.
At wasm, run_clvm Rust function is exposed to wasm, which accepts only clvm program and arguments, and returns only program result without value of cost.

#[wasm_bindgen]
pub fn run_clvm(program: &[u8], args: &[u8]) -> Vec<u8> {
// ...

On the other hand, Python's API accepts additional parameters and also return cost.

#[allow(clippy::too_many_arguments)]
#[pyfunction]
pub fn deserialize_and_run_program2(
    py: Python,
    program: &[u8],
    args: &[u8],
    quote_kw: u8,
    apply_kw: u8,
    opcode_lookup_by_name: HashMap<String, Vec<u8>>,
    max_cost: Cost,
    flags: u32,
) -> PyResult<(Cost, LazyNode)> {
// ...

At a quick glance, I think arguments quote_kw, apply_kw, opcode_lookup_by_name in deserialize_and_run_program2 are not necessary for wasm's run_clvm because those arguments seem always the same value and no user interference.
Question is whether the above assuption is correct or not.

As for max_cost and flags, I'll find the good way/appropriate type to connect to JavaScript. (JavaScript built-in number cannot represent unsigned int 64bit as is. So u64 of Rust should be represented in uint8array in JavaScript or something)

P.S.

In case you are interested, I'll attach the benchmark result among

  • clvm_tools(js)-clvm(js)
  • clvm_tools(js)-clvm(rust)
  • clvm_tools(python)-clvm(python)
  • clvm_tools(python)-clvm(rust)

benchmark-result-32bit-value-200-ops-clvm_rs_sum_all

benchmark-result-32bit-value-200-ops-clvm_rs_assemble_from_ir

benchmark-result-32bit-value-200-ops-clvm_rs_to_sexp_f

benchmark-result-32bit-value-200-ops-clvm_rs_run_program

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions