Skip to content

Commit

Permalink
Merge pull request #2 from Inco-fhevm/am/new-solidity
Browse files Browse the repository at this point in the history
chore: Update deps (fhevmjs, solidity contracts)
  • Loading branch information
lovenoble authored Feb 9, 2024
2 parents 44e3629 + d8e429c commit 0a82102
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion contracts/EncryptedERC20.sol
Original file line number Diff line number Diff line change
@@ -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";

Check warning on line 5 in contracts/EncryptedERC20.sol

View workflow job for this annotation

GitHub Actions / ci

global import of path fhevm/abstracts/EIP712WithModifier.sol is not allowed. Specify names to import individually

Expand Down
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (!mnemonic) {
}

const chainIds = {
local: 9091,
local: 9090,
inco: 9090,
"arbitrum-mainnet": 42161,
avalanche: 43114,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
"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",
"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",
Expand Down Expand Up @@ -91,5 +92,8 @@
},
"dependencies": {
"@openzeppelin/contracts": "^4.9.2"
},
"resolutions": {
"node-tfhe": "0.5.1"
}
}
53 changes: 38 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/generated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FHE_LIB_ADDRESS = "0x000000000000000000000000000000000000005d";
export const OPTIMISTIC_REQUIRES_ENABLED: boolean = true;
23 changes: 14 additions & 9 deletions test/instance.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -10,7 +11,7 @@ let chainId: number;

export const createInstances = async (
contractAddress: string,
ethers: any,
ethers: typeof hethers,
accounts: Signers,
): Promise<FhevmInstances> => {
if (!publicKey || !chainId) {
Expand All @@ -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
Expand All @@ -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);
};

0 comments on commit 0a82102

Please sign in to comment.