1 of 68

Evolution of Smart Contract Security in the Ethereum Ecosystem

Manuel Araoz, CTO at

@maraoz

2 of 68

The Year in Smart Contract Security

New Security Patterns and Techniques

Pending Challenges

3 of 68

Pre-history: The Dark Ages

4 of 68

Pre-history: The Dark Ages

The DAO

FirePonzi scam

RNG seed fails

Governmental

ETH-backed ERC20 token

The King of the Ether

Rock paper scissors

Rubixi

2016

5 of 68

Rubixi

6 of 68

Rubixi

7 of 68

Rubixi

8 of 68

Pre-history: The Dark Age

MAY 2016:

“We Need Some Best Practices For Smart Contracts”, Peter Vessenes

JUNE 2016: TheDAO Hack��- 14% of all ether tokens were held by TheDAO contract.

- 50M in USD value stolen with the hack.

- Solution: Hard fork :/

9 of 68

The Age of Enlightenment

10 of 68

OpenZeppelin

SEPT 2016: OpenZeppelin is born, a week before DEVCON2!

11 of 68

12 of 68

OpenZeppelin

2017

>8% weekly growth for 3 months.

1800+ slack members��60+ contributors

280+ pull requests

220+ issues

13 of 68

OpenZeppelin

2017

>8% weekly growth for 3 months.

1800+ slack members��60+ contributors

280+ pull requests

220+ issues

14 of 68

Ethereum platform updates

15 of 68

Ethereum platform matured a lot

EIP150

callstack

attack

16 of 68

Solidity new keywords

payable

assert

transfer

pure/view

require

revert

17 of 68

Serpent R.I.P.

  • 8 critical vulnerabilities found
  • REP token frozen

18 of 68

Byzantium’s impact on Security

Added support for big integer modular exponentiation (EIP198)

=> RSA signature verification

https://github.com/ethereum/EIPs/pull/214

New opcode: STATICCALL (EIP214)

=> non-state-changing calls to other contracts

https://github.com/ethereum/EIPs/pull/214

Added opcodes for return data handling. (EIP211)

=> upgradability proxies

https://github.com/ethereum/EIPs/pull/211

19 of 68

New Security Patterns and Techniques

20 of 68

Adding features safely

21 of 68

Token with lockup: design

Goals:

  • Allow any token holder to lock tokens for others.�
  • Add as little extra code as possible

22 of 68

Token with lockup: design

Goals:

  • Allow any token holder to lock tokens for others.�
  • Add as little extra code as possible

Idea:

  1. Add extra lock function that transfers the tokens and stores when they should be released.�
  2. Modify the standard transfer functions to honor these additional restrictions.

23 of 68

Token with lockup: code (1/3)

24 of 68

Token with lockup: code (2/3)

25 of 68

Token with lockup: code (3/3)

26 of 68

Token with lockup: code (3/3)

27 of 68

Can you spot the problem?

28 of 68

Can you spot the problem?

29 of 68

Token with lockup: simple fix

30 of 68

Token with lockup: modular approach

31 of 68

Security and Functionality

32 of 68

Crowdsale: modular approach

Crowdsale.sol

Token.sol

33 of 68

What can Software Engineering

teach us on

Smart Contract Security?

34 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.

35 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.

36 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.

!=

37 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.

38 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!

StandardToken.sol MyToken.sol Token.sol

ERC20.sol Coin.sol

39 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.

40 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.
  • Don’t repeat yourself.

41 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.
  • Don’t repeat yourself.
  • Write tests!!!

42 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.
  • Don’t repeat yourself.
  • Write tests!!!

43 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.
  • Don’t repeat yourself.
  • Write tests!!!

44 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.
  • Don’t repeat yourself.
  • Write tests!!!

45 of 68

Security and Software Engineering

  • Clear and simple code is ALWAYS better for security.
  • Naming matters.
  • Reuse existing audited code!
  • Don’t copy-paste.
  • Don’t repeat yourself.
  • Write tests!!!

46 of 68

Security and Software Engineering

47 of 68

Security and Trust Reduction

48 of 68

Security and Trust Reduction

49 of 68

Security and Trust Reduction

Add tokens for the Foundation please. This ERC20 token will be GREAT!

50 of 68

Security and Trust Reduction

Add tokens for the Foundation please. This ERC20 token will be GREAT!

Sure boss!

51 of 68

Security and Trust Reduction

52 of 68

Security and Trust Reduction

But make it

��TRUSTLESS

53 of 68

Security and Trust Reduction

54 of 68

Security and Trust Reduction

msg.value = 0

55 of 68

“Sometimes, it’s totally OK to reduce trustlessness in order to increase security”

56 of 68

Open Problems

in Smart Contract Development/Security

57 of 68

Pending Problems

upgradability

gas costs

code duplication

interoperability

58 of 68

Pending Problems

upgradability

gas costs

code duplication

interoperability

59 of 68

60 of 68

Code Duplication

61 of 68

Upgradeability

62 of 68

Upgradeability

63 of 68

Scheduler and Marketplace

  • Gas concerns for smart contract operations.��

64 of 68

Scheduler and Marketplace

  • Gas concerns for smart contract operations.�����
  • Contract-to-contract interaction.��

65 of 68

Smart Contract SDK

66 of 68

Learn more!

https://zeppelinos.org

67 of 68

Solidity CTF Contest

https://ethernaut.zeppelin.solutions/��10k USD in prizes!

68 of 68

Manuel Araoz

@maraoz

Thanks! We’re hiring!