I have created a contract in truffle suite and deployed it successfully. I have used the TFHE library of fhevm by Zama. I have taken an encrypted variable and unencrypted variable and made a function for performing addition. Here is the contract:
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.0;
import "../fhevm/lib/TFHE.sol";
contract AddValue {
function add(euint32 a, uint32 b) public view returns (euint32) {
return TFHE.add(a, b);
}
}
This contract is placed in contracts folder which gets generated after running the command truffle init
After deployment and instantiating when i am trying to call the add() function and pass the parameters then it is showing an error:
Uncaught Error: VM Exception while processing transaction: revert
at evalmachine.<anonymous>:1:20
at evalmachine.<anonymous>:2:48
at sigintHandlersWrap (node:vm:258:12)
at Script.runInContext (node:vm:131:14)
at runScript (C:\Users\Ronita Adhikari\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:505:1)
at Console.interpret (C:\Users\Ronita Adhikari\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:520:1)
at bound (node:domain:432:15)
at REPLServer.runBound [as eval] (node:domain:443:12)
at REPLServer.onLine (node:repl:929:10)
at REPLServer.emit (node:events:514:28)
at REPLServer.emit (node:domain:488:12)
at REPLServer.[_onLine] [as _onLine] (node:internal/readline/interface:416:12)
at REPLServer.[_line] [as _line] (node:internal/readline/interface:887:18)
at REPLServer.[_ttyWrite] [as _ttyWrite] (node:internal/readline/interface:1265:22)
at REPLServer.self._ttyWrite (node:repl:1024:9)
at ReadStream.onkeypress (node:internal/readline/interface:264:20)
at ReadStream.emit (node:events:514:28)
at ReadStream.emit (node:domain:488:12)
at emitKeys (node:internal/readline/utils:371:14)
at emitKeys.next (<anonymous>) {
code: -32000,
data: '0x',
hijackedStack: 'Error: VM Exception while processing transaction: revert\n' +
' at C:\\Users\\Ronita Adhikari\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:25:1\n' +
' at C:\\Users\\Ronita Adhikari\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:166:1\n' +
' at C:\\Users\\Ronita Adhikari\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-providers-http\\lib\\index.js:127:1\n' +
' at processTicksAndRejections (node:internal/process/task_queues:95:5)'
} ```
Please point out the problem and probably recommend me a solution. All I want to do is take one encrypted value and the other unencrypted and return the sum in encrypted format.
Solidity contracts using the fhEVM library (TFHE.sol) needs to run on a fhEVM, an EVM with the possibility to compute on ciphertext. So you can't use ganache or hardhat network, you need to run everything on a "real" fhEVM. To do that, you can use the docker image and configure truffle to use
localhost:Otherwise, the recommend way to develop contracts on fhEVM is to use the hardhat template because you also have a mocked version of
TFHE.soland everything is ready to use. https://docs.zama.ai/fhevm/how-to/write_contract/hardhat