Skip to content

Commit

Permalink
Store threshold in ritual struct, but not allow initiator to set it f…
Browse files Browse the repository at this point in the history
…or the moment

We currently define it as the lowest value that produces a threshold set that's strictly greater than the 50% of the overall size.
See nucypher/nucypher#3095
  • Loading branch information
cygnusv committed Aug 21, 2023
1 parent cd4c65a commit 2c27bc7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ contract Coordinator is AccessControlDefaultAdminRules {
bytes decryptionRequestStaticKey;
}

// TODO: Optimize layout
struct Ritual {
address initiator;
uint32 initTimestamp;
uint32 endTimestamp;
uint16 totalTranscripts;
uint16 totalAggregations;

address authority;
uint16 dkgSize;
uint16 threshold;
bool aggregationMismatch;

IEncryptionAuthorizer accessController;
BLS12381.G1Point publicKey;
bytes aggregatedTranscript;
Expand Down Expand Up @@ -197,6 +199,11 @@ contract Coordinator is AccessControlDefaultAdminRules {
return ritual.participant;
}

function getThresholdForRitualSize(uint16 size) public pure returns (uint16) {
return 1 + size / 2;
// Alternatively: 1 + 2*size/3 (for >66.6%) or 1 + 3*size/5 (for >60%)
}

function initiateRitual(
address[] calldata providers,
address authority,
Expand All @@ -210,16 +217,16 @@ contract Coordinator is AccessControlDefaultAdminRules {
isInitiationPublic || hasRole(INITIATOR_ROLE, msg.sender),
"Sender can't initiate ritual"
);
// TODO: Validate service fees, expiration dates, threshold
uint256 length = providers.length;
uint16 length = uint16(providers.length);
require(2 <= length && length <= maxDkgSize, "Invalid number of nodes");
require(duration > 0, "Invalid ritual duration"); // TODO: We probably want to restrict it more

uint32 id = uint32(rituals.length);
Ritual storage ritual = rituals.push();
ritual.initiator = msg.sender;
ritual.authority = authority;
ritual.dkgSize = uint16(length);
ritual.dkgSize = length;
ritual.threshold = getThresholdForRitualSize(length);
ritual.initTimestamp = uint32(block.timestamp);
ritual.endTimestamp = ritual.initTimestamp + duration;
ritual.accessController = accessController;
Expand Down

0 comments on commit 2c27bc7

Please sign in to comment.