Commit 3033dd63 authored by Maurelian's avatar Maurelian

feat(ctb): Remove redundant check in LivenessModule

test(ctb): Add test for get75PercentThreshold
parent b6a38049
......@@ -305,6 +305,11 @@ LegacyERC20ETH_Test:test_transferFrom_doesNotExist_reverts() (gas: 12957)
LegacyERC20ETH_Test:test_transfer_doesNotExist_reverts() (gas: 10755)
LegacyMessagePasser_Test:test_passMessageToL1_succeeds() (gas: 34524)
LibPosition_Test:test_pos_correctness_succeeds() (gas: 38689)
LivenessGuard_ShowLiveness_Test:test_showLiveness_succeeds() (gas: 51339)
LivenessModule_Get75PercentThreshold_Test:test_get75PercentThreshold_Works() (gas: 26339)
LivenessModule_RemoveOwner_Test:test_removeOwner_allOwners_succeeds() (gas: 159764)
LivenessModule_RemoveOwner_Test:test_removeOwner_oneOwner_succeeds() (gas: 109028)
LivnessGuard_CheckTx_Test:test_checkTransaction_succeeds() (gas: 160454)
MIPS_Test:test_add_succeeds() (gas: 122932)
MIPS_Test:test_addiSign_succeeds() (gas: 122923)
MIPS_Test:test_addi_succeeds() (gas: 123120)
......
......@@ -18,6 +18,8 @@
"src/L2/L2StandardBridge.sol": "0x284ebf5569c75d98f2d1920a276d1116524399355708c4a60ea5892283c56719",
"src/L2/L2ToL1MessagePasser.sol": "0xafc710b4d320ef450586d96a61cbd58cac814cb3b0c4fdc280eace3efdcdf321",
"src/L2/SequencerFeeVault.sol": "0x883e434a69b4789997a4a9a32060dbbd2e12db6f1970927f1310820336119575",
"src/Safe/LivenessGuard.sol": "0x31b4ecc88c982490243ab42914c3de75e5acfa421ffc0ea0d0f0997dcc0341b5",
"src/Safe/LivenessModule.sol": "0xb8c8178c1f4f78eed4777846a40eda6a3a0c1710085822d92267339ae752799b",
"src/dispute/BlockOracle.sol": "0x7e724b1ee0116dfd744f556e6237af449c2f40c6426d6f1462ae2a47589283bb",
"src/dispute/DisputeGameFactory.sol": "0xfdfa141408d7f8de7e230ff4bef088e30d0e4d569ca743d60d292abdd21ff270",
"src/dispute/FaultDisputeGame.sol": "0x0766707ab32338a6586c2340ddfbfd4e9023eeb9dfa3ef87e4b404fb0260479f",
......
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { Safe } from "safe-contracts/Safe.sol";
import { Safe, OwnerManager } from "safe-contracts/Safe.sol";
import { Enum } from "safe-contracts/common/Enum.sol";
import { OwnerManager } from "safe-contracts/base/OwnerManager.sol";
import { LivenessGuard } from "src/Safe/LivenessGuard.sol";
......@@ -29,6 +29,9 @@ contract LivenessModule is ISemver {
/// @notice The fallback owner of the Safe
address public fallbackOwner;
/// @notice The address of the first owner in the linked list of owners
address internal constant SENTINEL_OWNERS = address(0x1);
/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.0";
......@@ -120,15 +123,15 @@ contract LivenessModule is ISemver {
address[] memory owners = safe.getOwners();
uint256 numOwners = owners.length;
require(
(numOwners == 1 && owners[0] == fallbackOwner) || (numOwners >= minOwners),
"LivenessModule: Safe must have at least 1 owner or minOwners"
(numOwners >= minOwners) || (numOwners == 1 && owners[0] == fallbackOwner),
"LivenessModule: Safe must have the minimum number of owners, or be owned solely by the fallback owner"
);
// Check that the threshold is correct
uint256 threshold = safe.getThreshold();
require(
threshold == get75PercentThreshold(numOwners) || (numOwners == 1 && threshold == 1),
"LivenessModule: threshold must be 75% of the number of owners, or 1 if there is only 1 owner"
threshold == get75PercentThreshold(numOwners),
"LivenessModule: threshold must be 75% of the number of owners"
);
}
......@@ -137,7 +140,7 @@ contract LivenessModule is ISemver {
for (uint256 i = 0; i < owners.length; i++) {
if (owners[i] == owner) {
if (i == 0) {
prevOwner_ = address(0x1); // OwnerManager.SENTINEL_OWNERS
prevOwner_ = SENTINEL_OWNERS;
break;
}
prevOwner_ = owners[i - 1];
......@@ -147,6 +150,7 @@ contract LivenessModule is ISemver {
}
/// @notice For a given number of owners, return the lowest threshold which is greater than 75.
/// Note: this function returns 1 for numOwners == 1.
function get75PercentThreshold(uint256 _numOwners) public pure returns (uint256 threshold_) {
threshold_ = (_numOwners * 75 + 99) / 100;
}
......
......@@ -36,6 +36,33 @@ contract LivnessModule_TestInit is Test, SafeTestTools {
}
}
contract LivenessModule_Get75PercentThreshold_Test is LivnessModule_TestInit {
/// @dev check the return values of the get75PercentThreshold function against manually
/// calculated values.
function test_get75PercentThreshold_Works() external {
assertEq(livenessModule.get75PercentThreshold(20), 15);
assertEq(livenessModule.get75PercentThreshold(19), 15);
assertEq(livenessModule.get75PercentThreshold(18), 14);
assertEq(livenessModule.get75PercentThreshold(17), 13);
assertEq(livenessModule.get75PercentThreshold(16), 12);
assertEq(livenessModule.get75PercentThreshold(15), 12);
assertEq(livenessModule.get75PercentThreshold(14), 11);
assertEq(livenessModule.get75PercentThreshold(13), 10);
assertEq(livenessModule.get75PercentThreshold(12), 9);
assertEq(livenessModule.get75PercentThreshold(11), 9);
assertEq(livenessModule.get75PercentThreshold(10), 8);
assertEq(livenessModule.get75PercentThreshold(9), 7);
assertEq(livenessModule.get75PercentThreshold(8), 6);
assertEq(livenessModule.get75PercentThreshold(7), 6);
assertEq(livenessModule.get75PercentThreshold(6), 5);
assertEq(livenessModule.get75PercentThreshold(5), 4);
assertEq(livenessModule.get75PercentThreshold(4), 3);
assertEq(livenessModule.get75PercentThreshold(3), 3);
assertEq(livenessModule.get75PercentThreshold(2), 2);
assertEq(livenessModule.get75PercentThreshold(1), 1);
}
}
contract LivenessModule_RemoveOwner_Test is LivnessModule_TestInit {
function test_removeOwner_oneOwner_succeeds() external {
uint256 ownersBefore = safeInstance.owners.length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment