ethereum network the most interesting transactions on the ...to the dao and the ethereum community,...

142
Smart Contract Vulnerabilities The most interesting transactions on the Ethereum network

Upload: others

Post on 12-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Smart Contract VulnerabilitiesThe most interesting transactions on the Ethereum network

Page 2: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Hi! Hai! I’m maurelian

ConsenSys Diligence

Page 3: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

This talk will be:

● Storytelling meets vulnerability postmortems

● First, a quick and dirty intro to the Ethereum blockchain

● Then, deep dives into various incidents

Page 4: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Things we should tell you before anything else will be interesting

Ethereum Basics

Page 5: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Ethereum is a blockchain

That has a turing complete virtual machine

“Distributed state machine”

Page 6: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Accounts and State

Page 7: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Accounts

{ nonce,balance,code,storage

}

Replay protection

Ether (ETH)

Ethereum VM Bytecode

256 bit values

Page 8: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

{ nonce,balance,0x0,0x0

}

Accounts

{ nonce,balance,code,storage

}

“Contract” Accounts “Keypair” Accounts

Page 9: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The State

Global State is a mapping of addressesto accounts

state[0xabcd]={ nonce,balance,code,storage

}

Page 10: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

state[0xabcd]={ nonce,balance,code,storage

}

EVM OpcodesPUSH1, PUSH2… SWAPDUP1, DUP2… ~~~~SHA3SSTOREDELEGATECALLCODECOPYCREATEGAS

Page 11: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

TransactionsThere are two main types of transactions

I Alice send 1 eth to Bob

signature

Alice

Bob

I Alice call function x

signature

Alice

Contract C

Page 12: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Contract AccountsCan do any arbitrary computation

I Alice call function x

signature

Alice

Contract C Contract E

I Contract C send 1 eth toBob

I Contract C call function z on Contract D

Bob

Contract D

Page 13: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Transactions...

… result in State Transitions

STATE STATE’

TXNFrom: Acct1 To: Acct2Value: 1000Data:0xabbaSig:30452..

Acct1: Bal: 1024 eth

Acct2: Bal: 5202 ethCode: 0x60604…Storage: [1,2,3]

Acct2: Bal: 5202 ethCode: 0x60604…Storage: [1,2,3]

Acct1: Bal: 24 eth

Acct2: Bal: 6202 ethCode: 0x60604…Storage: [2,3,1]

Acct2: Bal: 5202 ethCode: 0x60604…Storage: [1,2,3]

Page 14: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

What is a trace?A “step” in the execution of a transaction

I Alice call function x

signature

Alice

Contract C

I Contract C call function z on Contract D

Contract D

I Contract Dcall function z on Contract E

Contract E

I Contract E call function z on Contract F

Contract F

Page 15: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

What about the halting problem?

Page 16: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Gas!Every opcode has a gas rate

Page 17: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Gas!Computational limits are set by economics

transaction cost = gas used X gas price(eth) (gas) (eth/gas)

Block Gas Limit = max gas per block

Page 18: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Blockchains have blocks

Transaction root

Receipt root

State root

+ nonce+ Hash of the previous

block

I Alice send 1 eth to Bob

signature

Alice

Alice

hash( )

Page 19: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The blocks are chained

+ nonce+ Hash of the previous

block

+ nonce+ Hash of the previous

block

+ nonce+ Hash of the previous

block

Transaction root

Receipt root

State root

Transaction root

Receipt root

State root

Transaction root

Receipt root

State root

Page 20: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

How do we decide who gets to mine the next block?

+ nonce+ Hash of the previous

block

??

Page 21: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Proof of work!

Miners are searching for a nonce such that the block hash will be lower than the difficulty of the network+ nonce

+ Hash of the previous block

Page 22: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Tokens

Page 23: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

And it’s all public… on the chain.

Page 24: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding
Page 25: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary● Blockchain● State Machine● Accounts ● Contracts● Opcodes● Gas!● Transactions● Blocks● Mining

Page 26: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Incident reports adventures

Page 27: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

TheDAO Saga

Block: 1428757 (Apr-30-2016)TxHash: 0xe9ebfecc2fa10100db51a4408d18193b3ac504584b51a4e55bdef1318f0a30f9

Page 28: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The mood in early 2016

Page 29: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Enter TheDAO

The DAO was a digital decentralized autonomous organization, and a form of investor-directed venture capital fund.

- Wikipedia

Page 30: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

How TheDAO Worked

Page 31: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Massive interest!

Page 32: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Hang on...

Page 33: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

No worries!

Page 34: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

But what’s up with this race to empty reentrancy thing?

(A brief diversion)

Page 35: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Reentrancy Vuln Pattern

Verify sufficient balance

withdraw(_value)

Send _value to caller

Reduce balance by _value

>

Page 36: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Reentrancy Vuln Pattern

>

attack()

fallback fn

Page 37: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Reentrancy Vuln Pattern

Page 38: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

All in the ordering of 2

lines!

Page 39: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

… now, where were we?

Page 40: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

We were talking about TheDAO…

Page 41: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

No worries!

Page 42: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Just kidding

Page 43: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

TheDAO

Page 44: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

TheDAO

Page 45: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Whitehats Appear

Page 46: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Whitehats AppearEveryone be like:

DAOSaster!!!

Page 47: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Whitehats Appear

Page 48: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

“===== BEGIN SIGNED MESSAGE =====

To the DAO and the Ethereum community,

I have carefully examined the code of The DAO and decided to participate after finding the feature where splitting is rewarded with additional ether. I have made use of this feature and have rightfully claimed 3,641,694 ether, and would like to thank the DAO for this reward.

The hacker speaks

Page 49: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

But wait...

Page 50: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Maybe… there is no hack…

Page 51: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

To fork or not to fork?

Page 52: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Fork happens

“Ethereum classic”is born

Page 53: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Fork happens

“Ethereum classic”is born

Page 54: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The first chain split

Page 55: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary:

● The first known use of a rentrancy exploit● Massive loss of funds and community panic● Resulted in the first chain split of a

blockchain

Page 56: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDos

Block: 2286910 - 2717576 (Sep-19-2016 - Nov-29-2016)

Page 57: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosFirst wave: Geth out of memory

Page 58: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosFirst wave: Geth out of memory

https://github.com/ethereum/go-ethereum/issues/3002

Tx payload: 0x913fdfbd00000000000000000000000000000000000000000000000000000000000000550000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000104661687274206e61636820486175736500000000000000000000000000000000

Utf-8: �?ß½U`Fahrt nach Hause

Page 59: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosFrom Shanghai, with love (1.4.12)

Page 60: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDos

Page 61: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosSecond wave: Improperly priced opcode

Tx hash: 0x7bf56f8f9b98e51fd7d1c76818f6c0607e9738f191afae87edd3a34595803455

Number of traces: 1023

Opcode: extcodesize

Page 62: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosSecond wave: Improperly priced opcode

extcodesize was getting called on average 50,000 times per block

2-3x reduction in the rate of block creation

Page 63: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosA series of patches

Page 64: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosThird wave: State trie bloat

Tx hash: 0x69210972f11c2c37a203d0ef1d25b1b9d491510440bca4db846571875cf51436

Number of traces: 1920

Approx 19 million empty accounts

Page 65: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Third wave: State trie bloat DDos

I Alice call function x

signature

Alice

Contract CCounter = 0

Contract D

Page 66: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Third wave: State trie bloat

DDos

I Alice call function x

signature

Alice

Contract CCounter = 0

Contract D

I Contract C Call selfdestruct on Contract D with arg Counter

Contract D

I Contract D refund my balance

Account 0

Page 67: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Third wave: State trie bloat

DDos

I Alice call function x

signature

Alice

Contract CCounter = 1

I Contract D refund my balance

Contract D

Account 0

Page 68: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Third wave: State trie bloat DDos

I Alice call function x

signature

Alice

Contract CCounter = 1

I Contract C Call selfdestruct on Contract D with arg Counter

Contract D

I Contract D refund my balance

Account 0

I Contract D refund my balance

Account 1

Page 69: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosThe fixes:

● self destruct triggers an additional cost if it touches a newly created account

● Adding a gas cost to creating a new account● If an operation would result in an address having an

empty balance, the address is removed

Contract 1: 0x6a0a0fc761c612c340a0e98d33b37a75e5268472

Contract 2: 0x7c20218efc2e07c8fe2532ff860d4a5d8287cb31

Page 70: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDos Number of traces

TimeChart by Thomas Jay Rush

Page 71: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDos

Chart by Thomas Jay Rush

Page 72: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DDosScope of impact

Increased the total number of accounts to around 20 million, which required around 10 gigabytes of disk space

With state clearing complete, the total number of accounts was brought back down to 772530, which require around 1 gigabyte of disk space.

Page 73: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary:

● DDos was actually a series of events● Some were protocol bugs, some bugs in

client implementation● No lost funds, but possible market

manipulation

Page 74: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

“Anomaly on the main network”

Block: 2675119 (Nov-22-2016)TxHash: 0xcf416c536ec1a19ed1fb89e4ec7ffb3cf73aa413b3aa9b77d60e4fd81a4296ba

The point of this is not so much about the TX itself, but the concepts of:

-Multiple client impls-Maintaining consensus-Having a written specification

Page 75: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Ethereum network runs on multiple client implementations!

Page 76: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Anomaly on the main networkThe Ethereum network runs on multiple clients implementations!

Each client needs to agree about the result of each transaction, or the network will split.

Page 77: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Anomaly on the main networkThe Yellow Paper reference specification

Page 78: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Anomaly on the main networkThe Yellow Paper reference specification

Fun Read!

Page 79: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Anomaly on the main network

Page 80: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Anomaly on the main network

Empty “State Bloat” Accounts

Page 81: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Edge case!

Address Precompile Contract

0x01 ECDSARECOVER0x02 SHA30x03 RIPEMD0x04 IDENTITY

Page 82: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Edge case!

RIPEMD was “deleted”

Page 83: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Anomaly on the main network

Page 84: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary:

● Consensus w/ bug for bug compatibility is hard

● Edge cases abound in this complex system● This was a lucky accident!

Page 85: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Poloniex short address bug

Block: 3375451 (Mar-18-2017)TxHash: 0x0213fb70e8174c5cbd9233a8e95905462cd7f1b498c12ff5e8ec071f4cc99347

Page 86: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

0x0213fb70e8174c5cbd9233a8e95905462cd7f1b498c12ff5e8ec071f4cc99347

Page 87: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

How we build function args

First_4_bytes(Hash(“transfer(address _to, uint256 value)”))

“0xa9059cbb” +

address“0000000000000000000000007fe2b88f2e4858de375832fbf54ac7cf1a78ca51” +

uint256“000000000000000000000000000000000000000000000001ab5465169ad10800”

Page 88: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

0xa9059cbb0000000000000000000000000 797350000000000000000000000000000000000000000000005150ac4c39a6f3f0000

0xa9059cbb000000000000000000000000797350000000000000000000000000000000000000000000005150ac4c39a6f3 f??????????????????????????????????????

0xa9059cbb000000000000000000000000797350000000000000000000000000000000000000000000005150ac4c39a6f3f 000000000000000000000000000000000000000

_value = 00000000000005150ac4c39a6f3f000000000000000000000000000000000000000

Page 89: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

0x1800607697a4213241bf78a8271dc3985a72f6bd427974ae8e4d4e4c9e5f797b

Page 90: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary:

● Bug is peripheral to Ethereum itself● Basically equivalent to calling functions

with invalid args● Minimal damage

Page 91: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The front running underground

Page 92: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

which will influence the price of the equity,

Front-running is when a broker enters a trade with foreknowledge of a transaction

Front Running

Front-running is a prohibited practice for brokers.

Investopedia definition:

resulting in an economic gain for the broker.

Page 93: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Mempool of pending tx

Transactions included in blocks

Page 94: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Front Running

Page 95: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

0x0000F7F3… the dominant front runner

Page 96: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

0x000F7… has diverse revenue streams

Page 97: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

● Shit is crazy out there.

Summary:

Page 98: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Parity

Block: 4043800 (Jul-19-2017)TxHash: 0x9dbf0326a03a2a3719c27be4fa69aacc9857fd231a8d9dcaede4bb083def75ec

Page 99: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Parity

Page 100: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Parity

Attacker 0xb3764761e297d6f121e79c32a65829cd1ddb4d32 sends:

The vulnerability is in Parity’s multisig wallet

Page 101: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ParityAnyone can claim wallets

I Attacker call function x with args y

signature

Child Multisig Contract

I Child Multisig call InitWallet on Multisig Library

Multisig Library COntract

Owners = [someLegimateOwners]

Function initWallet(args) { //Update Owners array}

internal

Child Multisig Contract

Child Multisig Contract

Child Multisig Contract

Owners = [someLegimateOwners]

Owners = [someLegimateOwners]

Page 102: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ParityAnyone can claim wallets

I Attacker call function x with args y

signature

Child Multisig Contract

I Child Multisig call InitWallet on Multisig Library

Multisig Library COntract

Owners = [Attacker]

Child Multisig Contract

Child Multisig Contract

Child Multisig Contract

Owners = [Attacker]

Owners = [Attacker]

Page 103: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ParityAttacker was able to steal approx 30 million in three hours

Page 104: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

PLOT TWISTIt’s not over

Page 105: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Parity

Approximately 152 million dollars or 513,743 eth are frozen

Page 106: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Parity

Vuln 2: Deleting the Multisig Library

Page 107: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

… or are they?

“This document proposes to restore the contract code of the WalletLibrary contract at 0x863DF6BFa4469f3ead0bE8f9F2AAE51c91A907b4 with a patched version. The contract was accidentally self-destructed and renders a significant amount of Ether inaccessible.”

EIP 999

Page 108: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding
Page 109: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary:

● Two related vulnerabilities● Significant theft and even more significant

amount of frozen funds● Reveals a weakness in the child/library

pattern

Page 110: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

XSS in EtherDelta

Block: 3375451 (Mar-18-2017)TxHash: 0x0213fb70e8174c5cbd9233a8e95905462cd7f1b498c12ff5e8ec071f4cc99347

Page 111: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Etherdelta is a popular Decentralized Exchange or “DEX”

Page 112: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

DEX interface

Page 113: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding
Page 114: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Using EtherDelta

Page 115: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Using EtherDeltaOption 1: the MetaMask extension

Private keys in a sandboxed browser extension

Page 116: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Option 1: the MetaMask extensionUsing EtherDelta

Page 117: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Option 2: Etherdelta’s web walletUsing EtherDelta Priv keys in the web app!!

Page 118: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Metadata

Token MetaData

Page 119: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

The Attack

Page 120: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Step 1: Launch a token

Page 121: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Step 2: Rename the tokenrename(string _name)

Convert to UTF8

Page 122: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

That’s a weird name

Page 123: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

That’s a weird name

Page 124: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Step 3: Have someone look your token up on EtherDelta…

Page 125: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Step 3: Have someone look your token up on EtherDelta…

PROFIT

Page 126: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Re-rename it

Page 127: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Etherdelta XSS

Page 128: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Etherdelta XSS

pownedpowned(sic?)

Page 129: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Summary:

● Sanitize yer inputs!

Page 130: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

We’ve got more stories, but we’re out of time.

Page 131: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Conclusion

Uhh .. it’s been a wild ride

Also we’re hiring

Page 133: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding
Page 134: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

End. Scratch space below.

Page 135: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

Mythril

Page 136: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

“ETH account balance manipulation" (at Coinbase!)

Deposits made from a smart contract were credited to the customer’s balance, even though the transaction was REVERTed.

Page 137: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding
Page 138: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ETH account balance Error Handling in the EVM

Try to send

If it fails: Undo everything

Page 139: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ETH account balance

Page 140: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ETH account balance Making a fake deposit to Coinbase

Make 5 deposits

Just kidding! ¯\_(ツ)_/¯

Page 141: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

ETH account balance What was Coinbase actually doing???

Todo: Add some kind of schematic showing the relationship to Coinbase’s servers, and the blockchain, and the transaction.

Page 142: Ethereum network The most interesting transactions on the ...To the DAO and the Ethereum community, I have carefully examined the code of The DAO and decided to participate after finding

● They weren’t using the blockchain right… at all

Summary: