Skip to content

Commit

Permalink
Merge branch 'main' of github.com:safe-global/safe-contracts into bou…
Browse files Browse the repository at this point in the history
…nty_module_pagination
  • Loading branch information
mmv08 committed Jan 13, 2023
2 parents 32c86d9 + 5a91e2c commit ed1faee
Show file tree
Hide file tree
Showing 32 changed files with 3,599 additions and 3,078 deletions.
2 changes: 0 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ INFURA_KEY=""
# Used for custom network
NODE_URL=""
ETHERSCAN_API_KEY=""
# Use the Safe singleton factory for singleton deployment. This is required if EIP-155 is enforce on a chain.
# CUSTOM_DETERMINISTIC_DEPLOYMENT="true"
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ about: Bug report about the Safe smart contracts
## Prerequisites

- First, many thanks for taking part in the community and helping us improve. We appreciate that a lot.
- Support questions are better asked in our Gitter chat: https://gitter.im/gnosis/Safe
- Support questions are better asked in our Discord: https://chat.safe.global
- Please ensure the issue isn't already reported.

*Please delete the above section and the instructions in the sections below before submitting*
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ about: Suggest an idea or feature request for the Safe smart contracts project
## Prerequisites

- First, many thanks for taking part in the community and helping us improve. We appreciate that a lot.
- Support questions are better asked in our Gitter chat: https://gitter.im/gnosis/Safe
- Support questions are better asked in our Discord: https://chat.safe.global
- Please ensure the issue isn't already reported.

*Please delete the above section and the instructions in the sections below before submitting*
Expand Down
68 changes: 34 additions & 34 deletions CHANGELOG.md

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Gnosis Safe Contracts
=====================
Safe Contracts
==============

[![npm version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-contracts.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-contracts)
[![Build Status](https://github.com/gnosis/safe-contracts/workflows/safe-contracts/badge.svg?branch=development)](https://github.com/gnosis/safe-contracts/actions)
[![Coverage Status](https://coveralls.io/repos/github/gnosis/safe-contracts/badge.svg?branch=development)](https://coveralls.io/github/gnosis/safe-contracts)
[![Build Status](https://github.com/safe-global/safe-contracts/workflows/safe-contracts/badge.svg?branch=development)](https://github.com/safe-global/safe-contracts/actions)
[![Coverage Status](https://coveralls.io/repos/github/safe-global/safe-contracts/badge.svg?branch=development)](https://coveralls.io/github/safe-global/safe-contracts)

> :warning: **This branch contains changes that are under development** To use the latest audited version make sure to use the correct commit. The tagged versions that are used by the Gnosis Safe team can be found in the [releases](https://github.com/gnosis/safe-contracts/releases).
> :warning: **This branch contains changes that are under development** To use the latest audited version make sure to use the correct commit. The tagged versions that are used by the Safe team can be found in the [releases](https://github.com/safe-global/safe-contracts/releases).
Usage
-----
Expand All @@ -24,15 +24,15 @@ yarn test

### Deployments

A collection of the different Safe contract deployments and their addresses can be found in the [Safe deployments](https://github.com/gnosis/safe-deployments) repository.
A collection of the different Safe contract deployments and their addresses can be found in the [Safe deployments](https://github.com/safe-global/safe-deployments) repository.

To add support for a new network follow the steps of the ``Deploy`` section and create a PR in the [Safe deployments](https://github.com/gnosis/safe-deployments) repository.
To add support for a new network follow the steps of the ``Deploy`` section and create a PR in the [Safe deployments](https://github.com/safe-global/safe-deployments) repository.

### Deploy

> :warning: **Make sure to use the correct commit when deploying the contracts.** Any change (even comments) within the contract files will result in different addresses. The tagged versions that are used by the Gnosis Safe team can be found in the [releases](https://github.com/gnosis/safe-contracts/releases).
> :warning: **Make sure to use the correct commit when deploying the contracts.** Any change (even comments) within the contract files will result in different addresses. The tagged versions that are used by the Safe team can be found in the [releases](https://github.com/safe-global/safe-contracts/releases).
> **Current version:** The latest release is [v1.3.0-libs.0](https://github.com/gnosis/safe-contracts/tree/v1.3.0-libs.0) on the commit [767ef36](https://github.com/gnosis/safe-contracts/commit/767ef36bba88bdbc0c9fe3708a4290cabef4c376)
> **Current version:** The latest release is [v1.3.0-libs.0](https://github.com/safe-global/safe-contracts/tree/v1.3.0-libs.0) on the commit [767ef36](https://github.com/safe-global/safe-contracts/commit/767ef36bba88bdbc0c9fe3708a4290cabef4c376)
This will deploy the contracts deterministically and verify the contracts on etherscan using [Solidity 0.7.6](https://github.com/ethereum/solidity/releases/tag/v0.7.6) by default.

Expand Down Expand Up @@ -66,11 +66,11 @@ Note: Address will vary if contract code is changed or a different Solidity vers

#### Replay protection (EIP-155)

Some networks require replay protection. This is not possible with the default deployment process as it relies on a presigned transaction without replay protection (see https://github.com/Arachnid/deterministic-deployment-proxy).
Some networks require replay protection, making it incompatible with the default deployment process as it relies on a presigned transaction without replay protection (see https://github.com/Arachnid/deterministic-deployment-proxy).

It is possible to enable deployment via a different determinisitic deployment proxy (https://github.com/gnosis/safe-singleton-factory). To enable this the `CUSTOM_DETERMINISTIC_DEPLOYMENT` env var has to be set to `true` (see `.env.sample`). To make sure that the latest version of this package is install, make sure to run `yarn add @gnosis.pm/safe-singleton-factory` before deployment.
Safe contracts use a different deterministic deployment proxy (https://github.com/safe-global/safe-singleton-factory). To make sure that the latest version of this package is installed, make sure to run `yarn add @gnosis.pm/safe-singleton-factory` before deployment. For more information, including how to deploy the factory to a new network, please refer to the factory repo.

Note: This will result in different addresses compared to the default deployment process.
Note: This will result in different addresses compared to hardhat's default deterministic deployment process.

### Verify contract

Expand All @@ -86,7 +86,7 @@ yarn hardhat --network <network> etherscan-verify

Documentation
-------------
- [Safe developer portal](http://docs.gnosis.io/safe)
- [Safe developer portal](http://docs.safe.global)
- [Error codes](docs/error_codes.md)
- [Coding guidelines](docs/guidelines.md)

Expand Down
24 changes: 19 additions & 5 deletions benchmark/GnosisSafe.Proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@ import { buildSafeTransaction } from "../src/utils/execution";
import { benchmark } from "./utils/setup"
import { getFactory } from "../test/utils/setup";

const testTarget = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"

benchmark("Proxy", [{
name: "creation",
prepare: async (contracts,_,nonce) => {
const factory = contracts.additions.factory
const data = factory.interface.encodeFunctionData("createProxy", [testTarget, "0x"])
// We're cheating and passing the factory address as a singleton address to bypass a check that singleton contract exists
const data = factory.interface.encodeFunctionData("createProxyWithNonce", [factory.address, "0x", 0])
return buildSafeTransaction({ to: factory.address, data, safeTxGas: 1000000, nonce })
},
fixture: async () => {
return {
factory: await getFactory(),
}
}
}])

benchmark("Proxy", [{
name: "chain specific creation",
prepare: async (contracts,_,nonce) => {
const factory = contracts.additions.factory
// We're cheating and passing the factory address as a singleton address to bypass a check that singleton contract exists
const data = factory.interface.encodeFunctionData("createChainSpecificProxyWithNonce", [factory.address, "0x", 0])
return buildSafeTransaction({ to: factory.address, data, safeTxGas: 1000000, nonce })
},
fixture: async () => {
return {
factory: await getFactory()
factory: await getFactory(),
}
}
}])
}])
4 changes: 2 additions & 2 deletions benchmark/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const generateTarget = async (owners: Wallet[], threshold: number, guardAddress:
export const configs = [
{ name: "single owner", signers: [user1], threshold: 1 },
{ name: "single owner and guard", signers: [user1], threshold: 1, useGuard: true },
{ name: "2 out of 23", signers: [user1, user2], threshold: 2 },
{ name: "2 out of 2", signers: [user1, user2], threshold: 2 },
{ name: "3 out of 3", signers: [user1, user2, user3], threshold: 3 },
{ name: "3 out of 5", signers: [user1, user2, user3, user4, user5], threshold: 3 },
]
Expand All @@ -33,7 +33,7 @@ export const setupBenchmarkContracts = (benchmarkFixture?: () => Promise<any>, l
await deployments.fixture();
const guardFactory = await hre.ethers.getContractFactory("DelegateCallTransactionGuard");
const guard = await guardFactory.deploy(AddressZero)
const targets = []
const targets: Contract[] = []
for (const config of configs) {
targets.push(await generateTarget(config.signers, config.threshold, config.useGuard ? guard.address : AddressZero, logGasUsage))
}
Expand Down
6 changes: 6 additions & 0 deletions contracts/base/Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import "../common/Enum.sol";
/// @title Executor - A contract that can execute transactions
/// @author Richard Meissner - <[email protected]>
contract Executor {
/// @dev Executes either a delegatecall or a call with provided parameters
/// @param to Destination address.
/// @param value Ether value.
/// @param data Data payload.
/// @param operation Operation type.
/// @return success boolean flag indicating if the call succeeded
function execute(
address to,
uint256 value,
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/GuardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract contract BaseGuard is Guard {
}
}

/// @title Fallback Manager - A contract that manages fallback calls made to this contract
/// @title Guard Manager - A contract that manages transaction guards which perform pre and post-checks on execution by multisig owners
/// @author Richard Meissner - <[email protected]>
contract GuardManager is SelfAuthorized {
event ChangedGuard(address guard);
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract ModuleManager is SelfAuthorized, Executor {
// Only whitelisted modules are allowed.
require(msg.sender != SENTINEL_MODULES && modules[msg.sender] != address(0), "GS104");
// Execute transaction without further confirmations.
success = execute(to, value, data, operation, gasleft());
success = execute(to, value, data, operation, type(uint256).max);
if (success) emit ExecutionFromModuleSuccess(msg.sender);
else emit ExecutionFromModuleFailure(msg.sender);
}
Expand Down
44 changes: 44 additions & 0 deletions contracts/examples/guards/OnlyOwnersGuard.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "../../common/Enum.sol";
import "../../base/GuardManager.sol";
import "../../GnosisSafe.sol";

interface ISafe {
function getOwners() external view returns (address[] memory);
}

contract OnlyOwnersGuard is BaseGuard {
ISafe public safe;

constructor() {}

function checkTransaction(
address,
uint256,
bytes memory,
Enum.Operation,
uint256,
uint256,
uint256,
address,
// solhint-disable-next-line no-unused-vars
address payable,
bytes memory,
address msgSender
) external override {
// Only owners can exec
address[] memory owners = ISafe(msg.sender).getOwners();
for (uint256 i = 0; i < owners.length; i++) {
if (owners[i] == msgSender) {
return;
}
}

// msg sender is not an owner
revert("msg sender is not allowed to exec");
}

function checkAfterExecution(bytes32, bool) external view override {}
}
2 changes: 1 addition & 1 deletion contracts/handler/CompatibilityFallbackHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract CompatibilityFallbackHandler is DefaultCallbackHandler, ISignatureValid
* @param _signature Signature byte array associated with _data
* @return a bool upon valid or invalid signature with corresponding _data
*/
function isValidSignature(bytes calldata _data, bytes calldata _signature) public view override returns (bytes4) {
function isValidSignature(bytes memory _data, bytes memory _signature) public view override returns (bytes4) {
// Caller should be a Safe
GnosisSafe safe = GnosisSafe(payable(msg.sender));
bytes32 messageHash = getMessageHashForSafe(safe, _data);
Expand Down
Loading

0 comments on commit ed1faee

Please sign in to comment.