SlideShare a Scribd company logo
1 of 48
Download to read offline
Porosity
Decompiling Ethereum Smart-Contracts
Matt Suiche (@msuiche)
Founder, Comae Technologies
m@comae.io
Whoami
ī‚¯ @msuiche
ī‚¯ Comae Technologies
ī‚¯ OPCDE - www.opcde.com
ī‚¯ First time in Vegas since BlackHat 2011
ī‚¯ Mainly Windows-related stuff
ī‚¯ CloudVolumes (VMware App Volumes)
ī‚¯ Memory Forensics for DFIR (Hibr2Bin, DumpIt etc.)
ī‚¯ “looks like such fun guy” – TheShadowBrokers
ī‚¯ Didn’t know much about blockchain before this project
Just so you knowâ€Ļ
ī‚¯ We won’t talk about POW/POS stuff
ī‚¯ We won’t talk about Merkle Trees
ī‚¯ We won’t talk about how to becoming a crypto-currency millionaire
ī‚¯ We will talk about the Ethereum EVM
ī‚¯ We will talk about Solidity
ī‚¯ We will talk about smart-contract bytecodes
ī‚¯ And yes, the tool isn’t perfect â˜ē
Agenda
ī‚¯ Ethereum Virtual Machine (EVM)
ī‚¯ Memory Management
ī‚¯ Addresses
ī‚¯ Call Types
ī‚¯ Type Discovery
ī‚¯ Smart-Contract
ī‚¯ Code Analysis
ī‚¯ Known Bugs
ī‚¯ Future
Solidity
ī‚¯ Solidity the quality or state of being firm or strong in
structure.
ī‚¯ But also the name of Ethereum’s smart-contracts compiler
ī‚¯ Porosity is the quality of being porous, or full of tiny holes.
Liquids go right through things that have porosity.
ī‚¯ But also the name of Comae’s smart-contract decompiler.
Accounts
ī‚¯ Normal Accounts: 3,488,419 (July 15)
ī‚¯ Contract Accounts: 930,889 (July 15)
ī‚¯ Verified Contract Accounts: 2285 (July 15)
ī‚¯ Source code is provided.
ī‚¯ 40M$ lost in July
ī‚¯ 10M$ in CoinDash’s ICO
ī‚¯ http://www.coindesk.com/coindash-ico-hacker-nets-additional-
ether-theft-tops-10-million/
ī‚¯ 30M$ due to Parity’s wallet.sol vulnerability
ī‚¯ https://blog.parity.io/security-alert-high-2/
ī‚¯ https://github.com/paritytech/parity/pull/6103
Ethereum Virtual Machine (EVM)
ī‚¯ Account/Contract/Blockchain
ī‚¯ A Smart-Contract is made of bytecode stored in the blockchain.
ī‚¯ An address is a 160-bits value & corresponds to an “account”
ī‚¯ Operates 256-bits pseudo-registers
ī‚¯ EVM does not really have registers, but uses a virtual stack to replace them.
Solidity & “Smart Contracts”
ī‚¯ Solidity compiles JavaScript-like code into Ethereum bytecode.contract Coin {
// The keyword "public" makes those variables
// readable from outside.
address public minter;
mapping (address => uint) public balances;
// Events allow light clients to react on
// changes efficiently.
event Sent(address from, address to, uint amount);
// This is the constructor whose code is
// run only when the contract is created.
function Coin() {
minter = msg.sender;
}
function mint(address receiver, uint amount) {
if (msg.sender != minter) return;
balances[receiver] += amount;
}
function send(address receiver, uint amount) {
if (balances[msg.sender] < amount) return;
balances[msg.sender] -= amount;
balances[receiver] += amount;
Sent(msg.sender, receiver, amount);
}
}
Memory Management
ī‚¯ Stack
ī‚¯ Virtual stack is being used for operations to pass parameters to opcodes.
ī‚¯ 256-bit values/entries
ī‚¯ Maximum size of 1024 elements
ī‚¯ Storage (Persistent)
ī‚¯ Key-value storage mapping (256-to-256-bit integers)
ī‚¯ Can’t be enumerated.
ī‚¯ SSTORE/SLOAD
ī‚¯ Memory (Volatile)
ī‚¯ 256-bit values (lots of AND operations, useful for type discovery)
ī‚¯ MSTORE/MLOAD
Basic Blocks
ī‚¯ Usually start with the JUMPDEST instruction – except few cases.
ī‚¯ JUMP* instruction jump to the address contained in the 1st element
of the stack.
ī‚¯ JUMP* instruction are (almost always) preceded by PUSH instruction
ī‚¯ This allows to push the destination address in the stack, instead of
hardcoding the destination offset.
ī‚¯ SWAP/DUP/POP stack manipulation instructions can make jump
destination address harder to retrieve
ī‚¯ This requires dynamic analysis to rebuild the relationship between each
basic block.
EVM functions/instructions
ī‚¯ EVM instructions are more like functions, such as:
ī‚¯ Arithmetic, Comparison & Bitwise Logic Operations
ī‚¯ SHA3
ī‚¯ Environmental & Block Information
ī‚¯ Stack, Memory, Storage and Flow Operations
ī‚¯ Logging & System Operations
Instruction call - Addition
ī‚¯ The above translates at the EVM-pseudo code:
ī‚¯ add(0x2, 0x1)
Offset Instruction Stack[0] Stack[2]
n PUSH1 0x1 0x1
n + 1 PUSH1 0x2 0x2 0x1
n + 2 ADD 0x3
EVM Call
ī‚¯ Can be identified by the CALL instruction.
ī‚¯ Call external accounts/contracts pointed by the second
parameter
ī‚¯ The second parameter contains the actual 160 address of the
external contract
ī‚¯ With the exception of 4 hardcoded contracts:
ī‚¯ 1 – elliptic curve public key recovery function
ī‚¯ 2- SHA2 function
ī‚¯ 3- RIPEMD160 function
ī‚¯ 4- Identity function
call(
gasLimit,
to,
value,
inputOffset,
inputSize,
outputOffset,
outputSize
)
User-Defined functions (Solidity)
ī‚¯ CALLDATALOAD instruction is used to read the Environmental
Information Block (EIB) such as parameters.
ī‚¯ First 4 bytes of the EIB contains the 32-bits hash of the called
function.
ī‚¯ Followed by the parameters based on their respective types.
ī‚¯ e.g. int would be a 256 bits word.
ī‚¯ a = calldataload(0x4)
ī‚¯ b = calldataload(0x24)
ī‚¯ add(calldataload(0x4), calldataload(0x24)
function foo(int a, int b) {
return a + b;
}
Type Discovery - Addresses
ī‚¯ As an example, addresses are 160-bit words
ī‚¯ Since stack registers are 256-bit words, they can easily be identified
through AND operations using the
0xffffffffffffffffffffffffffffffffffffffff mask.
ī‚¯ Mask can be static or computed dynamically
Ethereum Assembly Translation (msg.sender)
CALLER
PUSH1 0x01
PUSH 0xA0
PUSH1 0x02
EXP
SUB
AND
and(reg256, sub(exp(2, 0xa0), 1)) (EVM)
reg256 & (2 ** 0xA0) - 1) (Intermediate)
address (Solidity)
Bytecode
ī‚¯ The bytecode is divided in two categories:
ī‚¯ Pre-loader code
ī‚¯ Found at the beginning that contains the routine to bootstrap
the contract
ī‚¯ Runtime code of the contract
ī‚¯ The core code written by the user that got compiled by
Solidity
ī‚¯ Each contract contain a dispatch function that redirects the
call to the corresponding function based on the provided
hash function.
Bytecode – Pre-loader
ī‚¯ CODECOPY copies the runtime part of the contract into the EVM
memory – which gets executed at base address 0x0
00000000 6060
00000002 6040
00000004 52
00000005 6000
00000007 6001
00000009 6000
0000000b 610001
0000000e 0a
0000000f 81
00000010 54
00000011 81
00000012 60ff
00000014 02
00000015 19
00000016 16
00000017 90
00000018 83
00000019 02
0000001a 17
0000001b 90
0000001c 55
0000001d 50
0000001e 61bb01
00000021 80
00000022 612b00
00000025 6000
00000027 39
00000028 6000
0000002a f3
PUSH1 60
PUSH1 40
MSTORE
PUSH1 00
PUSH1 01
PUSH1 00
PUSH2 0001
EXP
DUP2
SLOAD
DUP2
PUSH1 ff
MUL
NOT
AND
SWAP1
DUP4
MUL
OR
SWAP1
SSTORE
POP
PUSH2 bb01
DUP1
PUSH2 2b00
PUSH1 00
CODECOPY
PUSH1 00
RETURN
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
calldataload(0x0) / exp(0x2, 0xe0)
Function Hashes
ī‚¯ The 4 bytes of the sha3 (keccak256) value for the string
functionName(param1Type, param2Type, etc)
[
{
"constant":false,
"inputs":[{ "name":"a", "type":"uint256" }],
"name":"double",
"outputs":[{ "name":"", "type":"uint256" }],
"type":"function"
}
]
keccak256("double(uint256)") =>
eee972066698d890c32fec0edb38a360c32b71d0a29ffc75b6ab6d2774ec9901
double(uint256) -> 0xeee97206
triple(uint256) -> 0xf40a049d
Extracting function hash
ī‚¯ calldataload(0x0) / exp(0x2, 0xe0)
ī‚¯ (0x12345678xxxx / 0x00000001xxxx) = 0x12345678
ī‚¯ jumpi(eq(calldataload(0x0) / exp(0x2, 0xe0), 0xeee97206))
PS C:Program FilesGeth> .evm.exe 
--code 60e060020a60003504 
--debug 
--input 12345678aaaaaaaabbbbbbbbccccccccdddddddd
PC 00000009: STOP GAS: 9999999923 COST: 0
STACK = 1
0000: 0000000000000000000000000000000000000000000000000000000012345678
MEM = 0
STORAGE = 0
Ethereum Emulator
Static CFG (--cfg) Emulated CFG (--cfg-full)
Control Flow Graph
Dispatcher – pseudo code
hash = calldataload(0x0) / exp(0x2, 0xe0);
switch (hash) {
case 0xeee97206: // double(uint256)
memory[0x60] = calldataload(0x4) * 2;
return memory[0x60];
break;
case 0xf40a049d: // triple(uint256)
memory[0x60] = calldataload(0x4) * 3;
return memory[0x60];
break;
default:
// STOP
break;
}
contract C {
function double(int arg_4) {
return arg_4 * 2;
}
function triple(int arg_4) {
return arg_4 * 3;
}
}
Pseudo-Code
Translated Code
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
Bytecode – Dispatcher (--list)
loc_00000000:
0x00000000 60 60 PUSH1 60
0x00000002 60 40 PUSH1 40
0x00000004 52 MSTORE
0x00000005 60 e0 PUSH1 e0
0x00000007 60 02 PUSH1 02
0x00000009 0a EXP
0x0000000a 60 00 PUSH1 00
0x0000000c 35 CALLDATALOAD
0x0000000d 04 DIV
0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee
0x00000013 81 DUP2
0x00000014 14 EQ
0x00000015 60 24 PUSH1 24
0x00000017 57 JUMPI
loc_00000018:
0x00000018 80 DUP1
0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4
0x0000001e 14 EQ
0x0000001f 60 35 PUSH1 35
0x00000021 57 JUMPI
loc_00000022:
0x00000022 5b JUMPDEST
0x00000023 00 STOP
double(uint256):
0x00000024 5b JUMPDEST
0x00000025 60 45 PUSH1 45
0x00000027 60 04 PUSH1 04
0x00000029 35 CALLDATALOAD
0x0000002a 60 00 PUSH1 00
0x0000002c 60 4f PUSH1 4f
0x0000002e 82 DUP3
0x0000002f 60 02 PUSH1 02
loc_00000031:
0x00000031 5b JUMPDEST
0x00000032 02 MUL
0x00000033 90 SWAP1
0x00000034 56 JUMP
triple(uint256):
0x00000035 5b JUMPDEST
0x00000036 60 45 PUSH1 45
0x00000038 60 04 PUSH1 04
0x0000003a 35 CALLDATALOAD
0x0000003b 60 00 PUSH1 00
0x0000003d 60 4f PUSH1 4f
0x0000003f 82 DUP3
0x00000040 60 03 PUSH1 03
0x00000042 60 31 PUSH1 31
0x00000044 56 JUMP
DELEGATECALL & $30M Parity Bug
contract Wallet {
address _walletLibrary;
address owner;
// initWallet() is only invoked by the constructor. WalletLibrary is hardcoded.
function Wallet(address _owner) {
_walletLibrary = 0xa657491c1e7f16adb39b9b60e87bbb8d93988bc3;
_walletLibrary.delegatecall(bytes4(sha3("initWallet(address)")), _owner);
}
(â€Ļ)
// fallback function behaves like a “generic forward” (WTF?)
// Wallet.initWallet(attacker) becomes walletLibrary.initWallet(attacker)
function () payable {
_walletLibrary.delegatecall(msg.data);
}
}
Abusing the dispatcher to reinitialize a wallet?
Generic-Forward & Fall back functions
ī‚¯ Typical issue introduce by the lack of upgradeability of smart-
contract
ī‚¯ Software engineering is hard enough, but smart-contracts need to
be:
ī‚¯ Backward-Compatible
ī‚¯ Forward-Compatible
ī‚¯ Does not help to make the language verifiable.
ī‚¯ Fall back functions are undefined behaviors.
ī‚¯ Imagine if your kernel would behave like that.
ī‚¯ Scary, right ? Now, imagine if that’s your bankâ€Ļ
Fixing the initialization bug
- function initMultiowned(address[] _owners, uint _required) {
+ function initMultiowned(address[] _owners, uint _required) internal {
- function initDaylimit(uint _limit) {
+ function initDaylimit(uint _limit) internal {
+ modifier only_uninitialized { if (m_numOwners > 0) throw; _; }
- function initWallet(address[] _owners, uint _required, uint _daylimit) {
+ function initWallet(address[] _owners, uint _required, uint _daylimit)
only_uninitialized {
Code Analysis – Vulnerable Contract
contract SendBalance {
mapping ( address => uint ) userBalances ;
bool withdrawn = false ;
function getBalance (address u) constant returns ( uint ){
return userBalances [u];
}
function addToBalance () {
userBalances[msg.sender] += msg.value ;
}
function withdrawBalance (){
if (!(msg.sender.call.value(
userBalances [msg.sender])())) { throw ; }
userBalances [msg.sender] = 0;
}
}
Code Analysis – Vulnerable Contract
contract SendBalance {
mapping ( address => uint ) userBalances ;
bool withdrawn = false ;
function getBalance (address u) constant returns ( uint ){
return userBalances [u];
}
function addToBalance () {
userBalances[msg.sender] += msg.value ;
}
function withdrawBalance (){
if (!(msg.sender.call.value(
userBalances [msg.sender])())) { throw ; }
userBalances [msg.sender] = 0;
}
}
Caller contract can recall this function
using its fallback function
Understanding the control flow
ī‚¯ In the case of reentrant vulnerability, since we can
record the EVM state at each instruction using
porosity.
ī‚¯ We can track in which basic block SSTORE
instructions are called.
ī‚¯ userBalances [msg.sender] = 0;
ī‚¯ And track states for each basic block.
.demo.ps1
$porosity = 'E:projectsporosityDebugporosity.exe'
$abi =
'[{"constant":false,"inputs":[],"name":"withdrawBalance","outputs":[],"ty
pe":"function"},{"constant":false,"inputs":[],"name":"addToBalance","out
puts":[],"type":"function"},{"constant":true,"inputs":[{"name":"u","ty
pe":"address"}],"name":"getBalance","outputs":[{"name":"","type":"ui
nt256"}],"type":"function"}]'
$code =
'60606040526000357c01000000000000000000000000000000000000000000000000000000009004806
35fd8c7101461004f578063c0e317fb1461005e578063f8b2cb4f1461006d5761004d565b005b61005c6
004805050610099565b005b61006b600480505061013e565b005b6100836004808035906020019091905
05061017d565b6040518082815260200191505060405180910390f35b3373fffffffffffffffffffffff
fffffffffffffffff16611111600060005060003373ffffffffffffffffffffffffffffffffffffffff1
6815260200190815260200160002060005054604051809050600060405180830381858888f1935050505
0151561010657610002565b6000600060005060003373fffffffffffffffffffffffffffffffffffffff
f168152602001908152602001600020600050819055505b565b34600060005060003373fffffffffffff
fffffffffffffffffffffffffff168152602001908152602001600020600082828250540192505081905
5505b565b6000600060005060008373ffffffffffffffffffffffffffffffffffffffff1681526020019
081526020016000206000505490506101b6565b91905056’
& $porosity --abi $abi --runtime-code $code --decompile --verbose 0
Known class of bugs
ī‚¯ Reentrant Vulnerabilities / Race Condition
ī‚¯ Famously known because of the $50M USD DAO hack (2016) [8]
ī‚¯ Call Stack Vulnerabilities
ī‚¯ Got 1024 frames but a bug ain’t one – c.f. Least Authority [12]
ī‚¯ Time Dependency Vulnerabilities
ī‚¯ @mhswende blogposts are generally awesome, particularly the roulette
one [10]
ī‚¯ Unconditional DELEGATECALL
Porosity + Quorum = <3
ī‚¯ Quorum: Ethereum code fork created by J.P. Morgan
ī‚¯ aimed at enterprises that want to use a permissioned blockchain that adds
private smart contract execution & configurable consensus.
ī‚¯ Quorum now includes Porosity integrated directly into geth out of
the box:
ī‚¯ Scan private contracts sent to your node from other network participants
ī‚¯ Incorporate into security & patching processes for private networks with
formalized governance models
ī‚¯ Automate scanning and analyze risk across semi-public Quorum networks
ī‚¯ https://github.com/jpmorganchase/quorum
Future
ī‚¯ Ethereum DApps created a new segment for softwares.
ī‚¯ Porosity
ī‚¯ Improving support for conditional and loop statements
ī‚¯ Ethereum / Solidity & Security
ī‚¯ Fast growing community and more tools such as OYENTE or Porosity
ī‚¯ Personally, looking forward seeing the Underhanded Solidity Coding
Contest [10] results
ī‚¯ EVM vulnerabilities triggered by malicious bytecode? CLOUDBURST on the
blockchain
ī‚¯ More Blockchain VMs ?
ī‚¯ Swapping the EVM for Web Assembly (WASM) for 2018
Future - WebAssembly
ī‚¯ New Ethereum Roadmap (March 2017) mentions making the EVM
obsolete and replacing it with WebAssembly for 2018.
ī‚¯ “WebAssembly (or WASM) is a new, portable, size- and load-time-
efficient format.”
ī‚¯ WebAssembly is currently being designed as an open standard by a W3C
Community Group.
ī‚¯ WebAssembly defines an instruction set, intermediate source format
(WAST) and a binary encoded format (WASM).
ī‚¯ Major browser JavaScript engines will notably have native support for
WebAssembly – including V8, Chakra and Spidermonkey.
ī‚¯ https://github.com/ewasm/design
WASM + DApps + Blockchain
ī‚¯ C++ -> WASM is already a thing
ī‚¯ https://mbebenita.github.io/WasmExplorer/
ī‚¯ And a similar thing is planned for eWASM
Acknowledgements
ī‚¯ Mohamed Saher
ī‚¯ Halvar Flake
ī‚¯ DEFCON Review Board Team
ī‚¯ Max Vorobjov & Andrey Bazhan
ī‚¯ Martin H. Swende
ī‚¯ Gavin Wood
ī‚¯ Andreas Olofsson
References
[1] Woods, Gavin. "Ethereum: A Secure Decentralised Generalised Transaction Ledger." Web. https://github.com/ethereum/yellowpaper.pdf
[2] Olofsson, Andreas. "Solidity Workshop." Web. https://github.com/androlo/solidity-workshop
[3] Olofsson, Andreas. "Solidity Contracts." Web. https://github.com/androlo/standard-contracts
[4] Velner, Yarn, Jason Teutsch, and Loi Luu. "Smart Contracts Make Bitcoin Mining Pools Vulnerable." Web. https://eprint.iacr.org/2017/230.pdf
[5] Luu, Loi, Duc-Hiep Chu, Hrishi Olickel, Aquinas Hobor. "Making Smart Contracts Smarter." Web.
https://www.comp.nus.edu.sg/%7Ehobor/Publications/2016/Making%20Smart%20Contracts%20Smarter.pdf
[6] Atzei, Nicola, Massimo Bartoletti, and Tiziana Cimoli. " A Survey of Attacks on Ethereum Smart Contracts." Web.
https://eprint.iacr.org/2016/1007.pdf
[7] Sarkar, Abhiroop. "Understanding the Transactional Nature of Smart-Contracts." Web. https://abhiroop.github.io/Exceptions-and-Transactions
[8] Siegel, David. "Understanding The DAO Attack." Web. http://www.coindesk.com/understanding-dao-hack-journalists
[9] Blockchain software for asset management. "OYENTE: An Analysis Tool for Smart Contracts." Web. https://github.com/melonproject/oyente
[10] Holst Swende, Martin. “Breaking the house.“ Web. http://martin.swende.se/blog/Breaking_the_house.html
[11] Buterin, Vitalik. "Thinking About Smart Contract Security.“Web. https://blog.ethereum.org/2016/06/19/thinking-smart-contract-security
[12] Least Authority. "Gas Economics: Call Stack Depth Limit Errors." Web. https://github.com/LeastAuthority/ethereum-
analyses/blob/master/GasEcon.md#callstack-depth-limit-errors
[13] Underhanded Solidity Coding Contest, Web. http://u.solidity.cc/
[14] Quorum. "A permissioned implementation of Ethereum supporting data privacy." https://github.com/jpmorganchase/quorum
m@comae.io / @msuiche
https://github.com/comaeio/porosity

More Related Content

What's hot

exchange rate basics
exchange rate basicsexchange rate basics
exchange rate basicsdeepak gupta
 
Present Value of Uneven Cash Flows
Present Value of Uneven Cash FlowsPresent Value of Uneven Cash Flows
Present Value of Uneven Cash Flowsefinancemanagement.com
 
FIM - Currency Futures PPT
FIM - Currency Futures PPTFIM - Currency Futures PPT
FIM - Currency Futures PPTBishnu Kumar
 
Investment management chapter 5 the arbitrage pricing theory
Investment management chapter 5 the arbitrage pricing theoryInvestment management chapter 5 the arbitrage pricing theory
Investment management chapter 5 the arbitrage pricing theoryHeng Leangpheng
 
Interest Rates and Bond Evaluation by Junaid Chohan
Interest Rates and Bond Evaluation by Junaid ChohanInterest Rates and Bond Evaluation by Junaid Chohan
Interest Rates and Bond Evaluation by Junaid ChohanJunaid Ashraf
 
Stock Valuation
Stock ValuationStock Valuation
Stock ValuationBimarsh Giri
 
Bonds and their valuation
Bonds and their valuationBonds and their valuation
Bonds and their valuationShamal Firake
 
Unit 1 financial derivatives
Unit 1 financial derivativesUnit 1 financial derivatives
Unit 1 financial derivativesSudarshan Kadariya
 
Currency Hedging Presentation
Currency Hedging PresentationCurrency Hedging Presentation
Currency Hedging PresentationPaul Stafford
 
Introduction to graphs and their ability to represent images
Introduction to graphs and their ability to represent imagesIntroduction to graphs and their ability to represent images
Introduction to graphs and their ability to represent imagesAnyline
 
Term Structure Of Interest Rate
Term  Structure Of  Interest  RateTerm  Structure Of  Interest  Rate
Term Structure Of Interest RateMaroof Hussain Sabri
 
Effects of operating and financial Leverages
Effects of operating and financial Leverages  Effects of operating and financial Leverages
Effects of operating and financial Leverages sangamdesai
 
Chapter 3- Interest Rate/Cost of Money/BBS 4th
Chapter 3- Interest Rate/Cost of Money/BBS 4thChapter 3- Interest Rate/Cost of Money/BBS 4th
Chapter 3- Interest Rate/Cost of Money/BBS 4thBikash Adhikari
 
5.capital asset pricing model
5.capital asset pricing model5.capital asset pricing model
5.capital asset pricing modelAkash Bakshi
 
The behaviour of interest rates
The behaviour of interest ratesThe behaviour of interest rates
The behaviour of interest ratesRhazes Zy
 
Investment Portfolio
Investment PortfolioInvestment Portfolio
Investment Portfolioazarazua
 
Chapter 12 Cost Of Capital
Chapter 12 Cost Of CapitalChapter 12 Cost Of Capital
Chapter 12 Cost Of CapitalAlamgir Alwani
 
Cash and marketable securities management
Cash and marketable securities managementCash and marketable securities management
Cash and marketable securities managementNikhil Soares
 

What's hot (20)

exchange rate basics
exchange rate basicsexchange rate basics
exchange rate basics
 
Present Value of Uneven Cash Flows
Present Value of Uneven Cash FlowsPresent Value of Uneven Cash Flows
Present Value of Uneven Cash Flows
 
FIM - Currency Futures PPT
FIM - Currency Futures PPTFIM - Currency Futures PPT
FIM - Currency Futures PPT
 
Investment management chapter 5 the arbitrage pricing theory
Investment management chapter 5 the arbitrage pricing theoryInvestment management chapter 5 the arbitrage pricing theory
Investment management chapter 5 the arbitrage pricing theory
 
Basic07
Basic07Basic07
Basic07
 
Types of investment
Types of investmentTypes of investment
Types of investment
 
Interest Rates and Bond Evaluation by Junaid Chohan
Interest Rates and Bond Evaluation by Junaid ChohanInterest Rates and Bond Evaluation by Junaid Chohan
Interest Rates and Bond Evaluation by Junaid Chohan
 
Stock Valuation
Stock ValuationStock Valuation
Stock Valuation
 
Bonds and their valuation
Bonds and their valuationBonds and their valuation
Bonds and their valuation
 
Unit 1 financial derivatives
Unit 1 financial derivativesUnit 1 financial derivatives
Unit 1 financial derivatives
 
Currency Hedging Presentation
Currency Hedging PresentationCurrency Hedging Presentation
Currency Hedging Presentation
 
Introduction to graphs and their ability to represent images
Introduction to graphs and their ability to represent imagesIntroduction to graphs and their ability to represent images
Introduction to graphs and their ability to represent images
 
Term Structure Of Interest Rate
Term  Structure Of  Interest  RateTerm  Structure Of  Interest  Rate
Term Structure Of Interest Rate
 
Effects of operating and financial Leverages
Effects of operating and financial Leverages  Effects of operating and financial Leverages
Effects of operating and financial Leverages
 
Chapter 3- Interest Rate/Cost of Money/BBS 4th
Chapter 3- Interest Rate/Cost of Money/BBS 4thChapter 3- Interest Rate/Cost of Money/BBS 4th
Chapter 3- Interest Rate/Cost of Money/BBS 4th
 
5.capital asset pricing model
5.capital asset pricing model5.capital asset pricing model
5.capital asset pricing model
 
The behaviour of interest rates
The behaviour of interest ratesThe behaviour of interest rates
The behaviour of interest rates
 
Investment Portfolio
Investment PortfolioInvestment Portfolio
Investment Portfolio
 
Chapter 12 Cost Of Capital
Chapter 12 Cost Of CapitalChapter 12 Cost Of Capital
Chapter 12 Cost Of Capital
 
Cash and marketable securities management
Cash and marketable securities managementCash and marketable securities management
Cash and marketable securities management
 

Similar to Decompile Ethereum Smart Contracts

Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session ëŗ‘ė™„ ėž„
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Pluginsamiable_indian
 
How to be a smart contract engineer
How to be a smart contract engineerHow to be a smart contract engineer
How to be a smart contract engineerOded Noam
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentOOO "Program Verification Systems"
 
Embedded systemsproject_2020
Embedded systemsproject_2020Embedded systemsproject_2020
Embedded systemsproject_2020Nikos Mouzakitis
 
Ethereum hackers
Ethereum hackersEthereum hackers
Ethereum hackersgavofyork
 
“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip PandeyEIT Digital Alumni
 
Ethereum: Coding Society
Ethereum: Coding SocietyEthereum: Coding Society
Ethereum: Coding Societygavofyork
 
QuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.comQuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.comPreetam Rao
 
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdfscribdsituation719
 
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...Felipe Prado
 
äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12
äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12
äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12Aludirk Wong
 
0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and ProfitRussell Sanford
 
EVM - The Heart of Ethereum
EVM - The Heart of EthereumEVM - The Heart of Ethereum
EVM - The Heart of EthereumTruong Nguyen
 
EthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxEthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxWijdenBenothmen1
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackironSource
 
BERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery AttackBERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery AttackAlex Matrosov
 
Ethereum Blockchain and DApps - Workshop at Software University
Ethereum Blockchain and DApps  - Workshop at Software UniversityEthereum Blockchain and DApps  - Workshop at Software University
Ethereum Blockchain and DApps - Workshop at Software UniversityOpen Source University
 

Similar to Decompile Ethereum Smart Contracts (20)

Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
How to be a smart contract engineer
How to be a smart contract engineerHow to be a smart contract engineer
How to be a smart contract engineer
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications development
 
Embedded systemsproject_2020
Embedded systemsproject_2020Embedded systemsproject_2020
Embedded systemsproject_2020
 
Ethereum hackers
Ethereum hackersEthereum hackers
Ethereum hackers
 
“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey
 
Ethereum: Coding Society
Ethereum: Coding SocietyEthereum: Coding Society
Ethereum: Coding Society
 
QuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.comQuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.com
 
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
 
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
 
äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12
äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12
äģĨå¤Ē坊äģŖåšŖäģ˜æŦžå§”託 @ Open Source Developer Meetup #12
 
0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit
 
EVM - The Heart of Ethereum
EVM - The Heart of EthereumEVM - The Heart of Ethereum
EVM - The Heart of Ethereum
 
EthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxEthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptx
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
BERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery AttackBERserk: New RSA Signature Forgery Attack
BERserk: New RSA Signature Forgery Attack
 
Ethereum Blockchain and DApps - Workshop at Software University
Ethereum Blockchain and DApps  - Workshop at Software UniversityEthereum Blockchain and DApps  - Workshop at Software University
Ethereum Blockchain and DApps - Workshop at Software University
 

More from Shakacon

Web (dis)assembly
Web (dis)assemblyWeb (dis)assembly
Web (dis)assemblyShakacon
 
Macdoored
MacdooredMacdoored
MacdooredShakacon
 
I can be apple and so can you
I can be apple and so can youI can be apple and so can you
I can be apple and so can youShakacon
 
Cloud forensics putting the bits back together
Cloud forensics putting the bits back togetherCloud forensics putting the bits back together
Cloud forensics putting the bits back togetherShakacon
 
Pwned in Translation - from Subtitles to RCE
Pwned in Translation - from Subtitles to RCEPwned in Translation - from Subtitles to RCE
Pwned in Translation - from Subtitles to RCEShakacon
 
Oversight: Exposing spies on macOS
Oversight: Exposing spies on macOS Oversight: Exposing spies on macOS
Oversight: Exposing spies on macOS Shakacon
 
Modern Reconnaissance Phase on APT - protection layer
Modern Reconnaissance Phase on APT - protection layerModern Reconnaissance Phase on APT - protection layer
Modern Reconnaissance Phase on APT - protection layerShakacon
 
Shamoon
ShamoonShamoon
ShamoonShakacon
 
Honey, I Stole Your C2 Server: A Dive into Attacker Infrastructure
Honey, I Stole Your C2 Server:  A Dive into Attacker InfrastructureHoney, I Stole Your C2 Server:  A Dive into Attacker Infrastructure
Honey, I Stole Your C2 Server: A Dive into Attacker InfrastructureShakacon
 
Dock ir incident response in a containerized, immutable, continually deploy...
Dock ir   incident response in a containerized, immutable, continually deploy...Dock ir   incident response in a containerized, immutable, continually deploy...
Dock ir incident response in a containerized, immutable, continually deploy...Shakacon
 
Reviewing the Security of ASoC Drivers in Android Kernel
Reviewing the Security of ASoC Drivers in Android KernelReviewing the Security of ASoC Drivers in Android Kernel
Reviewing the Security of ASoC Drivers in Android KernelShakacon
 
Silent Protest: A Wearable Protest Network
Silent Protest:  A Wearable Protest NetworkSilent Protest:  A Wearable Protest Network
Silent Protest: A Wearable Protest NetworkShakacon
 
WiFi-Based IMSI Catcher
WiFi-Based IMSI CatcherWiFi-Based IMSI Catcher
WiFi-Based IMSI CatcherShakacon
 
Sad Panda Analysts: Devolving Malware
Sad Panda Analysts:  Devolving MalwareSad Panda Analysts:  Devolving Malware
Sad Panda Analysts: Devolving MalwareShakacon
 
reductio [ad absurdum]
reductio [ad absurdum]reductio [ad absurdum]
reductio [ad absurdum]Shakacon
 
XFLTReat: a new dimension in tunnelling
XFLTReat:  a new dimension in tunnellingXFLTReat:  a new dimension in tunnelling
XFLTReat: a new dimension in tunnellingShakacon
 
Windows Systems & Code Signing Protection by Paul Rascagneres
Windows Systems & Code Signing Protection by Paul RascagneresWindows Systems & Code Signing Protection by Paul Rascagneres
Windows Systems & Code Signing Protection by Paul RascagneresShakacon
 
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...Shakacon
 
The Search for the Perfect Door - Deviant Ollam
The Search for the Perfect Door - Deviant OllamThe Search for the Perfect Door - Deviant Ollam
The Search for the Perfect Door - Deviant OllamShakacon
 
Swift Reversing by Ryan Stortz
Swift Reversing by Ryan StortzSwift Reversing by Ryan Stortz
Swift Reversing by Ryan StortzShakacon
 

More from Shakacon (20)

Web (dis)assembly
Web (dis)assemblyWeb (dis)assembly
Web (dis)assembly
 
Macdoored
MacdooredMacdoored
Macdoored
 
I can be apple and so can you
I can be apple and so can youI can be apple and so can you
I can be apple and so can you
 
Cloud forensics putting the bits back together
Cloud forensics putting the bits back togetherCloud forensics putting the bits back together
Cloud forensics putting the bits back together
 
Pwned in Translation - from Subtitles to RCE
Pwned in Translation - from Subtitles to RCEPwned in Translation - from Subtitles to RCE
Pwned in Translation - from Subtitles to RCE
 
Oversight: Exposing spies on macOS
Oversight: Exposing spies on macOS Oversight: Exposing spies on macOS
Oversight: Exposing spies on macOS
 
Modern Reconnaissance Phase on APT - protection layer
Modern Reconnaissance Phase on APT - protection layerModern Reconnaissance Phase on APT - protection layer
Modern Reconnaissance Phase on APT - protection layer
 
Shamoon
ShamoonShamoon
Shamoon
 
Honey, I Stole Your C2 Server: A Dive into Attacker Infrastructure
Honey, I Stole Your C2 Server:  A Dive into Attacker InfrastructureHoney, I Stole Your C2 Server:  A Dive into Attacker Infrastructure
Honey, I Stole Your C2 Server: A Dive into Attacker Infrastructure
 
Dock ir incident response in a containerized, immutable, continually deploy...
Dock ir   incident response in a containerized, immutable, continually deploy...Dock ir   incident response in a containerized, immutable, continually deploy...
Dock ir incident response in a containerized, immutable, continually deploy...
 
Reviewing the Security of ASoC Drivers in Android Kernel
Reviewing the Security of ASoC Drivers in Android KernelReviewing the Security of ASoC Drivers in Android Kernel
Reviewing the Security of ASoC Drivers in Android Kernel
 
Silent Protest: A Wearable Protest Network
Silent Protest:  A Wearable Protest NetworkSilent Protest:  A Wearable Protest Network
Silent Protest: A Wearable Protest Network
 
WiFi-Based IMSI Catcher
WiFi-Based IMSI CatcherWiFi-Based IMSI Catcher
WiFi-Based IMSI Catcher
 
Sad Panda Analysts: Devolving Malware
Sad Panda Analysts:  Devolving MalwareSad Panda Analysts:  Devolving Malware
Sad Panda Analysts: Devolving Malware
 
reductio [ad absurdum]
reductio [ad absurdum]reductio [ad absurdum]
reductio [ad absurdum]
 
XFLTReat: a new dimension in tunnelling
XFLTReat:  a new dimension in tunnellingXFLTReat:  a new dimension in tunnelling
XFLTReat: a new dimension in tunnelling
 
Windows Systems & Code Signing Protection by Paul Rascagneres
Windows Systems & Code Signing Protection by Paul RascagneresWindows Systems & Code Signing Protection by Paul Rascagneres
Windows Systems & Code Signing Protection by Paul Rascagneres
 
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
 
The Search for the Perfect Door - Deviant Ollam
The Search for the Perfect Door - Deviant OllamThe Search for the Perfect Door - Deviant Ollam
The Search for the Perfect Door - Deviant Ollam
 
Swift Reversing by Ryan Stortz
Swift Reversing by Ryan StortzSwift Reversing by Ryan Stortz
Swift Reversing by Ryan Stortz
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Decompile Ethereum Smart Contracts

  • 1. Porosity Decompiling Ethereum Smart-Contracts Matt Suiche (@msuiche) Founder, Comae Technologies m@comae.io
  • 2. Whoami ī‚¯ @msuiche ī‚¯ Comae Technologies ī‚¯ OPCDE - www.opcde.com ī‚¯ First time in Vegas since BlackHat 2011 ī‚¯ Mainly Windows-related stuff ī‚¯ CloudVolumes (VMware App Volumes) ī‚¯ Memory Forensics for DFIR (Hibr2Bin, DumpIt etc.) ī‚¯ “looks like such fun guy” – TheShadowBrokers ī‚¯ Didn’t know much about blockchain before this project
  • 3. Just so you knowâ€Ļ ī‚¯ We won’t talk about POW/POS stuff ī‚¯ We won’t talk about Merkle Trees ī‚¯ We won’t talk about how to becoming a crypto-currency millionaire ī‚¯ We will talk about the Ethereum EVM ī‚¯ We will talk about Solidity ī‚¯ We will talk about smart-contract bytecodes ī‚¯ And yes, the tool isn’t perfect â˜ē
  • 4. Agenda ī‚¯ Ethereum Virtual Machine (EVM) ī‚¯ Memory Management ī‚¯ Addresses ī‚¯ Call Types ī‚¯ Type Discovery ī‚¯ Smart-Contract ī‚¯ Code Analysis ī‚¯ Known Bugs ī‚¯ Future
  • 5. Solidity ī‚¯ Solidity the quality or state of being firm or strong in structure. ī‚¯ But also the name of Ethereum’s smart-contracts compiler ī‚¯ Porosity is the quality of being porous, or full of tiny holes. Liquids go right through things that have porosity. ī‚¯ But also the name of Comae’s smart-contract decompiler.
  • 6. Accounts ī‚¯ Normal Accounts: 3,488,419 (July 15) ī‚¯ Contract Accounts: 930,889 (July 15) ī‚¯ Verified Contract Accounts: 2285 (July 15) ī‚¯ Source code is provided. ī‚¯ 40M$ lost in July ī‚¯ 10M$ in CoinDash’s ICO ī‚¯ http://www.coindesk.com/coindash-ico-hacker-nets-additional- ether-theft-tops-10-million/ ī‚¯ 30M$ due to Parity’s wallet.sol vulnerability ī‚¯ https://blog.parity.io/security-alert-high-2/ ī‚¯ https://github.com/paritytech/parity/pull/6103
  • 7. Ethereum Virtual Machine (EVM) ī‚¯ Account/Contract/Blockchain ī‚¯ A Smart-Contract is made of bytecode stored in the blockchain. ī‚¯ An address is a 160-bits value & corresponds to an “account” ī‚¯ Operates 256-bits pseudo-registers ī‚¯ EVM does not really have registers, but uses a virtual stack to replace them.
  • 8. Solidity & “Smart Contracts” ī‚¯ Solidity compiles JavaScript-like code into Ethereum bytecode.contract Coin { // The keyword "public" makes those variables // readable from outside. address public minter; mapping (address => uint) public balances; // Events allow light clients to react on // changes efficiently. event Sent(address from, address to, uint amount); // This is the constructor whose code is // run only when the contract is created. function Coin() { minter = msg.sender; } function mint(address receiver, uint amount) { if (msg.sender != minter) return; balances[receiver] += amount; } function send(address receiver, uint amount) { if (balances[msg.sender] < amount) return; balances[msg.sender] -= amount; balances[receiver] += amount; Sent(msg.sender, receiver, amount); } }
  • 9. Memory Management ī‚¯ Stack ī‚¯ Virtual stack is being used for operations to pass parameters to opcodes. ī‚¯ 256-bit values/entries ī‚¯ Maximum size of 1024 elements ī‚¯ Storage (Persistent) ī‚¯ Key-value storage mapping (256-to-256-bit integers) ī‚¯ Can’t be enumerated. ī‚¯ SSTORE/SLOAD ī‚¯ Memory (Volatile) ī‚¯ 256-bit values (lots of AND operations, useful for type discovery) ī‚¯ MSTORE/MLOAD
  • 10. Basic Blocks ī‚¯ Usually start with the JUMPDEST instruction – except few cases. ī‚¯ JUMP* instruction jump to the address contained in the 1st element of the stack. ī‚¯ JUMP* instruction are (almost always) preceded by PUSH instruction ī‚¯ This allows to push the destination address in the stack, instead of hardcoding the destination offset. ī‚¯ SWAP/DUP/POP stack manipulation instructions can make jump destination address harder to retrieve ī‚¯ This requires dynamic analysis to rebuild the relationship between each basic block.
  • 11. EVM functions/instructions ī‚¯ EVM instructions are more like functions, such as: ī‚¯ Arithmetic, Comparison & Bitwise Logic Operations ī‚¯ SHA3 ī‚¯ Environmental & Block Information ī‚¯ Stack, Memory, Storage and Flow Operations ī‚¯ Logging & System Operations
  • 12. Instruction call - Addition ī‚¯ The above translates at the EVM-pseudo code: ī‚¯ add(0x2, 0x1) Offset Instruction Stack[0] Stack[2] n PUSH1 0x1 0x1 n + 1 PUSH1 0x2 0x2 0x1 n + 2 ADD 0x3
  • 13. EVM Call ī‚¯ Can be identified by the CALL instruction. ī‚¯ Call external accounts/contracts pointed by the second parameter ī‚¯ The second parameter contains the actual 160 address of the external contract ī‚¯ With the exception of 4 hardcoded contracts: ī‚¯ 1 – elliptic curve public key recovery function ī‚¯ 2- SHA2 function ī‚¯ 3- RIPEMD160 function ī‚¯ 4- Identity function call( gasLimit, to, value, inputOffset, inputSize, outputOffset, outputSize )
  • 14. User-Defined functions (Solidity) ī‚¯ CALLDATALOAD instruction is used to read the Environmental Information Block (EIB) such as parameters. ī‚¯ First 4 bytes of the EIB contains the 32-bits hash of the called function. ī‚¯ Followed by the parameters based on their respective types. ī‚¯ e.g. int would be a 256 bits word. ī‚¯ a = calldataload(0x4) ī‚¯ b = calldataload(0x24) ī‚¯ add(calldataload(0x4), calldataload(0x24) function foo(int a, int b) { return a + b; }
  • 15. Type Discovery - Addresses ī‚¯ As an example, addresses are 160-bit words ī‚¯ Since stack registers are 256-bit words, they can easily be identified through AND operations using the 0xffffffffffffffffffffffffffffffffffffffff mask. ī‚¯ Mask can be static or computed dynamically Ethereum Assembly Translation (msg.sender) CALLER PUSH1 0x01 PUSH 0xA0 PUSH1 0x02 EXP SUB AND and(reg256, sub(exp(2, 0xa0), 1)) (EVM) reg256 & (2 ** 0xA0) - 1) (Intermediate) address (Solidity)
  • 16. Bytecode ī‚¯ The bytecode is divided in two categories: ī‚¯ Pre-loader code ī‚¯ Found at the beginning that contains the routine to bootstrap the contract ī‚¯ Runtime code of the contract ī‚¯ The core code written by the user that got compiled by Solidity ī‚¯ Each contract contain a dispatch function that redirects the call to the corresponding function based on the provided hash function.
  • 17. Bytecode – Pre-loader ī‚¯ CODECOPY copies the runtime part of the contract into the EVM memory – which gets executed at base address 0x0 00000000 6060 00000002 6040 00000004 52 00000005 6000 00000007 6001 00000009 6000 0000000b 610001 0000000e 0a 0000000f 81 00000010 54 00000011 81 00000012 60ff 00000014 02 00000015 19 00000016 16 00000017 90 00000018 83 00000019 02 0000001a 17 0000001b 90 0000001c 55 0000001d 50 0000001e 61bb01 00000021 80 00000022 612b00 00000025 6000 00000027 39 00000028 6000 0000002a f3 PUSH1 60 PUSH1 40 MSTORE PUSH1 00 PUSH1 01 PUSH1 00 PUSH2 0001 EXP DUP2 SLOAD DUP2 PUSH1 ff MUL NOT AND SWAP1 DUP4 MUL OR SWAP1 SSTORE POP PUSH2 bb01 DUP1 PUSH2 2b00 PUSH1 00 CODECOPY PUSH1 00 RETURN
  • 18. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP calldataload(0x0) / exp(0x2, 0xe0)
  • 19. Function Hashes ī‚¯ The 4 bytes of the sha3 (keccak256) value for the string functionName(param1Type, param2Type, etc) [ { "constant":false, "inputs":[{ "name":"a", "type":"uint256" }], "name":"double", "outputs":[{ "name":"", "type":"uint256" }], "type":"function" } ] keccak256("double(uint256)") => eee972066698d890c32fec0edb38a360c32b71d0a29ffc75b6ab6d2774ec9901 double(uint256) -> 0xeee97206 triple(uint256) -> 0xf40a049d
  • 20. Extracting function hash ī‚¯ calldataload(0x0) / exp(0x2, 0xe0) ī‚¯ (0x12345678xxxx / 0x00000001xxxx) = 0x12345678 ī‚¯ jumpi(eq(calldataload(0x0) / exp(0x2, 0xe0), 0xeee97206)) PS C:Program FilesGeth> .evm.exe --code 60e060020a60003504 --debug --input 12345678aaaaaaaabbbbbbbbccccccccdddddddd PC 00000009: STOP GAS: 9999999923 COST: 0 STACK = 1 0000: 0000000000000000000000000000000000000000000000000000000012345678 MEM = 0 STORAGE = 0 Ethereum Emulator
  • 21. Static CFG (--cfg) Emulated CFG (--cfg-full) Control Flow Graph
  • 22. Dispatcher – pseudo code hash = calldataload(0x0) / exp(0x2, 0xe0); switch (hash) { case 0xeee97206: // double(uint256) memory[0x60] = calldataload(0x4) * 2; return memory[0x60]; break; case 0xf40a049d: // triple(uint256) memory[0x60] = calldataload(0x4) * 3; return memory[0x60]; break; default: // STOP break; } contract C { function double(int arg_4) { return arg_4 * 2; } function triple(int arg_4) { return arg_4 * 3; } } Pseudo-Code Translated Code
  • 23. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 24. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 25. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 26. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 27. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 28. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 29. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 30. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 31. Bytecode – Dispatcher (--list) loc_00000000: 0x00000000 60 60 PUSH1 60 0x00000002 60 40 PUSH1 40 0x00000004 52 MSTORE 0x00000005 60 e0 PUSH1 e0 0x00000007 60 02 PUSH1 02 0x00000009 0a EXP 0x0000000a 60 00 PUSH1 00 0x0000000c 35 CALLDATALOAD 0x0000000d 04 DIV 0x0000000e 63 06 72 e9 ee PUSH4 06 72 e9 ee 0x00000013 81 DUP2 0x00000014 14 EQ 0x00000015 60 24 PUSH1 24 0x00000017 57 JUMPI loc_00000018: 0x00000018 80 DUP1 0x00000019 63 9d 04 0a f4 PUSH4 9d 04 0a f4 0x0000001e 14 EQ 0x0000001f 60 35 PUSH1 35 0x00000021 57 JUMPI loc_00000022: 0x00000022 5b JUMPDEST 0x00000023 00 STOP double(uint256): 0x00000024 5b JUMPDEST 0x00000025 60 45 PUSH1 45 0x00000027 60 04 PUSH1 04 0x00000029 35 CALLDATALOAD 0x0000002a 60 00 PUSH1 00 0x0000002c 60 4f PUSH1 4f 0x0000002e 82 DUP3 0x0000002f 60 02 PUSH1 02 loc_00000031: 0x00000031 5b JUMPDEST 0x00000032 02 MUL 0x00000033 90 SWAP1 0x00000034 56 JUMP triple(uint256): 0x00000035 5b JUMPDEST 0x00000036 60 45 PUSH1 45 0x00000038 60 04 PUSH1 04 0x0000003a 35 CALLDATALOAD 0x0000003b 60 00 PUSH1 00 0x0000003d 60 4f PUSH1 4f 0x0000003f 82 DUP3 0x00000040 60 03 PUSH1 03 0x00000042 60 31 PUSH1 31 0x00000044 56 JUMP
  • 32. DELEGATECALL & $30M Parity Bug contract Wallet { address _walletLibrary; address owner; // initWallet() is only invoked by the constructor. WalletLibrary is hardcoded. function Wallet(address _owner) { _walletLibrary = 0xa657491c1e7f16adb39b9b60e87bbb8d93988bc3; _walletLibrary.delegatecall(bytes4(sha3("initWallet(address)")), _owner); } (â€Ļ) // fallback function behaves like a “generic forward” (WTF?) // Wallet.initWallet(attacker) becomes walletLibrary.initWallet(attacker) function () payable { _walletLibrary.delegatecall(msg.data); } } Abusing the dispatcher to reinitialize a wallet?
  • 33. Generic-Forward & Fall back functions ī‚¯ Typical issue introduce by the lack of upgradeability of smart- contract ī‚¯ Software engineering is hard enough, but smart-contracts need to be: ī‚¯ Backward-Compatible ī‚¯ Forward-Compatible ī‚¯ Does not help to make the language verifiable. ī‚¯ Fall back functions are undefined behaviors. ī‚¯ Imagine if your kernel would behave like that. ī‚¯ Scary, right ? Now, imagine if that’s your bankâ€Ļ
  • 34. Fixing the initialization bug - function initMultiowned(address[] _owners, uint _required) { + function initMultiowned(address[] _owners, uint _required) internal { - function initDaylimit(uint _limit) { + function initDaylimit(uint _limit) internal { + modifier only_uninitialized { if (m_numOwners > 0) throw; _; } - function initWallet(address[] _owners, uint _required, uint _daylimit) { + function initWallet(address[] _owners, uint _required, uint _daylimit) only_uninitialized {
  • 35. Code Analysis – Vulnerable Contract contract SendBalance { mapping ( address => uint ) userBalances ; bool withdrawn = false ; function getBalance (address u) constant returns ( uint ){ return userBalances [u]; } function addToBalance () { userBalances[msg.sender] += msg.value ; } function withdrawBalance (){ if (!(msg.sender.call.value( userBalances [msg.sender])())) { throw ; } userBalances [msg.sender] = 0; } }
  • 36. Code Analysis – Vulnerable Contract contract SendBalance { mapping ( address => uint ) userBalances ; bool withdrawn = false ; function getBalance (address u) constant returns ( uint ){ return userBalances [u]; } function addToBalance () { userBalances[msg.sender] += msg.value ; } function withdrawBalance (){ if (!(msg.sender.call.value( userBalances [msg.sender])())) { throw ; } userBalances [msg.sender] = 0; } } Caller contract can recall this function using its fallback function
  • 37. Understanding the control flow ī‚¯ In the case of reentrant vulnerability, since we can record the EVM state at each instruction using porosity. ī‚¯ We can track in which basic block SSTORE instructions are called. ī‚¯ userBalances [msg.sender] = 0; ī‚¯ And track states for each basic block.
  • 38. .demo.ps1 $porosity = 'E:projectsporosityDebugporosity.exe' $abi = '[{"constant":false,"inputs":[],"name":"withdrawBalance","outputs":[],"ty pe":"function"},{"constant":false,"inputs":[],"name":"addToBalance","out puts":[],"type":"function"},{"constant":true,"inputs":[{"name":"u","ty pe":"address"}],"name":"getBalance","outputs":[{"name":"","type":"ui nt256"}],"type":"function"}]' $code = '60606040526000357c01000000000000000000000000000000000000000000000000000000009004806 35fd8c7101461004f578063c0e317fb1461005e578063f8b2cb4f1461006d5761004d565b005b61005c6 004805050610099565b005b61006b600480505061013e565b005b6100836004808035906020019091905 05061017d565b6040518082815260200191505060405180910390f35b3373fffffffffffffffffffffff fffffffffffffffff16611111600060005060003373ffffffffffffffffffffffffffffffffffffffff1 6815260200190815260200160002060005054604051809050600060405180830381858888f1935050505 0151561010657610002565b6000600060005060003373fffffffffffffffffffffffffffffffffffffff f168152602001908152602001600020600050819055505b565b34600060005060003373fffffffffffff fffffffffffffffffffffffffff168152602001908152602001600020600082828250540192505081905 5505b565b6000600060005060008373ffffffffffffffffffffffffffffffffffffffff1681526020019 081526020016000206000505490506101b6565b91905056’ & $porosity --abi $abi --runtime-code $code --decompile --verbose 0
  • 39.
  • 40. Known class of bugs ī‚¯ Reentrant Vulnerabilities / Race Condition ī‚¯ Famously known because of the $50M USD DAO hack (2016) [8] ī‚¯ Call Stack Vulnerabilities ī‚¯ Got 1024 frames but a bug ain’t one – c.f. Least Authority [12] ī‚¯ Time Dependency Vulnerabilities ī‚¯ @mhswende blogposts are generally awesome, particularly the roulette one [10] ī‚¯ Unconditional DELEGATECALL
  • 41. Porosity + Quorum = <3 ī‚¯ Quorum: Ethereum code fork created by J.P. Morgan ī‚¯ aimed at enterprises that want to use a permissioned blockchain that adds private smart contract execution & configurable consensus. ī‚¯ Quorum now includes Porosity integrated directly into geth out of the box: ī‚¯ Scan private contracts sent to your node from other network participants ī‚¯ Incorporate into security & patching processes for private networks with formalized governance models ī‚¯ Automate scanning and analyze risk across semi-public Quorum networks ī‚¯ https://github.com/jpmorganchase/quorum
  • 42.
  • 43. Future ī‚¯ Ethereum DApps created a new segment for softwares. ī‚¯ Porosity ī‚¯ Improving support for conditional and loop statements ī‚¯ Ethereum / Solidity & Security ī‚¯ Fast growing community and more tools such as OYENTE or Porosity ī‚¯ Personally, looking forward seeing the Underhanded Solidity Coding Contest [10] results ī‚¯ EVM vulnerabilities triggered by malicious bytecode? CLOUDBURST on the blockchain ī‚¯ More Blockchain VMs ? ī‚¯ Swapping the EVM for Web Assembly (WASM) for 2018
  • 44. Future - WebAssembly ī‚¯ New Ethereum Roadmap (March 2017) mentions making the EVM obsolete and replacing it with WebAssembly for 2018. ī‚¯ “WebAssembly (or WASM) is a new, portable, size- and load-time- efficient format.” ī‚¯ WebAssembly is currently being designed as an open standard by a W3C Community Group. ī‚¯ WebAssembly defines an instruction set, intermediate source format (WAST) and a binary encoded format (WASM). ī‚¯ Major browser JavaScript engines will notably have native support for WebAssembly – including V8, Chakra and Spidermonkey. ī‚¯ https://github.com/ewasm/design
  • 45. WASM + DApps + Blockchain ī‚¯ C++ -> WASM is already a thing ī‚¯ https://mbebenita.github.io/WasmExplorer/ ī‚¯ And a similar thing is planned for eWASM
  • 46. Acknowledgements ī‚¯ Mohamed Saher ī‚¯ Halvar Flake ī‚¯ DEFCON Review Board Team ī‚¯ Max Vorobjov & Andrey Bazhan ī‚¯ Martin H. Swende ī‚¯ Gavin Wood ī‚¯ Andreas Olofsson
  • 47. References [1] Woods, Gavin. "Ethereum: A Secure Decentralised Generalised Transaction Ledger." Web. https://github.com/ethereum/yellowpaper.pdf [2] Olofsson, Andreas. "Solidity Workshop." Web. https://github.com/androlo/solidity-workshop [3] Olofsson, Andreas. "Solidity Contracts." Web. https://github.com/androlo/standard-contracts [4] Velner, Yarn, Jason Teutsch, and Loi Luu. "Smart Contracts Make Bitcoin Mining Pools Vulnerable." Web. https://eprint.iacr.org/2017/230.pdf [5] Luu, Loi, Duc-Hiep Chu, Hrishi Olickel, Aquinas Hobor. "Making Smart Contracts Smarter." Web. https://www.comp.nus.edu.sg/%7Ehobor/Publications/2016/Making%20Smart%20Contracts%20Smarter.pdf [6] Atzei, Nicola, Massimo Bartoletti, and Tiziana Cimoli. " A Survey of Attacks on Ethereum Smart Contracts." Web. https://eprint.iacr.org/2016/1007.pdf [7] Sarkar, Abhiroop. "Understanding the Transactional Nature of Smart-Contracts." Web. https://abhiroop.github.io/Exceptions-and-Transactions [8] Siegel, David. "Understanding The DAO Attack." Web. http://www.coindesk.com/understanding-dao-hack-journalists [9] Blockchain software for asset management. "OYENTE: An Analysis Tool for Smart Contracts." Web. https://github.com/melonproject/oyente [10] Holst Swende, Martin. “Breaking the house.“ Web. http://martin.swende.se/blog/Breaking_the_house.html [11] Buterin, Vitalik. "Thinking About Smart Contract Security.“Web. https://blog.ethereum.org/2016/06/19/thinking-smart-contract-security [12] Least Authority. "Gas Economics: Call Stack Depth Limit Errors." Web. https://github.com/LeastAuthority/ethereum- analyses/blob/master/GasEcon.md#callstack-depth-limit-errors [13] Underhanded Solidity Coding Contest, Web. http://u.solidity.cc/ [14] Quorum. "A permissioned implementation of Ethereum supporting data privacy." https://github.com/jpmorganchase/quorum