2

I am trying to create an 'obfuscator' for Ethereum smart contracts, it can either obfuscate solidity code or the 'bytecode'.

  • Is there any encryption techniques which can help in protecting 'sensitive information' to prevent decompiler like Etherscan? It's basically to not show the flow of the program and the name of the functions to the rest.
1
  • Don't use blockchains is you do not want to public your source code and data. There is nothing you can do about it. Commented Dec 3, 2022 at 9:18

3 Answers 3

3

We must remember that we are working on a "public and open" blockchain , this means that all data is accessible in some way. Therefore, we cannot restrict read access to a Smart Contract state variable, just as we cannot hide the balance of a wallet.

  • With Web3js library we can call the method “getStorageAt(addressContratct, index)” to subtract the values ​​of the variables, maybe that is you are looking for.

But there is no security mechanism in Solidity that allows us to obfuscate or absolutely block the reading of any data (state variables) of a 'Smart Contract'.

It is used to create an interface that determines the most 'optimal' and secure way to interact with a smart contract, either through an external property account or another contract. It applies to both state variables and functions. But remember that the 'nodes' are open source and manipulable, just like their replicas of the Blockchain.

Setter (write) type functions can be controlled/blocked through the visibility conditions and the global variables of the transaction, for example:

require(msg.sender == owner);

Since the well-intentioned 'nodes' will not save the changes in the state of the contract, and therefore in the new mined block and its version of the Blockchain. In the EVM (Ethereum virtual machines) of these 'nodes', the contracts will strictly comply with the visibility filters or requires that the developer implements for each method.

If you are a malicious node you can manipulate your version of the Blockchain but the Consensus Algorithm will rule you out when mining new blocks. You will literally be a branch of the blockchain that nobody will take into account, unless you have at least 51% of the network.

Visibility Types:

  • Public: Fully accessible, whatever the origin.

  • External: Accessible from an external property account and through a message (call from another contract). It is not accessible from a function of the same contract or one derived from it.

  • Internal: Accessible only through another function included in the same contract, or from a function of a contract that derives from it. It is NOT accessible from an external contract message or external transaction.

  • Private: Accessible only through a function included in the same contract, between "public" and "external" in many cases it is preferable to use "external", if the business logic allows it. Since this visibility modifier consumes less gas.

Default visibility

Contract state variables (general scope is 'internal') and functions are (public).

NOTE: If we declare a state variable as "public", when we compile the Smart Contract, a getter type method with the same name as the variable will automatically be generated. No need to be declared in the source code.

1

So, two approaches: obfuscation and encryption of data.

Obfuscation

Firstly, you can just skip verifying your contract and then nobody can get the source code. In that case you can only get the bytecode from Etherscan.

So, Etherscan is not a decompiler. It only shows the source code if someone uploads it there.

In theory someone can reverse engineer the bytecode, but that will already result in very obfuscated code. No tool can create "non-obfuscated" source code from bytecode.

If, for some weird reason, you still want to obfuscate the source code itself, you can basically just replace variables and functions with dummy names (except those required by standards). I'm not aware of any tool which does that for Solidity.

Encryption

You can only encrypt data which is not used by the blockchain. So for example person's first name. Encrypt before sending to the contract and decrypt when reading from the contract (off-chain).

Ethereum really isn't meant for private data, since everything is public.

1
  • Yes, that's it, overall your last phrase @Lauri Peltonen Commented Nov 7, 2022 at 2:10
0

You can try BiAn tool. BiAn is a source code level code obfuscation tool developed for Solidity smart contracts. See it here. I've been working with it for a short time, however its not easy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.