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
0318Substrateプレゼン資料.pdf
Search
Stake Technologies
March 18, 2019
Technology
640
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
0318Substrateプレゼン資料.pdf
Stake Technologies
March 18, 2019
More Decks by Stake Technologies
See All by Stake Technologies
Plasma NFT Deposit Range
staketechnologies
0
94
Substrate ink!
staketechnologies
0
48
Plasma on Substrate @Fukuoka
staketechnologies
0
94
Sub0 Recap Japanese
staketechnologies
0
79
Plasm Introduction
staketechnologies
1
130
2019.01ブロックチェーントレンド
staketechnologies
0
54
Other Decks in Technology
See All in Technology
生成AIを使って「人が」考える技術 ― AI時代の人機共想と実践ノウハウ|UNITT AC2026
ishiirikie
0
580
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
1.9k
会社説明資料
persolserverworks
0
9.7k
SREでアラート疲れを 解決しよう!
kairim0
1
220
「Docker Desktop不要の時代」は 来たのか?
ueponx
0
470
パッチ更新でterraform initが落ちた日
grimoh
1
120
ハードウェアコンペでもAI駆動開発が進んでいる話
iotengineer22
1
680
AI 時代の Azure エンジニアリング ~ 私たちは何を磨き、何を任せるのか ~
chack411
1
580
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
230
カンファレンスに参加した後の浮遊感とセルフケア
pauli
0
320
スキルを作る、その前に!複数人で使われるスキルを 作るためのプロセス
junkifurukawa
2
380
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
130
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
260
Test your architecture with Archunit
thirion
2
2.4k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Accessibility Awareness
sabderemane
1
240
Skip the Path - Find Your Career Trail
mkilby
1
250
The Cost Of JavaScript in 2023
addyosmani
55
10k
Color Theory Basics | Prateek | Gurzu
gurzu
1
480
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Transcript
Staked Substrate 2019.03.18 勉強会プレゼンスライド @StakedT
山下琢巳(@public_sate) 東京大学大学院 未踏クリエーター2018 昔の趣味 競技プログラミング (ACM-ICPC 2016-2017 World Final)
Splatoon(WiiU) (Splatoon 甲子園関東3位) スマブラ (地元最強) 週刊少年ジャンプ Twitter / 同人誌(C91) 自己紹介 2
SubstrateとはParity Technologiesが開発をしているOSSプロジェクト。ブロックチェーンを作 るとき必要となるコンポネントをフレームワーク化して提供している。 SubstrateはEthereumとPolkadotを作る上で学んだレッスンを活かし、その知見がツールに落とし 込まれている。そして、ユーザーはその恩恵を無料で手に入れることができるのだ。 Dr. Gavin Wood フレームワークを細かく見てみると、大きく分けて
Substrate Core Substrate Runtime Module Library(SRML) という2つによって構成されている。 Substrate Coreでブロックチェーンを作るのに最低限必要なコン ポネントを提供し、SRMLをプラグインすることによってブロックチェーンをカスタマイズすることがで きる。 3 Substrate Introduction
4 Overview
1. ブロックの同期 2. JSON-RPC API エンドポイント 3. 暗号技術に関するライブラリー 4. 安全で普及性の高い
libp2p 5. ストレージ 6. テレメトリー(リアルタイムの情報を遠隔サーバーに送信するための遠隔通信システム) 7. ライトクライアント 8. チェーンとバージョン管理 9. プラグイン可能なコンセンサス 10. JavaScript utils(JSのクラス) 11. トランザクションとブロック生成のメカニズム 12. WebAssenbly インタープレター 13. Polkadotによおるインターチェーンコネクティビティー 5 Substrate Core
1. Accounts & Balances(暗号通貨の残高を確認するアカウント) 2. Assets(ファンジブルアセット) 3. Consensus(コンセンサスのアップデート機能) 4. Contracts(スマートコントラクト機能)
5. Council(プライベート投票機能) 6. Democracy(公開投票機能) 7. Sessions(Authoritiesのローテーション機能) 8. Staking(PoS機能) 9. Timestamp(タイムスタンプ機能) 10. Treasury(DAO機能) 6 Substrate Runtime Module Library
Transaction Life Cycle 7 Substrate Node Transaction Tx Tx Tx
Tx Transaction 検証 Tx0 Tx1 Tx2 順序付け Block 実行 Substrate Nodes Broad Cast Client
Substrate is a fully extendable and customizable framework, it is
possible to define your own custom consensus algorithm. 例:GRANDPA: GHOST-based Recursive Ancestor Deriving Prefix Agreement 単一のブロックに投票するのではなく、highest blockに対して投票を行う。2/3を 得ているブロックが確定される。 • ブロックの生成とファイナリティを完全に分岐する。 • 並列に生成されたブロックについて、並列に検証する。 • 過半数の投票を得たブロックの最近祖先が最終確定する。 この図の場合、A,B,Cが確定される。 8 Consensus
9 インストールから起動 Reference: https://docs.substrate.dev/docs/creating-a-custom-substrate-chain
新しいモジュールを作る(demo:賭けゲーム) 10 今回のサンプルチェーンでは SRML で定義されているバランスを扱う Trait を継承する。 balances::Trait は system::Trait
を継承している。 Trait を定義する。 SRML で既に定義されている Trait をベースとして継承すると楽に書ける。
ストレージを定義する 11 decl_storage! マクロを用いて定義する。 Reference: https://wiki.parity.io/decl_storage 文法 <ストレージ名(UpperCamel)> get(<ストレージ名(snake_camel)>): build(<初期化式>):
<ストレージの型> キーバリューストレージ型の定義 <ストレージの型> := map <キー値の型> => <バリュー値の型>
ストレージを定義する 12 Map version
Rust で標準的に使用可能な型に加え以下の型が Storage の型として利用できるプリミティブな型として用意されている。 • type AccountId = <Signature as
Verify>::Signer = H256 • type AccountIndex = u32 • type Balance = u128 • type Block = Block<Header, UncheckedExtrinsic> • type BlockId = BlockId<Block> • type BlockNumber = u64 • type Hash = H256 • type Header = Header<BlockNumber, BlakeTwo256, DigestItem<Hash, SessionKey>> • type Index = u64 • type SessionKey = Ed25519AuthorityId • type Signature = Ed25519Signature • type Timestamp = u64 • type UncheckedExtrinsict = OpaqueExtrinsict 13 ストレージを定義する。 ハッシュ関数: BLAKE2
ストレージを定義する 14 今回のサンプルチェーンでは簡単な賭けゲームを作る。 - 賭け金を設定する Payment - 現在溜まっている金額 Pot -
乱数を生成するための変数 Nonce をストレージとして用意する。
モジュールを定義する 15 Reference: https://docs.substrate.dev/docs/decl_module
モジュールを定義する 16 ※おまじない ※イベント を呼び出す予約関数を使えるようにする。 自分で定義した 公開メソッド (エントリポイント) 第一引数は `origin`
で固定 型 Origin を省略して書く。 Origin の実際の中身は Root/SignedAccountId/Inherent のいずれか 返り値 Result は `Result<(), &'static str>` 成功時は Ok(()) を返す。
モジュールを定義する(注意) 17 1. トランザクションは実行中に中断されたとしても変更は永続的である。 a. 問題点 i. つまり、トランザクションが途中で終了してもロールバックが発生しない。 ii. 設計者にトランザクションのアトミック性の保証を委ねている。
b. 解決策 i. デザインパターンで解決を模索。 ii. コード解析で解決策を模索。 2. DoS 対策をすべきである。 a. 問題点 i. 計算コストが少なからず発生するため、実行者はそこにリスクが無い限り 容易に大量の関数を叩く攻撃が可能である。 ii. invalid な関数を大量に投げることでも DoS 攻撃が可能である。 b. 解決策 i. 利用者の balance から手数料を引くなどの設計をする。 ii. 攻撃者に対するペナルティを設ける。
モジュールを定義する 18 変更は必ず最後にまとめて行う
テストを書く 19 1. Test 環境に Origin を実装 2. Test 環境にTrait
を実装 Reference: https://github.com/satellitex/example_substrate/blob/master/runtime/src/demo.rs#L91 簡単のためテスト環境では AccountId は u64型
テストを書く 20 簡単のためテスト環境では AccountId を u64型で代用できる。
UI の設定 21 + + Reference: https://github.com/satellitex/example_ui_substrate
https://qiita.com/SotaWatanabe/items/f8c1d2cf6ff2606b42a9 22 参考 https://github.com/satellitex/example_substrate https://github.com/satellitex/example_ui_substrate 今回書いた Sample Code リンクまとめ 公式ドキュメント
> cargo doc --package substrate --open
4/9 DOT DAY in Tokyo で登壇します(いまのところ) 23 アナウンス