Skip to content

Commit 2c7bacb

Browse files
committed
did some more contracts
1 parent 4f21baa commit 2c7bacb

10 files changed

Lines changed: 84 additions & 65 deletions

contracts/Safe.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ contract Safe is
438438
//
439439
// WARNING: We do not clean potential dirty bits in types that are less than 256 bits (addresses and `Enum.Operation`)
440440
// Solidity types that are smaller than 256 bit can have dirty high bits when accessed in assembly according to the spec
441-
// (see the warning in <https://docs.soliditylang.org/en/latest/assembly.html#access-to-external-variables-functions-and-libraries>).
441+
// (see the warning in <https://docs.soliditylang.org/en/v0.7.6/assembly.html#access-to-external-variables-functions-and-libraries>).
442442
// However, we read most of the data from calldata, where the variables are not packed, and the only variable we read from storage is `uint256 nonce`.
443443
// This is not a problem, however, we must consider this for potential future changes.
444444
/* solhint-disable no-inline-assembly */

contracts/base/FallbackManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ abstract contract FallbackManager is SelfAuthorized, IFallbackManager {
6565
assembly {
6666
// When compiled with the optimizer, the compiler relies on certain assumptions on how the
6767
// memory is used, therefore we need to guarantee memory safety (keeping the free memory pointer
68-
// at memory offset 0x40 intact, not going beyond the scratch space, etc)
68+
// at memory offset 0x40 intact, not going beyond the scratch space, etc).
6969
// See: <https://docs.soliditylang.org/en/latest/assembly.html#memory-safety>
7070

7171
let handler := sload(FALLBACK_HANDLER_STORAGE_SLOT)

contracts/common/NativeCurrencyPaymentFallback.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
pragma solidity >=0.7.0 <0.9.0;
33

44
/**
5-
* @title NativeCurrencyPaymentFallback - A contract that has a fallback to accept native currency payments.
5+
* @title Native Currency Payment Fallback
6+
* @notice A contract that has a fallback to accept native token payments.
67
* @author Richard Meissner - @rmeissner
78
*/
89
abstract contract NativeCurrencyPaymentFallback {
10+
/**
11+
* @notice Native tokens were received.
12+
* @param sender The address that sent the tokens.
13+
* @param value The native token value that was received.
14+
*/
915
event SafeReceived(address indexed sender, uint256 value);
1016

1117
/**
12-
* @notice Receive function accepts native currency transactions.
18+
* @notice Receive function that accepts native token transactions.
1319
* @dev Emits an event with sender and received value.
1420
*/
1521
receive() external payable {

contracts/common/SecuredTokenTransfer.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
pragma solidity >=0.7.0 <0.9.0;
33

44
/**
5-
* @title SecuredTokenTransfer - Secure token transfer.
5+
* @title Secured Token Transfer
6+
* @notice Securely transfer tokens, handling non-standard ERC-20 tokens.
67
* @author Richard Meissner - @rmeissner
78
*/
89
abstract contract SecuredTokenTransfer {
910
/**
10-
* @notice Transfers a token and returns a boolean if it was a success
11+
* @notice Transfers a token and returns `true` if it was successful, `false` otherwise.
1112
* @dev It checks the return data of the transfer call and returns true if the transfer was successful.
1213
* It doesn't check if the `token` address is a contract or not.
13-
* @param token Token that should be transferred
14-
* @param receiver Receiver to whom the token should be transferred
15-
* @param amount The amount of tokens that should be transferred
16-
* @return transferred Returns true if the transfer was successful
14+
* @param token Token that should be transferred.
15+
* @param receiver Receiver to whom the token should be transferred.
16+
* @param amount The amount of tokens that should be transferred.
17+
* @return transferred Boolean indicating whether or not the transfer was successful.
1718
*/
1819
function transferToken(address token, address receiver, uint256 amount) internal returns (bool transferred) {
19-
// 0xa9059cbb - bytes4(keccak256("transfer(address,uint256)"))
20+
// The transfer function selector `0xa9059cbb`, precomputed value of `bytes4(keccak256("transfer(address,uint256)"))`.
2021
bytes memory data = abi.encodeWithSelector(0xa9059cbb, receiver, amount);
2122
/* solhint-disable no-inline-assembly */
2223
/// @solidity memory-safe-assembly
2324
assembly {
2425
// We write the return value to scratch space.
25-
// See https://docs.soliditylang.org/en/v0.7.6/internals/layout_in_memory.html#layout-in-memory
26+
// See <https://docs.soliditylang.org/en/v0.7.6/internals/layout_in_memory.html#layout-in-memory>
2627
let success := call(sub(gas(), 10000), token, 0, add(data, 0x20), mload(data), 0, 0x20)
2728
switch returndatasize()
2829
case 0 {

contracts/common/SelfAuthorized.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ pragma solidity >=0.7.0 <0.9.0;
44
import {ErrorMessage} from "../libraries/ErrorMessage.sol";
55

66
/**
7-
* @title SelfAuthorized - Authorizes current contract to perform actions to itself.
7+
* @title Self Authorized
8+
* @notice Authorizes current contract to perform actions on itself.
89
* @author Richard Meissner - @rmeissner
910
*/
1011
abstract contract SelfAuthorized is ErrorMessage {
12+
/**
13+
* @dev Ensure that the `msg.sender` is the current contract.
14+
*/
1115
function requireSelfCall() private view {
1216
if (msg.sender != address(this)) revertWithError("GS031");
1317
}
1418

19+
/**
20+
* @notice Ensure that a function is authorized.
21+
* @dev This modifier authorizes calls by ensuring that the contract called itself.
22+
*/
1523
modifier authorized() {
16-
// Modifiers are copied around during compilation. This is a function call as it minimized the bytecode size
24+
// Modifiers are copied around during compilation. This is a function call to minimized the bytecode size.
1725
requireSelfCall();
1826
_;
1927
}

contracts/common/SignatureDecoder.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
pragma solidity >=0.7.0 <0.9.0;
33

44
/**
5-
* @title SignatureDecoder - Decodes signatures encoded as bytes
5+
* @title Signature Decoder
6+
* @notice Decodes encoded packed signatures bytes.
67
* @author Richard Meissner - @rmeissner
78
*/
89
abstract contract SignatureDecoder {
910
/**
10-
* @notice Splits signature bytes into `uint8 v, bytes32 r, bytes32 s`.
11-
* @dev Make sure to perform a bounds check for @param pos, to avoid out of bounds access on @param signatures
12-
* The signature format is a compact form of {bytes32 r}{bytes32 s}{uint8 v}
13-
* Compact means uint8 is not padded to 32 bytes.
14-
* @param pos Which signature to read.
15-
* A prior bounds check of this parameter should be performed, to avoid out of bounds access.
16-
* @param signatures Concatenated {r, s, v} signatures.
11+
* @notice Splits signature bytes into its `v`, `r` and `s` components, starting from `pos`.
12+
* @dev Make sure to perform a bounds check for `pos`, to avoid out of bounds access on `signatures`.
13+
* The signature format is a compact form of `r:bytes32 || s:bytes32 || v:uint8`,
14+
* where `v` is a single byte and not padded to 32 bytes.
15+
* @param pos Position to start reading the packed signature components.
16+
* Bounds check that `signatures[pos:pos+65]` is valid must be performed by the caller.
17+
* @param signatures Encoded packed signatures bytes.
1718
* @return v Recovery ID or Safe signature type.
1819
* @return r Output value r of the signature.
1920
* @return s Output value s of the signature.

contracts/common/Singleton.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
pragma solidity >=0.7.0 <0.9.0;
33

44
/**
5-
* @title Singleton - Base for singleton contracts (should always be the first super contract)
6-
* This contract is tightly coupled to our proxy contract (see `proxies/SafeProxy.sol`)
5+
* @title Singleton
6+
* @notice Base contract for singleton that can be used as implementations for {SafeProxy}s.
7+
* @dev This must always be the first super contract.
8+
* This contract is tightly coupled to our {SafeProxy} contract (see `proxies/SafeProxy.sol`).
79
* @author Richard Meissner - @rmeissner
810
*/
911
abstract contract Singleton {
10-
// singleton always has to be the first declared variable to ensure the same location as in the Proxy contract.
11-
// It should also always be ensured the address is stored alone (uses a full word)
12+
/**
13+
* @dev `singleton` must be the first declared variable to ensure it has the same storage location as in the {SafeProxy} contract.
14+
* The address must be stored alone: it must use a full 32-byte word and cannot be packed with other storage variables.
15+
*/
1216
address private singleton;
1317
}

contracts/common/StorageAccessible.sol

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
pragma solidity >=0.7.0 <0.9.0;
33

44
/**
5-
* @title StorageAccessible - A generic base contract that allows callers to access all internal storage.
6-
* @notice See https://github.com/gnosis/util-contracts/blob/bb5fe5fb5df6d8400998094fb1b32a178a47c3a1/contracts/StorageAccessible.sol
7-
* It removes a method from the original contract not needed for the Safe Smart Account contracts.
5+
* @title Storage Accessible
6+
* @notice A generic base contract that allows callers to access all internal storage.
7+
* @dev See <https://github.com/gnosis/util-contracts/blob/bb5fe5fb5df6d8400998094fb1b32a178a47c3a1/contracts/StorageAccessible.sol>
8+
* It removes a method from the original contract not needed for the Safe Smart Account contracts.
89
* @author Gnosis Developers
910
*/
1011
abstract contract StorageAccessible {
1112
/**
1213
* @notice Reads `length` bytes of storage in the current contract
13-
* @param offset - the offset in the current contract's storage in words to start reading from
14-
* @param length - the number of words (32 bytes) of data to read
15-
* @return the bytes that were read.
14+
* @param offset The offset in the current contract's storage in words to start reading from.
15+
* @param length The number of words (32 bytes) of data to read.
16+
* @return The bytes that were read.
1617
*/
1718
function getStorageAt(uint256 offset, uint256 length) public view returns (bytes memory) {
18-
// We use `<< 5` instead of `* 32` as SHR / SHL opcode only uses 3 gas, while DIV / MUL opcode uses 5 gas.
19+
// We use `<< 5` instead of the equivalent `* 32` as `SHL` opcode only uses 3 gas, while the `MUL` opcode uses 5 gas.
1920
bytes memory result = new bytes(length << 5);
2021
for (uint256 index = 0; index < length; ++index) {
2122
/* solhint-disable no-inline-assembly */
@@ -30,13 +31,11 @@ abstract contract StorageAccessible {
3031
}
3132

3233
/**
33-
* @dev Performs a delegatecall on a targetContract in the context of self.
34-
* Internally reverts execution to avoid side effects (making it effectively static).
35-
*
36-
* This method reverts with data equal to `abi.encodePacked(uint256(success), uint256(response.length), bytes(response))`.
37-
* Specifically, the `returndata` after a call to this method will be:
38-
* `success:uint256 || response.length:uint256 || response:bytes`.
39-
*
34+
* @notice Performs a `DELEGATECALL` to a `targetContract` in the context of self.
35+
* @dev Internally reverts execution to avoid side effects (making it effectively static).
36+
* This method reverts with data equal to `abi.encodePacked(uint256(success), uint256(response.length), bytes(response))`.
37+
* Specifically, the return data after a call to this method will be:
38+
* `success:uint256 || response.length:uint256 || response:bytes`.
4039
* @param targetContract Address of the contract containing the code to execute.
4140
* @param calldataPayload Calldata that should be sent to the target contract (encoded method name and arguments).
4241
*/
@@ -45,7 +44,7 @@ abstract contract StorageAccessible {
4544
/// @solidity memory-safe-assembly
4645
assembly {
4746
let success := delegatecall(gas(), targetContract, add(calldataPayload, 0x20), mload(calldataPayload), 0, 0)
48-
// Load free memory location
47+
// Load free memory location.
4948
let ptr := mload(0x40)
5049
mstore(ptr, success)
5150
mstore(add(ptr, 0x20), returndatasize())

contracts/external/SafeMath.sol

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
pragma solidity >=0.7.0 <0.9.0;
33

44
/**
5-
* @title SafeMath
6-
* @notice Math operations with safety checks that revert on error (overflow/underflow)
5+
* @title Safe Math
6+
* @notice Math operations with safety checks that revert on error (overflow/underflow).
77
*/
88
library SafeMath {
99
/**
1010
* @notice Multiplies two numbers, reverts on overflow.
11-
* @param a First number
12-
* @param b Second number
13-
* @return Product of a and b
11+
* @param a First number.
12+
* @param b Second number.
13+
* @return Product of `a` and `b`.
1414
*/
1515
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
16-
// Gas optimization: this is cheaper than requiring 'a' not to be zero, but the
17-
// benefit is lost if 'b' is also tested.
18-
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
16+
// Gas optimization: this is cheaper than requiring 'a' not to be zero,
17+
// but the benefit is lost if 'b' is also tested.
18+
// See: <https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522>
1919
if (a == 0) {
2020
return 0;
2121
}
@@ -28,9 +28,9 @@ library SafeMath {
2828

2929
/**
3030
* @notice Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
31-
* @param a First number
32-
* @param b Second number
33-
* @return Difference of a and b
31+
* @param a First number.
32+
* @param b Second number.
33+
* @return Difference of `a` and `b`.
3434
*/
3535
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
3636
require(b <= a);
@@ -41,9 +41,9 @@ library SafeMath {
4141

4242
/**
4343
* @notice Adds two numbers, reverts on overflow.
44-
* @param a First number
45-
* @param b Second number
46-
* @return Sum of a and b
44+
* @param a First number.
45+
* @param b Second number.
46+
* @return Sum of `a` and `b`.
4747
*/
4848
function add(uint256 a, uint256 b) internal pure returns (uint256) {
4949
uint256 c = a + b;
@@ -54,9 +54,9 @@ library SafeMath {
5454

5555
/**
5656
* @notice Returns the largest of two numbers.
57-
* @param a First number
58-
* @param b Second number
59-
* @return Largest of a and b
57+
* @param a First number.
58+
* @param b Second number.
59+
* @return Largest of `a` and `b`.
6060
*/
6161
function max(uint256 a, uint256 b) internal pure returns (uint256) {
6262
return a >= b ? a : b;

docs/guidelines.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ We are manually reviewing the NatSpec documentation to make sure there aren't an
5252
- [x] base/GuardManager.sol
5353
- [x] base/ModuleManager.sol
5454
- [x] base/OwnerManager.sol
55-
- [ ] common/NativeCurrencyPaymentFallback.sol
56-
- [ ] common/SecuredTokenTransfer.sol
57-
- [ ] common/SelfAuthorized.sol
58-
- [ ] common/SignatureDecoder.sol
59-
- [ ] common/Singleton.sol
60-
- [ ] common/StorageAccessible.sol
61-
- [ ] external/SafeMath.sol
55+
- [x] common/NativeCurrencyPaymentFallback.sol
56+
- [x] common/SecuredTokenTransfer.sol
57+
- [x] common/SelfAuthorized.sol
58+
- [x] common/SignatureDecoder.sol
59+
- [x] common/Singleton.sol
60+
- [x] common/StorageAccessible.sol
61+
- [x] external/SafeMath.sol
6262
- [ ] handler/CompatibilityFallbackHandler.sol
6363
- [ ] handler/ExtensibleFallbackHandler.sol
6464
- [ ] handler/HandlerContext.sol

0 commit comments

Comments
 (0)