This guide will walk you through the process of taking a simple contract that tracks the sum of all numbers passed as arguments to the add function, and converting it into a privacy-enabled version.
Copy and paste the following smart contract into a new file Counter.sol:
The next thing we will want to do is import the MPC Core library, which will help us make calls to the precompiled contracts that allow us to work with private data types.
Now we are ready to integrate private computations into our smart contract!
To do this, we can change the types of _sum and value to their equivalent private data type (utUint64 and itUint64 respectively).
If you would try to compile this smart contract, you will encounter a compilation error. This is because _sum and value are of different types and they do not support the standard Solidity arithmetic operators. Let's update the code so that it uses the appropriate methods provided to us by the MPC Core library.
This code will compile successfully, but if we were to deploy it and then try to call add, we would find that the transaction would be reverted. This is because by default, the storage slot used by the _sum state variable is initialized to zero. This causes an error when we try to onboard it into the gcEVM, since it was not encrypted using the network AES key. Let's fix the issue by setting the value of _sum inside of the constructor.
Lastly, since values that are encrypted with the network AES key are not very useful to dApps and users, we will update the sum function to return only the value encrypted with the user's AES key.