Skip to content

Commit

Permalink
can deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
poppyseedDev committed Dec 6, 2024
1 parent a88b03a commit e0cd93f
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 632 deletions.
12 changes: 8 additions & 4 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ network instance. To run the tests in mocked mode, you can use directly the foll
pnpm test
```

You can still use all the usual specific [hardhat network methods](https://hardhat.org/hardhat-network/docs/reference#hardhat-network-methods), such as `evm_snapshot`, `evm_mine`, `evm_increaseTime`, etc, which are very helpful in a testing context. Another useful hardhat feature, is the [console.log](https://hardhat.org/hardhat-network/docs/reference#console.log) function which can be used in fhevm smart contracts in mocked mode as well.

To analyze the coverage of the tests (in mocked mode necessarily, as this cannot be done on the real fhEVM node), you
can use this command :

Expand All @@ -153,18 +155,20 @@ Then open the file `coverage/index.html`. You can see there which line or branch
covered or missed by your test suite. This allows increased security by pointing out missing branches not covered yet by
the current tests.

Finally, a new fhevm-specific feature is available in mocked mode: the `debug.decrypt[XX]` functions, which can decrypt directly any encrypted value. Please refer to the [utils.ts](https://github.com/zama-ai/fhevm/blob/main/test/utils.ts#L87-L317) file for the corresponding documentation.

> [!Note]
> Due to intrinsic limitations of the original EVM, the mocked version differs in rare edge cases from the real fhEVM, the main difference is the gas consumption for the FHE operations (native gas is around 5% underestimated in mocked mode). This means that before deploying to production, developers should still run the tests with the original fhEVM node, as a final check - i.e in non-mocked mode (see next section).
> Due to intrinsic limitations of the original EVM, the mocked version differs in rare edge cases from the real fhEVM, the main difference is the gas consumption for the FHE operations (native gas is around 20% underestimated in mocked mode). This means that before deploying to production, developers should still run the tests with the original fhEVM node, as a final check - i.e in non-mocked mode (see next section).
### Non-mocked mode
### Non-mocked mode - Sepolia

To run your test on a real fhevm node, you can use the coprocessor deployed on the Sepolia test network. To do this, ensure you are using a valid value `SEPOLIA_RPC_URL` in your `.env` file. Then you should use the following command:
To run your test on a real fhevm node, you can use the coprocessor deployed on the Sepolia test network. To do this, ensure you are using a valid value `SEPOLIA_RPC_URL` in your `.env` file. You can get free Sepolia RPC URLs by creating an account on services such as [Infura](https://www.infura.io/) or [Alchemy](https://www.alchemy.com/). Then you should use the following command:

```bash
npx hardhat test [PATH_TO_YOUR_TEST] --network sepolia
```

The `--network sepolia` flag will make your test run on a real fhevm coprocessor.
The `--network sepolia` flag will make your test run on a real fhevm coprocessor. Obviously, for the same tests to pass on Sepolia, contrarily to mocked mode, you are not allowed to use any hardhat node specific method, and neither use any of the `debug.decrypt[XX]` functions.

> [!Note]
> For this test to succeed, first ensure you set your own private `MNEMONIC` variable in the `.env` file and then ensure you have funded your test accounts on Sepolia. For example you can use the following command to get the corresponding private keys associated with the first `5` accounts derived from the mnemonic:
Expand Down
212 changes: 0 additions & 212 deletions contracts/contracts/EncryptedERC20.sol

This file was deleted.

17 changes: 17 additions & 0 deletions contracts/contracts/MyConfidentialERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import "fhevm/config/ZamaFHEVMConfig.sol";
import "fhevm-contracts/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol";

/// @notice This contract implements an encrypted ERC20-like token with confidential balances using Zama's FHE library.
/// @dev It supports typical ERC20 functionality such as transferring tokens, minting, and setting allowances,
/// @dev but uses encrypted data types.
contract MyConfidentialERC20 is SepoliaZamaFHEVMConfig, ConfidentialERC20Mintable {
/// @notice Constructor to initialize the token's name and symbol, and set up the owner
/// @param name_ The name of the token
/// @param symbol_ The symbol of the token
constructor(string memory name_, string memory symbol_) ConfidentialERC20Mintable(name_, symbol_, msg.sender) {}
}
27 changes: 27 additions & 0 deletions contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

// Deploy MyConfidentialERC20
const deployedERC20 = await deploy("MyConfidentialERC20", {
from: deployer,
args: ["Naraggara", "NARA"],
log: true,
});
console.log(`MyConfidentialERC20 contract: `, deployedERC20.address);

// Deploy EncryptedCounter4
const deployedCounter = await deploy("EncryptedCounter4", {
from: deployer,
args: [], // No constructor arguments needed
log: true,
});
console.log(`EncryptedCounter4 contract: `, deployedCounter.address);
};

export default func;
func.id = "deploy_confidentialERC20"; // id required to prevent reexecution
func.tags = ["MyConfidentialERC20"];
10 changes: 6 additions & 4 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.8.0",
"extra-bigint": "^1.1.18",
"fhevm": "^0.6.0-8",
"fhevm": "^0.6.0",
"fhevm-core-contracts": "0.6.0-5",
"fhevmjs": "^0.6.0-16",
"fhevmjs": "^0.6.0",
"fs-extra": "^10.1.0",
"globals": "^15.9.0",
"hardhat": "^2.22.8",
Expand Down Expand Up @@ -90,9 +90,11 @@
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"test": "hardhat test --network hardhat",
"coverage": "hardhat coverage"
"coverage": "hardhat coverage",
"deploy-sepolia": "hardhat deploy --network sepolia"
},
"dependencies": {
"bigint-buffer": "^1.1.5"
"bigint-buffer": "^1.1.5",
"fhevm-contracts": "^0.2.0"
}
}
Loading

0 comments on commit e0cd93f

Please sign in to comment.