Skip to content

Commit c265a99

Browse files
committed
only one my confidential erc20
1 parent 86d7a20 commit c265a99

File tree

6 files changed

+12
-94
lines changed

6 files changed

+12
-94
lines changed

hardhat/contracts/MyConfidentialERC20.sol

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,17 @@ pragma solidity ^0.8.24;
44

55
import "fhevm/lib/TFHE.sol";
66
import "fhevm/config/ZamaFHEVMConfig.sol";
7-
import "fhevm/config/ZamaGatewayConfig.sol";
8-
import "fhevm/gateway/GatewayCaller.sol";
9-
import "fhevm-contracts/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol";
7+
import "fhevm-contracts/contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol";
108

119
/// @notice This contract implements an encrypted ERC20-like token with confidential balances using Zama's FHE library.
1210
/// @dev It supports typical ERC20 functionality such as transferring tokens, minting, and setting allowances,
1311
/// @dev but uses encrypted data types.
14-
contract MyConfidentialERC20 is
15-
SepoliaZamaFHEVMConfig,
16-
SepoliaZamaGatewayConfig,
17-
GatewayCaller,
18-
ConfidentialERC20Mintable
19-
{
20-
// @note `SECRET` is not so secret, since it is trivially encrypted and just to have a decryption test
21-
euint64 internal immutable SECRET;
22-
23-
// @note `revealedSecret` will hold the decrypted result once the Gateway will relay the decryption of `SECRET`
24-
uint64 public revealedSecret;
25-
12+
contract MyConfidentialERC20 is SepoliaZamaFHEVMConfig, ConfidentialERC20WithErrorsMintable {
2613
/// @notice Constructor to initialize the token's name and symbol, and set up the owner
2714
/// @param name_ The name of the token
2815
/// @param symbol_ The symbol of the token
29-
constructor(string memory name_, string memory symbol_) ConfidentialERC20Mintable(name_, symbol_, msg.sender) {
30-
SECRET = TFHE.asEuint64(42);
31-
TFHE.allowThis(SECRET);
32-
}
33-
34-
/// @notice Request decryption of `SECRET`
35-
function requestSecret() public {
36-
uint256[] memory cts = new uint256[](1);
37-
cts[0] = Gateway.toUint256(SECRET);
38-
Gateway.requestDecryption(cts, this.callbackSecret.selector, 0, block.timestamp + 100, false);
39-
}
40-
41-
/// @notice Callback function for `SECRET` decryption
42-
/// @param `decryptedValue` The decrypted 64-bit unsigned integer
43-
function callbackSecret(uint256, uint64 decryptedValue) public onlyGateway {
44-
revealedSecret = decryptedValue;
45-
}
16+
constructor(
17+
string memory name_,
18+
string memory symbol_
19+
) ConfidentialERC20WithErrorsMintable(name_, symbol_, msg.sender) {}
4620
}

hardhat/contracts/auctions/MyConfidentialERC20.sol

Lines changed: 0 additions & 46 deletions
This file was deleted.

hardhat/contracts/confidentialCounter/sample4.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ contract EncryptedCounter4 is SepoliaZamaFHEVMConfig {
1414
mapping(address => euint8) private counters;
1515

1616
function incrementBy(einput amount, bytes calldata inputProof) public {
17-
// Initialize counter if it doesn't exist
18-
counters[msg.sender] = TFHE.asEuint8(0);
19-
2017
// Convert input to euint8 and add to sender's counter
2118
euint8 incrementAmount = TFHE.asEuint8(amount, inputProof);
2219
counters[msg.sender] = TFHE.add(counters[msg.sender], incrementAmount);
23-
TFHE.allowThis(counters[msg.sender]);
20+
TFHE.allow(counters[msg.sender], address(this));
2421
TFHE.allow(counters[msg.sender], msg.sender);
2522
}
2623

hardhat/test/blindAuction/ConfidentialERC20.fixture.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ethers } from "hardhat";
22

3-
import type { BlindAuctionConfidentialERC20 } from "../../types";
3+
import type { MyConfidentialERC20 } from "../../types";
44
import { getSigners } from "../signers";
55

6-
export async function deployConfidentialERC20Fixture(): Promise<BlindAuctionConfidentialERC20> {
6+
export async function deployConfidentialERC20Fixture(): Promise<MyConfidentialERC20> {
77
const signers = await getSigners();
88

9-
const contractFactory = await ethers.getContractFactory("BlindAuctionConfidentialERC20");
9+
const contractFactory = await ethers.getContractFactory("MyConfidentialERC20");
1010
const contract = await contractFactory.connect(signers.alice).deploy("Naraggara", "NARA"); // City of Zama's battle
1111
await contract.waitForDeployment();
1212

hardhat/test/confidentialERC20/ConfidentialERC20.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from "chai";
22
import { network } from "hardhat";
33

4-
import { awaitAllDecryptionResults, initGateway } from "../asyncDecrypt";
4+
import { initGateway } from "../asyncDecrypt";
55
import { createInstance } from "../instance";
66
import { reencryptEuint64 } from "../reencrypt";
77
import { getSigners, initSigners } from "../signers";
@@ -180,14 +180,6 @@ describe("ConfidentialERC20", function () {
180180
expect(balanceBob2).to.equal(1337); // check that transfer did happen this time
181181
});
182182

183-
it("should decrypt the SECRET value", async function () {
184-
const tx2 = await this.erc20.requestSecret();
185-
await tx2.wait();
186-
await awaitAllDecryptionResults();
187-
const y = await this.erc20.revealedSecret();
188-
expect(y).to.equal(42n);
189-
});
190-
191183
it("DEBUG - using debug.decrypt64 for debugging transfer", async function () {
192184
if (network.name === "hardhat") {
193185
// using the debug.decryptXX functions is possible only in mocked mode

hardhat/test/fheWordle/FHEwordle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe("FHEwordle contract via proxy via FHEwordleFactory", function () {
122122
before(async function () {
123123
await initSigners();
124124
this.signers = await getSigners();
125+
await initGateway();
125126
});
126127

127128
beforeEach(async function () {

0 commit comments

Comments
 (0)