Skip to content

Commit 4563dd7

Browse files
committed
Document GROUP_INDEX_FLAG usage
1 parent 21e70e7 commit 4563dd7

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

solidity/contracts/libraries/operator/Groups.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ library Groups {
1010
using SafeMath for uint256;
1111
using BytesLib for bytes;
1212

13+
// The index of a group is flagged with the most significant bit set,
14+
// to distinguish the group `0` from null.
15+
// The flag is toggled with bitwise XOR (`^`)
16+
// which keeps all other bits intact but flips the flag bit.
1317
uint256 constant GROUP_INDEX_FLAG = 1 << 255;
1418

1519
struct Group {
@@ -56,7 +60,7 @@ library Groups {
5660
Storage storage self,
5761
bytes memory groupPubKey
5862
) internal {
59-
self.groupIndices[groupPubKey] = (self.groups.length | GROUP_INDEX_FLAG);
63+
self.groupIndices[groupPubKey] = (self.groups.length ^ GROUP_INDEX_FLAG);
6064
self.groups.push(Group(groupPubKey, uint64(block.number), false));
6165
}
6266

0 commit comments

Comments
 (0)