Skip to content

Commit 89621b5

Browse files
committed
contracts compiling
1 parent b8bcb11 commit 89621b5

16 files changed

+715
-526
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ contracts-exposed
6262
/cache_forge
6363

6464
yarn.lock
65+
fhevmTemp

contracts/interfaces/IConfidentialFungibleToken.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { einput, euint64 } from "fhevm/lib/TFHE.sol";
4+
import { euint64, externalEuint64 } from "@fhevm/solidity/lib/FHE.sol";
55

66
/// @dev Draft interface for a confidential fungible token standard utilizing the Zama TFHE library.
77
interface IConfidentialFungibleToken {
@@ -57,12 +57,12 @@ interface IConfidentialFungibleToken {
5757
*/
5858
function confidentialTransfer(
5959
address to,
60-
einput encryptedAmount,
60+
externalEuint64 encryptedAmount,
6161
bytes calldata inputProof
6262
) external returns (euint64);
6363

6464
/**
65-
* @dev Similar to {confidentialTransfer-address-einput-bytes} but without an input proof. The caller
65+
* @dev Similar to {confidentialTransfer-address-externalEuint64-bytes} but without an input proof. The caller
6666
* *must* already be allowed by ACL for the given `amount`.
6767
*/
6868
function confidentialTransfer(address to, euint64 amount) external returns (euint64 transferred);
@@ -76,26 +76,27 @@ interface IConfidentialFungibleToken {
7676
function confidentialTransferFrom(
7777
address from,
7878
address to,
79-
einput encryptedAmount,
79+
externalEuint64 encryptedAmount,
8080
bytes calldata inputProof
8181
) external returns (euint64);
8282

8383
/**
84-
* @dev Similar to {confidentialTransferFrom-address-address-einput-bytes} but without an input proof. The caller
85-
* *must* be already allowed by ACL for the given `amount`.
84+
* @dev Similar to {confidentialTransferFrom-address-address-externalEuint64-bytes} but without an input proof.
85+
* The caller *must* be already allowed by ACL for the given `amount`.
8686
*/
8787
function confidentialTransferFrom(address from, address to, euint64 amount) external returns (euint64 transferred);
8888

8989
/**
90-
* @dev Similar to {confidentialTransfer-address-einput-bytes} but with a callback to `to` after the transfer.
90+
* @dev Similar to {confidentialTransfer-address-externalEuint64-bytes} but with a callback to `to` after
91+
* the transfer.
9192
*
9293
* The callback is made to the {IConfidentialFungibleTokenReceiver-onConfidentialTransferReceived} function on the
9394
* to address with the actual transferred amount (may differ from the given `encryptedAmount`) and the given
9495
* data `data`.
9596
*/
9697
function confidentialTransferAndCall(
9798
address to,
98-
einput encryptedAmount,
99+
externalEuint64 encryptedAmount,
99100
bytes calldata inputProof,
100101
bytes calldata data
101102
) external returns (euint64 transferred);
@@ -108,13 +109,13 @@ interface IConfidentialFungibleToken {
108109
) external returns (euint64 transferred);
109110

110111
/**
111-
* @dev Similar to {confidentialTransferFrom-address-address-einput-bytes} but with a callback to `to` after
112-
* the transfer.
112+
* @dev Similar to {confidentialTransferFrom-address-address-externalEuint64-bytes} but with a callback to `to`
113+
* after the transfer.
113114
*/
114115
function confidentialTransferFromAndCall(
115116
address from,
116117
address to,
117-
einput encryptedAmount,
118+
externalEuint64 encryptedAmount,
118119
bytes calldata inputProof,
119120
bytes calldata data
120121
) external returns (euint64 transferred);

contracts/interfaces/IConfidentialFungibleTokenReceiver.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { ebool, euint64 } from "fhevm/lib/TFHE.sol";
4+
import { ebool, euint64 } from "@fhevm/solidity/lib/FHE.sol";
55

66
/// @dev Interface for contracts that can receive confidential token transfers with a callback.
77
interface IConfidentialFungibleTokenReceiver {

contracts/mocks/ConfidentialFungibleTokenERC20WrapperMock.sol

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
5-
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
4+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
65
import {
76
ConfidentialFungibleTokenERC20Wrapper,
87
ConfidentialFungibleToken
98
} from "../token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol";
109
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
1110

12-
contract ConfidentialFungibleTokenERC20WrapperMock is
13-
SepoliaZamaFHEVMConfig,
14-
SepoliaZamaGatewayConfig,
15-
ConfidentialFungibleTokenERC20Wrapper
16-
{
11+
contract ConfidentialFungibleTokenERC20WrapperMock is SepoliaConfig, ConfidentialFungibleTokenERC20Wrapper {
1712
constructor(
1813
IERC20 token,
1914
string memory name,

contracts/mocks/ConfidentialFungibleTokenMock.sol

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
pragma solidity ^0.8.24;
44

5-
import { TFHE, euint64, einput } from "fhevm/lib/TFHE.sol";
5+
import { FHE, euint64, externalEuint64 } from "@fhevm/solidity/lib/FHE.sol";
66
import { ConfidentialFungibleToken } from "../token/ConfidentialFungibleToken.sol";
7-
import { SepoliaZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";
8-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
7+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
98

10-
contract ConfidentialFungibleTokenMock is ConfidentialFungibleToken, SepoliaZamaFHEVMConfig, SepoliaZamaGatewayConfig {
9+
contract ConfidentialFungibleTokenMock is ConfidentialFungibleToken, SepoliaConfig {
1110
address private immutable _OWNER;
1211

1312
constructor(
@@ -20,50 +19,50 @@ contract ConfidentialFungibleTokenMock is ConfidentialFungibleToken, SepoliaZama
2019

2120
function _update(address from, address to, euint64 amount) internal virtual override returns (euint64 transferred) {
2221
transferred = super._update(from, to, amount);
23-
TFHE.allow(totalSupply(), _OWNER);
22+
FHE.allow(totalSupply(), _OWNER);
2423
}
2524

2625
function $_mint(
2726
address to,
28-
einput encryptedAmount,
27+
externalEuint64 encryptedAmount,
2928
bytes calldata inputProof
3029
) public returns (euint64 transferred) {
31-
return _mint(to, TFHE.asEuint64(encryptedAmount, inputProof));
30+
return _mint(to, FHE.fromExternal(encryptedAmount, inputProof));
3231
}
3332

3433
function $_transfer(
3534
address from,
3635
address to,
37-
einput encryptedAmount,
36+
externalEuint64 encryptedAmount,
3837
bytes calldata inputProof
3938
) public returns (euint64 transferred) {
40-
return _transfer(from, to, TFHE.asEuint64(encryptedAmount, inputProof));
39+
return _transfer(from, to, FHE.fromExternal(encryptedAmount, inputProof));
4140
}
4241

4342
function $_transferAndCall(
4443
address from,
4544
address to,
46-
einput encryptedAmount,
45+
externalEuint64 encryptedAmount,
4746
bytes calldata inputProof,
4847
bytes calldata data
4948
) public returns (euint64 transferred) {
50-
return _transferAndCall(from, to, TFHE.asEuint64(encryptedAmount, inputProof), data);
49+
return _transferAndCall(from, to, FHE.fromExternal(encryptedAmount, inputProof), data);
5150
}
5251

5352
function $_burn(
5453
address from,
55-
einput encryptedAmount,
54+
externalEuint64 encryptedAmount,
5655
bytes calldata inputProof
5756
) public returns (euint64 transferred) {
58-
return _burn(from, TFHE.asEuint64(encryptedAmount, inputProof));
57+
return _burn(from, FHE.fromExternal(encryptedAmount, inputProof));
5958
}
6059

6160
function $_update(
6261
address from,
6362
address to,
64-
einput encryptedAmount,
63+
externalEuint64 encryptedAmount,
6564
bytes calldata inputProof
6665
) public virtual returns (euint64 transferred) {
67-
return _update(from, to, TFHE.asEuint64(encryptedAmount, inputProof));
66+
return _update(from, to, FHE.fromExternal(encryptedAmount, inputProof));
6867
}
6968
}

contracts/mocks/ConfidentialFungibleTokenReceiverMock.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { TFHE, ebool, euint64 } from "fhevm/lib/TFHE.sol";
5-
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
4+
import { FHE, ebool, euint64 } from "@fhevm/solidity/lib/FHE.sol";
5+
import { SepoliaConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
66
import { IConfidentialFungibleTokenReceiver } from "../interfaces/IConfidentialFungibleTokenReceiver.sol";
77

8-
contract ConfidentialFungibleTokenReceiverMock is IConfidentialFungibleTokenReceiver, SepoliaZamaFHEVMConfig {
9-
using TFHE for *;
10-
8+
contract ConfidentialFungibleTokenReceiverMock is IConfidentialFungibleTokenReceiver, SepoliaConfig {
119
event ConfidentialTransferCallback(bool success);
1210

1311
error InvalidInput(uint8 input);
@@ -21,8 +19,8 @@ contract ConfidentialFungibleTokenReceiverMock is IConfidentialFungibleTokenRece
2119
bool success = input == 1;
2220
emit ConfidentialTransferCallback(success);
2321

24-
ebool returnVal = TFHE.asEbool(success);
25-
returnVal.allowTransient(msg.sender);
22+
ebool returnVal = FHE.asEbool(success);
23+
FHE.allowTransient(returnVal, msg.sender);
2624

2725
return returnVal;
2826
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { TFHE, einput, ebool, euint64 } from "fhevm/lib/TFHE.sol";
4+
import { FHE, externalEuint64, ebool, euint64 } from "@fhevm/solidity/lib/FHE.sol";
55
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
66
import { ConfidentialFungibleToken } from "../../token/ConfidentialFungibleToken.sol";
77

88
contract ConfidentialFungibleTokenMintableBurnable is ConfidentialFungibleToken, Ownable {
9-
using TFHE for *;
9+
using FHE for *;
1010

1111
constructor(
1212
address owner,
@@ -15,11 +15,11 @@ contract ConfidentialFungibleTokenMintableBurnable is ConfidentialFungibleToken,
1515
string memory uri
1616
) ConfidentialFungibleToken(name, symbol, uri) Ownable(owner) {}
1717

18-
function mint(address to, einput amount, bytes memory inputProof) public onlyOwner {
19-
_mint(to, amount.asEuint64(inputProof));
18+
function mint(address to, externalEuint64 amount, bytes memory inputProof) public onlyOwner {
19+
_mint(to, amount.fromExternal(inputProof));
2020
}
2121

22-
function burn(address from, einput amount, bytes memory inputProof) public onlyOwner {
23-
_burn(from, amount.asEuint64(inputProof));
22+
function burn(address from, externalEuint64 amount, bytes memory inputProof) public onlyOwner {
23+
_burn(from, amount.fromExternal(inputProof));
2424
}
2525
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { einput, euint64, TFHE } from "fhevm/lib/TFHE.sol";
4+
import { FHE, externalEuint64, euint64 } from "@fhevm/solidity/lib/FHE.sol";
55
import { IConfidentialFungibleToken } from "../../interfaces/IConfidentialFungibleToken.sol";
66

77
contract SwapConfidentialFungibleTokenToConfidentialFungibleToken {
88
function swapConfidentialForConfidential(
99
IConfidentialFungibleToken fromToken,
1010
IConfidentialFungibleToken toToken,
1111
address from,
12-
einput amountInput,
12+
externalEuint64 amountInput,
1313
bytes calldata inputProof
1414
) public virtual {
1515
require(fromToken.isOperator(address(this), msg.sender));
1616

17-
euint64 amount = TFHE.asEuint64(amountInput, inputProof);
17+
euint64 amount = FHE.fromExternal(amountInput, inputProof);
1818

19-
TFHE.allowTransient(amount, address(fromToken));
19+
FHE.allowTransient(amount, address(fromToken));
2020
euint64 amountTransferred = fromToken.confidentialTransferFrom(msg.sender, address(this), amount);
2121

22-
TFHE.allowTransient(amountTransferred, address(toToken));
22+
FHE.allowTransient(amountTransferred, address(toToken));
2323
toToken.confidentialTransfer(msg.sender, amountTransferred);
2424
}
2525
}

contracts/mocks/docs/SwapConfidentialToERC20.sol

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4-
import { TFHE, einput, euint64 } from "fhevm/lib/TFHE.sol";
5-
import { Gateway } from "fhevm/gateway/lib/Gateway.sol";
6-
import { GatewayCaller } from "fhevm/gateway/GatewayCaller.sol";
4+
import { FHE, externalEuint64, euint64 } from "@fhevm/solidity/lib/FHE.sol";
75
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
86
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
97

108
import { IConfidentialFungibleToken } from "../../interfaces/IConfidentialFungibleToken.sol";
119

12-
contract SwapConfidentialToERC20 is GatewayCaller {
13-
using TFHE for *;
10+
contract SwapConfidentialToERC20 {
11+
using FHE for *;
1412

1513
error SwapConfidentialToERC20InvalidGatewayRequest(uint256 requestId);
1614

@@ -23,26 +21,21 @@ contract SwapConfidentialToERC20 is GatewayCaller {
2321
_toToken = toToken;
2422
}
2523

26-
function swapConfidentialToERC20(einput encryptedInput, bytes memory inputProof) public {
27-
euint64 amount = encryptedInput.asEuint64(inputProof);
24+
function swapConfidentialToERC20(externalEuint64 encryptedInput, bytes memory inputProof) public {
25+
euint64 amount = encryptedInput.fromExternal(inputProof);
2826
amount.allowTransient(address(_fromToken));
2927
euint64 amountTransferred = _fromToken.confidentialTransferFrom(msg.sender, address(this), amount);
3028

31-
uint256[] memory cts = new uint256[](1);
29+
bytes32[] memory cts = new bytes32[](1);
3230
cts[0] = euint64.unwrap(amountTransferred);
33-
uint256 requestID = Gateway.requestDecryption(
34-
cts,
35-
this.finalizeSwap.selector,
36-
0,
37-
block.timestamp + 1 days, // Max delay is 1 day
38-
false
39-
);
31+
uint256 requestID = FHE.requestDecryption(cts, this.finalizeSwap.selector);
4032

4133
// register who is getting the tokens
4234
_receivers[requestID] = msg.sender;
4335
}
4436

45-
function finalizeSwap(uint256 requestID, uint64 amount) public virtual onlyGateway {
37+
function finalizeSwap(uint256 requestID, uint64 amount, bytes[] memory signatures) public virtual {
38+
FHE.checkSignatures(requestID, signatures);
4639
address to = _receivers[requestID];
4740
require(to != address(0), SwapConfidentialToERC20InvalidGatewayRequest(requestID));
4841
delete _receivers[requestID];

0 commit comments

Comments
 (0)