Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Known Attacks from Ethereum Smart Contract Best...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for Ara Ara
November 15, 2018

Known Attacks from Ethereum Smart Contract Best Practices

Ethereum Smart Contract Best Practices https://consensys.github.io/smart-contract-best-practices に書かれている既知の攻撃についてまとめました。

参考

● Known Attacks - Ethereum Smart Contract Best Practices
https://consensys.github.io/smart-contract-best-practices/known_attacks/

● 既知の攻撃方法 - Ethereum Smart Contract Best Practices(日本語訳)
https://msykd.github.io/smart-contract-best-practices/known_attacks/

● スマートコントラクトのセキュリティ Part 1 – Loom Network JP – Medium
https://medium.com/loom-network-japanese/%E3%82%B9%E3%83%9E%E3%83%BC%E3%83%88%E3%82%B3%E3%83%B3%E3
%83%88%E3%83%A9%E3%82%AF%E3%83%88%E3%81%AE%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E
3%82%A3-part-1-817472e0fe4e

● スマートコントラクトのセキュリティ Part 2 – Loom Network JP – Medium
https://medium.com/loom-network-japanese/%E3%82%B9%E3%83%9E%E3%83%BC%E3%83%88%E3%82%B3%E3%83%B3%E3
%83%88%E3%83%A9%E3%82%AF%E3%83%88%E3%81%AE%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E
3%82%A3-part-2-6ef700df00af

● 【Ethereum】ERC20トークンで発生した脆弱性「batchOverflow」について - Paoの技術力を磨くブログ
http://pao2.hatenablog.com/entry/2018/04/27/005224

● デリゲートコール参考:
https://blog.zeppelin.solutions/on-the-parity-wallet-multisig-hack-405a8c12e8f7
https://zoom-blc.com/how-to-develop-upgradable-contracts
http://sakataharumi.hatenablog.jp/entry/2018/10/09/224806

Avatar for Ara

Ara

November 15, 2018
Tweet

More Decks by Ara

Other Decks in Programming

Transcript

  1. 再入性(Reentrancy) • fallback 関数で何度も呼び出されることで、 コントラクトの残高がなくなる or GAS が尽きるまで送金され続ける • 回避方法

    ◦ 状態変更したあとに外部関数を呼び出す ◦ call.value()() の代わりに send() を使う(GAS 上限がある) 攻撃用コントラクトの fallback 関数
  2. オーバーフローとアンダーフロー • Solidity は 256ビットの数値まで扱える • 符号なし整数で 2²⁵⁶-1 を超えると 0

    になり、0 を下回ると最大値になる • 対策:OpenZeppelin の SafeMath ライブラリを使う
  3. オーバーフローとアンダーフロー いくつかの ERC20 トークンで見つかった BatchOverFlow 脆弱性 _value に非常に大きな数を渡すと、 合計値 amount

    が桁溢れで小さくなり、 送信者の残高のチェックをすり抜けて、 ありもしない金額が送金されたことになる
  4. コントラクトへの強制送金 • selfdestruct(address) = コントラクトを削除する関数 ◦ 引数で指定したアドレスに、コントラクトの残高が送金される ◦ 仕様上、このとき指定アドレスの fallback

    関数は呼び出されない(!) → fallback 関数でコントラクトへの送金を失敗させるコードを書いてい ても、強制的に送金されうる • 意図しない挙動を防ぐため、コントラクトの残高がないことを require で確 認するようなコードは書いてはならない
  5. 可視性とデリゲートコール • 可視性 ◦ Parity ウォレットのハック事件:意図しない関数が public だった ◦ 外部のやりとりが必要でない限り、関数は

    private または internal にす ること • デリゲートコール(delegatecall,委譲呼び出し) ◦ delegatecall() 実行元のコントラクトを A、呼び出し先のコントラクト を B としたとき、B が指す Storage 領域は A のものになる ◦ 詳しくは・・・ ▪ https://blog.zeppelin.solutions/on-the-parity-wallet-multisig-hack-405a8c12e8f7 ▪ https://zoom-blc.com/how-to-develop-upgradable-contracts ▪ http://sakataharumi.hatenablog.jp/entry/2018/10/09/224806
  6. さいごに Solidity で Ethereum スマートコントラクトを書くなら Ethereum Smart Contract Best Practices

    https://consensys.github.io/smart-contract-best-practices/ は絶対に読まないとだめ!
  7. 参考 • Known Attacks - Ethereum Smart Contract Best Practices

    https://consensys.github.io/smart-contract-best-practices/known_attacks/ • 既知の攻撃方法 - Ethereum Smart Contract Best Practices(日本語訳) https://msykd.github.io/smart-contract-best-practices/known_attacks/ • スマートコントラクトのセキュリティ Part 1 – Loom Network JP – Medium https://medium.com/loom-network-japanese/%E3%82%B9%E3%83%9E%E3%83%BC%E3%83%88%E3%82%B3%E3%83%B3%E3 %83%88%E3%83%A9%E3%82%AF%E3%83%88%E3%81%AE%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E 3%82%A3-part-1-817472e0fe4e • スマートコントラクトのセキュリティ Part 2 – Loom Network JP – Medium https://medium.com/loom-network-japanese/%E3%82%B9%E3%83%9E%E3%83%BC%E3%83%88%E3%82%B3%E3%83%B3%E3 %83%88%E3%83%A9%E3%82%AF%E3%83%88%E3%81%AE%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E 3%82%A3-part-2-6ef700df00af • 【Ethereum】ERC20トークンで発生した脆弱性「batchOverflow」について - Paoの技術力を磨くブログ http://pao2.hatenablog.com/entry/2018/04/27/005224