-
Notifications
You must be signed in to change notification settings - Fork 30
Omnibus Extension #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Omnibus Extension #186
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0089bc6
Omnibus Extension
arr00 bc7a3a7
add changeset
arr00 8d6ec12
up
arr00 dc60f5d
update tests
arr00 b4b79f8
add back encrypted sender
arr00 38f8bd5
Update .changeset/stupid-fans-bow.md
arr00 1b08ed4
add additional omnibus transfer functions
arr00 aa4777c
review feedback
arr00 bea3092
update tests
arr00 19dbe15
add acl allowance to transferred for callback func
arr00 94100e4
update docs
arr00 3ee756a
Merge branch 'master' into feat/omni-bus
arr00 44fe57c
fix tests
arr00 11a451a
check acl allowance
arr00 347a8d8
move transfer logic to internal function
arr00 e647dc2
nit
arr00 2da39f5
add docs
arr00 2267cb5
update error
arr00 c3fb2f4
feedback
arr00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'openzeppelin-confidential-contracts': minor | ||
| --- | ||
|
|
||
| `ERC7984Omnibus`: Add an extension of `ERC7984` that exposes new functions for transferring between confidential subaccounts on omnibus wallets. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.27; | ||
|
|
||
| import {euint64} from "@fhevm/solidity/lib/FHE.sol"; | ||
| import {ERC7984Omnibus} from "../../token/ERC7984/extensions/ERC7984Omnibus.sol"; | ||
| import {ERC7984Mock, ERC7984} from "./ERC7984Mock.sol"; | ||
|
|
||
| abstract contract ERC7984OmnibusMock is ERC7984Omnibus, ERC7984Mock { | ||
| function _update( | ||
| address from, | ||
| address to, | ||
| euint64 amount | ||
| ) internal virtual override(ERC7984Mock, ERC7984) returns (euint64) { | ||
| return super._update(from, to, amount); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.27; | ||
|
|
||
| import {FHE, euint64, externalEuint64, externalEaddress, eaddress} from "@fhevm/solidity/lib/FHE.sol"; | ||
| import {ERC7984} from "../ERC7984.sol"; | ||
|
|
||
arr00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * @dev Extension of {ERC7984} that emits additional events for omnibus transfers. | ||
| * These events contain encrypted addresses for the sub-account sender and recipient. | ||
| * | ||
| * NOTE: There is no onchain accounting for sub-accounts--integrators must track sub-account | ||
| * balances externally. | ||
| */ | ||
| abstract contract ERC7984Omnibus is ERC7984 { | ||
| /** | ||
| * @dev Emitted when a confidential transfer is made representing the onchain settlement of | ||
| * an omnibus transfer from `sender` to `recipient` of amount `amount`. Settlement occurs between | ||
| * `omnibusFrom` and `omnibusTo` and is represented in a matching {IERC7984-ConfidentialTransfer} event. | ||
| * | ||
| * NOTE: `omnibusFrom` and `omnibusTo` get permanent ACL allowances for `sender` and `recipient`. | ||
| */ | ||
| event OmnibusConfidentialTransfer( | ||
| address indexed omnibusFrom, | ||
| address indexed omnibusTo, | ||
| eaddress sender, | ||
james-toussaint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| eaddress indexed recipient, | ||
| euint64 amount | ||
| ); | ||
|
|
||
| /** | ||
| * @dev The caller `user` does not have access to the encrypted address `addr`. | ||
| * | ||
| * NOTE: Try using the equivalent transfer function with an input proof. | ||
| */ | ||
| error ERC7984UnauthorizedUseOfEncryptedAddress(eaddress addr, address user); | ||
|
|
||
| /// @dev Wraps the {confidentialTransfer-address-externalEuint64-bytes} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferOmnibus( | ||
arr00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| address omnibusTo, | ||
| externalEaddress externalSender, | ||
| externalEaddress externalRecipient, | ||
| externalEuint64 externalAmount, | ||
| bytes calldata inputProof | ||
| ) public virtual returns (euint64) { | ||
| return | ||
| confidentialTransferFromOmnibus( | ||
| msg.sender, | ||
| omnibusTo, | ||
| externalSender, | ||
| externalRecipient, | ||
| externalAmount, | ||
| inputProof | ||
| ); | ||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransfer-address-euint64} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferOmnibus( | ||
| address omnibusTo, | ||
| eaddress sender, | ||
| eaddress recipient, | ||
james-toussaint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| euint64 amount | ||
| ) public virtual returns (euint64) { | ||
| return confidentialTransferFromOmnibus(msg.sender, omnibusTo, sender, recipient, amount); | ||
james-toussaint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransferFrom-address-address-externalEuint64-bytes} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferFromOmnibus( | ||
| address omnibusFrom, | ||
| address omnibusTo, | ||
| externalEaddress externalSender, | ||
| externalEaddress externalRecipient, | ||
| externalEuint64 externalAmount, | ||
| bytes calldata inputProof | ||
| ) public virtual returns (euint64) { | ||
| eaddress sender = FHE.fromExternal(externalSender, inputProof); | ||
| eaddress recipient = FHE.fromExternal(externalRecipient, inputProof); | ||
| euint64 amount = FHE.fromExternal(externalAmount, inputProof); | ||
|
|
||
| return _confidentialTransferFromOmnibus(omnibusFrom, omnibusTo, sender, recipient, amount); | ||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransferFrom-address-address-euint64} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferFromOmnibus( | ||
| address omnibusFrom, | ||
| address omnibusTo, | ||
| eaddress sender, | ||
| eaddress recipient, | ||
| euint64 amount | ||
| ) public virtual returns (euint64) { | ||
| require(FHE.isAllowed(sender, msg.sender), ERC7984UnauthorizedUseOfEncryptedAddress(sender, msg.sender)); | ||
| require(FHE.isAllowed(recipient, msg.sender), ERC7984UnauthorizedUseOfEncryptedAddress(recipient, msg.sender)); | ||
|
|
||
| return _confidentialTransferFromOmnibus(omnibusFrom, omnibusTo, sender, recipient, amount); | ||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransferAndCall-address-externalEuint64-bytes-bytes} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferAndCallOmnibus( | ||
| address omnibusTo, | ||
| externalEaddress externalSender, | ||
| externalEaddress externalRecipient, | ||
| externalEuint64 externalAmount, | ||
| bytes calldata inputProof, | ||
| bytes calldata data | ||
| ) public virtual returns (euint64) { | ||
| return | ||
| confidentialTransferFromAndCallOmnibus( | ||
| msg.sender, | ||
| omnibusTo, | ||
| externalSender, | ||
| externalRecipient, | ||
| externalAmount, | ||
| inputProof, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransferAndCall-address-euint64-bytes} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferAndCallOmnibus( | ||
| address omnibusTo, | ||
| eaddress sender, | ||
| eaddress recipient, | ||
| euint64 amount, | ||
| bytes calldata data | ||
| ) public virtual returns (euint64) { | ||
| return confidentialTransferFromAndCallOmnibus(msg.sender, omnibusTo, sender, recipient, amount, data); | ||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransferFromAndCall-address-address-externalEuint64-bytes-bytes} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferFromAndCallOmnibus( | ||
| address omnibusFrom, | ||
| address omnibusTo, | ||
| externalEaddress externalSender, | ||
| externalEaddress externalRecipient, | ||
| externalEuint64 externalAmount, | ||
| bytes calldata inputProof, | ||
| bytes calldata data | ||
| ) public virtual returns (euint64) { | ||
| eaddress sender = FHE.fromExternal(externalSender, inputProof); | ||
| eaddress recipient = FHE.fromExternal(externalRecipient, inputProof); | ||
| euint64 amount = FHE.fromExternal(externalAmount, inputProof); | ||
|
|
||
| return _confidentialTransferFromAndCallOmnibus(omnibusFrom, omnibusTo, sender, recipient, amount, data); | ||
| } | ||
|
|
||
| /// @dev Wraps the {confidentialTransferFromAndCall-address-address-euint64-bytes} function and emits the {OmnibusConfidentialTransfer} event. | ||
| function confidentialTransferFromAndCallOmnibus( | ||
| address omnibusFrom, | ||
| address omnibusTo, | ||
| eaddress sender, | ||
| eaddress recipient, | ||
| euint64 amount, | ||
| bytes calldata data | ||
| ) public virtual returns (euint64) { | ||
| require(FHE.isAllowed(sender, msg.sender), ERC7984UnauthorizedUseOfEncryptedAddress(sender, msg.sender)); | ||
| require(FHE.isAllowed(recipient, msg.sender), ERC7984UnauthorizedUseOfEncryptedAddress(recipient, msg.sender)); | ||
|
|
||
| return _confidentialTransferFromAndCallOmnibus(omnibusFrom, omnibusTo, sender, recipient, amount, data); | ||
| } | ||
|
|
||
| /// @dev Handles the ACL allowances, does the transfer without a callback, and emits {OmnibusConfidentialTransfer}. | ||
| function _confidentialTransferFromOmnibus( | ||
| address omnibusFrom, | ||
| address omnibusTo, | ||
| eaddress sender, | ||
| eaddress recipient, | ||
| euint64 amount | ||
| ) internal virtual returns (euint64) { | ||
| FHE.allowThis(sender); | ||
| FHE.allow(sender, omnibusFrom); | ||
| FHE.allow(sender, omnibusTo); | ||
|
|
||
| FHE.allowThis(recipient); | ||
| FHE.allow(recipient, omnibusFrom); | ||
| FHE.allow(recipient, omnibusTo); | ||
|
|
||
| euint64 transferred = confidentialTransferFrom(omnibusFrom, omnibusTo, amount); | ||
| emit OmnibusConfidentialTransfer(omnibusFrom, omnibusTo, sender, recipient, transferred); | ||
| return transferred; | ||
| } | ||
|
|
||
| /// @dev Handles the ACL allowances, does the transfer with a callback, and emits {OmnibusConfidentialTransfer}. | ||
| function _confidentialTransferFromAndCallOmnibus( | ||
| address omnibusFrom, | ||
| address omnibusTo, | ||
| eaddress sender, | ||
| eaddress recipient, | ||
| euint64 amount, | ||
| bytes calldata data | ||
| ) internal virtual returns (euint64) { | ||
| euint64 transferred = confidentialTransferFromAndCall(omnibusFrom, omnibusTo, amount, data); | ||
|
|
||
| FHE.allowThis(sender); | ||
| FHE.allow(sender, omnibusFrom); | ||
| FHE.allow(sender, omnibusTo); | ||
|
|
||
| FHE.allowThis(recipient); | ||
| FHE.allow(recipient, omnibusFrom); | ||
| FHE.allow(recipient, omnibusTo); | ||
|
|
||
| FHE.allowThis(transferred); | ||
| FHE.allow(transferred, omnibusFrom); | ||
| FHE.allow(transferred, omnibusTo); | ||
|
|
||
| emit OmnibusConfidentialTransfer(omnibusFrom, omnibusTo, sender, recipient, transferred); | ||
| return transferred; | ||
| } | ||
james-toussaint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
james-toussaint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.