03月16, 2020

security of smart contracts

基于区块链发展的smart contracts, 它比区块链的灵活性更高,可以实现任何逻辑放到区块上执行。由于去中心化的线上持有大量虚拟货币,它一直是攻击者的目标。

1- EVM上已经部署超过2000万个samrt contracts

2- 其中最搞价值smart contract 有180万个ETH, 价值约4亿美元

3- 其中发生的最知名攻击为,利用Re-entrancy vulnerability in the DAO, 造成7000万美金损失,由于权限管理问题,Parity multisig wallet 导致3100万美金损失,允许黑客kill smart contract, 冻结1.53亿美金;EOSBet smart contract 造成50万美金损失。

现有分析和保护smart contracts的方法分两大类:

1- offline 分析contract 以发现漏洞,检查正确性,逆向工程bytecode,检测恶意合约。 由于缺乏runtime info 和 所选择的技术限制,offline方法不能保证漏洞被检测和移除。

2- online 检测合约运行情况,或者在部署后保护合约免受攻击。分为2种

1) source/ byte code 插入保护码,收到 EVM bytecode和gus机制的大小限制。 2)保护代码插入EVM runtime, 不容易扩展检测新的攻击。 稍后补充更多细节

功能、效率和兼容性与现有的在线方法有所不同 1)可扩展, 分层设计,信息收集和攻击检测 两个部分。

对EVM进行检测,收集攻击所需的原始信息

11种结构

覆盖8种情况:

1- Re-entrancy

2- unexpected function invocation,

3- invalid input data,

4- incorrect check for authorization,

5- no check after contract invocation,

6- missing the Transfer event,

7- strict check for balance,

8- dependency of block number and timestamp.

异步运行,提高效率, 采用了dynamic linking来消除inter-process communication(IPC)的开销

用户可以使用任何可以生成动态链接库(dll)的编程语言开发检测应用程序。这样的设计可以在区块链执行期间安装/删除检测应用程序,从而有助于快速响应新的攻击。

在处理历史数据块时,没有/有8个检测应用程序的SODA开销分别为0.4%/25.5%(§V-D),这对于回顾性分析(如攻击取证)是可以接受的

与任何采用EVM作为智能合约运行时的区块链都兼容。EVM最初是为以太坊设计的,随后迅速被许多其他区块链(如Expanse[40]、Wanchain[41]、Tomochain[42]、SmartMesh[43]、CPChain[44]、ThunderCore[45])采用。

3个区块链中,即Ethereum、Expanse和Wanchain


Block: A blockchain is a growing list of blocks [46], each of which contains a cryptographic hash of the previous block for linking the previous block, a timestamp when the block was mined, and transactions [46]. Blocks are produced by mining. account: there are two kinds of accounts in Ethereum: external owned account (EOA) and smart contract [39]. An EOA is controlled by a private key and does not contain the EVM bytecode. A smart contract account contains its EVM bytecode of executable code, and it should be created by an EOA or another smart contract. Each account is referred to by its address, a 20-byte value.

Solidity [47]), and then compiled into EVM bytecode, which is a sequence of EVM instructions.

EVM uses its interpreter to execute EVM instructions and it currently supports more than 130 unique EVM instructions

Before invoking a smart contract, its EVM bytecode should be deployed on the blockchain. To call a function in a smart contract, the function id rather than the function name of the callee should be provided. The function id is the first 4 bytes of the hash of the function signature which is the function name with the list of parameter types

EVM是一个基于堆栈的虚拟机stack-based virtual machine,它使用堆栈来记录操作数、EVM指令的计算结果、函数参数等[39]。Memory是存储函数参数、函数返回值等的临时空间[39]。Storage是一个类似于数据库的永久空间,用于存储键值对.

交易Transaction。交易是由帐户[49],[50]发送的消息。根据发件人的不同,有两种类型的事务。更准确地说,EOA发送外部事务,而智能合约发送内部事务[49]。块只记录外部事务,因为可以通过执行智能合约来复制内部事务。事务携带关键信息,例如要发送的ETH量、要部署的智能合约的EVM字节码、调用智能合约的参数.

事件Event。智能合约使用日志指令发出事件,即LOG0、LOG1、LOG2、LOG3和LOG4[47]。一个事件由零个或多个主题和一个数据字段组成[47]。

ETH, Token。ETH是以太坊的本地加密货币。当一个区块被开采,矿工将得到以太币奖励。以太坊支持许多代币,它们是作为智能合约实现的加密货币。Token通常应该与一些令牌标准兼容,例如,ERC-20[51],ERC-721[52]。否则,第三方工具(如钱包、外汇市场)就无法与之正常互动[53]。

全节点Full node。为了挖掘和验证区块,区块链完整节点从其他节点下载所有历史区块,并重放区块中包含的交易。一个完整的节点配备了一个EVM来运行智能合约。因此,一个完整的节点可以观察块、事务和智能合约执行的所有信息。

可以拿到 runtime information of blocks

本文链接:https://harry.ren/post/sofsc.html

-- EOF --

Comments