Skip to content
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

Auryn/unit-tests #99

Merged
merged 8 commits into from
Sep 19, 2024
2 changes: 1 addition & 1 deletion packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
CommitteeSelectionFailed()
);

emit E3Requested(e3Id, e3s[e3Id], filter, e3Program);
emit E3Requested(e3Id, e3, filter, e3Program);
}

function activate(uint256 e3Id) external returns (bool success) {
Expand Down
56 changes: 29 additions & 27 deletions packages/evm/contracts/registry/CiphernodeRegistryOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {
uint256 public numCiphernodes;
LeanIMTData public ciphernodes;

mapping(uint256 e3Id => IRegistryFilter filter) public requests;
mapping(uint256 e3Id => IRegistryFilter filter) public filters;
mapping(uint256 e3Id => uint256 root) public roots;
mapping(uint256 e3Id => bytes publicKey) public publicKeys;

Expand All @@ -36,7 +36,7 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {

error CommitteeAlreadyRequested();
error CommitteeAlreadyPublished();
error CommitteeDoesNotExist();
error OnlyFilter();
error CommitteeNotPublished();
error CiphernodeNotEnabled(address node);
error OnlyEnclave();
Expand Down Expand Up @@ -80,10 +80,10 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {
uint32[2] calldata threshold
) external onlyEnclave returns (bool success) {
require(
requests[e3Id] == IRegistryFilter(address(0)),
filters[e3Id] == IRegistryFilter(address(0)),
CommitteeAlreadyRequested()
);
requests[e3Id] = IRegistryFilter(filter);
filters[e3Id] = IRegistryFilter(filter);
roots[e3Id] = root();

IRegistryFilter(filter).requestCommittee(e3Id, threshold);
Expand All @@ -97,23 +97,12 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {
bytes calldata publicKey
) external {
// only to be published by the filter
require(address(requests[e3Id]) == msg.sender, CommitteeDoesNotExist());
require(address(filters[e3Id]) == msg.sender, OnlyFilter());

publicKeys[e3Id] = publicKey;
emit CommitteePublished(e3Id, publicKey);
}

////////////////////////////////////////////////////////////
// //
// Set Functions //
// //
////////////////////////////////////////////////////////////

function setEnclave(address _enclave) public onlyOwner {
enclave = _enclave;
emit EnclaveSet(_enclave);
}

function addCiphernode(address node) external onlyOwner {
uint160 ciphernode = uint160(node);
ciphernodes._insert(ciphernode);
Expand All @@ -130,21 +119,22 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {
address node,
uint256[] calldata siblingNodes
) external onlyOwner {
uint256 ciphernode = uint256(bytes32(bytes20(node)));
ciphernodes._remove(ciphernode, siblingNodes);
uint160 ciphernode = uint160(node);
uint256 index = ciphernodes._indexOf(ciphernode);
ciphernodes._remove(ciphernode, siblingNodes);
numCiphernodes--;
emit CiphernodeAdded(
node,
ciphernodes._indexOf(ciphernode),
numCiphernodes,
ciphernodes.size
);
emit CiphernodeRemoved(node, index, numCiphernodes, ciphernodes.size);
}

function isCiphernodeEligible(address node) external view returns (bool) {
return isEnabled(node);
////////////////////////////////////////////////////////////
// //
// Set Functions //
// //
////////////////////////////////////////////////////////////

function setEnclave(address _enclave) public onlyOwner {
enclave = _enclave;
emit EnclaveSet(_enclave);
}

////////////////////////////////////////////////////////////
Expand All @@ -160,8 +150,12 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {
require(publicKey.length > 0, CommitteeNotPublished());
}

function isCiphernodeEligible(address node) external view returns (bool) {
return isEnabled(node);
}

function isEnabled(address node) public view returns (bool) {
return ciphernodes._has(uint256(bytes32(bytes20(node))));
return ciphernodes._has(uint160(node));
}

function root() public view returns (uint256) {
Expand All @@ -171,4 +165,12 @@ contract CiphernodeRegistryOwnable is ICiphernodeRegistry, OwnableUpgradeable {
function rootAt(uint256 e3Id) public view returns (uint256) {
return roots[e3Id];
}

function getFilter(uint256 e3Id) public view returns (IRegistryFilter) {
return filters[e3Id];
}

function treeSize() public view returns (uint256) {
return ciphernodes.size;
}
}
12 changes: 12 additions & 0 deletions packages/evm/contracts/registry/NaiveRegistryFilter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,16 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
function setRegistry(address _registry) public onlyOwner {
registry = _registry;
}

////////////////////////////////////////////////////////////
// //
// Get Functions //
// //
////////////////////////////////////////////////////////////

function getCommittee(
uint256 e3Id
) external view returns (Committee memory) {
return committees[e3Id];
}
}
Loading
Loading