chore: rename commitmentIndex to nextCommitmentIndex

This commit is contained in:
Richard Ramos 2024-09-11 10:36:02 -04:00
parent 22ddb35d34
commit a658315e03
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
3 changed files with 16 additions and 16 deletions

View File

@ -54,8 +54,8 @@ contract Membership {
/// @notice List of registered memberships
mapping(uint256 idCommitment => MembershipInfo member) public members;
/// @notice The index of the next member to be registered
uint32 public commitmentIndex;
/// @notice The index on the merkle tree for the next member to be registered
uint32 public nextCommitmentIndex;
/// @notice track available indices that are available due to expired memberships being removed
uint32[] public availableExpiredIndices;
@ -273,7 +273,7 @@ contract Membership {
availableExpiredIndices.pop();
reusedIndex = true;
} else {
index = commitmentIndex;
index = nextCommitmentIndex;
}
}

View File

@ -96,7 +96,7 @@ contract WakuRlnV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable, Member
SET_SIZE = uint32(1 << DEPTH);
deployedBlockNumber = uint32(block.number);
LazyIMT.init(imtData, DEPTH);
commitmentIndex = 0;
nextCommitmentIndex = 0;
}
function _authorizeUpgrade(address newImplementation) internal override onlyOwner { } // solhint-disable-line
@ -183,14 +183,14 @@ contract WakuRlnV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable, Member
/// @param reusedIndex indicates whether we're inserting a new element in the merkle tree or updating a existing
/// leaf
function _register(uint256 idCommitment, uint32 userMessageLimit, uint32 index, bool reusedIndex) internal {
if (commitmentIndex >= SET_SIZE) revert FullTree();
if (nextCommitmentIndex >= SET_SIZE) revert FullTree();
uint256 rateCommitment = PoseidonT3.hash([idCommitment, userMessageLimit]);
if (reusedIndex) {
LazyIMT.update(imtData, rateCommitment, index);
} else {
LazyIMT.insert(imtData, rateCommitment);
commitmentIndex += 1;
nextCommitmentIndex += 1;
}
emit MemberRegistered(rateCommitment, index);
@ -202,7 +202,7 @@ contract WakuRlnV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable, Member
/// @return The commitments of the members
function getCommitments(uint32 startIndex, uint32 endIndex) public view returns (uint256[] memory) {
if (startIndex > endIndex) revert InvalidPaginationQuery(startIndex, endIndex);
if (endIndex > commitmentIndex) revert InvalidPaginationQuery(startIndex, endIndex);
if (endIndex > nextCommitmentIndex) revert InvalidPaginationQuery(startIndex, endIndex);
uint256[] memory commitments = new uint256[](endIndex - startIndex + 1);
for (uint32 i = startIndex; i <= endIndex; i++) {

View File

@ -46,7 +46,7 @@ contract WakuRlnV2Test is Test {
token.approve(address(w), price);
w.register(idCommitment, userMessageLimit);
vm.pauseGasMetering();
assertEq(w.commitmentIndex(), 1);
assertEq(w.nextCommitmentIndex(), 1);
assertEq(w.memberExists(idCommitment), true);
(,,,,, uint32 fetchedUserMessageLimit, uint32 index, address holder,) = w.members(idCommitment);
assertEq(fetchedUserMessageLimit, userMessageLimit);
@ -664,7 +664,7 @@ contract WakuRlnV2Test is Test {
token.approve(address(w), price);
w.register(i, 20);
(,,,,,, index,,) = w.members(i);
assertEq(index, w.commitmentIndex() - 1); // TODO: renname commitmentIndex to nextCommitmentIndex
assertEq(index, w.nextCommitmentIndex() - 1);
commitmentsToErase[i - 1] = i;
}
@ -678,7 +678,7 @@ contract WakuRlnV2Test is Test {
assertEq(i, w.availableExpiredIndices(i));
}
uint32 currCommitmentIndex = w.commitmentIndex();
uint32 currnextCommitmentIndex = w.nextCommitmentIndex();
for (uint256 i = 1; i <= idCommitmentsLength; i++) {
uint256 idCommitment = i + 10;
uint256 expectedReusedIndexPos = idCommitmentsLength - i;
@ -691,7 +691,7 @@ contract WakuRlnV2Test is Test {
vm.expectRevert();
w.availableExpiredIndices(expectedReusedIndexPos);
// Should not have been affected
assertEq(currCommitmentIndex, w.commitmentIndex());
assertEq(currnextCommitmentIndex, w.nextCommitmentIndex());
}
// No indexes should be available for reuse
@ -702,8 +702,8 @@ contract WakuRlnV2Test is Test {
token.approve(address(w), price);
w.register(100, 20);
(,,,,,, index,,) = w.members(100);
assertEq(index, currCommitmentIndex);
assertEq(currCommitmentIndex + 1, w.commitmentIndex());
assertEq(index, currnextCommitmentIndex);
assertEq(currnextCommitmentIndex + 1, w.nextCommitmentIndex());
}
function test__RemoveExpiredMemberships(uint32 userMessageLimit) external {
@ -898,7 +898,7 @@ contract WakuRlnV2Test is Test {
/*| Name | Type | Slot | Offset | Bytes |
|---------------------|-----------------------------------------------------|------|--------|-------|
| commitmentIndex | uint32 | 206 | 0 | 4 | */
| nextCommitmentIndex | uint32 | 206 | 0 | 4 | */
/*
Pro tip: to easily find the storage slot of a variable, without having to calculate the storage layout
@ -916,7 +916,7 @@ contract WakuRlnV2Test is Test {
If the storage layout changes, update the next line accordingly
*/
// we set commitmentIndex to 4294967295 (1 << 20) = 0x00100000
// we set nextCommitmentIndex to 4294967295 (1 << 20) = 0x00100000
vm.store(address(w), bytes32(uint256(206)), 0x0000000000000000000000000000000000000000000000000000000000100000);
token.approve(address(w), price);
vm.expectRevert(FullTree.selector);
@ -928,7 +928,7 @@ contract WakuRlnV2Test is Test {
w.getCommitments(1, 0);
}
function test__InvalidPaginationQuery__EndIndexGTcommitmentIndex() external {
function test__InvalidPaginationQuery__EndIndexGTnextCommitmentIndex() external {
vm.expectRevert(abi.encodeWithSelector(InvalidPaginationQuery.selector, 0, 2));
w.getCommitments(0, 2);
}