Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
da8a1f23
Unverified
Commit
da8a1f23
authored
Oct 23, 2023
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(ctb): Extract execTransactionFromModule calls into helper functions
parent
20a0c6c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
39 deletions
+42
-39
LivenessModule.sol
packages/contracts-bedrock/src/Safe/LivenessModule.sol
+42
-39
No files found.
packages/contracts-bedrock/src/Safe/LivenessModule.sol
View file @
da8a1f23
...
@@ -83,59 +83,64 @@ contract LivenessModule is ISemver {
...
@@ -83,59 +83,64 @@ contract LivenessModule is ISemver {
uint256 numOwners = owners.length - 1;
uint256 numOwners = owners.length - 1;
uint256 thresholdAfter;
uint256 thresholdAfter;
if (hasMinOwners(numOwners)) {
if (hasMinOwners(numOwners)) {
// Preserves the invariant that the Safe has at least
8 o
wners
// Preserves the invariant that the Safe has at least
numO
wners
thresholdAfter = get75PercentThreshold(numOwners);
thresholdAfter = get75PercentThreshold(numOwners);
console.log("removing one owner. numOwners: %s, thresholdAfter: %s", numOwners, thresholdAfter);
console.log("removing one owner. numOwners: %s, thresholdAfter: %s", numOwners, thresholdAfter);
safe.execTransactionFromModule({
address prevOwner = _getPrevOwner(owner, owners);
to: address(safe),
// Call the Safe to remove the owner
value: 0,
_removeOwner({ _prevOwner: prevOwner, _owner: owner, _threshold: thresholdAfter });
data: abi.encodeCall(
// Call the Safe to remove the owner
OwnerManager.removeOwner,
(getPrevOwner(owner, owners), owner, thresholdAfter)
),
operation: Enum.Operation.Call
});
} else {
} else {
console.log("removing all owners. numOwnersAfter: %s", numOwners);
console.log("removing all owners. numOwnersAfter: %s", numOwners);
// The number of owners is dangerously low, so we wish to transfer the ownership of this Safe
to a new
// The number of owners is dangerously low, so we wish to transfer the ownership of this Safe
// to the fallback owner.
// to the fallback owner.
// The threshold will be 1 because we are removing all owners except the fallback owner
// The threshold will be 1 because we are removing all owners except the fallback owner
thresholdAfter = 1;
// thresholdAfter = 1; // todo: why is this here? We should be able to delete it.
// Remove owners one at a time starting from the last owner.
// Remove owners one at a time starting from the last owner.
// Since we're removing them in order, the ordering will remain constant,
// Since we're removing them in order
from last to first
, the ordering will remain constant,
//
and we shouldn't need to query the list of owners again.
// and we shouldn't need to query the list of owners again.
for (uint256 i = owners.length - 1; i >= 0; i--) {
for (uint256 i = owners.length - 1; i >= 0; i--) {
address currentOwner = owners[i];
address currentOwner = owners[i];
address prevOwner = getPrevOwner(currentOwner, owners);
address prevOwner =
_
getPrevOwner(currentOwner, owners);
if (currentOwner != address(this)) {
if (currentOwner != address(this)) {
safe.execTransactionFromModule({
// Call the Safe to remove the owner
to: address(safe),
_removeOwner({ _prevOwner: prevOwner, _owner: currentOwner, _threshold: 1 });
value: 0,
data: abi.encodeCall(
// Call the Safe to remove the owner
OwnerManager.removeOwner,
(prevOwner, currentOwner, 1)
),
operation: Enum.Operation.Call
});
}
}
}
}
// Add the fallback owner as the sole owner of the Safe
// Add the fallback owner as the sole owner of the Safe
safe.execTransactionFromModule({
_addOwnerWithThreshold({ _owner: fallbackOwner, _threshold: 1 });
to: address(safe),
value: 0,
data: abi.encodeCall(OwnerManager.addOwnerWithThreshold, (fallbackOwner, 1)),
operation: Enum.Operation.Call
});
}
}
_verifyFinalState();
_verifyFinalState();
}
}
/// @notice Adds the owner `owner` to the Safe and updates the threshold to `_threshold`.
/// @param _owner New owner address.
/// @param _threshold New threshold.
function _addOwnerWithThreshold(address _owner, uint256 _threshold) internal {
safe.execTransactionFromModule({
to: address(safe),
value: 0,
operation: Enum.Operation.Call,
data: abi.encodeCall(OwnerManager.addOwnerWithThreshold, (_owner, _threshold))
});
}
/// @notice Removes the owner `owner` from the Safe and updates the threshold to `_threshold`.
/// @param _prevOwner Owner that pointed to the owner to be removed in the linked list
/// @param _owner Owner address to be removed.
/// @param _threshold New threshold.
function _removeOwner(address _prevOwner, address _owner, uint256 _threshold) internal {
safe.execTransactionFromModule({
to: address(safe),
value: 0,
operation: Enum.Operation.Call,
data: abi.encodeCall(OwnerManager.removeOwner, (_prevOwner, _owner, _threshold))
});
}
/// @notice A FREI-PI invariant check enforcing requirements on number of owners and threshold.
/// @notice A FREI-PI invariant check enforcing requirements on number of owners and threshold.
function _verifyFinalState() internal view {
function _verifyFinalState() internal view {
address[] memory owners = safe.getOwners();
address[] memory owners = safe.getOwners();
...
@@ -154,16 +159,14 @@ contract LivenessModule is ISemver {
...
@@ -154,16 +159,14 @@ contract LivenessModule is ISemver {
}
}
/// @notice Get the previous owner in the linked list of owners
/// @notice Get the previous owner in the linked list of owners
function
getPrevOwner(address owner, address[] memory owners) public
pure returns (address prevOwner_) {
function
_getPrevOwner(address owner, address[] memory owners) internal
pure returns (address prevOwner_) {
for (uint256 i = 0; i < owners.length; i++) {
for (uint256 i = 0; i < owners.length; i++) {
if (owners[i] == owner) {
if (owners[i] != owner) continue;
if (i == 0) {
if (i == 0) {
prevOwner_ = SENTINEL_OWNERS;
prevOwner_ = SENTINEL_OWNERS;
break;
}
prevOwner_ = owners[i - 1];
break;
break;
}
}
prevOwner_ = owners[i - 1];
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment