diff --git a/packages/hebao_v2/contracts/base/SmartWallet.sol b/packages/hebao_v2/contracts/base/SmartWallet.sol index eec0cac90..ff6c7353f 100644 --- a/packages/hebao_v2/contracts/base/SmartWallet.sol +++ b/packages/hebao_v2/contracts/base/SmartWallet.sol @@ -108,12 +108,12 @@ contract SmartWallet is ERC1271 require(owner != address(0), "INVALID_OWNER"); wallet.owner = owner; - if (guardians.length != 0) { - wallet.setInitialGuardians(guardians); - } + wallet.addGuardiansImmediately(guardians); + if (quota != 0) { wallet.setQuota(quota, 0); } + if (inheritor != address(0)) { wallet.setInheritor(inheritor, 365 days); } diff --git a/packages/hebao_v2/contracts/base/libwallet/GuardianLib.sol b/packages/hebao_v2/contracts/base/libwallet/GuardianLib.sol index e7266061f..1be506a4e 100644 --- a/packages/hebao_v2/contracts/base/libwallet/GuardianLib.sol +++ b/packages/hebao_v2/contracts/base/libwallet/GuardianLib.sol @@ -35,15 +35,17 @@ library GuardianLib event GuardianAdded (address guardian, uint effectiveTime); event GuardianRemoved (address guardian, uint effectiveTime); - function setInitialGuardians( + function addGuardiansImmediately( Wallet storage wallet, address[] memory _guardians ) external { - require(_guardians.length < MAX_GUARDIANS, "TOO_MANY_GUARDIANS"); - for (uint i = 0; i < _guardians.length; i++) { - _addGuardian(wallet, _guardians[i], 0, true); + address guardian = address(0); + for (uint i = 0; i < _guardians.length; i++) { + require(_guardians[i] > guardian, "INVALID_ORDERING"); + guardian = _guardians[i]; + _addGuardian(wallet, guardian, 0, true); } } @@ -314,7 +316,7 @@ library GuardianLib uint pos = wallet.guardianIdx[addr]; - if(pos == 0) { + if (pos == 0) { // Add the new guardian Guardian memory _g = Guardian( addr, diff --git a/packages/hebao_v2/contracts/base/libwallet/RecoverLib.sol b/packages/hebao_v2/contracts/base/libwallet/RecoverLib.sol index 56915d662..1c8bc7b4b 100644 --- a/packages/hebao_v2/contracts/base/libwallet/RecoverLib.sol +++ b/packages/hebao_v2/contracts/base/libwallet/RecoverLib.sol @@ -56,12 +56,13 @@ library RecoverLib wallet.owner = newOwner; wallet.setLock(address(this), false); + if (newGuardians.length > 0) { - wallet.removeAllGuardians(); for (uint i = 0; i < newGuardians.length; i++) { require(newGuardians[i] != newOwner, "INVALID_NEW_WALLET_GUARDIAN"); } - wallet.setInitialGuardians(newGuardians); + wallet.removeAllGuardians(); + wallet.addGuardiansImmediately(newGuardians); } else { if (wallet.isGuardian(newOwner, true)) { wallet.deleteGuardian(newOwner, block.timestamp, true); diff --git a/packages/hebao_v2/contracts/base/libwallet/WalletData.sol b/packages/hebao_v2/contracts/base/libwallet/WalletData.sol index f00c593fb..0429ed3b3 100644 --- a/packages/hebao_v2/contracts/base/libwallet/WalletData.sol +++ b/packages/hebao_v2/contracts/base/libwallet/WalletData.sol @@ -51,7 +51,7 @@ struct Wallet // relayer => nonce uint nonce; // hash => consumed - mapping(bytes32 => bool) hashes; + mapping (bytes32 => bool) hashes; bool locked; @@ -65,5 +65,5 @@ struct Wallet Quota quota; // whitelisted address => effective timestamp - mapping(address => uint) whitelisted; + mapping (address => uint) whitelisted; } diff --git a/packages/hebao_v2/contracts/test/LRCToken.sol b/packages/hebao_v2/contracts/test/LRCToken.sol index f358010d6..1b23a2009 100644 --- a/packages/hebao_v2/contracts/test/LRCToken.sol +++ b/packages/hebao_v2/contracts/test/LRCToken.sol @@ -62,7 +62,7 @@ library SafeMath { */ contract BasicToken is ERC20Basic { using SafeMath for uint; - mapping(address => uint) balances; + mapping (address => uint) balances; uint totalSupply_; /** * @dev total number of tokens in existence diff --git a/packages/hebao_v2/contracts/thirdparty/MockContract.sol b/packages/hebao_v2/contracts/thirdparty/MockContract.sol index 32e8b12c3..eace54c2f 100644 --- a/packages/hebao_v2/contracts/thirdparty/MockContract.sol +++ b/packages/hebao_v2/contracts/thirdparty/MockContract.sol @@ -87,17 +87,17 @@ contract MockContract is MockInterface { bytes4 public constant SENTINEL_ANY_MOCKS = hex"01"; // A linked list allows easy iteration and inclusion checks - mapping(bytes32 => bytes) calldataMocks; - mapping(bytes => MockType) calldataMockTypes; - mapping(bytes => bytes) calldataExpectations; - mapping(bytes => string) calldataRevertMessage; - mapping(bytes32 => uint) calldataInvocations; - - mapping(bytes4 => bytes4) methodIdMocks; - mapping(bytes4 => MockType) methodIdMockTypes; - mapping(bytes4 => bytes) methodIdExpectations; - mapping(bytes4 => string) methodIdRevertMessages; - mapping(bytes32 => uint) methodIdInvocations; + mapping (bytes32 => bytes) calldataMocks; + mapping (bytes => MockType) calldataMockTypes; + mapping (bytes => bytes) calldataExpectations; + mapping (bytes => string) calldataRevertMessage; + mapping (bytes32 => uint) calldataInvocations; + + mapping (bytes4 => bytes4) methodIdMocks; + mapping (bytes4 => MockType) methodIdMockTypes; + mapping (bytes4 => bytes) methodIdExpectations; + mapping (bytes4 => string) methodIdRevertMessages; + mapping (bytes32 => uint) methodIdInvocations; MockType fallbackMockType; bytes fallbackExpectation; @@ -262,7 +262,7 @@ contract MockContract is MockInterface { bytes memory nextMock = calldataMocks[MOCKS_LIST_START]; bytes32 mockHash = keccak256(nextMock); // We cannot compary bytes - while(mockHash != MOCKS_LIST_END_HASH) { + while (mockHash != MOCKS_LIST_END_HASH) { // Reset all mock maps calldataMockTypes[nextMock] = MockType.Return; calldataExpectations[nextMock] = hex""; @@ -279,7 +279,7 @@ contract MockContract is MockInterface { // Reset all any calldataMocks bytes4 nextAnyMock = methodIdMocks[SENTINEL_ANY_MOCKS]; - while(nextAnyMock != SENTINEL_ANY_MOCKS) { + while (nextAnyMock != SENTINEL_ANY_MOCKS) { bytes4 currentAnyMock = nextAnyMock; methodIdMockTypes[currentAnyMock] = MockType.Return; methodIdExpectations[currentAnyMock] = hex""; @@ -298,7 +298,7 @@ contract MockContract is MockInterface { } function useAllGas() private { - while(true) { + while (true) { bool s; assembly { //expensive call to EC multiply contract diff --git a/packages/hebao_v2/contracts/thirdparty/strings.sol b/packages/hebao_v2/contracts/thirdparty/strings.sol index c2bfec675..ae6b91b9b 100644 --- a/packages/hebao_v2/contracts/thirdparty/strings.sol +++ b/packages/hebao_v2/contracts/thirdparty/strings.sol @@ -46,7 +46,7 @@ library strings { function memcpy(uint dest, uint src, uint _len) private pure { // Copy word-length chunks while possible - for(; _len >= 32; _len -= 32) { + for (; _len >= 32; _len -= 32) { assembly { mstore(dest, mload(src)) } @@ -165,13 +165,13 @@ library strings { assembly { b := and(mload(ptr), 0xFF) } if (b < 0x80) { ptr += 1; - } else if(b < 0xE0) { + } else if (b < 0xE0) { ptr += 2; - } else if(b < 0xF0) { + } else if (b < 0xF0) { ptr += 3; - } else if(b < 0xF8) { + } else if (b < 0xF8) { ptr += 4; - } else if(b < 0xFC) { + } else if (b < 0xFC) { ptr += 5; } else { ptr += 6; @@ -214,7 +214,7 @@ library strings { if (a != b) { // Mask out irrelevant bytes and check again uint256 mask = uint256(-1); // 0xffff... - if(shortest < 32) { + if (shortest < 32) { mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); } uint256 diff = (a & mask) - (b & mask); @@ -258,9 +258,9 @@ library strings { assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } if (b < 0x80) { l = 1; - } else if(b < 0xE0) { + } else if (b < 0xE0) { l = 2; - } else if(b < 0xF0) { + } else if (b < 0xF0) { l = 3; } else { l = 4; @@ -310,10 +310,10 @@ library strings { if (b < 0x80) { ret = b; length = 1; - } else if(b < 0xE0) { + } else if (b < 0xE0) { ret = b & 0x1F; length = 2; - } else if(b < 0xF0) { + } else if (b < 0xF0) { ret = b & 0x0F; length = 3; } else { @@ -697,14 +697,14 @@ library strings { return ""; uint length = self._len * (parts.length - 1); - for(uint i = 0; i < parts.length; i++) + for (uint i = 0; i < parts.length; i++) length += parts[i]._len; string memory ret = new string(length); uint retptr; assembly { retptr := add(ret, 32) } - for(uint i = 0; i < parts.length; i++) { + for (uint i = 0; i < parts.length; i++) { memcpy(retptr, parts[i]._ptr, parts[i]._len); retptr += parts[i]._len; if (i < parts.length - 1) {