Skip to content

Commit b4a5caa

Browse files
dong77Brechtpdkongliangzhongwangdong
authored
[hebao] 1.2.0 (#1926)
* [hebao] hebao optimization for gas reduction (#1891) * [hebao] A few behavior changes and important bug fixes (#1913) Change to use constant values instead of state variables for many configurations Change min guardian count to 1. Change lock period from 1 day to 3 days, change guardian addition/removal pending period from 1 day to 3 days. If a wallet owner's address is leaked, the owner now has more time to react. Fix a bug that we didn't check the number of guardians who signed transactions Allow guardian-approved transactions even if the wallet is locked. add addGuardianImmediately , removeGuardianImmediately and removeFromWhitelistImmediately (not tested yet) * [hebao 1.2] add multiple breaking changes (#1931) * [hebao1.2] fix tests (#1985) * BaseModule has a default bindableMethods impl * Remove MIN_ACTIVE_GUARDIANS and onlyHaveEnoughGuardians * Remove MIN_ACTIVE_GUARDIANS and onlyHaveEnoughGuardians * Remove MIN_ACTIVE_GUARDIANS and onlyHaveEnoughGuardians * [hebao 1.2] #2 lock permanently and unlock with approval (#1932) * lock permanently * lock permanently * lock permanently * more * more * more * more * more * more * more * more * more * more * Allow wallet owner to specify the inheritance waiting period (2 months to 10 years) Allow wallet owner to specify the inheritance waiting period (2 months to 10 years) Co-authored-by: wangdong <[email protected]> * remove two funcitons * Add guardian tx aware (#1937) * remove two funcitons * remove two funcitons Co-authored-by: wangdong <[email protected]> * more * more * remove addGuardiansWithTheirApproval * [Hebao1.2]Remove guardian group (#1938) * remove-guardian-group * more * more * more * fix calculation * more * more * more * owner himself cannot be the majority Co-authored-by: Daniel Wang <[email protected]> * rename trustedForwarder to metaTxForwarder (#1950) * Improve security store & remove all pending guardians after recovery (#1940) * remove-guardian-group * more * more * more * fix calculation * more * more * more * owner himself cannot be the majority * Improve SecurityStore * Improve SecurityStore * Improve SecurityStore * Improve SecurityStore * cancel on recovery * Further Improve security store impl (#1948) * more Co-authored-by: kongliangzhong <[email protected]> Co-authored-by: wangdong <[email protected]> * Shall we require at least one guardian in majority? (#1952) * [hebao] batch call (#1955) * change event name (#1958) * [hebao] add `lockWA` that does not use nonce (#1956) * [hebao 1.2] do not touch last active without inheritor (#1969) * adjust function modifier (#1971) * [hebao1.2] Allow unlimited quota (#1966) * [hebao 1.2] check caller only when necessary in datastore (#1973) * [hebao 1.2] allow disabling quota (or unlimited quota) * more * more * more * more * more * more * [hebao] QuotaStore optimizations (#1970) * fix one small bug * fix one small bug * check caller only when necessary in datastore * check caller only when necessary in datastore * Update GuardianStore.sol * merge * more * more * minor Co-authored-by: Brecht Devos <[email protected]> * [hebao 1.2] Start using immutable (#1979) * [hebao] Start using immutable * [hebao] More immutable * [hebao] Immutable stores in modules (#1981) * [hebao 1.2] remove unused files (#1982) * [hebao] Start using immutable * [hebao] More immutable * [hebao] Immutable stores in modules (#1981) * remove unused files Co-authored-by: Brechtpd <[email protected]> * [hebao1.2] fix tests * update * update * update * fix merge * update * update * update * fix testWalletCreation * update * update * update * update * all tests fixed * Update GuardianModule.sol * update Co-authored-by: Daniel Wang <[email protected]> Co-authored-by: wangdong <[email protected]> Co-authored-by: Brecht Devos <[email protected]> * set MAX_REIMBURSTMENT_OVERHEAD to 70000 * Update ForwarderModule.sol * update UpgraderModule.sol * update build-all-flattened.sh * [hebao 1.2] minor improvements and cleanups -part 1 (#1992) * [hebao 1.2] minor improvements and cleanups -part 2 (#1994) * [hebao 1.2] Minor improvements (#1999) * [hebao 1.2] Minor improvements * [hebao] Consistency * [hebao 1.2] Fix skipQuota (#1996) * [hebao 1.2] change GUARDIAN_PENDING_PERIOD to 3 days (#2006) Co-authored-by: Brecht Devos <[email protected]> Co-authored-by: kongliangzhong <[email protected]> Co-authored-by: wangdong <[email protected]>
1 parent a83618f commit b4a5caa

File tree

97 files changed

+3002
-3691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+3002
-3691
lines changed

packages/hebao_v1/GasUsage.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Gas usage comparison for a simple Ether/LRC transfer (v1.2.0)
2+
3+
| TX Type | Token Transfered | Update Quota? | Reimburst in LRC? | Gas Used |
4+
| :------ | :--------------: | ------------: | ----------------: | -------: |
5+
| MetaTx | ETH | N | N | 80118 |
6+
| MetaTx | ETH | N | Y | 100889 |
7+
| MetaTx | ETH | Y | N | 90916 |
8+
| MetaTx | ETH | Y | Y | 120845 |
9+
| MetaTx | LRC | N | N | 89591 |
10+
| MetaTx | LRC | N | Y | 113181 |
11+
| MetaTx | LRC | Y | N | 103949 |
12+
| MetaTx | LRC | Y | Y | 137625 |
13+
| Plain | ETH | N | N | 53336 |
14+
| Plain | ETH | Y | N | 64218 |
15+
| Plain | LRC | N | N | 62820 |
16+
| Plain | LRC | Y | N | 77166 |

packages/hebao_v1/audit_report_solidified_response.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,17 @@ Addressed in PR https://github.com/Loopring/protocols/pull/1185 and https://gith
6767

6868
Addressed in PR https://github.com/Loopring/protocols/pull/1189 and https://github.com/Loopring/protocols/pull/1184
6969

70-
7170
### 18. The initialization method initManager() could be front-run, unless it is called within the same transaction as the creation of the contract.
7271

7372
Addressed by PR https://github.com/Loopring/protocols/pull/1194
7473

75-
7674
### 19. AddressSet.sol
7775

78-
Addressed by PR https://github.com/Loopring/protocols/pull/1195
76+
Addressed by PR https://github.com/Loopring/protocols/pull/1195
7977

8078
### 20. Possible misleading comment in Module.sol
8179

82-
Addressed by PR https://github.com/Loopring/protocols/pull/1195
80+
Addressed by PR https://github.com/Loopring/protocols/pull/1195
8381

8482
### 21. Consider removing the option to make delegateCalls from wallet and vault
8583

@@ -89,7 +87,6 @@ This method is not used and is internal only. We'll keep it there just in case t
8987

9088
We implemented the `receive` function after sending the code for review: https://github.com/Loopring/protocols/blob/fc0a9bfdf82f07ccc60535b1a85493a29b897a6c/packages/hebao_v1/contracts/base/BaseWallet.sol#L226
9189

92-
9390
## Additional Changes:
9491

9592
- https://github.com/Loopring/protocols/pull/1201
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2017 Loopring Technology Limited.
3+
pragma solidity ^0.7.0;
4+
5+
import "../lib/Drainable.sol";
6+
import "../lib/OwnerManagable.sol";
7+
8+
9+
/// @title FeeCollector
10+
/// @author Daniel Wang - <[email protected]>
11+
contract FeeCollector is Drainable, OwnerManagable
12+
{
13+
function canDrain(address drainer, address /*token*/)
14+
public
15+
override
16+
view
17+
returns (bool)
18+
{
19+
return isManager(drainer) || drainer == owner;
20+
}
21+
22+
// Allow receiving ETH
23+
receive() payable external {}
24+
}

packages/hebao_v1/contracts/base/BaseWallet.sol

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import "./Controller.sol";
1313
/// @dev This contract provides basic implementation for a Wallet.
1414
///
1515
/// @author Daniel Wang - <[email protected]>
16-
///
17-
/// The design of this contract is inspired by Argent's contract codebase:
18-
/// https://github.com/argentlabs/argent-contracts
1916
abstract contract BaseWallet is ReentrancyGuard, Wallet
2017
{
2118
// WARNING: do not delete wallet state data to make this implementation
@@ -38,13 +35,6 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
3835
event MethodBound (bytes4 method, address module);
3936
event WalletSetup (address owner);
4037

41-
event Transacted(
42-
address module,
43-
address to,
44-
uint value,
45-
bytes data
46-
);
47-
4838
modifier onlyFromModule
4939
{
5040
require(modules[msg.sender], "MODULE_UNAUTHORIZED");
@@ -81,7 +71,6 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
8171
)
8272
external
8373
onlyFromFactory
84-
nonReentrant
8574
{
8675
require(controller != Controller(0), "NO_CONTROLLER");
8776
require(_owner == address(0), "INITIALIZED_ALREADY");
@@ -91,17 +80,18 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
9180
emit WalletSetup(_initialOwner);
9281
}
9382

94-
/// @dev Set up this wallet by assigning an controller.
83+
/// @dev Set up this wallet by assigning a controller and initial modules.
9584
///
9685
/// Note that calling this method more than once will throw.
9786
/// And this method must be invoked before owner is initialized
9887
///
9988
/// @param _controller The Controller instance.
100-
function initController(
101-
Controller _controller
89+
/// @param _modules The initial modules.
90+
function init(
91+
Controller _controller,
92+
address[] calldata _modules
10293
)
10394
external
104-
nonReentrant
10595
{
10696
require(
10797
_owner == address(0) &&
@@ -111,11 +101,16 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
111101
);
112102

113103
controller = _controller;
104+
105+
ModuleRegistry moduleRegistry = controller.moduleRegistry();
106+
for (uint i = 0; i < _modules.length; i++) {
107+
_addModule(_modules[i], moduleRegistry);
108+
}
114109
}
115110

116111
function owner()
117112
override
118-
external
113+
public
119114
view
120115
returns (address)
121116
{
@@ -125,7 +120,6 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
125120
function setOwner(address newOwner)
126121
external
127122
override
128-
nonReentrant
129123
onlyFromModule
130124
{
131125
require(newOwner != address(0), "ZERO_ADDRESS");
@@ -137,7 +131,6 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
137131

138132
function setController(Controller newController)
139133
external
140-
nonReentrant
141134
onlyFromModule
142135
{
143136
require(newController != controller, "SAME_CONTROLLER");
@@ -151,7 +144,7 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
151144
override
152145
onlyFromFactoryOrModule
153146
{
154-
addModuleInternal(_module);
147+
_addModule(_module, controller.moduleRegistry());
155148
}
156149

157150
function removeModule(address _module)
@@ -167,7 +160,7 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
167160
}
168161

169162
function hasModule(address _module)
170-
external
163+
public
171164
view
172165
override
173166
returns (bool)
@@ -190,7 +183,7 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
190183
}
191184

192185
function boundMethodModule(bytes4 _method)
193-
external
186+
public
194187
view
195188
override
196189
returns (address)
@@ -209,35 +202,15 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
209202
onlyFromFactoryOrModule
210203
returns (bytes memory returnData)
211204
{
212-
require(
213-
!controller.moduleRegistry().isModuleRegistered(to),
214-
"TRANSACT_ON_MODULE_DISALLOWED"
215-
);
216-
217205
bool success;
218-
(success, returnData) = nonReentrantCall(mode, to, value, data);
206+
(success, returnData) = _call(mode, to, value, data);
219207

220208
if (!success) {
221209
assembly {
222210
returndatacopy(0, 0, returndatasize())
223211
revert(0, returndatasize())
224212
}
225213
}
226-
emit Transacted(msg.sender, to, value, data);
227-
}
228-
229-
function addModuleInternal(address _module)
230-
internal
231-
{
232-
require(_module != address(0), "NULL_MODULE");
233-
require(modules[_module] == false, "MODULE_EXISTS");
234-
require(
235-
controller.moduleRegistry().isModuleEnabled(_module),
236-
"INVALID_MODULE"
237-
);
238-
modules[_module] = true;
239-
emit ModuleAdded(_module);
240-
Module(_module).activate();
241214
}
242215

243216
receive()
@@ -263,16 +236,27 @@ abstract contract BaseWallet is ReentrancyGuard, Wallet
263236
}
264237
}
265238

266-
// This call is introduced to support reentrany check.
267-
// The caller shall NOT have the nonReentrant modifier.
268-
function nonReentrantCall(
239+
function _addModule(address _module, ModuleRegistry moduleRegistry)
240+
internal
241+
{
242+
require(_module != address(0), "NULL_MODULE");
243+
require(modules[_module] == false, "MODULE_EXISTS");
244+
require(
245+
moduleRegistry.isModuleEnabled(_module),
246+
"INVALID_MODULE"
247+
);
248+
modules[_module] = true;
249+
emit ModuleAdded(_module);
250+
Module(_module).activate();
251+
}
252+
253+
function _call(
269254
uint8 mode,
270255
address target,
271256
uint value,
272257
bytes calldata data
273258
)
274259
private
275-
nonReentrant
276260
returns (
277261
bool success,
278262
bytes memory returnData

packages/hebao_v1/contracts/base/Controller.sol

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
pragma solidity ^0.7.0;
44

55
import "../iface/ModuleRegistry.sol";
6-
import "../iface/WalletRegistry.sol";
76

87

98
/// @title Controller
109
///
1110
/// @author Daniel Wang - <[email protected]>
1211
abstract contract Controller
1312
{
14-
ModuleRegistry public moduleRegistry;
15-
WalletRegistry public walletRegistry;
16-
address public walletFactory;
13+
function moduleRegistry()
14+
external
15+
view
16+
virtual
17+
returns (ModuleRegistry);
18+
19+
function walletFactory()
20+
external
21+
view
22+
virtual
23+
returns (address);
1724
}

packages/hebao_v1/contracts/base/DataStore.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import "../iface/Wallet.sol";
1010
/// Using ModuleStorage will achieve better module decoupling.
1111
///
1212
/// @author Daniel Wang - <[email protected]>
13-
///
14-
/// The design of this contract is inspired by Argent's contract codebase:
15-
/// https://github.com/argentlabs/argent-contracts
1613
abstract contract DataStore
1714
{
1815
modifier onlyWalletModule(address wallet)
1916
{
20-
require(Wallet(wallet).hasModule(msg.sender), "UNAUTHORIZED");
17+
requireWalletModule(wallet);
2118
_;
2219
}
20+
21+
function requireWalletModule(address wallet) view internal
22+
{
23+
require(Wallet(wallet).hasModule(msg.sender), "UNAUTHORIZED");
24+
}
2325
}

packages/hebao_v1/contracts/base/WalletRegistryImpl.sol

Lines changed: 0 additions & 66 deletions
This file was deleted.

packages/hebao_v1/contracts/iface/Module.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import "./Wallet.sol";
1010
/// @dev Base contract for all smart wallet modules.
1111
///
1212
/// @author Daniel Wang - <[email protected]>
13-
///
14-
/// The design of this contract is inspired by Argent's contract codebase:
15-
/// https://github.com/argentlabs/argent-contracts
1613
interface Module
1714
{
1815
/// @dev Activates the module for the given wallet (msg.sender) after the module is added.

0 commit comments

Comments
 (0)