BiAn is a source code level code obfuscation tool developed for Solidity smart contracts. We will obfuscate the Solidity smart contract from the following three aspects:
- Layout obfuscation.
- Data flow obfuscation.
- Control flow obfuscation. This aspect will be developed by the project collaborator ZhangMeng.
Enter the following instructions in the terminal (eg., ubuntu os):
git clone https://github.com/xf97/BiAn
cd BiAn/src
python main.py yourContract.sol yourContract.sol's_json.ast
and you're done.
Feature completed:
- Layout obfuscation:
- Delete comments.
- Disrupt the formatting.
- Replace variable's name.
- Data flow obfuscation.
- Convert local variables to state variables. This feature is turned off by default, because changing local variables to state variables in Solidity may cause compile error in the pure or view function. User can manually modify the configuration file to turn up this feature.
- Dynamically generate static data.
- Convert integer literals to arithmetic expressions.
- Split boolean variables.
- Scalar to vector.
The configuration file (Configuration.json) is a json file, and users can turn on or off various features by modifying this file, and can specify the activation probability of each feature (this function is used to balance the degree of confusion and gas growth).
The following features' development has been stopped due to current restrictions. Uncompleted features:
- Data flow obfuscation.
- Collapse and merge arrays.
- Split functions and contracts.
Use BiAn (default configuration) to obfuscate the following contract. Before obfuscation:
The obfuscated contract can still be compiled (no errors or warnings).
BiAn's input: solFile(.sol) and its corresponding jsonAstFile(.json_ast). Users can use the solc compiler to generate the corresponding jsonAst file.
BiAn's output: The contract after code obfuscation(.sol).
Limited by our technical level, the number of currently available tools and test cases, BiAn still has the following limitations:
- BiAn cannot handle the solFile that contains multiple contracts.
- BiAn cannot handle contracts that generate warnings at compile time. We use the local compiler (solc) to compile a contract. If a warning is generated when compiling the contract, the local compiler (solc) does not output the compilation result, which leads to errors in the following obfuscation steps.
- BiAn may run abnormally when it confuses a contract. We welcome users to submit bug issues.
We hope that BiAn can play a role in the following aspects:
- Enhance bug smart contracts.
- Protect the contract source code.
In the Convert Integer Literals to Arithmetic Expressions and Split boolean variables function, I use the code from project Auto-Generate-Expression (contributed by @threeworld et al). Since our requirements do not exactly match the project Auto-Generate-Expression's function, I rewrite some code.
This program is issued, reproduced or used under the permission of MIT. Please indicate the source when using.