Skip to content

Commit

Permalink
fix: more efficient duplicate members check
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Sep 23, 2024
1 parent df502c7 commit 522599c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/WakuRlnV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ contract WakuRlnV2 is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, M
_;
}

modifier noDuplicateMembers(uint256 idCommitment) {
if (members[idCommitment].userMessageLimit != 0) revert DuplicateIdCommitment();
_;
}

constructor() {
_disableInitializers();
}
Expand Down Expand Up @@ -133,9 +138,14 @@ contract WakuRlnV2 is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, M
/// @notice Allows a user to register as a member
/// @param idCommitment The idCommitment of the member
/// @param userMessageLimit The message limit of the member
function register(uint256 idCommitment, uint32 userMessageLimit) external onlyValidIdCommitment(idCommitment) {
if (memberExists(idCommitment)) revert DuplicateIdCommitment();

function register(
uint256 idCommitment,
uint32 userMessageLimit
)
external
onlyValidIdCommitment(idCommitment)
noDuplicateMembers(idCommitment)
{
uint32 index;
bool reusedIndex;
(index, reusedIndex) = _acquireMembership(_msgSender(), idCommitment, userMessageLimit, true);
Expand All @@ -154,9 +164,8 @@ contract WakuRlnV2 is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, M
)
external
onlyValidIdCommitment(idCommitment)
noDuplicateMembers(idCommitment)
{
if (memberExists(idCommitment)) revert DuplicateIdCommitment();

for (uint256 i = 0; i < membershipsToErase.length; i++) {
uint256 idCommitmentToErase = membershipsToErase[i];
MembershipInfo memory mdetails = members[idCommitmentToErase];
Expand Down

0 comments on commit 522599c

Please sign in to comment.