Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashConsensus gas optimization #234

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 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,9 @@ 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 +289,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
Loading