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.