Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Introduction to mcl-wasm
Search
herumi
September 15, 2023
Technology
910
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to mcl-wasm
herumi
September 15, 2023
More Decks by herumi
See All by herumi
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.5k
Constant Integer Division and Modulo Optimization Revisited (English)
herumi
0
140
定数整数除算・剰余算最適化再考
herumi
1
250
Constant integer division faster than compiler-generated code
herumi
2
1.2k
Batch Processing Algorithm for Elliptic Curve Operations and Its AVX-512 Implementation
herumi
0
310
Mathematics used in cryptography around us
herumi
2
1.2k
Xbyak Internals and Hacks
herumi
1
880
The NOPs You Don't Know
herumi
4
600
LLVM/ASMを使った有限体の高速実装
herumi
0
350
Other Decks in Technology
See All in Technology
Issue 駆動でスペシャリストの意図を届ける、AI 実装のアクセシビリティ向上
thkt
0
120
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2.1k
SREは、MCPとAutopilotをこう使え!
kazumax55
3
910
【技術的負債conf】事業成長に伴う技術的負債の説明責任とAIによるモニタリング、認知的負債について
i35_267
3
1.8k
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
9
4.6k
リアーキテクチャ後の障害ゼロを目指したShadow Testingの取り組み
nihonbuson
PRO
1
160
AI時代、データエンジニアが一番おもろい
genshun9
0
670
SREの視点で考えるSIEM活用術 〜AWS環境でのセキュリティ強化〜
cscengineer
PRO
0
120
エージェントはローカル、検証はMicroVM — Lambda MicroVMsでつくるServerless CI
fujioka6789
3
410
AIは推し活である。
kurazuuuuuu
1
830
越境するなら専門用語を使うな高校校歌 / If you wanna cross border, you shouldn't use jargon
vtryo
0
150
サーバーレスをどこまで使う? WebRTC対戦ゲームで選んだVPSとの共存設計
kaidouji85
0
120
Featured
See All Featured
Site-Speed That Sticks
csswizardry
13
1.5k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
990
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
280
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
730
Faster Mobile Websites
deanohume
310
32k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Rails Girls Zürich Keynote
gr2m
96
14k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Transcript
暗号プリミティブライブラリ mcl-wasmの紹介 2023/9/15 WebAssembly night #11 光成滋生
@herumi • サイボウズ・ラボで暗号と最適化の研究・OSS開発 • ペアリング/BLS署名ライブラリmcl/bls • https://github.com/herumi/mcl • Go/Java/C#/Rust binding
• Node.js/Wasm用パッケージ(今回紹介) • x64用JITアセンブラXbyak • https://github.com/herumi/xbyak • Intelの深層学習フレームワークoneDNNのエンジン • スーパーコンピュータ富岳版Xbyak_aarch64も関わる • RISC-V版も開発中 2 / 8
mcl/-wasm • 様々な暗号技術の基本パーツを提供 https://www.npmjs.com/package/mcl-wasm • IDベース暗号・準同型暗号 • BLS署名・集約署名 • ゼロ知識証明・秘密分散など
• Ethereum Foundationや Optimismのgrantを受ける • アクセス数 • GitHubのDependency graph : 15万 Repositories • 2021/4/1からの総download数 : 1200万over • https://npm-stat.com/charts.html?package=mcl-wasm&from=2021-04-01 3 / 8 600K 2021/Apr 2023/Sep 月間ダウンロード数 400K 200K
BLS署名 • nodeでの実行例 • bls-eth-wasmなどの専用packageも提供 const mcl = require('mcl-wasm') mcl.init().then(()
=> { const P = new mcl.G1() P.setStr('1 -1 1') // 初期設定 const s = new mcl.Fr() s.setByCSPRNG() // 署名鍵(秘密鍵)の作成 const Q = mcl.mul(P, s) // 検証鍵(公開鍵)の作成 const H = mcl.hashAndMapToG2('abc') // 検証文字列のハッシュ const sig = mcl.mul(H, s) // ハッシュに対する署名 const ok = mcl.pairing(Q,H).isEqual(mcl.pairing(P,sig))//署名の検証 // 注意 : もっと効率のよい方法はある }) 4 / 8
• JavaScriptのBigIntによる有限体Frの演算実装 • 加減乗算の後に素数rで割った余りを求める操作 • 性能評価 • 単位:usec • あれ,
add/subはBigIntの方が速い??? mcl-wasmの多倍長演算とBigIntとの比較 const g_r = BigInt(254ビットの素数) function FrAdd (x, y) { const z = x + y return z >= g_r ? (z - g_r) : z } function FrMul (x, y) { return (x * y) % g_r } BigInt mcl-wasm add 0.113 0.437 sub 0.099 0.444 mul 0.681 0.572 5 / 8
• JavaScriptはdestructorが無い(GCがある)言語 • mcl-wasmは関数呼び出しをメモリ操作処理でラップしてる • WasmにGCが正式サポートされればまた変わるかも • JS側でメモリ管理を自分でするなら速い • 1回当たり約0.4usecの変換コスト(@Xeon
8280 2.8GHz) WAMの呼び出し変換コスト add(x : Fp, y : Fp) => Fp { const z = new Fp() const stack = mod.stackSave() // 現在のWasmのSPを取得 const xPos = x._sallocAndCopy() // スタックに確保して状態をコピー const yPos = y._sallocAndCopy() // スタックに確保して状態をコピー const zPos = z._salloc() // スタックに確保 mod._mclBnFpAdd(zPos, xPos, yPos) // Wasm関数呼び出し z._save(zPos) // 結果をzにコピー // スタックを元に戻す mod.stackRestore(stack) return z } BigInt mcl-wasm direct call add 0.113 0.437 0.035 sub 0.099 0.444 0.035 mul 0.681 0.572 0.130 6 / 8
• 楕円曲線の加算のベンチマーク • 変換コストは相対的に無視できる • ペアリングなどの複雑な演算処理はもっと差が開く 重たい計算はmcl-wasmが速い BigInt mcl-wasm direct
G1::add 21.609 7.9 7 / 8
• 暗号ライブラリmcl/mcl-wasmの紹介 • 軽い関数呼び出しはWasm側が不利になることがある • 暗号や実装の解説記事を書いてます • https://zenn.dev/herumi まとめ 8
/ 8