Skip to content

Add authorized re-encryption of past transfers#66

Open
eduv09 wants to merge 20 commits intodevelopfrom
encrypted-events
Open

Add authorized re-encryption of past transfers#66
eduv09 wants to merge 20 commits intodevelopfrom
encrypted-events

Conversation

@eduv09
Copy link
Copy Markdown
Contributor

@eduv09 eduv09 commented Apr 6, 2026

Fixes #63

@eduv09 eduv09 self-assigned this Apr 6, 2026
@eduv09 eduv09 requested a review from Copilot April 6, 2026 17:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements “authorized re-encryption” for historical transfers, enabling selective disclosure of encrypted transfer data to permitted viewers (Issue #63), plus an automatic recipient-readable encrypted value event when the recipient has a registered public key.

Changes:

  • Added on-chain historic transfer disclosure primitives: EncryptedTransfer emission, viewer authorization (time range / transferId), and requestDecryptHistoricTransferReEncryptedTransfer.
  • Added automatic per-transfer TransferValueEncryptedForRecipient emission (ECIES to recipient key when registered).
  • Expanded test coverage and updated README + generated interface/contract docs for the new disclosure flows.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
contracts/ConfidentialToken.sol Core implementation for emitting encrypted transfer metadata and handling authorized historic re-encryption requests.
contracts/interfaces/IConfidentialToken.sol Adds structs/events/errors and new public API for historic view authorization + decrypt requests.
test/ConfidentialToken.ts Extensive tests for authorization, edge cases, fee charging, replay, and recipient auto-encryption.
README.md Documents the historic transfer decryption feature and the recipient auto-encrypted value event.
docs/interfaces/IConfidentialToken.md Generated interface docs updated to include new structs/events/functions.
docs/ConfidentialToken.md Generated contract docs updated for new internal/external functions and updated signatures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/interfaces/IConfidentialToken.sol Outdated
Comment thread docs/interfaces/IConfidentialToken.md
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 98.58156% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.38%. Comparing base (5167aaf) to head (d0f1a17).

Files with missing lines Patch % Lines
contracts/ConfidentialToken.sol 97.91% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #66      +/-   ##
===========================================
+ Coverage    96.66%   97.38%   +0.71%     
===========================================
  Files            6        7       +1     
  Lines          270      382     +112     
  Branches        64       94      +30     
===========================================
+ Hits           261      372     +111     
- Misses           9       10       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eduv09 eduv09 marked this pull request as ready for review April 8, 2026 12:41
@eduv09 eduv09 requested a review from DimaStebaev as a code owner April 8, 2026 12:41
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/interfaces/IConfidentialToken.sol Outdated
Copilot AI review requested due to automatic review settings April 13, 2026 15:14
@eduv09 eduv09 force-pushed the encrypted-events branch from 39201de to 3c26898 Compare April 13, 2026 15:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/interfaces/IConfidentialToken.sol
Copilot AI review requested due to automatic review settings April 13, 2026 15:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/deployAndTestMintableCnfToken.ts
Comment thread scripts/deployAndTestMintableCnfToken.ts
Comment thread contracts/HistoricView.sol Outdated
@eduv09 eduv09 force-pushed the encrypted-events branch from b66b604 to da20709 Compare April 13, 2026 15:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 13, 2026 15:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread scripts/deployAndTestMintableCnfToken.ts
@eduv09 eduv09 requested a review from DimaStebaev April 14, 2026 13:00
Comment thread contracts/ConfidentialToken.sol
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread contracts/ConfidentialWrapper.sol Outdated
Comment thread test/tools/utils.ts
Copilot AI review requested due to automatic review settings April 14, 2026 16:26
@eduv09 eduv09 force-pushed the encrypted-events branch from 5ffa472 to 1df43a8 Compare April 14, 2026 16:29
@eduv09 eduv09 requested review from Copilot and removed request for Copilot April 14, 2026 16:29
@eduv09 eduv09 force-pushed the encrypted-events branch from 1df43a8 to 8243fe1 Compare April 14, 2026 16:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contracts/interfaces/IConfidentialToken.sol Outdated
Comment thread contracts/interfaces/IConfidentialToken.sol Outdated
Comment thread docs/interfaces/IConfidentialToken.md Outdated
Comment thread README.md Outdated
Copilot AI review requested due to automatic review settings April 14, 2026 16:40
@eduv09 eduv09 force-pushed the encrypted-events branch from 571adc1 to 2050616 Compare April 14, 2026 16:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/ConfidentialToken.ts
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread contracts/ConfidentialToken.sol Outdated
Copilot AI review requested due to automatic review settings April 16, 2026 15:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contracts/ConfidentialToken.sol Outdated
Comment thread contracts/HistoricView.sol Outdated
Comment thread contracts/interfaces/IConfidentialToken.sol
Copilot AI review requested due to automatic review settings April 23, 2026 15:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Comment thread scripts/deployAndTestMintableCnfToken.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 15:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +455 to +458
(address from, address to) = _historicViewAuth.decodeIfAuthorized(
sender,
decryptedArguments[0]
);
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_handleHistoricViewRequest indexes decryptedArguments[0] without first validating that the callback provided at least one decrypted argument. If decryptedArguments is empty (or shorter than expected), this will revert with a panic (out-of-bounds) rather than a controlled custom error. Add an explicit length check (e.g., require decryptedArguments.length == 1) and revert with a project error like DecryptionBadFormat/WrongPlaintextFormat for predictable behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +452 to +466
address sender = address(bytes20(plaintextArguments[1]));
require(_knownPublicKey(sender), PublicKeyIsNotRegistered(sender));

(address from, address to) = _historicViewAuth.decodeIfAuthorized(
sender,
decryptedArguments[0]
);
emit ReEncryptedTransfer(
sender,
from,
to,
BITE.encryptECIES(
encryptECIESAddress,
decryptedArguments[0],
publicKeys[sender]
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In _handleHistoricViewRequest, the local variable sender is actually the historic-view viewer address extracted from plaintextArguments[1]. Renaming it to viewer/historicViewer would make the authorization and ReEncryptedTransfer emission logic much easier to follow and reduce confusion with msg.sender / transfer sender.

Suggested change
address sender = address(bytes20(plaintextArguments[1]));
require(_knownPublicKey(sender), PublicKeyIsNotRegistered(sender));
(address from, address to) = _historicViewAuth.decodeIfAuthorized(
sender,
decryptedArguments[0]
);
emit ReEncryptedTransfer(
sender,
from,
to,
BITE.encryptECIES(
encryptECIESAddress,
decryptedArguments[0],
publicKeys[sender]
address historicViewer = address(bytes20(plaintextArguments[1]));
require(_knownPublicKey(historicViewer), PublicKeyIsNotRegistered(historicViewer));
(address from, address to) = _historicViewAuth.decodeIfAuthorized(
historicViewer,
decryptedArguments[0]
);
emit ReEncryptedTransfer(
historicViewer,
from,
to,
BITE.encryptECIES(
encryptECIESAddress,
decryptedArguments[0],
publicKeys[historicViewer]

Copilot uses AI. Check for mistakes.
const deploy = async () => {
console.log(chalk.yellow("Deploying AccessManager..."));
const accessManagerFactory = await ethers.getContractFactory("AccessManager");
accessManager = await accessManagerFactory.deploy(deployer);
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accessManagerFactory.deploy(deployer) passes a SignerWithAddress object where the OpenZeppelin AccessManager constructor expects an address (initial admin). This is likely to throw at runtime with an “invalid address” error on ethers v6. Pass deployer.address (or await deployer.getAddress()) instead.

Suggested change
accessManager = await accessManagerFactory.deploy(deployer);
accessManager = await accessManagerFactory.deploy(deployer.address);

Copilot uses AI. Check for mistakes.
/// @notice Emitted when a holder revokes a viewer's access to transfers within a time range.
/// @param holder Address of the holder revoking access.
/// @param viewer Address of the viewer losing access.
event HistoricViewTimeRangeRevoked(address indexed holder,address indexed viewer);
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor formatting: HistoricViewTimeRangeRevoked is declared as event HistoricViewTimeRangeRevoked(address indexed holder,address indexed viewer); (missing a space after the comma). Align spacing with the rest of the interface for readability.

Suggested change
event HistoricViewTimeRangeRevoked(address indexed holder,address indexed viewer);
event HistoricViewTimeRangeRevoked(address indexed holder, address indexed viewer);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to disclose transfer data

3 participants