Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
スマートコントラクトの監査について
Search
yudetamago
September 25, 2018
Technology
2
620
スマートコントラクトの監査について
yudetamago
September 25, 2018
Tweet
Share
More Decks by yudetamago
See All by yudetamago
ブロックチェーンとIndexer
yudetamago
0
960
Unityでブロックチェーンアプリを作る
yudetamago
0
1.8k
DApps開発特有の_ハマりポイントご紹介.pdf
yudetamago
1
1.4k
DApps開発事例 ~CryptoCrystal概要編~
yudetamago
3
340
Gasを誰が払うのか問題について
yudetamago
5
4.6k
Solidityの複数コントラク ト連携を色々試してる話
yudetamago
1
2.3k
Dapps開発におけるSoliidityのはまりどころ
yudetamago
3
2.4k
Other Decks in Technology
See All in Technology
Lambda Web AdapterでLambdaをWEBフレームワーク利用する
sahou909
0
180
TypeScript 7.0の現在地と備え方
uhyo
7
1.8k
アーキテクチャモダナイゼーションを実現する組織
satohjohn
1
1.1k
Go 1.26 Genericsにおける再帰的型制約 / Recursive Type Constraints in Go 1.26 Generics
ryokotmng
0
130
AWS CDK「読めるけど書けない」を脱却するファーストステップ
smt7174
3
190
Oracle Cloud Infrastructure IaaS 新機能アップデート 2025/12 - 2026/2
oracle4engineer
PRO
0
170
【Oracle Cloud ウェビナー】【入門編】はじめてのOracle AI Data Platform - AIのためのデータ準備&自社用AIエージェントをワンストップで実現
oracle4engineer
PRO
1
170
Go標準パッケージのI/O処理をながめる
matumoto
0
230
Yahoo!ショッピングのレコメンデーション・システムにおけるML実践の一例
lycorptech_jp
PRO
1
230
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
400
最強のAIエージェントを諦めたら品質が上がった話 / how quality improved after giving up on the strongest AI agent
kt2mikan
0
200
詳解 強化学習 / In-depth Guide to Reinforcement Learning
prinlab
0
300
Featured
See All Featured
Color Theory Basics | Prateek | Gurzu
gurzu
0
260
Music & Morning Musume
bryan
47
7.1k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Design in an AI World
tapps
0
170
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
How to Talk to Developers About Accessibility
jct
2
150
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
260
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
640
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
Producing Creativity
orderedlist
PRO
348
40k
Six Lessons from altMBA
skipperchong
29
4.2k
Transcript
スマートコントラクトの 監査について ゆで卵(@takayukib) 2018/9/25 blockchain.tokyo #12
⾃⼰紹介的なやつ 名前:ゆで卵(@takayukib) 所属:フリーランス、トークンポケット株式会社 その他 • CryptoCrystalというDappsを作っています • 株式会社LayerXでもお仕事してます 1
監査は何故必要か üスマートコントラクトはデプロイすると基 本的にはアップデート出来ない ü通貨・トークンを扱うためミッションクリ ティカルである 2
今⽇のテーマ スマートコントラクトの開発者・監査者 どちらもが幸せになれるように 良いコードを書きましょう! 3
4 監査対象になるもの(⼀例) スコープ ü セキュリティ ü トークンの仕様 ü トラストレス性 ü
アーキテクチャ ü ⾔語の慣習 ü WPとの整合性 内容 ü コード本体 ü デプロイ⽤スクリプト ü ホワイトペーパー(WP) ü (テストコード) 参考: https://www.smartcontractsecurityalliance.com/
監査内容の各例 5
セキュリティ(よくある例) üオーバーフロー 基本的に計算部分は全てSafeMath等のライブラリを使うことを推奨 üfor loopのindexの上限 forループの上限値が無いとblock gas limitをオーバーするリスクがある üアクセス制御の付け忘れ onlyOwnerや、特定のコントラクトからのみ呼ばれるなど
6
アクセス制御の例(Proxy Pattern) 7 Main Contract Proxy Contract Deployer Another User
onlyOwner onlyProxy Contract これを付ける 参考: https://blog.zeppelinos.org/proxy-patterns/
unbounded loopの例 function addTokenGrant(address _grantee, uint256 _value) external onlyOwner {
… for (uint i = 0; i < tokenGrantees.length; i++). { require(tokenGrantees[i] != _grantee); } 8 block gas limitを超えないように 常にループ回数の上限は確認する https://blog.zeppelin.solutions/kin-token-audit-121788c06fe これ
トラストレス性 極⼒onlyOwner等のトラストレス性を無くすものは付けないよう にする。 例外と思われるもの üProxy Patternでのコントラクトアップデート(ownerが必要) üCloudSaleのロックアップ期間の設定(法律改正によって変わる可能性があるなど) 9 参考: SolidifiedによるCycled
ICOに対するトラストレス性の指摘 https://github.com/solidified- platform/audits/blob/22cda93a7897b4e2f2b0f3689b170eea918fc85d/Audit%20Report%20- %20Cycled%20ICO%20%5B04.25.18%5D.pdf
トークンの仕様(ERC20の例) 基本的にはOpenZeppelin Solidityを 使っていれば問題なし。 標準以外の機能を追加するとき ütransfer、transferFromでboolを返す üトークンのdistribution、airdropはトークン⾃体のコントラクトと分ける 10
⾔語の標準的な慣習(Solidityの例) üOpenZeppelin Solidityを使う üコンパイラのバージョンを最新にする üuint, uint256などの表記ゆれを無くす üLinter(solium, solhint)を使う 11 ⼀番重要
アーキテクチャ 12 ü よく知られているパ ターンを使う ü 図があると良い Facadeパターンの例 https://github.com/cryptocrystalio/crypto crystal-
bounty/blob/118cd744ffc2d8ff0682ef0638 43c4704133fab5/basic.md
アーキテクチャの良い例 0x protocol 2.0.0 specification (ERC20 Exchange) 13 https://github.com/ConsenSys/0x_audit_report_2018-07-23 https://github.com/0xProject/0x-protocol-
specification/blob/189eaf696b35e021860bd9a4f147ed0eed148441/v2/v2-specification.md
14 今後の展望と課題
auditの⾃動化(サービス) Quantstampの例 https://quantstamp.com/public-reports reentrancyのチェックや、assertがfailする条件などを⾃動で確 かめることが出来る 15
auditの⾃動化(ツール) mythril https://github.com/ConsenSys/mythril 16 ※厳密にはconcolic 参考: https://github.com/b-mueller/laser-ethereum üシンボリック実⾏(※)をするツール üバックエンドはlaser-ethereumというシンボリック実⾏⽤の VMを利⽤
まとめ ü⽬的・全体像・仕様はWPなどで⽂書・図にまとめる üOpenzeppelin Solidity使う üコード・関連スクリプト・テストなどを全て含める üセキュリティ・実装はベストプラクティスに従う 17