From 77dcc0f97283d64742745546f8bb30dbbffb7350 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:29:13 +0100 Subject: [PATCH 1/5] Update contracts --- contracts/EncryptedERC20.sol | 2 +- hardhat.config.ts | 4 ++-- package.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/EncryptedERC20.sol b/contracts/EncryptedERC20.sol index c6acd26..1bf0477 100644 --- a/contracts/EncryptedERC20.sol +++ b/contracts/EncryptedERC20.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BSD-3-Clause-Clear -pragma solidity 0.8.19; +pragma solidity ^0.8.20; import "fhevm/abstracts/EIP712WithModifier.sol"; diff --git a/hardhat.config.ts b/hardhat.config.ts index b9392fa..b23acd3 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -20,7 +20,7 @@ if (!mnemonic) { } const chainIds = { - local: 9091, + local: 9090, inco: 9090, "arbitrum-mainnet": 42161, avalanche: 43114, @@ -106,7 +106,7 @@ const config: HardhatUserConfig = { tests: "./test", }, solidity: { - version: "0.8.19", + version: "0.8.22", settings: { metadata: { // Not including the metadata hash diff --git a/package.json b/package.json index 4f84113..38aa3a3 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "eslint": "^8.28.0", "eslint-config-prettier": "^8.5.0", "ethers": "^6.8.0", - "fhevm": "^0.2.2", - "fhevmjs": "^0.2.2", + "fhevm": "^0.3.0", + "fhevmjs": "^0.3.2", "fs-extra": "^10.1.0", "hardhat": "^2.18.1", "hardhat-deploy": "^0.11.29", From 5882bd9a0f8c157a00641981869186877384ab84 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:50:53 +0100 Subject: [PATCH 2/5] fix instance --- test/generated.ts | 2 ++ test/instance.ts | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test/generated.ts diff --git a/test/generated.ts b/test/generated.ts new file mode 100644 index 0000000..d8508aa --- /dev/null +++ b/test/generated.ts @@ -0,0 +1,2 @@ +export const FHE_LIB_ADDRESS = "0x000000000000000000000000000000000000005d"; +export const OPTIMISTIC_REQUIRES_ENABLED: boolean = true; diff --git a/test/instance.ts b/test/instance.ts index 301b521..97c7308 100644 --- a/test/instance.ts +++ b/test/instance.ts @@ -1,7 +1,8 @@ import { Signer } from "ethers"; import fhevmjs, { FhevmInstance } from "fhevmjs"; +import { ethers as hethers } from "hardhat"; -// import { ethers as hethers } from "hardhat"; +import { FHE_LIB_ADDRESS } from "./generated"; import type { Signers } from "./signers"; import { FhevmInstances } from "./types"; @@ -10,7 +11,7 @@ let chainId: number; export const createInstances = async ( contractAddress: string, - ethers: any, + ethers: typeof hethers, accounts: Signers, ): Promise => { if (!publicKey || !chainId) { @@ -21,9 +22,13 @@ export const createInstances = async ( chainId = +network.chainId.toString(); // Need to be a number // Get blockchain public key - publicKey = await provider.call({ - to: "0x0000000000000000000000000000000000000044", + const ret = await provider.call({ + to: FHE_LIB_ADDRESS, + // first four bytes of keccak256('fhePubKey(bytes1)') + 1 byte for library + data: "0xd9d47bb001", }); + const decoded = ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ret); + publicKey = decoded[0]; } // Create instance @@ -41,15 +46,15 @@ export const createInstances = async ( const generateToken = async (contractAddress: string, signer: Signer, instance: FhevmInstance) => { // Generate token to decrypt - const generatedToken = instance.generateToken({ + const generatedToken = instance.generatePublicKey({ verifyingContract: contractAddress, }); // Sign the public key const signature = await signer.signTypedData( - generatedToken.token.domain, - { Reencrypt: generatedToken.token.types.Reencrypt }, // Need to remove EIP712Domain from types - generatedToken.token.message, + generatedToken.eip712.domain, + { Reencrypt: generatedToken.eip712.types.Reencrypt }, // Need to remove EIP712Domain from types + generatedToken.eip712.message, ); - instance.setTokenSignature(contractAddress, signature); + instance.setSignature(contractAddress, signature); }; From 2a6aa07b6eb38f400eee997307a22fb96052d97b Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:34:02 +0100 Subject: [PATCH 3/5] Use node-tfhe 0.5.1 --- package.json | 4 ++++ pnpm-lock.yaml | 53 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 38aa3a3..4658792 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "hardhat-gas-reporter": "^1.0.9", "lodash": "^4.17.21", "mocha": "^10.1.0", + "node-tfhe": "^0.5.1", "prettier": "^2.8.4", "prettier-plugin-solidity": "^1.1.2", "rimraf": "^4.1.2", @@ -91,5 +92,8 @@ }, "dependencies": { "@openzeppelin/contracts": "^4.9.2" + }, + "resolutions": { + "node-tfhe": "0.5.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 17ef9a4..1c05e77 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + node-tfhe: 0.5.1 + dependencies: '@openzeppelin/contracts': specifier: ^4.9.2 @@ -71,11 +74,11 @@ devDependencies: specifier: ^6.8.0 version: 6.8.0 fhevm: - specifier: ^0.2.2 - version: 0.2.2 + specifier: ^0.3.0 + version: 0.3.0(hardhat@2.18.1) fhevmjs: - specifier: ^0.2.2 - version: 0.2.2 + specifier: ^0.3.2 + version: 0.3.2 fs-extra: specifier: ^10.1.0 version: 10.1.0 @@ -94,6 +97,9 @@ devDependencies: mocha: specifier: ^10.1.0 version: 10.1.0 + node-tfhe: + specifier: 0.5.1 + version: 0.5.1 prettier: specifier: ^2.8.4 version: 2.8.4 @@ -1248,6 +1254,11 @@ packages: /@openzeppelin/contracts@4.9.2: resolution: {integrity: sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==} + dev: false + + /@openzeppelin/contracts@5.0.1: + resolution: {integrity: sha512-yQJaT5HDp9hYOOp4jTYxMsR02gdFZFXhewX5HW9Jo4fsqSVqqyIO/xTHdWDaKX5a3pv1txmf076Lziz+sO7L1w==} + dev: true /@scure/base@1.1.1: resolution: {integrity: sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==} @@ -3140,14 +3151,17 @@ packages: reusify: 1.0.4 dev: true - /fhevm@0.2.2: - resolution: {integrity: sha512-6KUHVimpMrYGarOzfBwFBAUDCMmsfFYIoFWL/rYLUXz6XIJDHEzbCDLPF5HToP4IOppv5tfH6w0314ThfPer5A==} + /fhevm@0.3.0(hardhat@2.18.1): + resolution: {integrity: sha512-+xLuWQ0B0GeO/cPsmEvfW9yUEMIPlYoZ8v26sCjtWHyWzr4WBNHhxbMYxvZiW/hLTJTKCc91hBxGpdQjH4zBWw==} dependencies: - '@openzeppelin/contracts': 4.9.2 + '@openzeppelin/contracts': 5.0.1 + hardhat-preprocessor: 0.1.5(hardhat@2.18.1) + transitivePeerDependencies: + - hardhat dev: true - /fhevmjs@0.2.2: - resolution: {integrity: sha512-FTeJgVNA2cF233WS3gwtOg5aglzwv4SWbM6+ckpVcHjQQoR+i7iOa15uH8C6BgkERciuLC5U8rc//0aBk1ALDg==} + /fhevmjs@0.3.2: + resolution: {integrity: sha512-/6D8uqlU3UYQRxyQJWxr6F6qjwe5pLvqeIZlp3YRilLytiFEoBQT5bwSbXzQ7UtY7VuTr82BfIUpNlSBItD5ww==} hasBin: true dependencies: commander: 11.0.0 @@ -3155,9 +3169,9 @@ packages: ethers: 6.8.0 libsodium: 0.7.11 libsodium-wrappers: 0.7.11 - node-tfhe: 0.3.1 + node-tfhe: 0.5.1 sha3: 2.1.4 - tfhe: 0.3.1 + tfhe: 0.4.2 transitivePeerDependencies: - bufferutil - utf-8-validate @@ -3665,6 +3679,15 @@ packages: - '@codechecks/client' dev: true + /hardhat-preprocessor@0.1.5(hardhat@2.18.1): + resolution: {integrity: sha512-j8m44mmPxpxAAd0G8fPHRHOas/INZdzptSur0TNJvMEGcFdLDhbHHxBcqZVQ/bmiW42q4gC60AP4CXn9EF018g==} + peerDependencies: + hardhat: ^2.0.5 + dependencies: + hardhat: 2.18.1(ts-node@10.9.1)(typescript@5.1.6) + murmur-128: 0.2.1 + dev: true + /hardhat@2.18.1(ts-node@10.9.1)(typescript@5.1.6): resolution: {integrity: sha512-b55rW7Ka+fvJeg6oWuBTXoYQEUurevCCankjGNTwczwD3GnkhV9GEei7KUT+9IKmWx3lC+zyxlFxeDbg0gUoHw==} hasBin: true @@ -4673,8 +4696,8 @@ packages: resolution: {integrity: sha512-+M0PwXeU80kRohZ3aT4J/OnR+l9/KD2nVLNNoRgFtnf+umQVFdGBAO2N8+nCnEi0xlh/Wk3zOGC+vNNx+uM79Q==} dev: true - /node-tfhe@0.3.1: - resolution: {integrity: sha512-re5tBgPMwoSWl6b/pL13MWKnsBUv9nldAXoWkokG1aiUm9P0aOjJoz0J9+zOwV/dB0i9xN/TI//mnqF3uWAOIg==} + /node-tfhe@0.5.1: + resolution: {integrity: sha512-jSPB9gsEoPL21Q5gNWTxxedJ0YxKDfnb7W3uIcKjEGvsw0QMMV4uD/NsACNltDplQ2cmIsK/z+4jC5LJxfw5kQ==} dev: true /nofilter@3.1.0: @@ -5787,8 +5810,8 @@ packages: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} dev: true - /tfhe@0.3.1: - resolution: {integrity: sha512-PqnsUVChETviwd5ebfJoj9yueUxIKPaSsfSGVmgvpUsUqAlianAx+4UH9hEmjDxgshSRDgm1Fp0/rRgCx2BYog==} + /tfhe@0.4.2: + resolution: {integrity: sha512-mf6LqRcClIJB5D6thrnDR73Zrq82QwFsmRros9RuFLIEm1S836CjrVuXrKq6Nmsm07ekh0peznscxMfshPykwA==} dev: true /then-request@6.0.2: From 625ae38d2f6cf51b49bfcc9f993282960cc90ed9 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:40:47 +0100 Subject: [PATCH 4/5] Fix lint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4658792..7513e6d 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,6 @@ "@openzeppelin/contracts": "^4.9.2" }, "resolutions": { - "node-tfhe": "0.5.1" + "node-tfhe": "0.5.1" } } From d8e429c6ac881a80f83df99b23afa268fffc30f5 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:41:34 +0100 Subject: [PATCH 5/5] compiler version to 0.8.22 --- .prettierrc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierrc.yml b/.prettierrc.yml index 3b6e085..42ad8c5 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -11,7 +11,7 @@ trailingComma: "all" overrides: - files: "*.sol" options: - compiler: "0.8.17" + compiler: "0.8.22" parser: "solidity-parse" tabWidth: 4 - files: "*.ts"