certifying functional correctness of ethereum smart
play

Certifying functional correctness of Ethereum smart contracts Dr. - PowerPoint PPT Presentation

Certifying functional correctness of Ethereum smart contracts Dr. Petar Tsankov Co-founder and Chief scientist, ChainSecurity Senior researcher, ICE center, ETH Zurich @ptsankov Inter-disciplinary research center at Next-generation blockchain


  1. Certifying functional correctness of Ethereum smart contracts Dr. Petar Tsankov Co-founder and Chief scientist, ChainSecurity Senior researcher, ICE center, ETH Zurich @ptsankov

  2. Inter-disciplinary research center at Next-generation blockchain security the #1 CS department in Europe using automated reasoning https://chainsecurity.com @chain_security Blockchain Safety of AI Security security and privacy

  3. What do these have in common? contract Token { mapping(addr=>uint) balances; function balanceOf(address a){ return balances[a]; Must not fail! } function transfer(address to, uint n){ balances[msg.sender] -= n; balances[to] += n; }

  4. What sets them apart ? contract Token { mapping(addr=>uint) balances; function balanceOf(address a){ return balances[a]; } Certified using formal verification Ce Be Best-ef effor ort function transfer(address to, uint n){ balances[msg.sender] -= n; balances[to] += n; }

  5. What sets them apart ? contract Token { mapping(addr=>uint) balances; function balanceOf(address a){ return balances[a]; } Certified using formal verification Ce Be Best-ef effor ort function transfer(address to, uint n){ balances[msg.sender] -= n; balances[to] += n; }

  6. Our mission Bring formal security guarantees to contracts - Mathematically model all behaviors of smart contracts - Prove that no bugs can occur - Scale via automation and state-of-the-art research

  7. Our mission Bring formal security guarantees to contracts VerX Formal verifier for certifying custom functional - Mathematically model all behaviors of smart contracts specifications of Ethereum contracts - Prove that no bugs can occur - Scale via automation and state-of-the-art research

  8. Why is it hard to ce certify the custom behavior of smart contracts? Note: Find generic vulnerabilities Certify cu custom m behavior

  9. Functional correctness Crowdsale Escrow uint raised; mapping(address => uint) deposits; uint goal; uint closeTime; function deposit() { .. } function withdraw() { .. } function invest() { .. } function claimRefund() { .. } function close(){ .. } Requirements Sum of all deposits equals the escrow’s ether balance - Investors cannot claim refunds after the goal is reached -

  10. Step 1: Fo Formalize requirements (Informal) requirement: ”Sum of all deposits equals the escrow’s ether balance” Formal property always sum(Escrow.deposits) == Escrow.balance)

  11. Step 2: Ch Check formal property Initial state invest(0) invest(9999) claimRefund() ... ... claimRefund() invest (0) invest(9999) Unbounded depth Infeasible to brute-force width

  12. Methods and guarantees RELIABILITY Time consuming - Manual review Ca Can miss errors -

  13. Methods and guarantees RELIABILITY Fuzzing - Automated testing Symbolic execution - Ca Can mi miss er errors - Time consuming - Manual review Ca Can miss errors -

  14. Checked states Fuzzing Missed states Initial state invest(9999) invest(0) claimRefund() ... ... claimRefund() invest (0) invest(9999) Tools: ChainFuzz, Echidna, ContractFuzzer, Harvey, … To

  15. Checked states Symbolic execution Missed states Initial state invest(9999) invest(0) claimRefund() ... ... invest (0) invest(9999) claimRefund() Tools: Oyente, Manticore, Mythril, MAIAN, … To

  16. Methods and guarantees Automated program - Formal verification RELIABILITY verification Prove Pr ves absence of errors - Fuzzing - Automated testing Symbolic execution - Ca Can mi miss er errors - Time consuming - Manual review Ca Can miss errors -

  17. Checked states Formal verification invest(0) invest(0) invest(9999) invest(9999) claimRefund() claimRefund() ... ... ... ... VerX claimRefund() claimRefund() invest (0) invest (0) invest(9999) invest(9999)

  18. Automated formal verification with VerX “Investors can claim refunds only if the sum of deposits never exceeded 10,000 ether “ Smart contract Formal property mapping(address => uint) deposits; (always Escrow.claimRefund function claimRefund(){..} ==> !before(sum(deposits) >= 10000) Ve Verified Ma May not t hold

  19. Expressive and intuitive specifications always Escrow.deposit(address) Access control ==> (msg.sender == Escrow.owner)

  20. Expressive and intuitive specifications always Escrow.deposit(address) Access control ==> (msg.sender == Escrow.owner) State-based always (now > Vault.refundTime + 1 week) properties ==> ! Vault.refund(uint256)

  21. Expressive and intuitive specifications always Escrow.deposit(address) Access control ==> (msg.sender == Escrow.owner) State-based always (now > Vault.refundTime + 1 week) properties ==> ! Vault.refund(uint256) State machine always !(once(state == REFUND) properties && once(state == FINALIZED)

  22. Expressive and intuitive specifications always Escrow.deposit(address) Access control ==> (msg.sender == Escrow.owner) State-based always (now > Vault.refundTime + 1 week) properties ==> ! Vault.refund(uint256) State machine always !(once(state == REFUND) properties && once(state == FINALIZED) Invariants over always totalSupply == sum(balances) aggregates

  23. Expressive and intuitive specifications always Escrow.deposit(address) Access control ==> (msg.sender == Escrow.owner) State-based always (now > Vault.refundTime + 1 week) properties ==> ! Vault.refund(uint256) State machine always !(once(state == REFUND) properties && once(state == FINALIZED) Invariants over always totalSupply == sum(balances) aggregates Multi-contract always Token.totalSupply >= Sale.issuance invariants

  24. Expressive and intuitive specifications always Escrow.deposit(address) Access control ==> (msg.sender == Escrow.owner) State-based always (now > Vault.refundTime + 1 week) properties ==> ! Vault.refund(uint256) Solid formal foundation State machine always (! once(state == REFUND) (Temporal logic) properties && once(state == FINALIZED) Invariants over always totalSupply == sum(balances) aggregates Multi-contract always Token.totalSupply >= Sale.issuance invariants

  25. Dealing with unbo unded state spaces unbounde Use symbolic (not concrete) Initial state values invest(X) claimRefund(Y) Bounded depth Use program invest(X) claimRefund(Y) abstraction Feasible width

  26. Sound symbolic reasoning - Hash-based storage allocation - Gas mechanics - Calls to untrusted contracts - Dynamically constructed contracts

  27. Impact and experience Fast and sc scalable formal verification of Ethereum contracts Fa (157+ contracts, 100+ properties, ~1 min / property) Benefits: - Certif Ce tify what works (go beyond bug finding) - Re Re-us use libraries of common specifications - cation is cheap Re Re-ce certi rtificati

  28. How to get access to VerX? Demo: http://verx.ch VerX as a service: contact@chainsecurity.com

  29. One more announcement…

  30. First automated framework for testing Solidity compilers

  31. First automated framework for testing Solidity compilers

  32. First automated framework for testing Solidity compilers https://github.com/eth-sri/soltix https://discord.gg/XKSVavS

  33. Safety certification of contracts VerX: Automated formal verification “Investors can claim refunds only if the sum of deposits never exceeded 10,000 ether “ Formal property Smart contract contract Token { mapping(addr=>uint) balances; mapping(address => uint) deposits; function balanceOf(address a){ (always Escrow.claimRefund return balances[a]; } Must not fail! function claimRefund(){..} function transfer(address to, ==> !before(sum(deposits) >= 10000) uint n){ balances[msg.sender] -= n; balances[to] += n; } Ve Verified May not hold Ma Methods and techniques Symbolic reasoning + abstraction Initial state invest(X) claimRefund(Y) - Automated program Formal verification - RELIABILITY verification Proves absence of errors Pr invest(X) claimRefund(Y) - Fuzzing - Symbolic execution Automated testing - Ca Can mis miss er errors - Time consuming Bounded depth - Manual review Can miss errors Ca Feasible width

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend