我已经在truffle suite中创建了一个合约并成功部署它。我使用了 Zama 的 fhevm 的 TFHE 库。我采用了加密变量和未加密变量,并制作了一个用于执行加法的函数。这是合同:
// 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);
}
}
此合约放置在运行命令后生成的contracts文件夹中
truffle init
部署并实例化后,当我尝试调用 add() 函数并传递参数时,它显示错误:
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.
使用 fhEVM 库 (TFHE.sol) 的 Solidity 合约需要在 fhEVM 上运行,fhEVM 是一个能够在密文上进行计算的 EVM。 因此,您不能使用 ganache 或 Hardhat 网络,您需要在“真正的”fhEVM 上运行所有内容。为此,您可以使用 docker 映像并配置 truffle 以使用
localhost
:
docker run -i -p 8545:8545 -p 8546:8546 --rm --name fhevm ghcr.io/zama-ai/ethermint-dev-node:v0.2.4
否则,在 fhEVM 上开发合约的推荐方法是使用安全帽模板,因为您还有
TFHE.sol
的模拟版本,并且一切都可以使用。 https://docs.zama.ai/fhevm/how-to/write_contract/hardhat