From 142e42042be9948e04620109f87a536e8053369e Mon Sep 17 00:00:00 2001 From: Arr00 <13561405+arr00@users.noreply.github.com> Date: Tue, 8 Jul 2025 08:46:27 -0600 Subject: [PATCH 1/2] Rename token functions --- .../governance/utils/VotesConfidential.sol | 6 +-- .../interfaces/IConfidentialFungibleToken.sol | 10 ++--- .../mocks/ConfidentialFungibleTokenMock.sol | 2 +- .../ConfidentialFungibleTokenVotesMock.sol | 4 +- contracts/token/ConfidentialFungibleToken.sol | 8 ++-- .../ConfidentialFungibleTokenVotes.sol | 6 +-- test/token/ConfidentialFungibleToken.test.ts | 40 +++++++++---------- .../ConfidentialFungibleTokenVotes.test.ts | 2 +- .../ConfidentialFungibleWrapper.test.ts | 10 ++--- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/contracts/governance/utils/VotesConfidential.sol b/contracts/governance/utils/VotesConfidential.sol index cab0364c..eecd6317 100644 --- a/contracts/governance/utils/VotesConfidential.sol +++ b/contracts/governance/utils/VotesConfidential.sol @@ -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) { @@ -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); } diff --git a/contracts/interfaces/IConfidentialFungibleToken.sol b/contracts/interfaces/IConfidentialFungibleToken.sol index 3ca06d74..57f060f6 100644 --- a/contracts/interfaces/IConfidentialFungibleToken.sol +++ b/contracts/interfaces/IConfidentialFungibleToken.sol @@ -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); @@ -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); diff --git a/contracts/mocks/ConfidentialFungibleTokenMock.sol b/contracts/mocks/ConfidentialFungibleTokenMock.sol index 631e8287..13d4a31f 100644 --- a/contracts/mocks/ConfidentialFungibleTokenMock.sol +++ b/contracts/mocks/ConfidentialFungibleTokenMock.sol @@ -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( diff --git a/contracts/mocks/ConfidentialFungibleTokenVotesMock.sol b/contracts/mocks/ConfidentialFungibleTokenVotesMock.sol index 2a680c3a..f20aba16 100644 --- a/contracts/mocks/ConfidentialFungibleTokenVotesMock.sol +++ b/contracts/mocks/ConfidentialFungibleTokenVotesMock.sol @@ -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( diff --git a/contracts/token/ConfidentialFungibleToken.sol b/contracts/token/ConfidentialFungibleToken.sol index c77f5278..47cd97e0 100644 --- a/contracts/token/ConfidentialFungibleToken.sol +++ b/contracts/token/ConfidentialFungibleToken.sol @@ -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]; } @@ -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 @@ -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); } diff --git a/contracts/token/extensions/ConfidentialFungibleTokenVotes.sol b/contracts/token/extensions/ConfidentialFungibleTokenVotes.sol index 0e069fdc..54bf07c8 100644 --- a/contracts/token/extensions/ConfidentialFungibleTokenVotes.sol +++ b/contracts/token/extensions/ConfidentialFungibleTokenVotes.sol @@ -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) { @@ -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); } } diff --git a/test/token/ConfidentialFungibleToken.test.ts b/test/token/ConfidentialFungibleToken.test.ts index a24abbab..d389b749 100644 --- a/test/token/ConfidentialFungibleToken.test.ts +++ b/test/token/ConfidentialFungibleToken.test.ts @@ -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)); @@ -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); @@ -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); @@ -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), @@ -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, ), @@ -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); @@ -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 () { @@ -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, ), ) @@ -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, ), @@ -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); @@ -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); @@ -556,7 +556,7 @@ 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') @@ -564,7 +564,7 @@ describe('ConfidentialFungibleToken', function () { }); 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; @@ -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); diff --git a/test/token/extensions/ConfidentialFungibleTokenVotes.test.ts b/test/token/extensions/ConfidentialFungibleTokenVotes.test.ts index f613c38e..92d51be2 100644 --- a/test/token/extensions/ConfidentialFungibleTokenVotes.test.ts +++ b/test/token/extensions/ConfidentialFungibleTokenVotes.test.ts @@ -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(); diff --git a/test/token/extensions/ConfidentialFungibleWrapper.test.ts b/test/token/extensions/ConfidentialFungibleWrapper.test.ts index 98c6034b..ecb91830 100644 --- a/test/token/extensions/ConfidentialFungibleWrapper.test.ts +++ b/test/token/extensions/ConfidentialFungibleWrapper.test.ts @@ -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)); @@ -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); @@ -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)); @@ -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)); @@ -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') From 393d269aeb7d4d48be5ed6afed556cf72c470454 Mon Sep 17 00:00:00 2001 From: Arr00 <13561405+arr00@users.noreply.github.com> Date: Tue, 8 Jul 2025 13:31:20 -0600 Subject: [PATCH 2/2] add changeset --- .changeset/nasty-camels-attack.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nasty-camels-attack.md diff --git a/.changeset/nasty-camels-attack.md b/.changeset/nasty-camels-attack.md new file mode 100644 index 00000000..5b6186ef --- /dev/null +++ b/.changeset/nasty-camels-attack.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-confidential-contracts': minor +--- + +`IConfidentialFungibleToken`: Prefix `totalSupply` and `balanceOf` functions with confidential.