-
Notifications
You must be signed in to change notification settings - Fork 11
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
TACo Encryption Allow Logic Interfaces #89
Changes from all commits
8d3dbcd
546a8b9
bfb63fa
ae6dda5
4a9f72f
29b3f36
8918d49
5499348
95ccb8b
7e8b9df
441d7ad
908c593
83b406c
5a3bf88
7bbae03
d15dfe8
d4a1c40
ef675bf
0610332
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
pragma solidity ^0.8.0; | ||
import "@openzeppelin/contracts/access/AccessControlDefaultAdminRules.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
import "./IEncryptionAuthorizer.sol"; | ||
import "./Coordinator.sol"; | ||
|
||
|
||
contract GlobalAllowList is AccessControlDefaultAdminRules, IEncryptionAuthorizer { | ||
using ECDSA for bytes32; | ||
|
||
Coordinator public coordinator; | ||
vzotova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mapping(uint256 => mapping(address => bool)) public authorizations; | ||
|
||
constructor( | ||
Coordinator _coordinator, | ||
address _admin | ||
) AccessControlDefaultAdminRules(0, _admin) { | ||
require(address(_coordinator) != address(0), "Coordinator cannot be zero address"); | ||
require(_coordinator.numberOfRituals() >= 0, "Invalid coordinator"); | ||
coordinator = _coordinator; | ||
vzotova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
modifier onlyAuthority(uint32 ritualId) { | ||
require(coordinator.getAuthority(ritualId) == msg.sender, | ||
"Only ritual authority is permitted"); | ||
_; | ||
} | ||
|
||
function setCoordinator(Coordinator _coordinator) public { | ||
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Only admin can set coordinator"); | ||
coordinator = _coordinator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the use case for setting the Coordinator after deployment, if it was already set on construction time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the event the coordinator is redeployed to support a security patch or new feature. |
||
} | ||
|
||
function isAuthorized( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the DKG client supposed to call this method at some point? Fore example, when picking nodes for the DKG cohort? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not when picking nodes for the cohort but rather when decryption is requested from the nodes. Each node that receives a decryption request will check to make sure that this encryptor is allowed to use the corresponding ritual/encrypting key and therefore worthy to be decrypted. This is showcased in WIP PR 3194 - see https://github.com/nucypher/nucypher/pull/3194/files#diff-8df83dacf71b2ff2ca3636cd470cba70eb6b141e3c8843fadfab72514aafa3f6R199 and https://github.com/nucypher/nucypher/pull/3194/files#diff-911a370c18d0d0e3ea62099fc5ff6daa16915da19cf5399f24e404b7d8d6d168R790 |
||
uint32 ritualId, | ||
bytes memory evidence, | ||
bytes32 digest | ||
) public view override returns(bool) { | ||
address recovered_address = digest.toEthSignedMessageHash().recover(evidence); | ||
return authorizations[ritualId][recovered_address]; | ||
} | ||
|
||
function authorize(uint32 ritualId, address[] calldata addresses) public onlyAuthority(ritualId) { | ||
require(coordinator.isRitualFinalized(ritualId), | ||
"Only active rituals can add authorizations"); | ||
for (uint256 i=0; i < addresses.length; i++) { | ||
authorizations[ritualId][addresses[i]] = true; | ||
} | ||
} | ||
|
||
function deauthorize(uint32 ritualId, address[] calldata addresses) public onlyAuthority(ritualId) { | ||
require(coordinator.isRitualFinalized(ritualId), | ||
"Only active rituals can add authorizations"); | ||
for (uint256 i=0; i < addresses.length; i++) { | ||
authorizations[ritualId][addresses[i]] = false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
interface IEncryptionAuthorizer { | ||
function isAuthorized( | ||
uint32 ritualID, | ||
bytes memory evidence, // signature | ||
bytes32 digest // signed message hash | ||
) external view returns(bool); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a comment for this PR, but something to consider I just realized: we may need to discern if a covenant is currently active or not, depending whether it's within its arranged duration or not. The fact that the ritual is
FINALIZED
is a prerequisite for that to happen, of course. I can address that in #107