Skip to content

Commit

Permalink
Merge c73aeb6 into 7126451
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Jan 13, 2023
2 parents 7126451 + c73aeb6 commit a159946
Show file tree
Hide file tree
Showing 50 changed files with 108 additions and 109 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
fail-fast: false
matrix:
contract-name: ["GnosisSafeL2"]
contract-name: ["SafeL2"]
env:
SAFE_CONTRACT_UNDER_TEST: ${{ matrix.contract-name }}
steps:
Expand Down Expand Up @@ -78,4 +78,4 @@ jobs:
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: (yarn --frozen-lockfile && yarn build && yarn hardhat codesize --contractname GnosisSafe && yarn benchmark) || echo "Benchmark failed"
- run: (yarn --frozen-lockfile && yarn build && yarn hardhat codesize --contractname Safe && yarn benchmark) || echo "Benchmark failed"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@nomiclabs/hardhat-ethers";
import { setupBenchmarkContracts } from "./utils/setup"

const contractSetup = setupBenchmarkContracts(undefined, true)
describe("GnosisSafe", async () => {
describe("Safe", async () => {
it("creation", async () => {
await contractSetup()
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions contracts/GnosisSafe.sol → contracts/Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import "./common/SignatureDecoder.sol";
import "./common/SecuredTokenTransfer.sol";
import "./common/StorageAccessible.sol";
import "./interfaces/ISignatureValidator.sol";
import "./external/GnosisSafeMath.sol";
import "./external/SafeMath.sol";

/// @title Gnosis Safe - A multisignature wallet with support for confirmations using signed messages based on ERC191.
/// @title Safe - A multisignature wallet with support for confirmations using signed messages based on ERC191.
/// @author Stefan George - <stefan@gnosis.io>
/// @author Richard Meissner - <richard@gnosis.io>
contract GnosisSafe is
contract Safe is
EtherPaymentFallback,
Singleton,
ModuleManager,
Expand All @@ -28,7 +28,7 @@ contract GnosisSafe is
StorageAccessible,
GuardManager
{
using GnosisSafeMath for uint256;
using SafeMath for uint256;

string public constant VERSION = "1.3.0";

Expand Down
6 changes: 3 additions & 3 deletions contracts/GnosisSafeL2.sol → contracts/SafeL2.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "./GnosisSafe.sol";
import "./Safe.sol";

/// @title Gnosis Safe - A multisignature wallet with support for confirmations using signed messages based on ERC191.
/// @title Safe - A multisignature wallet with support for confirmations using signed messages based on ERC191.
/// @author Stefan George - <stefan@gnosis.io>
/// @author Richard Meissner - <richard@gnosis.io>
contract GnosisSafeL2 is GnosisSafe {
contract SafeL2 is Safe {
event SafeMultiSigTransaction(
address to,
uint256 value,
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/Singleton.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.7.0 <0.9.0;

/// @title Singleton - Base for singleton contracts (should always be first super contract)
/// This contract is tightly coupled to our proxy contract (see `proxies/GnosisSafeProxy.sol`)
/// This contract is tightly coupled to our proxy contract (see `proxies/SafeProxy.sol`)
/// @author Richard Meissner - <richard@gnosis.io>
contract Singleton {
// singleton always needs to be first declared variable, to ensure that it is at the same location as in the Proxy contract.
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/guards/DebugTransactionGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0;

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

/// @title Debug Transaction Guard - A guard that will emit events with extended information.
/// @notice This guard is only meant as a development tool and example
Expand Down Expand Up @@ -48,7 +48,7 @@ contract DebugTransactionGuard is BaseGuard {
uint256 nonce;
bytes32 txHash;
{
GnosisSafe safe = GnosisSafe(payable(msg.sender));
Safe safe = Safe(payable(msg.sender));
nonce = safe.nonce() - 1;
txHash = safe.getTransactionHash(to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, nonce);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/guards/DelegateCallTransactionGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0;

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

contract DelegateCallTransactionGuard is BaseGuard {
address public immutable allowedTarget;
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/guards/OnlyOwnersGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0;

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

interface ISafe {
function getOwners() external view returns (address[] memory);
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/guards/ReentrancyTransactionGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0;

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

contract ReentrancyTransactionGuard is BaseGuard {
bytes32 internal constant GUARD_STORAGE_SLOT = keccak256("reentrancy_guard.guard.struct");
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/libraries/Migrate_1_3_0_to_1_2_0.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import "../../libraries/GnosisSafeStorage.sol";
import "../../libraries/SafeStorage.sol";

/// @title Migration - migrates a Safe contract from 1.3.0 to 1.2.0
/// @author Richard Meissner - <richard@gnosis.io>
contract Migration is GnosisSafeStorage {
contract Migration is SafeStorage {
bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749;

address public immutable migrationSingleton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
pragma solidity >=0.7.0 <0.9.0;

/**
* @title GnosisSafeMath
* @title SafeMath
* @dev Math operations with safety checks that revert on error
* Renamed from SafeMath to GnosisSafeMath to avoid conflicts
* TODO: remove once open zeppelin update to solc 0.5.0
*/
library GnosisSafeMath {
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
Expand Down
10 changes: 5 additions & 5 deletions contracts/handler/CompatibilityFallbackHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0;

import "./DefaultCallbackHandler.sol";
import "../interfaces/ISignatureValidator.sol";
import "../GnosisSafe.sol";
import "../Safe.sol";

/// @title Compatibility Fallback Handler - fallback handler to provider compatibility between pre 1.3.0 and 1.3.0+ Safe contracts
/// @author Richard Meissner - <richard@gnosis.pm>
Expand All @@ -27,7 +27,7 @@ contract CompatibilityFallbackHandler is DefaultCallbackHandler, ISignatureValid
*/
function isValidSignature(bytes memory _data, bytes memory _signature) public view override returns (bytes4) {
// Caller should be a Safe
GnosisSafe safe = GnosisSafe(payable(msg.sender));
Safe safe = Safe(payable(msg.sender));
bytes32 messageHash = getMessageHashForSafe(safe, _data);
if (_signature.length == 0) {
require(safe.signedMessages(messageHash) != 0, "Hash not approved");
Expand All @@ -41,14 +41,14 @@ contract CompatibilityFallbackHandler is DefaultCallbackHandler, ISignatureValid
/// @param message Message that should be hashed
/// @return Message hash.
function getMessageHash(bytes memory message) public view returns (bytes32) {
return getMessageHashForSafe(GnosisSafe(payable(msg.sender)), message);
return getMessageHashForSafe(Safe(payable(msg.sender)), message);
}

/// @dev Returns hash of a message that can be signed by owners.
/// @param safe Safe to which the message is targeted
/// @param message Message that should be hashed
/// @return Message hash.
function getMessageHashForSafe(GnosisSafe safe, bytes memory message) public view returns (bytes32) {
function getMessageHashForSafe(Safe safe, bytes memory message) public view returns (bytes32) {
bytes32 safeMessageHash = keccak256(abi.encode(SAFE_MSG_TYPEHASH, keccak256(message)));
return keccak256(abi.encodePacked(bytes1(0x19), bytes1(0x01), safe.domainSeparator(), safeMessageHash));
}
Expand All @@ -73,7 +73,7 @@ contract CompatibilityFallbackHandler is DefaultCallbackHandler, ISignatureValid
/// @return Array of modules.
function getModules() external view returns (address[] memory) {
// Caller should be a Safe
GnosisSafe safe = GnosisSafe(payable(msg.sender));
Safe safe = Safe(payable(msg.sender));
(address[] memory array, ) = safe.getModulesPaginated(SENTINEL_MODULES, 10);
return array;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title GnosisSafeStorage - Storage layout of the Safe contracts to be used in libraries
/// @title SafeStorage - Storage layout of the Safe contracts to be used in libraries
/// @author Richard Meissner - <richard@gnosis.io>
contract GnosisSafeStorage {
contract SafeStorage {
// From /common/Singleton.sol
address internal singleton;
// From /common/ModuleManager.sol
Expand All @@ -13,7 +13,7 @@ contract GnosisSafeStorage {
uint256 internal ownerCount;
uint256 internal threshold;

// From /GnosisSafe.sol
// From /Safe.sol
uint256 internal nonce;
bytes32 internal _deprecatedDomainSeparator;
mapping(bytes32 => uint256) internal signedMessages;
Expand Down
8 changes: 4 additions & 4 deletions contracts/libraries/SignMessageLib.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "./GnosisSafeStorage.sol";
import "../GnosisSafe.sol";
import "./SafeStorage.sol";
import "../Safe.sol";

/// @title SignMessageLib - Allows to set an entry in the signedMessages
/// @author Richard Meissner - <richard@gnosis.io>
contract SignMessageLib is GnosisSafeStorage {
contract SignMessageLib is SafeStorage {
//keccak256(
// "SafeMessage(bytes message)"
//);
Expand All @@ -29,6 +29,6 @@ contract SignMessageLib is GnosisSafeStorage {
function getMessageHash(bytes memory message) public view returns (bytes32) {
bytes32 safeMessageHash = keccak256(abi.encode(SAFE_MSG_TYPEHASH, keccak256(message)));
return
keccak256(abi.encodePacked(bytes1(0x19), bytes1(0x01), GnosisSafe(payable(address(this))).domainSeparator(), safeMessageHash));
keccak256(abi.encodePacked(bytes1(0x19), bytes1(0x01), Safe(payable(address(this))).domainSeparator(), safeMessageHash));
}
}
4 changes: 2 additions & 2 deletions contracts/proxies/IProxyCreationCallback.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import "./GnosisSafeProxy.sol";
import "./SafeProxy.sol";

interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
SafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ interface IProxy {
function masterCopy() external view returns (address);
}

/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @title SafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <stefan@gnosis.io>
/// @author Richard Meissner - <richard@gnosis.io>
contract GnosisSafeProxy {
contract SafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "./GnosisSafeProxy.sol";
import "./SafeProxy.sol";
import "./IProxyCreationCallback.sol";

/// @title Proxy Factory - Allows to create a new proxy contract and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <stefan@gnosis.pm>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
contract SafeProxyFactory {
event ProxyCreation(SafeProxy proxy, address singleton);

/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
return type(SafeProxy).creationCode;
}

/// @dev Allows to create a new proxy contract using CREATE2. Optionally executes an initializer call to a new proxy.
Expand All @@ -23,10 +23,10 @@ contract GnosisSafeProxyFactory {
address _singleton,
bytes memory initializer,
bytes32 salt
) internal returns (GnosisSafeProxy proxy) {
) internal returns (SafeProxy proxy) {
require(isContract(_singleton), "Singleton contract not deployed");

bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
bytes memory deploymentData = abi.encodePacked(type(SafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
Expand All @@ -51,7 +51,7 @@ contract GnosisSafeProxyFactory {
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
) public returns (SafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
proxy = deployProxy(_singleton, initializer, salt);
Expand All @@ -67,7 +67,7 @@ contract GnosisSafeProxyFactory {
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
) public returns (SafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce, getChainId()));
proxy = deployProxy(_singleton, initializer, salt);
Expand All @@ -84,7 +84,7 @@ contract GnosisSafeProxyFactory {
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
) public returns (SafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/ERC1155Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity >=0.7.0 <0.9.0;

import "../interfaces/ERC1155TokenReceiver.sol";
import "../external/GnosisSafeMath.sol";
import "../external/SafeMath.sol";

contract ERC1155Token {
using GnosisSafeMath for uint256;
using SafeMath for uint256;

// Mapping from token ID to owner balances
mapping(uint256 => mapping(address => uint256)) private _balances;
Expand Down
6 changes: 3 additions & 3 deletions docs/safe_tx_gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The behaviour of `safeTxGas` depends on the `gasPrice` value of the Safe transac

If `gasPrice` is set to a value `>0` the Safe contracts will issue a refund for the gas costs incured the execution of the Safe transaction. An example where this can be used are the relayers. These would execute the Safe transaction after it has been signed by the owners and then would get refunded for the execution.

The logic for this can be seen in [`GnosisSafe.sol`](https://github.com/safe-global/safe-contracts/blob/main/contracts/GnosisSafe.sol#L183-L185):
The logic for this can be seen in [`Safe.sol`](https://github.com/safe-global/safe-contracts/blob/main/contracts/Safe.sol#L183-L185):
```js
if (gasPrice > 0) {
payment = handlePayment(gasUsed, baseGas, gasPrice, gasToken, refundReceiver);
Expand All @@ -28,7 +28,7 @@ If `gasPrice` is set to `0` then the Safe contracts will **not** issue a refund

Therefore it is not necessary to be as strict on the gas being passed along with the execution of the Safe transaction. As no refund is triggered the Safe will not pay for the execution costs, based on this the Safe contracts will send along all available case when no refund is used.

Before the execution the Safe contracts always check if enough gas is available to satisfy the `safeTxGas`. This can be seen in [`GnosisSafe.sol`](hhttps://github.com/safe-global/safe-contracts/blob/main/contracts/GnosisSafe.sol#L168-L170):
Before the execution the Safe contracts always check if enough gas is available to satisfy the `safeTxGas`. This can be seen in [`Safe.sol`](hhttps://github.com/safe-global/safe-contracts/blob/main/contracts/Safe.sol#L168-L170):
```js
require(gasleft() >= ((safeTxGas * 64) / 63).max(safeTxGas + 2500) + 500, "GS010");
```
Expand All @@ -45,7 +45,7 @@ To make it easier to set the `safeTxGas` value a change has been made with the 1

**When `safeTxGas` is set to `0`, the Safe contract will revert if the internal Safe transaction fails** (see [#274](https://github.com/safe-global/safe-contracts/issues/274))

That means if `safeTxGas` is set to `0` the Safe contract sents along all awailable gas when performing the internal Safe transaction. If that transaction fails the Safe will revert and therefore also undo all State changes. This can be seen in [`GnosisSafe.sol`](https://github.com/safe-global/safe-contracts/blob/main/contracts/GnosisSafe.sol#L178-L180):
That means if `safeTxGas` is set to `0` the Safe contract sents along all awailable gas when performing the internal Safe transaction. If that transaction fails the Safe will revert and therefore also undo all State changes. This can be seen in [`Safe.sol`](https://github.com/safe-global/safe-contracts/blob/main/contracts/Safe.sol#L178-L180):
```js
require(success || safeTxGas != 0 || gasPrice != 0, "GS013");
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@gnosis.pm/safe-contracts",
"name": "@safe-global/safe-contracts",
"version": "1.3.0",
"description": "Ethereum multisig contract",
"homepage": "https://github.com/safe-global/safe-contracts/",
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/deploy_factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const deploy: DeployFunction = async function (
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;

await deploy("GnosisSafeProxyFactory", {
await deploy("SafeProxyFactory", {
from: deployer,
args: [],
log: true,
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/deploy_safe_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const deploy: DeployFunction = async function (
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;

await deploy("GnosisSafeL2", {
await deploy("SafeL2", {
from: deployer,
args: [],
log: true,
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/deploy_safe_singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const deploy: DeployFunction = async function (
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;

await deploy("GnosisSafe", {
await deploy("Safe", {
from: deployer,
args: [],
log: true,
Expand Down

0 comments on commit a159946

Please sign in to comment.