Skip to content

Commit

Permalink
hashConsensus gas optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
bulbozaur committed Dec 6, 2024
1 parent 8c28258 commit 4bf7a80
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions contracts/committees/HashConsensus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ abstract contract HashConsensus is Ownable {
/// @param newMembers The array of addresses to be added as new members.
/// @param executionQuorum The minimum number of members required for executing certain operations.
function _addMembers(address[] memory newMembers, uint256 executionQuorum) internal {
for (uint256 i = 0; i < newMembers.length; ++i) {
uint256 membersCount = newMembers.length;

for (uint256 i = 0; i < membersCount; ++i) {
if (newMembers[i] == address(0)) {
revert InvalidMemberAccount(newMembers[i]);
}
Expand All @@ -270,7 +272,8 @@ abstract contract HashConsensus is Ownable {
/// @param membersToRemove The array of addresses to be removed from the members list.
/// @param executionQuorum The updated minimum number of members required for executing certain operations.
function _removeMembers(address[] memory membersToRemove, uint256 executionQuorum) internal {
for (uint256 i = 0; i < membersToRemove.length; ++i) {
uint256 membersCount = membersToRemove.length;
for (uint256 i = 0; i < membersCount; ++i) {
if (!_members.remove(membersToRemove[i])) {
revert AccountIsNotMember(membersToRemove[i]);
}
Expand All @@ -285,7 +288,9 @@ abstract contract HashConsensus is Ownable {
/// @param hash The hash to check
/// @return support The number of votes in support of the hash
function _getSupport(bytes32 hash) internal view returns (uint256 support) {
for (uint256 i = 0; i < _members.length(); ++i) {
uint256 membersCount = _members.length();

for (uint256 i = 0; i < membersCount; ++i) {
if (approves[_members.at(i)][hash]) {
support++;
}
Expand Down

0 comments on commit 4bf7a80

Please sign in to comment.