Skip to content

Commit

Permalink
Merge e00c733 into 8823fa3
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Jan 27, 2023
2 parents 8823fa3 + e00c733 commit 5d29c72
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 188 deletions.
75 changes: 32 additions & 43 deletions contracts/Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,21 @@ contract Safe is
bytes32 txHash;
// Use scope here to limit variable lifetime and prevent `stack too deep` errors
{
bytes memory txHashData =
encodeTransactionData(
// Transaction info
to,
value,
data,
operation,
safeTxGas,
// Payment info
baseGas,
gasPrice,
gasToken,
refundReceiver,
// Signature info
nonce
);
bytes memory txHashData = encodeTransactionData(
// Transaction info
to,
value,
data,
operation,
safeTxGas,
// Payment info
baseGas,
gasPrice,
gasToken,
refundReceiver,
// Signature info
nonce
);
// Increase nonce and execute transaction.
nonce++;
txHash = keccak256(txHashData);
Expand Down Expand Up @@ -218,11 +217,7 @@ contract Safe is
* @param data That should be signed (this is passed to an external validator contract)
* @param signatures Signature data that should be verified. Can be ECDSA signature, contract signature (EIP-1271) or approved hash.
*/
function checkSignatures(
bytes32 dataHash,
bytes memory data,
bytes memory signatures
) public view {
function checkSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures) public view {
// Load threshold to avoid multiple storage loads
uint256 _threshold = threshold;
// Check that a threshold is set
Expand All @@ -237,12 +232,7 @@ contract Safe is
* @param signatures Signature data that should be verified. Can be ECDSA signature, contract signature (EIP-1271) or approved hash.
* @param requiredSignatures Amount of required valid signatures.
*/
function checkNSignatures(
bytes32 dataHash,
bytes memory data,
bytes memory signatures,
uint256 requiredSignatures
) public view {
function checkNSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures, uint256 requiredSignatures) public view {
// Check that the provided signature data is not too short
require(signatures.length >= requiredSignatures.mul(65), "GS020");
// There cannot be an owner with address 0.
Expand Down Expand Up @@ -352,22 +342,21 @@ contract Safe is
address refundReceiver,
uint256 _nonce
) public view returns (bytes memory) {
bytes32 safeTxHash =
keccak256(
abi.encode(
SAFE_TX_TYPEHASH,
to,
value,
keccak256(data),
operation,
safeTxGas,
baseGas,
gasPrice,
gasToken,
refundReceiver,
_nonce
)
);
bytes32 safeTxHash = keccak256(
abi.encode(
SAFE_TX_TYPEHASH,
to,
value,
keccak256(data),
operation,
safeTxGas,
baseGas,
gasPrice,
gasToken,
refundReceiver,
_nonce
)
);
return abi.encodePacked(bytes1(0x19), bytes1(0x01), domainSeparator(), safeTxHash);
}

Expand Down
10 changes: 1 addition & 9 deletions contracts/accessors/SimulateTxAccessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ contract SimulateTxAccessor is Executor {
uint256 value,
bytes calldata data,
Enum.Operation operation
)
external
onlyDelegateCall()
returns (
uint256 estimate,
bool success,
bytes memory returnData
)
{
) external onlyDelegateCall returns (uint256 estimate, bool success, bytes memory returnData) {
uint256 startGas = gasleft();
success = execute(to, value, data, operation, gasleft());
estimate = startGas - gasleft();
Expand Down
12 changes: 2 additions & 10 deletions contracts/base/OwnerManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ contract OwnerManager is SelfAuthorized {
/// @param prevOwner Owner that pointed to the owner to be removed in the linked list
/// @param owner Owner address to be removed.
/// @param _threshold New threshold.
function removeOwner(
address prevOwner,
address owner,
uint256 _threshold
) public authorized {
function removeOwner(address prevOwner, address owner, uint256 _threshold) public authorized {
// Only allow to remove an owner, if threshold can still be reached.
require(ownerCount - 1 >= _threshold, "GS201");
// Validate owner address and check that it corresponds to owner index.
Expand All @@ -91,11 +87,7 @@ contract OwnerManager is SelfAuthorized {
/// @param prevOwner Owner that pointed to the owner to be replaced in the linked list
/// @param oldOwner Owner address to be replaced.
/// @param newOwner New owner address.
function swapOwner(
address prevOwner,
address oldOwner,
address newOwner
) public authorized {
function swapOwner(address prevOwner, address oldOwner, address newOwner) public authorized {
// Owner address cannot be null, the sentinel or the Safe itself.
require(newOwner != address(0) && newOwner != SENTINEL_OWNERS && newOwner != address(this), "GS203");
// No duplicate owners allowed.
Expand Down
5 changes: 4 additions & 1 deletion contracts/common/Enum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ pragma solidity >=0.7.0 <0.9.0;
/// @title Enum - Collection of enums
/// @author Richard Meissner - <richard@gnosis.pm>
contract Enum {
enum Operation {Call, DelegateCall}
enum Operation {
Call,
DelegateCall
}
}
24 changes: 10 additions & 14 deletions contracts/common/SecuredTokenTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ contract SecuredTokenTransfer {
/// @param token Token that should be transferred
/// @param receiver Receiver to whom the token should be transferred
/// @param amount The amount of tokens that should be transferred
function transferToken(
address token,
address receiver,
uint256 amount
) internal returns (bool transferred) {
function transferToken(address token, address receiver, uint256 amount) internal returns (bool transferred) {
// 0xa9059cbb - keccack("transfer(address,uint256)")
bytes memory data = abi.encodeWithSelector(0xa9059cbb, receiver, amount);
// solhint-disable-next-line no-inline-assembly
Expand All @@ -21,15 +17,15 @@ contract SecuredTokenTransfer {
// See https://docs.soliditylang.org/en/v0.7.6/internals/layout_in_memory.html#layout-in-memory
let success := call(sub(gas(), 10000), token, 0, add(data, 0x20), mload(data), 0, 0x20)
switch returndatasize()
case 0 {
transferred := success
}
case 0x20 {
transferred := iszero(or(iszero(success), iszero(mload(0))))
}
default {
transferred := 0
}
case 0 {
transferred := success
}
case 0x20 {
transferred := iszero(or(iszero(success), iszero(mload(0))))
}
default {
transferred := 0
}
}
}
}
10 changes: 1 addition & 9 deletions contracts/common/SignatureDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ contract SignatureDecoder {
/// @notice Make sure to perform a bounds check for @param pos, to avoid out of bounds access on @param signatures
/// @param pos which signature to read. A prior bounds check of this parameter should be performed, to avoid out of bounds access
/// @param signatures concatenated rsv signatures
function signatureSplit(bytes memory signatures, uint256 pos)
internal
pure
returns (
uint8 v,
bytes32 r,
bytes32 s
)
{
function signatureSplit(bytes memory signatures, uint256 pos) internal pure returns (uint8 v, bytes32 r, bytes32 s) {
// The signature format is a compact form of:
// {bytes32 r}{bytes32 s}{uint8 v}
// Compact means, uint8 is not padded to 32 bytes.
Expand Down
24 changes: 3 additions & 21 deletions contracts/handler/DefaultCallbackHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ contract DefaultCallbackHandler is ERC1155TokenReceiver, ERC777TokensRecipient,
string public constant NAME = "Default Callback Handler";
string public constant VERSION = "1.0.0";

function onERC1155Received(
address,
address,
uint256,
uint256,
bytes calldata
) external pure override returns (bytes4) {
function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure override returns (bytes4) {
return 0xf23a6e61;
}

Expand All @@ -32,23 +26,11 @@ contract DefaultCallbackHandler is ERC1155TokenReceiver, ERC777TokensRecipient,
return 0xbc197c81;
}

function onERC721Received(
address,
address,
uint256,
bytes calldata
) external pure override returns (bytes4) {
function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
return 0x150b7a02;
}

function tokensReceived(
address,
address,
address,
uint256,
bytes calldata,
bytes calldata
) external pure override {
function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata) external pure override {
// We implement this for completeness, doesn't really have any value
}

Expand Down
7 changes: 1 addition & 6 deletions contracts/interfaces/ERC721TokenReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,5 @@ interface ERC721TokenReceiver {
/// @param _data Additional data with no specified format
/// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
/// unless throwing
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
) external returns (bytes4);
function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes calldata _data) external returns (bytes4);
}
6 changes: 1 addition & 5 deletions contracts/libraries/CreateCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ pragma solidity >=0.7.0 <0.9.0;
contract CreateCall {
event ContractCreation(address newContract);

function performCreate2(
uint256 value,
bytes memory deploymentData,
bytes32 salt
) public returns (address newContract) {
function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract) {
// solhint-disable-next-line no-inline-assembly
assembly {
newContract := create2(value, add(0x20, deploymentData), mload(deploymentData), salt)
Expand Down
12 changes: 6 additions & 6 deletions contracts/libraries/MultiSend.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ contract MultiSend {
let data := add(transactions, add(i, 0x55))
let success := 0
switch operation
case 0 {
success := call(gas(), to, value, data, dataLength, 0, 0)
}
case 1 {
success := delegatecall(gas(), to, data, dataLength, 0, 0)
}
case 0 {
success := call(gas(), to, value, data, dataLength, 0, 0)
}
case 1 {
success := delegatecall(gas(), to, data, dataLength, 0, 0)
}
if eq(success, 0) {
revert(0, 0)
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/libraries/MultiSendCallOnly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ contract MultiSendCallOnly {
let data := add(transactions, add(i, 0x55))
let success := 0
switch operation
case 0 {
success := call(gas(), to, value, data, dataLength, 0, 0)
}
// This version does not allow delegatecalls
case 1 {
revert(0, 0)
}
case 0 {
success := call(gas(), to, value, data, dataLength, 0, 0)
}
// This version does not allow delegatecalls
case 1 {
revert(0, 0)
}
if eq(success, 0) {
revert(0, 0)
}
Expand Down
7 changes: 1 addition & 6 deletions contracts/proxies/IProxyCreationCallback.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ pragma solidity >=0.7.0 <0.9.0;
import "./SafeProxy.sol";

interface IProxyCreationCallback {
function proxyCreated(
SafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
function proxyCreated(SafeProxy proxy, address _singleton, bytes calldata initializer, uint256 saltNonce) external;
}
12 changes: 2 additions & 10 deletions contracts/proxies/SafeProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ contract SafeProxyFactory {
/// @param _singleton Address of singleton contract. Must be deployed at the time of execution.
/// @param initializer Payload for a message call to be sent to a new proxy contract.
/// @param salt Create2 salt to use for calculating the address of the new proxy contract.
function deployProxy(
address _singleton,
bytes memory initializer,
bytes32 salt
) internal returns (SafeProxy proxy) {
function deployProxy(address _singleton, bytes memory initializer, bytes32 salt) internal returns (SafeProxy proxy) {
require(isContract(_singleton), "Singleton contract not deployed");

bytes memory deploymentData = abi.encodePacked(type(SafeProxy).creationCode, uint256(uint160(_singleton)));
Expand All @@ -47,11 +43,7 @@ contract SafeProxyFactory {
/// @param _singleton Address of singleton contract. Must be deployed at the time of execution.
/// @param initializer Payload for a message call to be sent to a new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (SafeProxy proxy) {
function createProxyWithNonce(address _singleton, bytes memory initializer, uint256 saltNonce) 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 Down
15 changes: 2 additions & 13 deletions contracts/test/ERC1155Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ contract ERC1155Token {
@param value Transfer amount
@param data Data forwarded to `onERC1155Received` if `to` is a contract receiver
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 value,
bytes calldata data
) external {
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external {
require(to != address(0), "ERC1155: target address must be non-zero");
require(
from == msg.sender || _operatorApprovals[from][msg.sender] == true,
Expand All @@ -60,12 +54,7 @@ contract ERC1155Token {
* @param value Amount of the token to be minted
* @param data Data forwarded to `onERC1155Received` if `to` is a contract receiver
*/
function mint(
address to,
uint256 id,
uint256 value,
bytes calldata data
) external {
function mint(address to, uint256 id, uint256 value, bytes calldata data) external {
require(to != address(0), "ERC1155: mint to the zero address");

_balances[id][to] = value + _balances[id][to];
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"hardhat": "^2.2.1",
"hardhat-deploy": "0.9.2",
"husky": "^5.1.3",
"prettier": "^2.1.2",
"prettier-plugin-solidity": "1.0.0-beta.10",
"prettier": "^2.8.3",
"prettier-plugin-solidity": "1.1.1",
"solc": "0.7.6",
"solhint": "3.3.4",
"solhint-plugin-prettier": "0.0.5",
Expand Down

0 comments on commit 5d29c72

Please sign in to comment.