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
初対面のメンバーがチームを組み、Claude Codeでゼロからサービスをリリース
mkdev10
1
120
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
370
ビジネスを止めない技術的負債の返済のための戦略とその手法 - 技術的負債と向き合う / Complexity and Simplicity
soudai
PRO
3
680
[AWS 秋のクラウドオペレーション祭り 2026]AWS DevOps Agentで変わるリリースと運用対応 ~リリース管理機能と Directed actions のご紹介~
furuton
4
1.2k
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
150
Running Kotlin + Quarkus with Lambda
nealle
0
380
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
130
Codex概要
ymiya55
0
500
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
6
4.4k
事業活動を AI Ready にする攻めと守りのデータエンジニアリング / data-engineering-for-ai-ready-business
pei0804
7
2.4k
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
120
go-sqletch
moznion
0
130
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
320
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
Evolving SEO for Evolving Search Engines
ryanjones
0
310
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
How to train your dragon (web standard)
notwaldorf
96
6.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
WENDY [Excerpt]
tessaabrams
14
40k
Skip the Path - Find Your Career Trail
mkilby
1
250
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
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 アナウンス