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

スマートコントラクト・セキュリティ最新事情

Avatar for YH YH
September 20, 2019

 スマートコントラクト・セキュリティ最新事情

Road to Devcon 4.0

Avatar for YH

YH

September 20, 2019
Tweet

More Decks by YH

Other Decks in Technology

Transcript

  1. A G E N D A 1. Smart Contractsについて 2.

    Quantstampについて 3. Smart Contract Vulnerabilities
 4. .transfer() vs .send() vs .call()
  2. About Smart Contracts • 取引の代替⼿手段
 • Trustless and Decentralized
 •

    過去2年年間で約2兆円以上が
 スマコンによって調達されている
 • スマコンの数は急増中
 

  3. Quantstampについて • Richard MaとSteven Stewart が2017に創業 • スマコンのセキュリティ・プロトコールを開発 • Y

    Combinator を卒業 (batch W2018) • コード監査によって1000億円以上を確保
 • 取引所のセキュリティアドバイザー

  4. function withdraw() public { # ユーザーの残⾼高を取得 amountToWithdraw = userBalances[msg.sender];  

    # 残⾼高の引き出し、fallbackを使⽤用して無限に引き出すことが可能 require(msg.sender.call.value(amountToWithdraw)()); # ユーザーの残⾼高を更更新 userBalances[msg.sender] = 0;    } Example: The DAO Hack
  5. function withdraw() public { # ユーザーの残⾼高を取得 amountToWithdraw = userBalances[msg.sender];  

    # 残⾼高の引き出し、fallbackを使⽤用して無限に引き出すことが可能 require(msg.sender.call.value(amountToWithdraw)()); # ユーザーの残⾼高を更更新 userBalances[msg.sender] = 0;    } 当時のレートで約50億円が流失… Example: The DAO Hack smart contact #fallback function
 function () public { …. }
  6. function withdraw() public { # ユーザーの残⾼高を取得 amountToWithdraw = userBalances[msg.sender];  

    # ユーザーの残⾼高を更更新 userBalances[msg.sender] = 0; # fallbackを使⽤用しても無限に引き出すことはできない require(msg.sender.call.value(amountToWithdraw)()); } Example: The DAO Hack smart contact #fallback function
 function () public { …. }
  7. .transfer() vs .send() vs .call() address.call.value() address.send() address.transfer() adjustable gas

    yes no no gas limit all/setable 2300 2300 return value on error FALSE FALSE exception
  8. EIP 1283: Net gas metering for SSTORE without dirty maps

    Before Constantinople After Constantinople all SSTORE operations > 5000 gas SSTORE operation > 200 gas > 2300 gas limit > 2300 gas limit
  9. function withdraw() public { # check amountToWithdraw = userBalances[msg.sender];  

    # effects userBalances[msg.sender] = 0; # interaction require(msg.sender.call.value(amountToWithdraw)()); } checks-effects- interaction pattern smart contact #fallback function
 function () public { …. }
  10. function withdraw() public nonReentrant { # check amountToWithdraw = userBalances[msg.sender];

      # interaction require(msg.sender.call.value(amountToWithdraw)()); # effects userBalances[msg.sender] = 0; } re-entrancy guards smart contact #fallback function
 function () public { …. }