- Dr. Petar Tsankov
Scientific Researcher, ICE center, ETH Zurich Co-founder and Chief Scientist, ChainSecurity AG http://www.ptsankov.com/ @ptsankov
Securify: Practical Security Analysis of Smart Contracts - - PowerPoint PPT Presentation
Securify: Practical Security Analysis of Smart Contracts https://securify.ch Dr. Petar Tsankov Scientific Researcher, ICE center, ETH Zurich Co-founder and Chief Scientist, ChainSecurity AG http://www.ptsankov.com/ @ptsankov
Scientific Researcher, ICE center, ETH Zurich Co-founder and Chief Scientist, ChainSecurity AG http://www.ptsankov.com/ @ptsankov
Vechev
Vanbever
Tsankov
Drachsler Timon Gehr Ahmed El-Hassany Maria Apostolaki Rüdiger Birkner Samuel Steffan Roland Meier Johannes Kapfhammer
mapping(address => uint) balances; function withdraw() { uint amount = balances[msg.sender]; msg.sender.call.value(amount); balances[msg.sender] = 0; }
mapping(address => uint) balances; function withdraw() { uint amount = balances[msg.sender]; msg.sender.call.value(amount)(); balances[msg.sender] = 0; }
function moveBalance() { bank.withdraw(); } ...
function () payable { // log payment }
Later…
mapping(address => uint) balances; function withdraw() { uint amount = balances[msg.sender]; msg.sender.call.value(amount)(); balances[msg.sender] = 0; } function moveBalance() { bank.withdraw(); } ...
function () payable { bank.withdraw(); }
...
address owner = ...; function initWallet(address _owner) {
} function withdraw(uint _amount) { if (msg.sender == owner) { msg.sender.transfer(_amount); } }
address walletLibrary = ... // address function() payable { walletLibrary.delegatecall(msg.data); } function withdraw(uint amount) { walletLibrary.delegatecall(msg.data); }
function() payable { // fallback } function withdraw(uint amount) { // withdraw funds }
address walletLibrary = ... // address function() payable { walletLibrary.delegatecall(msg.data); } function withdraw(uint amount) { walletLibrary.delegatecall(msg.data); }
... function() payable { // fallback } function withdraw(uint amount) { // withdraw funds }
function withdraw() { uint amount = balances[msg.sender]; msg.sender .call.value(amount)(); balances[msg.sender] = 0; }
Unsafe behaviors Safe behaviors
Violation No violation Warning
Infer facts Decompile Check patterns Intermediate Representation 00: x = Balance 02: y = 0x20 04: If (x == 0x00) 06: MStore(y, x) 08: z = y 0a: goto 0x42 ⋮ Semantic Representation MemTag(0x20, Balance) MemTag(0x40, Const) VarTag(z, Const) VarTag(k, Gas) Assign(s, 0x20) Call(s, k) ⋮ EVM Bytecode 00: 60 02: 5b 04: 42 06: 80 08: 90 0a: 56 ⋮
Decompile Intermediate Representation 00: x = Balance 02: y = 0x20 04: If (x == 0x00) 06: MStore(y, x) 08: z = y 0a: goto 0x42 ⋮ EVM Bytecode 00: 60 02: 5b 04: 42 06: 80 08: 90 0a: 56 ⋮
Infer facts Intermediate Representation 00: x = Balance 02: y = 0x20 04: If (x == 0x00) 06: MStore(y, x) 08: z = y 0a: goto 0x42 ⋮ Semantic Representation MemTag(0x20, Balance) MemTag(0x40, Const) VarTag(z, Const) VarTag(k, Gas) Assign(s, 0x20) Call(s, k) ⋮
1: x := 10 2: y := x + 20 5: y := 0 6: return 3: y--; 4: return
1: x := Balance 2: Mstore(0x20, x) 3: y := MLoad(0x20) 4: z := x + y
!"##"$(1,2) !"##"$(2,3) !"##"$(3,4) ,--./0 1, 23#3045 6-7"0-8 0x20 ;<8"=5 2, 0x20, 1 ;>"3? 3, @, 0x20 AB 4, C, 1 AB 4, C, @
;3@D5BA0 1, 8 ← ,--./0(1, 8) ;3@D5BA0 1, 8 ← AB(__, 1, 1G), ;3@D5BA0(1G, 8) ;3@D5BA0 1, 8 ← ;>"3? #, 1, " , .-7"0-8 #, " , ;5HI3/(#, ", 8) ;3@D5BA0 1, 8 ← ;>"3? #, 1, " , ¬.-7"0-8 #, " , ;5HI3/(#, __, 8) ;5HI3/ #, ", 8 ← ;<8"=5 #, ", 1 , .-7"0-8 " , ;3@D5BA0(1, 8) ;5HI3/ #, ⊤, 8 ← ;<8"=5 #, ", 1 , ¬.-7"0-8 " , ;3@D5BA0(1, 8) ;5HI3/ #, ", 8 ← !"##"$- #, #′ , ;5HI3/ #G, ", 8 , ¬;<8"=5(#, ", __)
Check patterns Semantic Representation MemTag(0x20, Balance) MemTag(0x40, Const) VarTag(z, Const) VarTag(k, Gas) Assign(s, 0x20) Call(s, k) ⋮
!"## #, _, _, _ : ¬∃))*+,- #., _, _ . 0"12+##+3(#, #.) !"## #, _, _, _ : ∃))*+,- #., _, _ . 067*2+##+3(#, #.)
function withdraw() { uint amount = balances[msg.sender]; msg.sender .call.value(amount)(); balances[msg.sender] = 0; }
!!"#$%(_, ), _): ,%"-. ), /011%$ !!"#$% 1, ), __ : ¬30.,%456 ), /011%$ ∧ ¬30.,%456(1, /011%$)
address owner = ...; function initWallet(address _owner) {
}
%
%
% 0% 20 % 40 % 60 %
Tr ue warnings Vi
a ti
False war nings Unrepo rted vulner abiliti e s Transaction reordering Reentrancy Handled exception Restricted transfer O y e n t e S e c u r i f y M y t h r i l S e c u r i f y O y e n t e S e c u r i f y M y t h r i l S e c u r i f y M y t h r i l O y e n t e
Securing the blockchain contact@chainsecurity.com @chain_security http://jsnice.org http://apk-deguard.com http://securify.ch http://psisolver.org http://eventracer.org
https://chainsecurity.com
jobs@chainsecurity.com
SECURE, RELIABLE, INTELLIGENT SYSTEMS LAB
http://ai2.ethz.ch