西安电子科技大学学报 ›› 2024, Vol. 51 ›› Issue (1): 178-186.doi: 10.19665/j.issn1001-2400.20230208

• 网络空间安全 • 上一篇    下一篇

一种支持内嵌数据处理的合约漏洞修复方案

彭泳翔1(), 刘志全1,2(), 王立波1(), 吴永东1(), 马建峰1,3(), 陈宁2()   

  1. 1.暨南大学 信息科学技术学院,广东 广州 510632
    2.广东省网络与信息安全漏洞研究重点实验室,广东 广州 510643
    3.西安电子科技大学 网络与信息安全学院,陕西 西安 710071
  • 收稿日期:2022-11-02 出版日期:2024-01-20 发布日期:2023-10-16
  • 通讯作者: 刘志全(1989—),男,副研究员,E-mail:zqliu@vip.qq.com
  • 作者简介:彭泳翔(1998—),男,暨南大学硕士研究生,E-mail:greapi@foxmail.com;
    王立波(1988—),男,讲师,E-mail:wanglibo12b@mails.ucas.edu.cn;
    吴永东(1970—),男,教授,E-mail:wuyd007@vip.qq.com;
    马建峰(1963—),男,教授,E-mail:jfma@mail.xidian.edu.cn;
    陈宁(1984—),女,工程师,E-mail:chenn@gditsec.org.cn
  • 基金资助:
    国家自然科学基金(62032025);国家自然科学基金(61932011);国家自然科学基金(62272195);广东省网络与信息安全漏洞研究重点实验室项目(2020B1212060081);广东省重点研发计划(2020B0101090002);广东省基础与应用基础研究基金(2022A1515010299);广东省基础与应用基础研究基金(2020A1515110364);广州市科技计划项目(202201010421);中央高校基本科研业务费专项资金(21622402)

Contract vulnerability repair scheme supporting inline data processing

PENG Yongxiang1(), LIU Zhiquan1,2(), WANG Libo1(), WU Yongdong1(), MA Jianfeng1,3(), CHEN Ning2()   

  1. 1. College of Information Science and Technology,Jinan University,Guangzhou 510632,China
    2. Guangdong Provincial Key Laboratory of Cyber and Information Security Vulnerability Research,Guangzhou 510643,China
    3. School of Cyber Engineering,XidianUniversity,Xi’an 710071,China
  • Received:2022-11-02 Online:2024-01-20 Published:2023-10-16

摘要:

智能合约是一段部署在区块链上的程序,为分布式交易提供了可能。然而,由于智能合约携带的金融属性及部署后不可改变的特性,使其成为黑客攻击的目标。因此,为保证合约的安全性,需对漏洞合约进行修复。然而,现有合约漏洞修复方案存在修复成功率低、无法处理复杂合约等问题,为此提出一种支持内嵌数据处理的合约漏洞修复方案。该方案首先研究并形式化以太坊虚拟机动态装载机制,并基于内存拷贝指令构建内嵌数据定位算法,解析并反编译智能合约字节码结构;接着基于蹦床机制对智能合约字节码进行重写,并修正因重写而产生的内嵌数据地址偏移;最终实现智能合约的漏洞修复。基于所提方案实现原型工具SCRepair,部署于本地测试网络Ganache以对其进行性能测试,并与现有漏洞修复工具EVMPatch和Smartshield进行比较。实验结果表明,相比于EVMPatch,SCRepair的合约字节码重写成功率提升了约26.9%,并有着更好的执行重写稳定性,受编译器版本的较影响小;相比于Smartshield,SCRepair能够更好地处理复杂合约。

关键词: 区块链, 智能合约, 字节码重写, 反编译, 蹦床

Abstract:

Smart contracts are programs deployed on the blockchain that enable distributed transactions.However,due to the financial attributes and immutable characteristics of smart contracts,they become targets of hacker attacks.Therefore,to ensure the security of contracts,it is necessary to repair vulnerable contracts.However,existing contract vulnerability repair schemes have problems such as low repair success rate and inability to handle complex contracts.To this end,a contract vulnerability repair scheme supporting inline data processing is proposed in this paper.The proposed scheme first studies and formalizes the dynamic loading mechanism of the Ethereum virtual machine,and constructs an inline data location algorithm based on memory copy instructions to parse and decompile the smart contract bytecode structure;then the smart contract bytecode is rewritten based on the trampoline mechanism,and the inline data address offset caused by rewriting is corrected,and finally the smart contract vulnerability repair is implemented.A prototype tool named SCRepair is implemented based on the proposed scheme,which is deployed on the local test network Ganache for performance testing,and compared with existing vulnerability repair tools EVMPatch and Smartshield.Experimental results show that the SCRepair improves the bytecode rewrite success rate by 26.9% when compared with the EVMPatch.Besides,the SCRepair has a better rewrite execution stability,and is less affected by the compiler version;the SCRepair can handle complex contracts better when compared with the Smartshield.

Key words: blockchain, smart contract, bytecode rewriting, decompilation, trampoline

中图分类号: 

  • TP309
Baidu
map