Unable to compile the Confidential ERC20 contract

I am trying to compile the contract from confidential-erc-20-tokens-using-homomorphic-encryption blog post , but it seems like i am missing onlySignedPublicKey identifier.
This is the error i am getting

Error: Compiler run failed:
Error (7920): Identifier not found or not unique.
  --> src/ERC20.sol:42:81:
   |
42 |     function balanceOf(bytes32 publicKey, bytes calldata signature) public view onlySignedPublicKey(publicKey, signature) returns (bytes memory) {

It seems you’re not using an up-to-date ERC20. Updated examples for fhEVM 0.5.0 are available here: fhevm/examples at release/0.5.x · zama-ai/fhevm · GitHub

1 Like

Yes i realised that just now, The blog post is not updated. I tried using the EncryptedERC20.sol from examples in the solidity library. But when i try to call the mint function

    function mint(uint64 mintedAmount) public virtual onlyOwner {
        balances[owner()] = TFHE.add(balances[owner()], mintedAmount); // overflow impossible because of next line
        TFHE.allowThis(balances[owner()]);
        TFHE.allow(balances[owner()], owner());
        _totalSupply = _totalSupply + mintedAmount;
        emit Mint(owner(), mintedAmount);
    }

and try to mint it using

 cast send $CONTRACT_ADDRESS \
"mint(uint64)" 1000 \
--private-key $PRIVATE_KEY \
--rpc-url $RPC_URL

the txn is being reverted. Its not a ownership problem since i checked the values later on after i deployed the contract on my FHEVM rollup.

Where do you test that? Locally? On a devnet.zama.ai?
If you want to write contract, I suggest you try the fhevm-hardhat-template or simply use our remix plugin with the devnet running fhEVM 0.5.0.

Actually I have a fhevm sovereign rollup that uses the zbc -geth implementation of zama , that is building blocks. I want to test the confidential erc20 sc .

What is the revert reason? It could be multiple things, but here a checklist:

1/ Did you deploy TFHEExecutor, ACL, KMSVerifier, … contracts? Did you deploy them with the default wallet? Addresses should be:
ACL: 0x2Fb4341027eb1d2aD8B5D9708187df8633cAFA92
TFHEExecutor: 0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c
KMSVerifier: 0x12B064FB845C1cc05e9493856a1D637a73e944bE
(these addresses are in config file here fhevm/lib at release/0.5.x · zama-ai/fhevm · GitHub)
Note that keeping these addresses are import in fhEVM 0.5.x because these addresses are static in the fhEVM library. It won’t be the case in fhEVM 0.6.x with the possibility to choose these addresses for developer.

To get these exact addresses, you need to deploy these contracts with nonce 0 and the default wallet set in the .env fhevm/.env.example at main · zama-ai/fhevm · GitHub
The script to deploy contracts in correct order is here fhevm/setup-local-fhevm.sh at release/0.5.x · zama-ai/fhevm · GitHub

2/ Can you get the public key from your node? If you don’t manage to do it, it’s probably because your precompiles doesn’t work.

First check these two items.

So just doing export TFHE_EXECUTOR_CONTRACT_ADDRESS=0x596E6682c72946AF006B27C131793F2b62527A4b and the rest of the contracts while building zbc-go-ethereum wont work?
We need to deploy those contracts seperately even if we use zbc-go-ethereum ?

Yes you need to deploy these contracts. These contracts are standard smart contract and not precompiled contract embedded in the EVM.

1 Like

I deployed the contracts ser using the local param (also i need ed to change the local network chainid to 80087)
in the terminal i am getting the right deployment address too

ACL was deployed at address: 0x2Fb4341027eb1d2aD8B5D9708187df8633cAFA92
TFHEExecutor was deployed at address: 0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c
KMSVerifier was deployed at address: 0x12B064FB845C1cc05e9493856a1D637a73e944bE

But still i am getting the revert error when i am trying to call the mint function in the constructor
Also how do i get the public key of my zbc-geth client if i am running it on docker?