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

Upgrade to WASM and Rust Node.js addon (N-API). #53

Closed
wants to merge 27 commits into from

Conversation

fanatid
Copy link
Member

@fanatid fanatid commented Mar 6, 2021

WIP... huge upgrade: move from C++ Node.js addon (NAN) and JS (elliptic) to WebAssembly and Rust Node.js addon (probably napi, or maybe neon? napi).

At the moment of creating pull request:

Next steps for moving pull request from the draft:


I hope that I can handle all this 😅

lib/validate.js Outdated
]);

function isUint8Array(value) {
return value instanceof Uint8Array;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc there was an issue in another library where some environments this doesn't work well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember only this issue -- cryptocoinjs/secp256k1-node#175 🤔 I think that value can be anything while it's correct work with Uint8Array.prototype.set (we copy input value data to WASM input buffer with set).

Copy link
Member Author

@fanatid fanatid Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it worth to change to something like?

function itemsInRange(value) {
  for (let i = 0; i < value.length; ++i) {
    if (value[i] < 0 || value[i] > 0xff) return false;
  }
  return true;
}

function isUint8ArrayLike(value, length) {
  return value instanceof Uint8Array || (
    value !== undefined && value !== null && value.length === length && itemsInRange(value)
  )
}

lib/index.js Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
@junderw
Copy link
Member

junderw commented Mar 7, 2021

At creation moment optimized release WASM file is ~400KB, what is insane.

My crappy wasm-pack WASM which did so many bad inefficient rust things was 153KB... but when it is gzipped it is reduced by size 65%.

Maybe some of the optimization tools I used (like wee_alloc and the WASM strippers I used in the docker command etc.) will help. I see you are already using wasm-opt.

wasm-strip https://github.com/WebAssembly/wabt
wee_alloc https://github.com/rustwasm/wee_alloc

@junderw
Copy link
Member

junderw commented Mar 7, 2021

This PR is historic and godlike.

Moving JS libraries to depend on libsecp256k1 via a slim interface built from a single rust code base compiled into WASM and NAPI/NEON bindings is a huge leap towards having a "less insecure" JS Bitcoin ecosystem.

@fanatid
Copy link
Member Author

fanatid commented Mar 7, 2021

My crappy wasm-pack WASM which did so many bad inefficient rust things was 153KB

wasm-bindgen which wasm-pack uses under the hood is an awesome project. Currently, 400KB because std allocator (but I hope that I'll able to exclude it completely), all functions from bitcoin-core/secp256k1 exported, etc...
Just checked junderw/tiny-secp256k1-wasm master and I get 289KB (91KB after gzip) for wasm-bindgen + wasm-strip + wasm-opt.
I'm not sure what secp256k1.wasm in bitauth/libauth include, but size is 176KB. This looks like a good size.

@fanatid
Copy link
Member Author

fanatid commented Mar 18, 2021

Finally, first benchmark! Wasm vs js: 2x for sign and pk creation, 4x for verify, etc.

full output (linux i5-8250U)
====================================================================================================
Benchmarking function: isPoint
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 2.57 us/op (389590.66 op/s), ±3.07 %
tiny-secp256k1 (wasm): 24.49 us/op (40839.50 op/s), ±2.81 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 2.86 us/op (349568.24 op/s), ±3.05 %
tiny-secp256k1@1.1.6 (elliptic): 91.66 us/op (10910.32 op/s), ±2.66 %
secp256k1@4.0.2 (C++ addon, N-API): 3.23 us/op (310048.31 op/s), ±3.01 %
secp256k1@4.0.2 (elliptic): 92.26 us/op (10839.08 op/s), ±2.82 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (rust addon)
====================================================================================================
Benchmarking function: isPrivate
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 0.02 us/op (40896080.36 op/s), ±5.88 %
tiny-secp256k1 (wasm): 0.03 us/op (38838795.43 op/s), ±5.69 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 0.18 us/op (5475140.47 op/s), ±3.70 %
tiny-secp256k1@1.1.6 (elliptic): 0.35 us/op (2889282.10 op/s), ±3.14 %
secp256k1@4.0.2 (C++ addon, N-API): 0.40 us/op (2524460.19 op/s), ±6.11 %
secp256k1@4.0.2 (elliptic): 0.28 us/op (3559401.45 op/s), ±6.42 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (rust addon)
====================================================================================================
Benchmarking function: pointAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 17.37 us/op (57559.79 op/s), ±8.01 %
tiny-secp256k1 (wasm): 150.92 us/op (6625.84 op/s), ±2.95 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 17.66 us/op (56622.59 op/s), ±3.36 %
tiny-secp256k1@1.1.6 (elliptic): 878.39 us/op (1138.45 op/s), ±5.72 %
secp256k1@4.0.2 (C++ addon, N-API): 19.02 us/op (52575.62 op/s), ±4.10 %
secp256k1@4.0.2 (elliptic): 474.96 us/op (2105.44 op/s), ±2.78 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (rust addon)
====================================================================================================
Benchmarking function: pointAddScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 31.55 us/op (31694.21 op/s), ±5.41 %
tiny-secp256k1 (wasm): 286.57 us/op (3489.51 op/s), ±3.17 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 30.92 us/op (32338.97 op/s), ±3.70 %
tiny-secp256k1@1.1.6 (elliptic): 898.08 us/op (1113.49 op/s), ±3.79 %
secp256k1@4.0.2 (C++ addon, N-API): 32.63 us/op (30643.85 op/s), ±4.33 %
secp256k1@4.0.2 (elliptic): 701.18 us/op (1426.17 op/s), ±3.62 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointCompress
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 4.97 us/op (201078.76 op/s), ±23.30 %
tiny-secp256k1 (wasm): 25.05 us/op (39913.99 op/s), ±3.14 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 3.81 us/op (262203.73 op/s), ±6.32 %
tiny-secp256k1@1.1.6 (elliptic): 192.66 us/op (5190.39 op/s), ±3.08 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointFromScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 31.17 us/op (32081.07 op/s), ±6.49 %
tiny-secp256k1 (wasm): 280.10 us/op (3570.21 op/s), ±4.32 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 30.12 us/op (33203.48 op/s), ±5.82 %
tiny-secp256k1@1.1.6 (elliptic): 542.96 us/op (1841.75 op/s), ±3.83 %
secp256k1@4.0.2 (C++ addon, N-API): 30.96 us/op (32298.58 op/s), ±3.76 %
secp256k1@4.0.2 (elliptic): 543.14 us/op (1841.16 op/s), ±3.76 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointMultiply
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 16.20 us/op (61742.44 op/s), ±7.38 %
tiny-secp256k1 (wasm): 139.97 us/op (7144.16 op/s), ±3.46 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 16.05 us/op (62298.03 op/s), ±4.11 %
tiny-secp256k1@1.1.6 (elliptic): 456.16 us/op (2192.23 op/s), ±5.16 %
secp256k1@4.0.2 (C++ addon, N-API): 17.13 us/op (58364.12 op/s), ±6.26 %
secp256k1@4.0.2 (elliptic): 261.01 us/op (3831.28 op/s), ±4.40 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: privateAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 2.41 us/op (415199.33 op/s), ±12.69 %
tiny-secp256k1 (wasm): 0.46 us/op (2166983.92 op/s), ±3.50 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 1.73 us/op (577760.82 op/s), ±6.60 %
tiny-secp256k1@1.1.6 (elliptic): 2.50 us/op (400189.68 op/s), ±3.38 %
secp256k1@4.0.2 (C++ addon, N-API): 2.76 us/op (362045.41 op/s), ±29.20 %
secp256k1@4.0.2 (elliptic): 1.74 us/op (574956.11 op/s), ±3.25 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (wasm)
====================================================================================================
Benchmarking function: privateSub
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 4.31 us/op (232056.60 op/s), ±27.53 %
tiny-secp256k1 (wasm): 0.62 us/op (1606071.15 op/s), ±3.82 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 1.63 us/op (612607.01 op/s), ±10.57 %
tiny-secp256k1@1.1.6 (elliptic): 2.54 us/op (393154.52 op/s), ±3.51 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (wasm)
====================================================================================================
Benchmarking function: sign
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 51.71 us/op (19340.42 op/s), ±2.92 %
tiny-secp256k1 (wasm): 469.03 us/op (2132.07 op/s), ±1.62 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 49.33 us/op (20272.72 op/s), ±3.16 %
tiny-secp256k1@1.1.6 (elliptic): 913.58 us/op (1094.60 op/s), ±0.64 %
secp256k1@4.0.2 (C++ addon, N-API): 50.89 us/op (19652.12 op/s), ±2.41 %
secp256k1@4.0.2 (elliptic): 949.71 us/op (1052.95 op/s), ±0.47 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: verify
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (rust addon): 60.34 us/op (16572.31 op/s), ±2.62 %
tiny-secp256k1 (wasm): 605.01 us/op (1652.87 op/s), ±0.41 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 58.61 us/op (17060.88 op/s), ±2.64 %
tiny-secp256k1@1.1.6 (elliptic): 2576.87 us/op (388.07 op/s), ±0.02 %
secp256k1@4.0.2 (C++ addon, N-API): 60.74 us/op (16464.75 op/s), ±2.48 %
secp256k1@4.0.2 (elliptic): 2290.39 us/op (436.61 op/s), ±0.21 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
full output for Apple M1
====================================================================================================
Benchmarking function: isPoint
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 2.20 us/op (454887.62 op/s), ±0.39 %
tiny-secp256k1 (WASM): 10.11 us/op (98863.16 op/s), ±0.13 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 2.21 us/op (452375.89 op/s), ±0.46 %
tiny-secp256k1@1.1.6 (elliptic): 58.58 us/op (17069.58 op/s), ±0.42 %
secp256k1@4.0.2 (C++ addon, N-API): 3.41 us/op (292836.95 op/s), ±0.82 %
secp256k1@4.0.2 (elliptic): 59.17 us/op (16901.85 op/s), ±0.65 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: isPrivate
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 0.04 us/op (27480382.67 op/s), ±3.15 %
tiny-secp256k1 (WASM): 0.04 us/op (26422560.36 op/s), ±3.06 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 0.12 us/op (8232758.93 op/s), ±3.26 %
tiny-secp256k1@1.1.6 (elliptic): 0.23 us/op (4442006.68 op/s), ±1.62 %
secp256k1@4.0.2 (C++ addon, N-API): 0.22 us/op (4467190.06 op/s), ±2.12 %
secp256k1@4.0.2 (elliptic): 0.20 us/op (5058893.50 op/s), ±2.53 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: pointAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 14.58 us/op (68592.80 op/s), ±3.74 %
tiny-secp256k1 (WASM): 62.76 us/op (15934.11 op/s), ±0.23 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 13.79 us/op (72537.33 op/s), ±2.64 %
tiny-secp256k1@1.1.6 (elliptic): 528.80 us/op (1891.07 op/s), ±0.24 %
secp256k1@4.0.2 (C++ addon, N-API): 21.20 us/op (47165.24 op/s), ±2.05 %
secp256k1@4.0.2 (elliptic): 287.98 us/op (3472.51 op/s), ±0.31 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointAddScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 23.99 us/op (41686.62 op/s), ±1.15 %
tiny-secp256k1 (WASM): 114.44 us/op (8738.56 op/s), ±0.36 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 23.70 us/op (42191.53 op/s), ±3.25 %
tiny-secp256k1@1.1.6 (elliptic): 531.21 us/op (1882.51 op/s), ±0.94 %
secp256k1@4.0.2 (C++ addon, N-API): 37.63 us/op (26576.75 op/s), ±1.54 %
secp256k1@4.0.2 (elliptic): 407.82 us/op (2452.09 op/s), ±1.08 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointCompress
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 3.51 us/op (284623.93 op/s), ±12.16 %
tiny-secp256k1 (WASM): 10.90 us/op (91715.19 op/s), ±6.29 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 2.63 us/op (380461.48 op/s), ±2.86 %
tiny-secp256k1@1.1.6 (elliptic): 122.54 us/op (8160.34 op/s), ±0.35 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointFromScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 21.12 us/op (47351.57 op/s), ±1.09 %
tiny-secp256k1 (WASM): 96.43 us/op (10369.95 op/s), ±0.44 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 20.70 us/op (48313.35 op/s), ±3.22 %
tiny-secp256k1@1.1.6 (elliptic): 316.96 us/op (3155.01 op/s), ±1.43 %
secp256k1@4.0.2 (C++ addon, N-API): 34.53 us/op (28960.08 op/s), ±1.55 %
secp256k1@4.0.2 (elliptic): 316.84 us/op (3156.21 op/s), ±1.41 %
noble-secp256k1@1.1.2 (BigInt): 165.28 us/op (6050.28 op/s), ±2.26 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: pointMultiply
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 13.79 us/op (72511.55 op/s), ±16.82 %
tiny-secp256k1 (WASM): 56.16 us/op (17805.52 op/s), ±0.73 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 12.09 us/op (82722.00 op/s), ±2.77 %
tiny-secp256k1@1.1.6 (elliptic): 276.20 us/op (3620.56 op/s), ±1.85 %
secp256k1@4.0.2 (C++ addon, N-API): 18.83 us/op (53106.11 op/s), ±2.33 %
secp256k1@4.0.2 (elliptic): 152.26 us/op (6567.80 op/s), ±1.81 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: privateAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 1.56 us/op (642059.81 op/s), ±33.59 %
tiny-secp256k1 (WASM): 0.24 us/op (4247181.94 op/s), ±1.49 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 0.64 us/op (1566565.56 op/s), ±9.88 %
tiny-secp256k1@1.1.6 (elliptic): 1.40 us/op (713778.70 op/s), ±0.23 %
secp256k1@4.0.2 (C++ addon, N-API): 1.49 us/op (672105.41 op/s), ±46.99 %
secp256k1@4.0.2 (elliptic): 0.85 us/op (1177602.23 op/s), ±0.19 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (WASM)
====================================================================================================
Benchmarking function: privateSub
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 3.65 us/op (273808.35 op/s), ±65.14 %
tiny-secp256k1 (WASM): 0.28 us/op (3594353.44 op/s), ±2.12 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 0.67 us/op (1493182.70 op/s), ±18.01 %
tiny-secp256k1@1.1.6 (elliptic): 1.35 us/op (740554.57 op/s), ±1.87 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (WASM)
====================================================================================================
Benchmarking function: sign
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 37.11 us/op (26946.55 op/s), ±0.40 %
tiny-secp256k1 (WASM): 133.19 us/op (7508.29 op/s), ±0.09 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 36.85 us/op (27134.74 op/s), ±1.97 %
tiny-secp256k1@1.1.6 (elliptic): 522.64 us/op (1913.38 op/s), ±0.21 %
secp256k1@4.0.2 (C++ addon, N-API): 67.96 us/op (14713.70 op/s), ±0.45 %
secp256k1@4.0.2 (elliptic): 562.57 us/op (1777.57 op/s), ±0.06 %
noble-secp256k1@1.1.2 (BigInt): 261.25 us/op (3827.71 op/s), ±0.08 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)
====================================================================================================
Benchmarking function: verify
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 46.41 us/op (21545.83 op/s), ±0.09 %
tiny-secp256k1 (WASM): 212.05 us/op (4715.89 op/s), ±0.04 %
tiny-secp256k1@1.1.6 (C++ addon, NAN/V8): 46.96 us/op (21296.16 op/s), ±0.53 %
tiny-secp256k1@1.1.6 (elliptic): 1515.26 us/op (659.95 op/s), ±0.03 %
secp256k1@4.0.2 (C++ addon, N-API): 86.85 us/op (11514.26 op/s), ±0.12 %
secp256k1@4.0.2 (elliptic): 1343.13 us/op (744.53 op/s), ±0.05 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Rust addon with different `opt-level` benchmarks
====================================================================================================
Benchmarking function: isPoint
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 2.69 us/op (371539.90 op/s), ±3.29 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 3.02 us/op (331315.46 op/s), ±3.71 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 3.00 us/op (333174.76 op/s), ±3.52 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: isPrivate
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 0.10 us/op (9940283.72 op/s), ±7.93 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 0.10 us/op (9629024.74 op/s), ±8.54 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 0.10 us/op (9828433.93 op/s), ±7.27 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: pointAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 17.70 us/op (56494.72 op/s), ±9.14 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 20.33 us/op (49181.63 op/s), ±13.44 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 19.35 us/op (51680.97 op/s), ±6.67 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: pointAddScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 31.91 us/op (31340.16 op/s), ±5.38 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 37.50 us/op (26665.18 op/s), ±13.94 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 35.54 us/op (28138.46 op/s), ±5.03 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: pointCompress
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 5.37 us/op (186150.91 op/s), ±29.67 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 5.33 us/op (187597.75 op/s), ±14.56 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 5.29 us/op (189093.07 op/s), ±14.08 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-z)
====================================================================================================
Benchmarking function: pointFromScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 31.34 us/op (31912.49 op/s), ±4.70 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 40.01 us/op (24995.73 op/s), ±5.80 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 40.31 us/op (24808.60 op/s), ±4.73 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: pointMultiply
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 16.66 us/op (60010.31 op/s), ±8.40 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 18.45 us/op (54187.41 op/s), ±7.12 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 18.53 us/op (53977.54 op/s), ±6.95 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: privateAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 2.58 us/op (387900.15 op/s), ±6.47 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 4.75 us/op (210589.27 op/s), ±84.74 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 2.60 us/op (384892.87 op/s), ±6.54 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: privateSub
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 4.49 us/op (222611.55 op/s), ±21.92 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 4.61 us/op (216906.69 op/s), ±22.10 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 4.77 us/op (209729.11 op/s), ±20.50 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: sign
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 52.40 us/op (19084.55 op/s), ±3.65 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 61.26 us/op (16325.12 op/s), ±3.31 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 62.06 us/op (16112.42 op/s), ±3.63 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
Benchmarking function: verify
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API, opt-level-3): 60.67 us/op (16482.53 op/s), ±3.20 %
tiny-secp256k1 (Rust addon, N-API, opt-level-s): 67.71 us/op (14768.41 op/s), ±2.47 %
tiny-secp256k1 (Rust addon, N-API, opt-level-z): 67.72 us/op (14767.04 op/s), ±2.46 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API, opt-level-3)
====================================================================================================
opt-level-3.so 1447000
opt-level-s.so 1353608
opt-level-z.so 1352792

after strip:

opt-level-3.so 383104
opt-level-s.so 309376
opt-level-z.so 309376
-Z build-std=panic_abort,std size size, after strip
yes 405208 366720
no 1448176 383104
bench on debian:i686 (VirtualBox)
====================================================================================================
Benchmarking function: isPoint
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 9.28 us/op (107720.02 op/s), ±3.28 %
tiny-secp256k1 (WASM): 113.20 us/op (8833.74 op/s), ±2.78 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: isPrivate
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 0.04 us/op (23150945.25 op/s), ±10.33 %
tiny-secp256k1 (WASM): 0.04 us/op (22990683.12 op/s), ±11.33 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: pointAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 60.38 us/op (16560.75 op/s), ±4.68 %
tiny-secp256k1 (WASM): 700.97 us/op (1426.60 op/s), ±2.57 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: pointAddScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 112.41 us/op (8895.81 op/s), ±5.24 %
tiny-secp256k1 (WASM): 1295.85 us/op (771.69 op/s), ±3.05 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: pointCompress
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 12.43 us/op (80457.22 op/s), ±9.14 %
tiny-secp256k1 (WASM): 111.72 us/op (8950.74 op/s), ±2.96 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: pointFromScalar
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 106.24 us/op (9412.77 op/s), ±4.17 %
tiny-secp256k1 (WASM): 1078.44 us/op (927.27 op/s), ±3.65 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: pointMultiply
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 57.94 us/op (17260.48 op/s), ±12.98 %
tiny-secp256k1 (WASM): 621.88 us/op (1608.02 op/s), ±3.76 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: privateAdd
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 3.48 us/op (287734.03 op/s), ±15.58 %
tiny-secp256k1 (WASM): 0.62 us/op (1609161.22 op/s), ±4.31 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (WASM)
====================================================================================================
Benchmarking function: privateSub
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 6.71 us/op (149037.59 op/s), ±34.65 %
tiny-secp256k1 (WASM): 0.81 us/op (1234345.31 op/s), ±6.81 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (WASM)
====================================================================================================
Benchmarking function: sign
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 348.95 us/op (2865.77 op/s), ±2.04 %
tiny-secp256k1 (WASM): 1442.88 us/op (693.06 op/s), ±0.36 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================
Benchmarking function: verify
----------------------------------------------------------------------------------------------------
tiny-secp256k1 (Rust addon, N-API): 404.37 us/op (2472.96 op/s), ±0.48 %
tiny-secp256k1 (WASM): 2381.73 us/op (419.86 op/s), ±0.32 %
----------------------------------------------------------------------------------------------------
Fastest: tiny-secp256k1 (Rust addon, N-API)
====================================================================================================

@fanatid fanatid marked this pull request as ready for review March 26, 2021 21:09
@fanatid
Copy link
Member Author

fanatid commented Mar 26, 2021

Need few more things:

but this should not prevent review.

Hope that review will not take a long time @junderw 😆

@junderw
Copy link
Member

junderw commented Mar 29, 2021

I am still in the middle of review.

One quick fix I would like to see:

  • Since we will bump major anyways, we should join sign and signWithEntropy. The Extra Data should just be an optional argument for sign... so basically remove sign and replace it with signWithEntropy.

@fanatid
Copy link
Member Author

fanatid commented Mar 29, 2021

Changed in fanatid#15.

@fanatid
Copy link
Member Author

fanatid commented Mar 30, 2021

Changed to ES6 import only in fanatid#16

@junderw
Copy link
Member

junderw commented Apr 12, 2021

tACK 364b416

@junderw
Copy link
Member

junderw commented Apr 12, 2021

Leftover tasks:

  1. README still says we are using C library. Which is true... but it should be more descriptive of how we use C -> Rust -> N-API / WASM.
  2. For releasing v2.0.0 I want to have some sort of PR where we can agree on a hash for the packaged WASM.
  • I will make a PR with v2.0.0 commit.
  • We will both build and create npm package with npm pack and try to get the same hash, or figure out why diff is occurring...
  • If not possible we should at least try to get WASM to same hash together.
  • Once we get the same hash and share it on the pull request, I will publish 2.0.0

@fanatid fanatid mentioned this pull request Apr 15, 2021
@fanatid
Copy link
Member Author

fanatid commented Apr 15, 2021

Moved to #55

@fanatid fanatid closed this Apr 15, 2021
@fanatid fanatid deleted the to-rust-update branch April 15, 2021 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants