Skip to content

Commit a3a5e06

Browse files
authored
Closes #223 remove unnecessary code (#275)
1 parent eb3239f commit a3a5e06

Some content is hidden

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

52 files changed

+564
-326
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ jobs:
2222
github-token: ${{ secrets.GITHUB_TOKEN }}
2323
benchmarks:
2424
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
solidity: ["0.7.6", "0.8.2"]
29+
include:
30+
- solidity: "0.8.2"
31+
settings: '{"viaIR":true,"optimizer":{"enabled":true,"runs":10000}}'
32+
env:
33+
SOLIDITY_VERSION: ${{ matrix.solidity }}
34+
SOLIDITY_SETTINGS: ${{ matrix.settings }}
2535
steps:
2636
- uses: actions/checkout@v2
2737
- uses: actions/setup-node@v2
@@ -33,4 +43,5 @@ jobs:
3343
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
3444
- run: yarn
3545
- run: yarn build
46+
- run: yarn hardhat codesize --contractname GnosisSafe
3647
- run: yarn benchmark

contracts/GnosisSafe.sol

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33

44
import "./base/ModuleManager.sol";
55
import "./base/OwnerManager.sol";
66
import "./base/FallbackManager.sol";
77
import "./common/EtherPaymentFallback.sol";
8-
import "./common/MasterCopy.sol";
8+
import "./common/Singleton.sol";
99
import "./common/SignatureDecoder.sol";
1010
import "./common/SecuredTokenTransfer.sol";
1111
import "./common/StorageAccessible.sol";
@@ -16,7 +16,7 @@ import "./external/GnosisSafeMath.sol";
1616
/// @author Stefan George - <stefan@gnosis.io>
1717
/// @author Richard Meissner - <richard@gnosis.io>
1818
contract GnosisSafe
19-
is EtherPaymentFallback, MasterCopy, ModuleManager, OwnerManager, SignatureDecoder, SecuredTokenTransfer, ISignatureValidatorConstants, FallbackManager, StorageAccessible {
19+
is EtherPaymentFallback, Singleton, ModuleManager, OwnerManager, SignatureDecoder, SecuredTokenTransfer, ISignatureValidatorConstants, FallbackManager, StorageAccessible {
2020

2121
using GnosisSafeMath for uint256;
2222

@@ -63,7 +63,7 @@ contract GnosisSafe
6363
constructor() {
6464
// By setting the threshold it is not possible to call setup anymore,
6565
// so we create a Safe with 0 owners and threshold 1.
66-
// This is an unusable Safe, perfect for the mastercopy
66+
// This is an unusable Safe, perfect for the singleton
6767
threshold = 1;
6868
}
6969

@@ -116,16 +116,16 @@ contract GnosisSafe
116116
function execTransaction(
117117
address to,
118118
uint256 value,
119-
bytes calldata data,
119+
bytes memory data,
120120
Enum.Operation operation,
121121
uint256 safeTxGas,
122122
uint256 baseGas,
123123
uint256 gasPrice,
124124
address gasToken,
125125
address payable refundReceiver,
126-
bytes calldata signatures
126+
bytes memory signatures
127127
)
128-
external
128+
public
129129
payable
130130
returns (bool success)
131131
{
@@ -307,29 +307,6 @@ contract GnosisSafe
307307
signedMessages[msgHash] = 1;
308308
emit SignMsg(msgHash);
309309
}
310-
311-
/**
312-
* Implementation of ISignatureValidator (see `interfaces/ISignatureValidator.sol`)
313-
* @dev Should return whether the signature provided is valid for the provided data.
314-
* The save does not implement the interface since `checkSignatures` is not a view method.
315-
* The method will not perform any state changes (see parameters of `checkSignatures`)
316-
* @param _data Arbitrary length data signed on the behalf of address(this)
317-
* @param _signature Signature byte array associated with _data
318-
* @return a bool upon valid or invalid signature with corresponding _data
319-
*/
320-
function isValidSignature(bytes calldata _data, bytes calldata _signature)
321-
external
322-
view
323-
returns (bytes4)
324-
{
325-
bytes32 messageHash = getMessageHash(_data);
326-
if (_signature.length == 0) {
327-
require(signedMessages[messageHash] != 0, "Hash not approved");
328-
} else {
329-
checkSignatures(messageHash, _data, _signature);
330-
}
331-
return EIP1271_MAGIC_VALUE;
332-
}
333310

334311
/// @dev Returns the chain id used by this contract.
335312
function getChainId() public view returns (uint256) {

contracts/accessors/SimulateTxAccessor.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity >=0.7.0 <0.8.0;
1+
pragma solidity >=0.7.0 <0.9.0;
22

33
import "../base/Executor.sol";
44

contracts/base/Executor.sol

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33
import "../common/Enum.sol";
44

5-
65
/// @title Executor - A contract that can execute transactions
76
/// @author Richard Meissner - <richard@gnosis.pm>
87
contract Executor {
9-
10-
function execute(address to, uint256 value, bytes memory data, Enum.Operation operation, uint256 txGas)
11-
internal
12-
returns (bool success)
13-
{
14-
if (operation == Enum.Operation.Call)
15-
success = executeCall(to, value, data, txGas);
16-
else if (operation == Enum.Operation.DelegateCall)
17-
success = executeDelegateCall(to, data, txGas);
18-
else
19-
success = false;
20-
}
21-
22-
function executeCall(address to, uint256 value, bytes memory data, uint256 txGas)
23-
internal
24-
returns (bool success)
25-
{
26-
// solium-disable-next-line security/no-inline-assembly
27-
assembly {
28-
success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0)
29-
}
30-
}
31-
32-
function executeDelegateCall(address to, bytes memory data, uint256 txGas)
33-
internal
34-
returns (bool success)
35-
{
36-
// solium-disable-next-line security/no-inline-assembly
37-
assembly {
38-
success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
8+
function execute(
9+
address to,
10+
uint256 value,
11+
bytes memory data,
12+
Enum.Operation operation,
13+
uint256 txGas
14+
) internal returns (bool success) {
15+
if (operation == Enum.Operation.DelegateCall) {
16+
// solium-disable-next-line security/no-inline-assembly
17+
assembly {
18+
success := delegatecall(
19+
txGas,
20+
to,
21+
add(data, 0x20),
22+
mload(data),
23+
0,
24+
0
25+
)
26+
}
27+
} else {
28+
// solium-disable-next-line security/no-inline-assembly
29+
assembly {
30+
success := call(
31+
txGas,
32+
to,
33+
value,
34+
add(data, 0x20),
35+
mload(data),
36+
0,
37+
0
38+
)
39+
}
3940
}
4041
}
4142
}

contracts/base/FallbackManager.sol

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33

44
import "../common/SelfAuthorized.sol";
55

66
/// @title Fallback Manager - A contract that manages fallback calls made to this contract
77
/// @author Richard Meissner - <richard@gnosis.pm>
88
contract FallbackManager is SelfAuthorized {
9-
109
// keccak256("fallback_manager.handler.address")
11-
bytes32 internal constant FALLBACK_HANDLER_STORAGE_SLOT = 0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d5;
10+
bytes32 internal constant FALLBACK_HANDLER_STORAGE_SLOT =
11+
0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d5;
1212

1313
function internalSetFallbackHandler(address handler) internal {
1414
bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;
@@ -22,36 +22,37 @@ contract FallbackManager is SelfAuthorized {
2222
/// Only fallback calls without value and with data will be forwarded.
2323
/// This can only be done via a Safe transaction.
2424
/// @param handler contract to handle fallbacks calls.
25-
function setFallbackHandler(address handler)
26-
public
27-
authorized
28-
{
25+
function setFallbackHandler(address handler) public authorized {
2926
internalSetFallbackHandler(handler);
3027
}
3128

32-
fallback()
33-
external
34-
{
29+
fallback() external {
3530
bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;
36-
address handler;
3731
// solium-disable-next-line security/no-inline-assembly
3832
assembly {
39-
handler := sload(slot)
40-
}
41-
42-
if (handler != address(0)) {
43-
// solium-disable-next-line security/no-inline-assembly
44-
assembly {
45-
calldatacopy(0, 0, calldatasize())
46-
// The msg.sender address is shifted to the left by 12 bytes to remove the padding
47-
// Then the address without padding is stored right after the calldata
48-
mstore(calldatasize(), shl(96, caller()))
49-
// Add 20 bytes for the address appended add the end
50-
let success := call(gas(), handler, 0, 0, add(calldatasize(), 20), 0, 0)
51-
returndatacopy(0, 0, returndatasize())
52-
if eq(success, 0) { revert(0, returndatasize()) }
53-
return(0, returndatasize())
33+
let handler := sload(slot)
34+
if iszero(handler) {
35+
return(0, 0)
36+
}
37+
calldatacopy(0, 0, calldatasize())
38+
// The msg.sender address is shifted to the left by 12 bytes to remove the padding
39+
// Then the address without padding is stored right after the calldata
40+
mstore(calldatasize(), shl(96, caller()))
41+
// Add 20 bytes for the address appended add the end
42+
let success := call(
43+
gas(),
44+
handler,
45+
0,
46+
0,
47+
add(calldatasize(), 20),
48+
0,
49+
0
50+
)
51+
returndatacopy(0, 0, returndatasize())
52+
if iszero(success) {
53+
revert(0, returndatasize())
5454
}
55+
return(0, returndatasize())
5556
}
5657
}
57-
}
58+
}

contracts/base/ModuleManager.sol

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33
import "../common/Enum.sol";
44
import "../common/SelfAuthorized.sol";
55
import "./Executor.sol";
@@ -26,7 +26,7 @@ contract ModuleManager is SelfAuthorized, Executor {
2626
modules[SENTINEL_MODULES] = SENTINEL_MODULES;
2727
if (to != address(0))
2828
// Setup has to complete successfully or transaction fails.
29-
require(executeDelegateCall(to, data, gasleft()), "Could not finish initialization");
29+
require(execute(to, 0, data, Enum.Operation.DelegateCall, gasleft()), "Could not finish initialization");
3030
}
3131

3232
/// @dev Allows to add a module to the whitelist.
@@ -116,24 +116,13 @@ contract ModuleManager is SelfAuthorized, Executor {
116116
return SENTINEL_MODULES != module && modules[module] != address(0);
117117
}
118118

119-
/// @dev Returns array of first 10 modules.
120-
/// @return Array of modules.
121-
function getModules()
122-
public
123-
view
124-
returns (address[] memory)
125-
{
126-
(address[] memory array,) = getModulesPaginated(SENTINEL_MODULES, 10);
127-
return array;
128-
}
129-
130119
/// @dev Returns array of modules.
131120
/// @param start Start of the page.
132121
/// @param pageSize Maximum number of modules that should be returned.
133122
/// @return array Array of modules.
134123
/// @return next Start of the next page.
135124
function getModulesPaginated(address start, uint256 pageSize)
136-
public
125+
external
137126
view
138127
returns (address[] memory array, address next)
139128
{

contracts/base/OwnerManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33
import "../common/SelfAuthorized.sol";
44

55
/// @title OwnerManager - Manages a set of owners and a threshold to perform actions.

contracts/common/Enum.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33

44

55
/// @title Enum - Collection of enums

contracts/common/EtherPaymentFallback.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2-
pragma solidity >=0.7.0 <0.8.0;
2+
pragma solidity >=0.7.0 <0.9.0;
33

44

55
/// @title EtherPaymentFallback - A contract that has a fallback to accept ether payments

contracts/common/MasterCopy.sol

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

0 commit comments

Comments
 (0)