Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-camels-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-confidential-contracts': minor
---

`IConfidentialFungibleToken`: Prefix `totalSupply` and `balanceOf` functions with confidential.
6 changes: 3 additions & 3 deletions contracts/governance/utils/VotesConfidential.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ abstract contract VotesConfidential is Nonces, EIP712, IERC6372 {
* @dev Returns the current total supply of votes as an encrypted uint64 (euint64). Must be implemented
* by the derived contract.
*/
function totalSupply() public view virtual returns (euint64);
function confidentialTotalSupply() public view virtual returns (euint64);

/// @dev Returns the delegate that `account` has chosen.
function delegates(address account) public view virtual returns (address) {
Expand Down Expand Up @@ -149,11 +149,11 @@ abstract contract VotesConfidential is Nonces, EIP712, IERC6372 {
* @dev Transfers, mints, or burns voting units. To register a mint, `from` should be zero. To register a burn, `to`
* should be zero. Total supply of voting units will be adjusted with mints and burns.
*
* WARNING: Must be called after {totalSupply} is updated.
* WARNING: Must be called after {confidentialTotalSupply} is updated.
*/
function _transferVotingUnits(address from, address to, euint64 amount) internal virtual {
if (from == address(0) || to == address(0)) {
_push(_totalCheckpoints, totalSupply());
_push(_totalCheckpoints, confidentialTotalSupply());
}
_moveDelegateVotes(delegates(from), delegates(to), amount);
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/interfaces/IConfidentialFungibleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface IConfidentialFungibleToken {
* Accounts with access to the encrypted amount `encryptedAmount` that is also accessible to this contract
* should be able to disclose the amount. This functionality is implementation specific.
*/
event EncryptedAmountDisclosed(euint64 indexed encryptedAmount, uint64 amount);
event AmountDisclosed(euint64 indexed encryptedAmount, uint64 amount);

/// @dev Returns the name of the token.
function name() external view returns (string memory);
Expand All @@ -34,11 +34,11 @@ interface IConfidentialFungibleToken {
/// @dev Returns the token URI.
function tokenURI() external view returns (string memory);

/// @dev Returns the encrypted total supply of the token.
function totalSupply() external view returns (euint64);
/// @dev Returns the confidential total supply of the token.
function confidentialTotalSupply() external view returns (euint64);

/// @dev Returns the encrypted balance of the account `account`.
function balanceOf(address account) external view returns (euint64);
/// @dev Returns the confidential balance of the account `account`.
function confidentialBalanceOf(address account) external view returns (euint64);

/// @dev Returns true if `spender` is currently an operator for `holder`.
function isOperator(address holder, address spender) external view returns (bool);
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ConfidentialFungibleTokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract ConfidentialFungibleTokenMock is ConfidentialFungibleToken, SepoliaConf

function _update(address from, address to, euint64 amount) internal virtual override returns (euint64 transferred) {
transferred = super._update(from, to, amount);
FHE.allow(totalSupply(), _OWNER);
FHE.allow(confidentialTotalSupply(), _OWNER);
}

function $_mint(
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/ConfidentialFungibleTokenVotesMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ abstract contract ConfidentialFungibleTokenVotesMock is ConfidentialFungibleToke
return super.clock();
}

function totalSupply()
function confidentialTotalSupply()
public
view
virtual
override(ConfidentialFungibleToken, ConfidentialFungibleTokenVotes)
returns (euint64)
{
return super.totalSupply();
return super.confidentialTotalSupply();
}

function _update(
Expand Down
8 changes: 4 additions & 4 deletions contracts/token/ConfidentialFungibleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ abstract contract ConfidentialFungibleToken is IConfidentialFungibleToken {
}

/// @inheritdoc IConfidentialFungibleToken
function totalSupply() public view virtual returns (euint64) {
function confidentialTotalSupply() public view virtual returns (euint64) {
return _totalSupply;
}

/// @inheritdoc IConfidentialFungibleToken
function balanceOf(address account) public view virtual returns (euint64) {
function confidentialBalanceOf(address account) public view virtual returns (euint64) {
return _balances[account];
}

Expand Down Expand Up @@ -203,7 +203,7 @@ abstract contract ConfidentialFungibleToken is IConfidentialFungibleToken {
}

/**
* @dev Discloses an encrypted amount `encryptedAmount` publicly via an {IConfidentialFungibleToken-EncryptedAmountDisclosed}
* @dev Discloses an encrypted amount `encryptedAmount` publicly via an {IConfidentialFungibleToken-AmountDisclosed}
* event. The caller and this contract must be authorized to use the encrypted amount on the ACL.
*
* NOTE: This is an asynchronous operation where the actual decryption happens off-chain and
Expand Down Expand Up @@ -231,7 +231,7 @@ abstract contract ConfidentialFungibleToken is IConfidentialFungibleToken {

euint64 requestHandle = _requestHandles[requestId];
require(FHE.isInitialized(requestHandle), ConfidentialFungibleTokenInvalidGatewayRequest(requestId));
emit EncryptedAmountDisclosed(requestHandle, amount);
emit AmountDisclosed(requestHandle, amount);

_requestHandles[requestId] = euint64.wrap(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {ConfidentialFungibleToken} from "../ConfidentialFungibleToken.sol";
import {VotesConfidential} from "../../governance/utils/VotesConfidential.sol";

abstract contract ConfidentialFungibleTokenVotes is ConfidentialFungibleToken, VotesConfidential {
function totalSupply()
function confidentialTotalSupply()
public
view
virtual
override(VotesConfidential, ConfidentialFungibleToken)
returns (euint64)
{
return super.totalSupply();
return super.confidentialTotalSupply();
}

function _update(address from, address to, euint64 amount) internal virtual override returns (euint64 transferred) {
Expand All @@ -24,6 +24,6 @@ abstract contract ConfidentialFungibleTokenVotes is ConfidentialFungibleToken, V
}

function _getVotingUnits(address account) internal view virtual override returns (euint64) {
return balanceOf(account);
return confidentialBalanceOf(account);
}
}
40 changes: 20 additions & 20 deletions test/token/ConfidentialFungibleToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ describe('ConfidentialFungibleToken', function () {
});
});

describe('balanceOf', function () {
describe('confidentialBalanceOf', function () {
it('handle can be reencryped by owner', async function () {
const balanceOfHandleHolder = await this.token.balanceOf(this.holder);
const balanceOfHandleHolder = await this.token.confidentialBalanceOf(this.holder);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, balanceOfHandleHolder, this.token.target, this.holder),
).to.eventually.equal(1000);
});

it('handle cannot be reencryped by non-owner', async function () {
const balanceOfHandleHolder = await this.token.balanceOf(this.holder);
const balanceOfHandleHolder = await this.token.confidentialBalanceOf(this.holder);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, balanceOfHandleHolder, this.token.target, this.accounts[0]),
).to.be.rejectedWith(generateReencryptionErrorMessage(balanceOfHandleHolder, this.accounts[0].address));
Expand All @@ -78,13 +78,13 @@ describe('ConfidentialFungibleToken', function () {
['$_mint(address,bytes32,bytes)'](this.holder, encryptedInput.handles[0], encryptedInput.inputProof);
}

const balanceOfHandleHolder = await this.token.balanceOf(this.holder);
const balanceOfHandleHolder = await this.token.confidentialBalanceOf(this.holder);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, balanceOfHandleHolder, this.token.target, this.holder),
).to.eventually.equal(existingUser ? 2000 : 1000);

// Check total supply
const totalSupplyHandle = await this.token.totalSupply();
const totalSupplyHandle = await this.token.confidentialTotalSupply();
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, totalSupplyHandle, this.token.target, this.holder),
).to.eventually.equal(existingUser ? 2000 : 1000);
Expand Down Expand Up @@ -121,13 +121,13 @@ describe('ConfidentialFungibleToken', function () {
.connect(this.holder)
['$_burn(address,bytes32,bytes)'](this.holder, encryptedInput.handles[0], encryptedInput.inputProof);

const balanceOfHandleHolder = await this.token.balanceOf(this.holder);
const balanceOfHandleHolder = await this.token.confidentialBalanceOf(this.holder);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, balanceOfHandleHolder, this.token.target, this.holder),
).to.eventually.equal(sufficientBalance ? 600 : 1000);

// Check total supply
const totalSupplyHandle = await this.token.totalSupply();
const totalSupplyHandle = await this.token.confidentialTotalSupply();
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, totalSupplyHandle, this.token.target, this.holder),
).to.eventually.equal(sufficientBalance ? 600 : 1000);
Expand Down Expand Up @@ -286,8 +286,8 @@ describe('ConfidentialFungibleToken', function () {
expect(transferEvent.args[1]).to.equal(this.recipient.address);

const transferAmountHandle = transferEvent.args[2];
const holderBalanceHandle = await this.token.balanceOf(this.holder);
const recipientBalanceHandle = await this.token.balanceOf(this.recipient);
const holderBalanceHandle = await this.token.confidentialBalanceOf(this.holder);
const recipientBalanceHandle = await this.token.confidentialBalanceOf(this.recipient);

await expect(
fhevm.userDecryptEuint(FhevmType.euint64, transferAmountHandle, this.token.target, this.holder),
Expand Down Expand Up @@ -341,14 +341,14 @@ describe('ConfidentialFungibleToken', function () {
}

it('full balance', async function () {
const fullBalanceHandle = await this.token.balanceOf(this.holder);
const fullBalanceHandle = await this.token.confidentialBalanceOf(this.holder);

await callTransfer(this.token, this.holder, this.recipient, fullBalanceHandle);

await expect(
fhevm.userDecryptEuint(
FhevmType.euint64,
await this.token.balanceOf(this.recipient),
await this.token.confidentialBalanceOf(this.recipient),
this.token.target,
this.recipient,
),
Expand All @@ -365,7 +365,7 @@ describe('ConfidentialFungibleToken', function () {
.connect(this.holder)
['$_mint(address,bytes32,bytes)'](this.recipient, encryptedInput.handles[0], encryptedInput.inputProof);

const recipientBalanceHandle = await this.token.balanceOf(this.recipient);
const recipientBalanceHandle = await this.token.confidentialBalanceOf(this.recipient);
await expect(callTransfer(this.token, this.holder, this.recipient, recipientBalanceHandle))
.to.be.revertedWithCustomError(this.token, 'ConfidentialFungibleTokenUnauthorizedUseOfEncryptedAmount')
.withArgs(recipientBalanceHandle, this.holder);
Expand All @@ -375,7 +375,7 @@ describe('ConfidentialFungibleToken', function () {
describe('without operator approval', function () {
beforeEach(async function () {
await this.token.connect(this.holder).setOperator(this.operator.address, 0);
await allowHandle(hre, this.holder, this.operator, await this.token.balanceOf(this.holder));
await allowHandle(hre, this.holder, this.operator, await this.token.confidentialBalanceOf(this.holder));
});

it('should revert', async function () {
Expand All @@ -384,7 +384,7 @@ describe('ConfidentialFungibleToken', function () {
this.token,
this.holder,
this.recipient,
await this.token.balanceOf(this.holder),
await this.token.confidentialBalanceOf(this.holder),
this.operator,
),
)
Expand Down Expand Up @@ -442,7 +442,7 @@ describe('ConfidentialFungibleToken', function () {
await expect(
fhevm.userDecryptEuint(
FhevmType.euint64,
await this.token.balanceOf(this.holder),
await this.token.confidentialBalanceOf(this.holder),
this.token.target,
this.holder,
),
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('ConfidentialFungibleToken', function () {
'0x',
);

const balanceOfHandle = await this.token.balanceOf(this.recipient);
const balanceOfHandle = await this.token.confidentialBalanceOf(this.recipient);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, balanceOfHandle, this.token.target, this.recipient),
).to.eventually.equal(1000);
Expand All @@ -526,7 +526,7 @@ describe('ConfidentialFungibleToken', function () {
});

it('user balance', async function () {
const holderBalanceHandle = await this.token.balanceOf(this.holder);
const holderBalanceHandle = await this.token.confidentialBalanceOf(this.holder);

await this.token.connect(this.holder).discloseEncryptedAmount(holderBalanceHandle);

Expand Down Expand Up @@ -556,15 +556,15 @@ describe('ConfidentialFungibleToken', function () {
});

it("other user's balance", async function () {
const holderBalanceHandle = await this.token.balanceOf(this.holder);
const holderBalanceHandle = await this.token.confidentialBalanceOf(this.holder);

await expect(this.token.connect(this.recipient).discloseEncryptedAmount(holderBalanceHandle))
.to.be.revertedWithCustomError(this.token, 'ConfidentialFungibleTokenUnauthorizedUseOfEncryptedAmount')
.withArgs(holderBalanceHandle, this.recipient);
});

it('invalid signature reverts', async function () {
const holderBalanceHandle = await this.token.balanceOf(this.holder);
const holderBalanceHandle = await this.token.confidentialBalanceOf(this.holder);
await this.token.connect(this.holder).discloseEncryptedAmount(holderBalanceHandle);

await expect(this.token.connect(this.holder).finalizeDiscloseEncryptedAmount(0, 0, [])).to.be.reverted;
Expand All @@ -576,7 +576,7 @@ describe('ConfidentialFungibleToken', function () {
await fhevm.awaitDecryptionOracle();

// Check that event was correctly emitted
const eventFilter = this.token.filters.EncryptedAmountDisclosed();
const eventFilter = this.token.filters.AmountDisclosed();
const discloseEvent = (await this.token.queryFilter(eventFilter))[0];
expect(discloseEvent.args[0]).to.equal(expectedHandle);
expect(discloseEvent.args[1]).to.equal(expectedAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('ConfidentialFungibleTokenVotes', function () {
const afterTransferBlock = await ethers.provider.getBlockNumber();

// Burn total balance
const amountToBurn = await this.token.balanceOf(this.holder);
const amountToBurn = await this.token.confidentialBalanceOf(this.holder);
await this.token.$_burn(this.holder, amountToBurn);
const afterBurnBlock = await ethers.provider.getBlockNumber();
await mine();
Expand Down
10 changes: 5 additions & 5 deletions test/token/extensions/ConfidentialFungibleWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('ConfidentialFungibleTokenWrapper', function () {
}

await expect(this.token.balanceOf(this.holder)).to.eventually.equal(ethers.parseUnits('900', 18));
const wrappedBalanceHandle = await this.wrapper.balanceOf(this.holder.address);
const wrappedBalanceHandle = await this.wrapper.confidentialBalanceOf(this.holder.address);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, wrappedBalanceHandle, this.wrapper.target, this.holder),
).to.eventually.equal(ethers.parseUnits('100', 9));
Expand All @@ -62,7 +62,7 @@ describe('ConfidentialFungibleTokenWrapper', function () {
await expect(this.token.balanceOf(this.holder)).to.eventually.equal(
ethers.parseUnits('1000', 18) - ethers.parseUnits('10', 9),
);
const wrappedBalanceHandle = await this.wrapper.balanceOf(this.holder.address);
const wrappedBalanceHandle = await this.wrapper.confidentialBalanceOf(this.holder.address);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, wrappedBalanceHandle, this.wrapper.target, this.holder),
).to.eventually.equal(10);
Expand All @@ -81,7 +81,7 @@ describe('ConfidentialFungibleTokenWrapper', function () {
);

await expect(this.token.balanceOf(this.holder)).to.eventually.equal(ethers.parseUnits('900', 18));
const wrappedBalanceHandle = await this.wrapper.balanceOf(this.recipient.address);
const wrappedBalanceHandle = await this.wrapper.confidentialBalanceOf(this.recipient.address);
await expect(
fhevm.userDecryptEuint(FhevmType.euint64, wrappedBalanceHandle, this.wrapper.target, this.recipient),
).to.eventually.equal(ethers.parseUnits('100', 9));
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('ConfidentialFungibleTokenWrapper', function () {
it('unwrap full balance', async function () {
await this.wrapper
.connect(this.holder)
.unwrap(this.holder, this.holder, await this.wrapper.balanceOf(this.holder.address));
.unwrap(this.holder, this.holder, await this.wrapper.confidentialBalanceOf(this.holder.address));
await fhevm.awaitDecryptionOracle();

await expect(this.token.balanceOf(this.holder)).to.eventually.equal(ethers.parseUnits('1000', 18));
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('ConfidentialFungibleTokenWrapper', function () {
});

it('with a value not allowed to sender', async function () {
const totalSupplyHandle = await this.wrapper.totalSupply();
const totalSupplyHandle = await this.wrapper.confidentialTotalSupply();

await expect(this.wrapper.connect(this.holder).unwrap(this.holder, this.holder, totalSupplyHandle))
.to.be.revertedWithCustomError(this.wrapper, 'ConfidentialFungibleTokenUnauthorizedUseOfEncryptedAmount')
Expand Down