Skip to content

Commit

Permalink
Merge pull request #43 from Into-the-Fathom/mainnet-deployment-reaudit
Browse files Browse the repository at this point in the history
Mainnet deployment reaudit
  • Loading branch information
TonioMacaronio authored Feb 15, 2023
2 parents 2a67812 + d49d2d0 commit c5ba9ca
Show file tree
Hide file tree
Showing 130 changed files with 3,622 additions and 1,564 deletions.
1 change: 0 additions & 1 deletion apothem-addresses-1.json

This file was deleted.

47 changes: 40 additions & 7 deletions contracts/common/Address.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

/**
* @dev Collection of functions related to the address type
Expand Down Expand Up @@ -62,7 +62,11 @@ library Address {
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}

Expand All @@ -77,7 +81,11 @@ library Address {
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}

Expand All @@ -87,7 +95,12 @@ library Address {
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");

Expand All @@ -111,7 +124,11 @@ library Address {
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");

(bool success, bytes memory returndata) = target.delegatecall(data);
Expand Down Expand Up @@ -168,20 +185,36 @@ library Address {
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");

(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}

function getExtCodeHash(address target) internal view returns (bytes32) {
bytes32 codeHash;
assembly {
codeHash := extcodehash(target)
}
return codeHash;
}

/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) internal pure returns (bytes memory) {
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/Context.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

/**
* @dev Provides information about the current execution context, including the
Expand Down
44 changes: 37 additions & 7 deletions contracts/common/SafeERC20.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity 0.8.13;
pragma solidity 0.8.16;

import "../dao/tokens/ERC20/IERC20.sol";
import "../dao/tokens/ERC20/extensions/IERC20Permit.sol";
Expand All @@ -19,11 +19,20 @@ import "./Address.sol";
library SafeERC20 {
using Address for address;

function safeTransfer(IERC20 token, address to, uint256 value) internal {
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}

function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}

Expand All @@ -34,20 +43,32 @@ library SafeERC20 {
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}

function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}

function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
Expand All @@ -56,7 +77,16 @@ library SafeERC20 {
}
}

function safePermit(IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) internal {
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
Expand Down
67 changes: 67 additions & 0 deletions contracts/common/SafeERC20Staking.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity 0.8.16;

import "../dao/tokens/ERC20/IERC20.sol";
import "../dao/tokens/ERC20/extensions/IERC20Permit.sol";
import "./Address.sol";

/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20Staking {
using Address for address;

function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}

/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}

/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.

bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
2 changes: 1 addition & 1 deletion contracts/common/Strings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

/**
* @dev String operations.
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/access/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

import "./IAccessControl.sol";
import "../Context.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/access/IAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

/**
* @dev External interface of AccessControl declared to support ERC165 detection.
Expand Down
28 changes: 23 additions & 5 deletions contracts/common/cryptography/ECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/ECDSA.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

import "../Strings.sol";

Expand Down Expand Up @@ -101,7 +101,11 @@ library ECDSA {
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
Expand All @@ -112,7 +116,11 @@ library ECDSA {
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
Expand All @@ -124,7 +132,12 @@ library ECDSA {
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
Expand Down Expand Up @@ -154,7 +167,12 @@ library ECDSA {
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
Expand Down
8 changes: 6 additions & 2 deletions contracts/common/cryptography/EIP712.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts v4.4.1 (utils/cryptography/EIP712.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

import "./ECDSA.sol";

Expand Down Expand Up @@ -101,7 +101,11 @@ abstract contract EIP712 {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}

function _buildDomainSeparator(bytes32 typeHash, bytes32 nameHash, bytes32 versionHash) private view returns (bytes32) {
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, getChainID(), address(this)));
}
}
2 changes: 1 addition & 1 deletion contracts/common/introspection/ERC165.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

import "./IERC165.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/common/introspection/IERC165.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Original Copyright OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
// Copyright Fathom 2022

pragma solidity 0.8.13;
pragma solidity 0.8.16;

/**
* @dev Interface of the ERC165 standard, as defined in the
Expand Down
Loading

0 comments on commit c5ba9ca

Please sign in to comment.