CN111680271A - Contract code obfuscation platform and method based on intelligent contract byte code characteristics - Google Patents

Contract code obfuscation platform and method based on intelligent contract byte code characteristics Download PDF

Info

Publication number
CN111680271A
CN111680271A CN202010489637.7A CN202010489637A CN111680271A CN 111680271 A CN111680271 A CN 111680271A CN 202010489637 A CN202010489637 A CN 202010489637A CN 111680271 A CN111680271 A CN 111680271A
Authority
CN
China
Prior art keywords
contract
instruction
jump
code
original
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010489637.7A
Other languages
Chinese (zh)
Inventor
程镇
周亚金
吴磊
任奎
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CN202010489637.7A priority Critical patent/CN111680271A/en
Publication of CN111680271A publication Critical patent/CN111680271A/en
Priority to PCT/CN2021/074634 priority patent/WO2021244054A1/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/10Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
    • G06F21/12Protecting executable software
    • G06F21/121Restricting unauthorised execution of programs
    • G06F21/125Restricting unauthorised execution of programs by manipulating the program code, e.g. source code, compiled code, interpreted code, machine code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Technology Law (AREA)
  • Computer Hardware Design (AREA)
  • Stored Programmes (AREA)

Abstract

The platform converts original byte codes into instruction sequences, extracts instruction positions needing to be rewritten and original jump target addresses according to the obfuscation method, then generates insertion instructions and inserts the insertion instructions at corresponding positions of the instruction sequences, then corrects the jump addresses of the instruction sequences to enable the jump addresses to correspond to correct jump addresses, and finally converts the corrected instruction sequences into byte codes, namely obfuscated byte codes and outputs the byte codes. The invention can prevent the contract information of the contract inventor from being easily analyzed by a tool by confusing the contract byte codes, thereby reducing the risk of randomly stealing codes by people on the chain of contracts.

Description

Contract code obfuscation platform and method based on intelligent contract byte code characteristics
Technical Field
The invention relates to the field of intelligent contracts, in particular to a contract code obfuscation platform and a contract code obfuscation method based on intelligent contract byte code characteristics.
Background
The intelligent contract was the idea proposed by nissabo in the 1990 s, almost as old as the internet. Because of the lack of a trusted execution environment, the smart contract is not applied to the actual industry, and since the birth of the bit currency, people recognize that the underlying technology blockchain of the bit currency can naturally provide a trusted execution environment for the smart contract. An intelligent contract is an assembly language programmed on a blockchain. Typically one will not write the bytecode itself, but will compile it from a higher level language.
Since the blockchain is an open distributed book, all the information owners on the blockchain are publicly visible, and the codes are often multiplexed, and since the contracts stored on the chain are in a byte code form and are difficult for people to read, in order to understand a contract which does not publish the source codes, people usually adopt various analysis means to understand how the contract operates to achieve different purposes. Such an environment is very hostile to a contract developer who is not willing to easily copy others or even find vulnerabilities to attack his contracts.
Disclosure of Invention
The invention aims to provide an intelligent contract code obfuscation platform aiming at the condition that the contract code on the existing chain can be easily analyzed by various analysis tools, and a contract developer can rewrite the contract code through the platform before deploying the contract to avoid the condition.
The purpose of the invention is realized by the following technical scheme:
a contract code obfuscation platform based on intelligent contract bytecode features, the platform comprising:
a bytecode/instruction converter for receiving original bytecode and converting said original bytecode into an instruction sequence according to a target obfuscation method to represent an executable segment;
the information extractor is used for extracting and injecting the information required by the re-analysis of the instruction sequence and the jump target according to an obfuscation method, wherein the information comprises an instruction position required to be rewritten and an original jump target address, the instruction position required to be rewritten is stored and sent to the byte code injector, and the original jump target address is sent to the re-analyzer of the jump target;
the bytecode injector generates an insertion instruction according to an obfuscation method, inserts the insertion instruction at a corresponding position of the instruction sequence to form a new instruction sequence and sends the new instruction sequence to the skip target re-analyzer;
a jump target re-resolver for correcting the jump address of the new instruction sequence to make it correspond to the correct jump target;
and the instruction/byte code converter is used for converting the corrected instruction sequence into byte codes, namely the confused byte codes, and outputting the byte codes.
A contract code obfuscation method based on intelligent contract byte code characteristics specifically comprises the following steps:
s1: the contract developer generates original byte codes through an intelligent contract compiler;
s2: inputting the original byte code into a contract code obfuscation platform, and selecting an obfuscation method expected to be used;
s3: the contract code obfuscation platform converts the original byte code into an instruction sequence, extracts an instruction position to be rewritten and an original jump target address according to the obfuscation method, then generates an insertion instruction and inserts the insertion instruction into a corresponding position of the instruction sequence, then corrects the jump address of the instruction sequence to enable the jump address to correspond to a correct jump address, and finally converts the corrected instruction sequence into the byte code, namely the obfuscated byte code, and outputs the byte code.
Further, the S3 specifically includes the following sub-steps:
s3.1: linearly scanning the original byte codes, and identifying a contract initialization code segment and a Swarm hash segment through a default contract initialization code segment and a Swarm hash start-end feature code given by a contract compiler in the process;
s3.2: decompiling the original byte codes into instructions and immediate data of the Etheng virtual machine, and creating a contract copy by using the information;
s3.3: by maintaining a simulation stack, the contract code obfuscating platform executes contract codes step by step, traverses all branches which can be reached, identifies a function selector section, a contract function section and a data section of a contract during the process, and marks a jump instruction in a contract copy and a value used by the jump instruction;
s3.4: generating and inserting an instruction sequence corresponding to the confusion method according to the marked instruction;
s3.5: and correcting the jump address misplaced in the instruction to finish the confusion.
Further, the obfuscation method selects any one of the following methods:
(1) by adding a PUSH instruction, the tool finds two contract initialization code starting characteristics which are recognized by mistake when the byte codes are scanned linearly, so that the tool recognizes wrong contract main body codes;
(2) by rewriting byte codes in the Swarm Hash segment and rewriting instructions near jump instructions in the contract, all the jump instructions in the original contract jump to respective target addresses through the Swarm Hash segment, and a control flow graph of the contract is flattened;
(3) preventing a contract analysis tool from acquiring a function signature stored in a contract through a feature sequence of the interrupt function selector;
(4) by inserting a large number of JUMPDEST instructions, an analysis tool using symbolic execution and simulation execution is forced to maintain a large number of basic block entry states, and further the tool runs slowly or even crashes;
(5) by changing the immediate for jumping into a series of immediate operation results, the default jumping target address is not able to analyze the jumping address in the contract;
(6) the target address used for jumping is put into a memory and retrieved by calling a precompiled contract, so that the static analysis tool mistakenly calls a contract on a chain, and the information of the target address of jumping is lost.
The invention has the following beneficial effects:
aiming at the situation that the intelligent contract byte codes can be analyzed by using the existing analysis tool, a contract developer can adopt the confusion device and the confusion method to add a layer of confusion to the contract, so that the non-readability of the contract byte codes of the contract developer is enhanced, and the protection of the contract codes is enhanced.
Drawings
FIG. 1 is a schematic diagram of a contract code obfuscation platform based on intelligent contract bytecode features;
FIG. 2 is a flow diagram of a contract code obfuscation method based on intelligent contract bytecode features.
Detailed Description
The present invention will be described in detail below with reference to the accompanying drawings and preferred embodiments, and the objects and effects of the present invention will become more apparent, it being understood that the specific embodiments described herein are merely illustrative of the present invention and are not intended to limit the present invention.
As shown in FIG. 1, the contract code obfuscation platform based on intelligent contract bytecode features of the present invention includes:
a bytecode/instruction converter for receiving original bytecode and converting said original bytecode into an instruction sequence according to a target obfuscation method to represent an executable segment;
the information extractor is used for extracting and injecting the information required by the re-analysis of the instruction sequence and the jump target according to an obfuscation method, wherein the information comprises an instruction position required to be rewritten and an original jump target address, the instruction position required to be rewritten is stored and sent to the byte code injector, and the original jump target address is sent to the re-analyzer of the jump target;
the bytecode injector generates an insertion instruction according to an obfuscation method, inserts the insertion instruction at a corresponding position of the instruction sequence to form a new instruction sequence and sends the new instruction sequence to the skip target re-analyzer; since the size of the original bytecode is changed, the original jump address does not correspond to the correct jump target any more, and therefore a new instruction sequence needs to be sent to the jump target re-parser to correct the misplaced jump addresses.
A jump target re-resolver for correcting the jump address of the new instruction sequence to make it correspond to the correct jump target;
and the instruction/byte code converter is used for converting the corrected instruction sequence into byte codes, namely the confused byte codes, and outputting the byte codes.
As shown in fig. 2, the contract code obfuscation method based on the intelligent contract bytecode feature of the present invention specifically includes the following steps:
s1: the contract developer generates original byte codes through an intelligent contract compiler;
s2: inputting the original byte code into a contract code obfuscation platform, and selecting an obfuscation method expected to be used;
s3: the contract code obfuscation platform converts the original byte code into an instruction sequence, extracts an instruction position to be rewritten and an original jump target address according to the obfuscation method, then generates an insertion instruction and inserts the insertion instruction into a corresponding position of the instruction sequence, then corrects the jump address of the instruction sequence to enable the jump address to correspond to a correct jump address, and finally converts the corrected instruction sequence into the byte code, namely the obfuscated byte code, and outputs the byte code. The specific process is as follows:
s3.1: linearly scanning the original byte codes, and identifying a contract initialization code segment and a Swarm hash segment through a default contract initialization code segment and a Swarm hash start-end feature code given by a contract compiler in the process;
s3.2: decompiling the original byte codes into instructions and immediate data of the Etheng virtual machine, and creating a contract copy by using the information;
s3.3: by maintaining a simulation stack, the contract code obfuscating platform executes contract codes step by step, traverses all branches which can be reached, identifies a function selector section, a contract function section and a data section of a contract during the process, and marks a jump instruction in a contract copy and a value used by the jump instruction;
s3.4: generating and inserting an instruction sequence corresponding to the confusion method according to the marked instruction;
s3.5: and correcting the jump address misplaced in the instruction to finish the confusion.
Specifically, there are six obfuscation methods used herein:
(1) by adding a PUSH instruction, the tool finds two contract initiation code start features that are misidentified when linearly scanning the bytecode, resulting in the tool identifying the wrong contract body code.
(2) By rewriting byte codes in the Swarm Hash segment and rewriting instructions near jump instructions in the contract, all the jump instructions in the original contract jump to respective target addresses through the Swarm Hash segment, and the control flow graph of the contract is flattened.
(3) The signature sequence of the break function selector prevents the contract analysis tool from acquiring the function signature stored in the contract.
(4) By inserting a large number of JUMPDEST instructions, an analysis tool that uses symbolic and analog execution is forced to maintain a large number of basic block entry states, thereby slowing or even crashing the tool.
(5) By changing the immediate for jumping into a series of immediate operation results, the default jump target address must be the immediate, so that the tool cannot resolve the jump address in the contract.
(6) By putting the target address for jumping into the memory and retrieving the target address by calling the precompiled contract, the static analysis tool mistakenly considers that a contract on a chain is called (namely dynamic information under an intelligent contract scene, the static analysis tool considers that the information is not known), and the information of the target address for jumping is lost.
It will be understood by those skilled in the art that the foregoing is only a preferred embodiment of the present invention, and is not intended to limit the invention, and although the invention has been described in detail with reference to the foregoing examples, it will be apparent to those skilled in the art that various changes in the form and details of the embodiments may be made and equivalents may be substituted for elements thereof. All modifications, equivalents and the like which come within the spirit and principle of the invention are intended to be included within the scope of the invention.

Claims (4)

1. A contract code obfuscation platform based on intelligent contract bytecode features, the platform comprising:
a bytecode/instruction converter for receiving original bytecode and converting said original bytecode into an instruction sequence according to a target obfuscation method to represent an executable segment;
the information extractor is used for extracting and injecting the information required by the re-analysis of the instruction sequence and the jump target according to an obfuscation method, wherein the information comprises an instruction position required to be rewritten and an original jump target address, the instruction position required to be rewritten is stored and sent to the byte code injector, and the original jump target address is sent to the re-analyzer of the jump target;
the bytecode injector generates an insertion instruction according to an obfuscation method, inserts the insertion instruction at a corresponding position of the instruction sequence to form a new instruction sequence and sends the new instruction sequence to the skip target re-analyzer;
a jump target re-resolver for correcting the jump address of the new instruction sequence to make it correspond to the correct jump target;
and the instruction/byte code converter is used for converting the corrected instruction sequence into byte codes, namely the confused byte codes, and outputting the byte codes.
2. A contract code obfuscation method based on intelligent contract bytecode features is characterized by comprising the following steps:
s1: the contract developer generates original byte codes through an intelligent contract compiler;
s2: inputting said raw bytecode into said contract code obfuscation platform of claim 1 and selecting an obfuscation method desired to be used;
s3: the contract code obfuscation platform converts the original byte code into an instruction sequence, extracts an instruction position to be rewritten and an original jump target address according to the obfuscation method, then generates an insertion instruction and inserts the insertion instruction into a corresponding position of the instruction sequence, then corrects the jump address of the instruction sequence to enable the jump address to correspond to a correct jump address, and finally converts the corrected instruction sequence into the byte code, namely the obfuscated byte code, and outputs the byte code.
3. A contract code obfuscation method based on intelligent contract bytecode features according to claim 2, wherein the S3 specifically includes the following sub-steps:
s3.1: linearly scanning the original byte codes, and identifying a contract initialization code segment and a Swarm hash segment through a default contract initialization code segment and a Swarm hash start-end feature code given by a contract compiler in the process;
s3.2: decompiling the original byte codes into instructions and immediate data of the Etheng virtual machine, and creating a contract copy by using the information;
s3.3: by maintaining a simulation stack, the contract code obfuscating platform executes contract codes step by step, traverses all branches which can be reached, identifies a function selector section, a contract function section and a data section of a contract during the process, and marks a jump instruction in a contract copy and a value used by the jump instruction;
s3.4: generating and inserting an instruction sequence corresponding to the confusion method according to the marked instruction;
s3.5: and correcting the jump address misplaced in the instruction to finish the confusion.
4. A contract code obfuscation method based on intelligent contract bytecode features according to claim 2, wherein the obfuscation method selects any one of the following methods:
(1) by adding a PUSH instruction, the tool finds two contract initialization code starting characteristics which are recognized by mistake when the byte codes are scanned linearly, so that the tool recognizes wrong contract main body codes;
(2) by rewriting byte codes in the Swarm Hash segment and rewriting instructions near jump instructions in the contract, all the jump instructions in the original contract jump to respective target addresses through the Swarm Hash segment, and a control flow graph of the contract is flattened;
(3) preventing a contract analysis tool from acquiring a function signature stored in a contract through a feature sequence of the interrupt function selector;
(4) by inserting a large number of JUMPDEST instructions, an analysis tool using symbolic execution and simulation execution is forced to maintain a large number of basic block entry states, and further the tool runs slowly or even crashes;
(5) by changing the immediate for jumping into a series of immediate operation results, the default jumping target address is not able to analyze the jumping address in the contract;
(6) the target address used for jumping is put into a memory and retrieved by calling a precompiled contract, so that the static analysis tool mistakenly calls a contract on a chain, and the information of the target address of jumping is lost.
CN202010489637.7A 2020-06-02 2020-06-02 Contract code obfuscation platform and method based on intelligent contract byte code characteristics Pending CN111680271A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010489637.7A CN111680271A (en) 2020-06-02 2020-06-02 Contract code obfuscation platform and method based on intelligent contract byte code characteristics
PCT/CN2021/074634 WO2021244054A1 (en) 2020-06-02 2021-02-01 Contract code obfuscation platform and obfuscation method based on smart contract bytecode features

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010489637.7A CN111680271A (en) 2020-06-02 2020-06-02 Contract code obfuscation platform and method based on intelligent contract byte code characteristics

Publications (1)

Publication Number Publication Date
CN111680271A true CN111680271A (en) 2020-09-18

Family

ID=72453031

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010489637.7A Pending CN111680271A (en) 2020-06-02 2020-06-02 Contract code obfuscation platform and method based on intelligent contract byte code characteristics

Country Status (2)

Country Link
CN (1) CN111680271A (en)
WO (1) WO2021244054A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113190850A (en) * 2021-05-24 2021-07-30 电子科技大学 Method for realizing intelligent contract short address attack detection tool
WO2021244054A1 (en) * 2020-06-02 2021-12-09 浙江大学 Contract code obfuscation platform and obfuscation method based on smart contract bytecode features

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114357389B (en) * 2021-12-31 2024-04-16 北京大学 LLVM (logical Low level virtual machine) -based instruction flower adding confusion method and device
CN115718922B (en) * 2022-11-28 2023-05-26 暨南大学 High-availability intelligent contract byte code rewriting method, medium and device

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853357A (en) * 2010-04-28 2010-10-06 北京飞天诚信科技有限公司 Software protection method
CN101986326A (en) * 2010-12-01 2011-03-16 浙江核新同花顺网络信息股份有限公司 Method and device for protecting software security
CN103544414A (en) * 2013-10-25 2014-01-29 苏州通付盾信息技术有限公司 Deep code obfuscation method for Android system applications
CN104573427A (en) * 2015-01-06 2015-04-29 北京邮电大学 Confusing method and device of executable application
EP3062256A1 (en) * 2015-02-26 2016-08-31 Nxp B.V. Flexible instructions sets for obfuscated virtual machines
CN107103213A (en) * 2017-03-23 2017-08-29 中国航天系统科学与工程研究院 A kind of software code based on genetic algorithm obscures operation system of selection
CN110175454A (en) * 2019-04-19 2019-08-27 肖银皓 A kind of intelligent contract safety loophole mining method and system based on artificial intelligence

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9164754B1 (en) * 2013-12-18 2015-10-20 Amazon Technologies, Inc. Runtime patching of native-code programs
CN111680271A (en) * 2020-06-02 2020-09-18 浙江大学 Contract code obfuscation platform and method based on intelligent contract byte code characteristics

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853357A (en) * 2010-04-28 2010-10-06 北京飞天诚信科技有限公司 Software protection method
CN101986326A (en) * 2010-12-01 2011-03-16 浙江核新同花顺网络信息股份有限公司 Method and device for protecting software security
CN103544414A (en) * 2013-10-25 2014-01-29 苏州通付盾信息技术有限公司 Deep code obfuscation method for Android system applications
CN104573427A (en) * 2015-01-06 2015-04-29 北京邮电大学 Confusing method and device of executable application
EP3062256A1 (en) * 2015-02-26 2016-08-31 Nxp B.V. Flexible instructions sets for obfuscated virtual machines
CN107103213A (en) * 2017-03-23 2017-08-29 中国航天系统科学与工程研究院 A kind of software code based on genetic algorithm obscures operation system of selection
CN110175454A (en) * 2019-04-19 2019-08-27 肖银皓 A kind of intelligent contract safety loophole mining method and system based on artificial intelligence

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021244054A1 (en) * 2020-06-02 2021-12-09 浙江大学 Contract code obfuscation platform and obfuscation method based on smart contract bytecode features
CN113190850A (en) * 2021-05-24 2021-07-30 电子科技大学 Method for realizing intelligent contract short address attack detection tool
CN113190850B (en) * 2021-05-24 2022-10-11 电子科技大学 Method for realizing intelligent contract short address attack detection tool

Also Published As

Publication number Publication date
WO2021244054A1 (en) 2021-12-09

Similar Documents

Publication Publication Date Title
CN111680271A (en) Contract code obfuscation platform and method based on intelligent contract byte code characteristics
CN110069905B (en) Device and method for encrypting and decrypting Springboot program
CN108932406B (en) Virtualization software protection method and device
JP5808019B2 (en) Interlocked binary protection using white-box encryption technology
EP2332090B1 (en) Method and device for code obfuscation
JP5785762B2 (en) Method, apparatus and computer program carrier for checksum verification of self-correcting computer code
CN110096853B (en) Unity android application reinforcement method based on Mono and storage medium
EP2897074A1 (en) Application code obfuscation device based on self-conversion and method therefor
CN108363911B (en) Python script obfuscating and watermarking method and device
KR101861341B1 (en) Deobfuscation apparatus of application code and method of deobfuscating application code using the same
US20120221864A1 (en) Method and apparatus for computer code obfuscation and deobfuscation using boot installation
CN1823323A (en) Method and apparatus for performing native binding
JP2017513077A (en) Code obfuscation apparatus and method using identifier conversion that is difficult to distinguish
CN104091100A (en) Software protection method based on intermediate result compiling
CN106682460B (en) It is a kind of based on the Code obfuscation method converted twice
US20110271350A1 (en) method for protecting software
JP2022009556A (en) Method for securing software codes
JP2004511031A (en) Digital data protection configuration
US20200380150A1 (en) Method of encoding and decoding memory data for software security, recording medium and apparatus for performing the method
CN109543368B (en) Cross-platform source code virtualization protection method based on intermediate language interpreter
CN113704706B (en) Code reinforcement method and device
KR101536920B1 (en) Method of Obfuscating Files Based on Advanced RISC Machine Processor
CN108733990B (en) Block chain-based file protection method and terminal equipment
CN109960510B (en) Method for reinforcing Android application dynamic link library and related equipment
CN113626773A (en) Code protection method based on intermediate language

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20200918