wasm vs asm returns different results
See original GitHub issueimport { asmJsInit } from "@polkadot/wasm-crypto-asmjs/data";
import { wasmBytes } from "@polkadot/wasm-crypto-wasm";
import { initWasm } from "@polkadot/wasm-crypto/bridge";
import { secp256k1FromSeed } from "@polkadot/wasm-crypto";
import * as imports from "@polkadot/wasm-crypto/imports";
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
wasmPromise.then(() => {
console.log(
secp256k1FromSeed([
203,
109,
249,
222,
30,
252,
167,
163,
153,
138,
142,
173,
78,
2,
21,
157,
95,
169,
156,
62,
13,
79,
214,
67,
38,
103,
57,
11,
180,
114,
104,
84,
])
);
});
outputs
[
203, 109, 249, 222, 30, 252, 167, 163, 153, 138, 142,
173, 78, 2, 21, 157, 95, 169, 156, 62, 13, 79,
214, 67, 38, 103, 57, 11, 180, 114, 104, 84, 2,
10, 16, 145, 52, 31, 229, 102, 75, 250, 23, 130,
213, 224, 71, 121, 104, 144, 104, 201, 22, 176, 76,
179, 101, 236, 49, 83, 117, 86, 132, 217, 161
]
however if you just use asm,
const wasmPromise = initWasm([], asmJsInit, imports).catch(() => null);
itll output
[
203, 109, 249, 222, 30, 252, 167, 163, 153, 138, 142, 173,
78, 2, 21, 157, 95, 169, 156, 62, 13, 79, 214, 67,
38, 103, 57, 11, 180, 114, 104, 84, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
]
seems like asm is somehow broken
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Why is webAssembly function almost 300 time slower than ...
Recognise that the result is never returned from the testing function, and hence remove the entire body of the test function.
Read more >Analyzing the Performance of WebAssembly vs. Native Code
We find that while WebAssembly runs faster than JavaScript (on average 1.3× faster across SPEC CPU), there remains a substantial gap between WebAssembly...
Read more >From ASM.JS to WebAssembly - Brendan Eich
(Media is an exception, but it's debatable as to whether the difference between product and source there is significant.) – wasm (whether binary ......
Read more >Analyzing the Performance of WebAssembly vs. Native Code
js. (i.e., they may be different browsers). These results show that WebAssembly consistently performs better than asm.js, with a mean speedup of ...
Read more >The dark side of WebAssembly - Virus Bulletin
WebAssembly has better performance when running native code than other variations of compiled JavaScript such as asm.js (Assembly JS). WebAssembly is often ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As an aside …
In the 5.0.1 release, the init would be simpler for asm-only or asm + wasm (intstead of duplicating what is done internally, this would hopefully make is easier for people to adjust) -
All the WASM generator deps have been bumped. This had no effect.
This HACK does yield the right results, which I’m certainly not happy with, but I have no other levers to pull here - https://github.com/polkadot-js/wasm/pull/310/commits/e840a6f3d436d0a3b512fd1b2415edd227adc102 (Or rather, no levers that I could find, maybe the
wasm2js
has an additional cli option that can help?)https://github.com/polkadot-js/wasm/blob/0dfb491e9d3b5691adb49b40f932773c238f3d03/packages/wasm-crypto/src/bundle.ts#L57-L72
Additionally going to add an assert in
@polkadot/util-crypto
to ensure that all-zero public keys are not returned. It went in here - https://github.com/polkadot-js/common/blob/2563a0ac3ddfc8de17f907861aa455b3d8db6b49/packages/util-crypto/src/secp256k1/pair/fromSeed.ts#L18-L32