Reencryption Issue

Hi,

I have an issue with reencryption.
I’m getting no response from the gateway after calling the reencrypt function (the promise stays pending forever).
The reencrypt feature is also not doing anything in the remix plugin (maybe same issue).
I have followed this guide on zama’s doc : docs.zama.ai/fhevm/guides/reencryption, with the vue.js template from github. (Sorry I still cannot post links.)
The doc version is 0.5, my contract code is the encrypted ERC20 example from the 0.5 release on github, everything works except the reencryption.

Here is a sample of my code :

onMounted(async () => {
    await fake_deployment();
    fhevmInstance = await createInstance({
    chainId : 9000,
    networkUrl : "https://devnet.zama.ai",
    gatewayUrl : "https://gateway.devnet.zama.ai"
  });
});

const reencryption = async (encrypted_value) => {
  const CONTRACT_ADDRESS = "0x21D3Ba01c914Af4f79a82fcfA0c84c2Fe3Fc4f92"; //contract_address.value
  const USER_ADDRESS = "0x00000f04950eddbea6c0b007debce7210fa4ff6a"; //account.value
  console.log("Reencrypting", encrypted_value);
  const {publicKey, privateKey } = fhevmInstance.generateKeypair();
  const eip721 = fhevmInstance.createEIP712(publicKey, CONTRACT_ADDRESS);
  const params = [USER_ADDRESS, JSON.stringify(eip721)];
  const signature = await window.ethereum.request({method: "eth_signTypedData_v4", params});
  console.log("Waiting for gateway.");
  console.log("contract address", CONTRACT_ADDRESS);
  console.log("user address", USER_ADDRESS);
  const decrypted_value = await fhevmInstance.reencrypt(encrypted_value, privateKey, publicKey, signature, CONTRACT_ADDRESS, USER_ADDRESS);
  console.log("Got gateway answer.", decrypted_value);
  return decrypted_value;
}; 

const call_contract_balanceof = async (inputValues: string[]) => {
  var target_address = inputValues[0];
  var result = await contract_instance.balanceOf(target_address);
  try {
    console.log("Awaiting reencryption.");
    var decrypted_result = await reencryption(result);
    console.log("decrypted output", decrypted_result);
    alert(decrypted_result);
  } catch (error){
    console.log("Error in reencryption :", error);
  }
};

call_contract_balanceof is called from a button after filling an input, so way after page loading.
Please note that USER_ADDRESS in the reencryption function is the same as target_address in call_contract_balanceof, CONTRACT_ADDRESS is also the same contract address stored in contract_instance.

In the documentation guide there is no “await” before the reencrypt function call, I have tried with and without, the result is the same, a pending promise.

Gateway_url in the guide seems outdated, same for chainId (in the fhevm instance creation), because I’m having an ID error (not matching with the chain) and a connection error to the gateway when I’m using the doc’s values.

Console output is looking like this :

Awaiting reencryption.
Reencrypting 48092937317521256430156378574340627610188571836993001509511764851372766594304n
Waiting for gateway.
contract address 0x21D3Ba01c914Af4f79a82fcfA0c84c2Fe3Fc4f92
user address 0x00000f04950eddbea6c0b007debce7210fa4ff6a

And it stays like that forever.

Thanks for reading.

Quick update,
It seems that the problem does indeed come from Zama’s Gateway because the exact same code works well on Inco Network.

1 Like

Hei @6yp, checked your code and there doesn’t seem to be any issues. The createInstance looks okay and there probably is some issue with our Gateway.
Checked it myself as well via the Remix plugin and it looks like that it is able to establish a connection, however it doesn’t seem to give a response once you submit a re-encrypt. Thanks for bringing this issue up, we’ll try to fix it asap :slight_smile:

Thank you ! Please keep me informed.

Alright should be working now, give a check :slight_smile:

Just checked, works well both on and off-chain.
Thanks !