Skip to content

Commit 414cb9e

Browse files
authored
Consistently name multiple returned values (#5177)
1 parent 4c481d6 commit 414cb9e

File tree

13 files changed

+156
-97
lines changed

13 files changed

+156
-97
lines changed

contracts/governance/Governor.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
802802
* @dev Try to parse a character from a string as a hex value. Returns `(true, value)` if the char is in
803803
* `[0-9a-fA-F]` and `(false, 0)` otherwise. Value is guaranteed to be in the range `0 <= value < 16`
804804
*/
805-
function _tryHexToUint(bytes1 char) private pure returns (bool, uint8) {
805+
function _tryHexToUint(bytes1 char) private pure returns (bool isHex, uint8 value) {
806806
uint8 c = uint8(char);
807807
unchecked {
808808
// Case 0-9

contracts/governance/extensions/GovernorStorage.sol

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ abstract contract GovernorStorage is Governor {
8888
*/
8989
function proposalDetails(
9090
uint256 proposalId
91-
) public view virtual returns (address[] memory, uint256[] memory, bytes[] memory, bytes32) {
91+
)
92+
public
93+
view
94+
virtual
95+
returns (address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
96+
{
9297
// here, using memory is more efficient than storage
9398
ProposalDetails memory details = _proposalDetails[proposalId];
9499
if (details.descriptionHash == 0) {
@@ -102,14 +107,19 @@ abstract contract GovernorStorage is Governor {
102107
*/
103108
function proposalDetailsAt(
104109
uint256 index
105-
) public view virtual returns (uint256, address[] memory, uint256[] memory, bytes[] memory, bytes32) {
106-
uint256 proposalId = _proposalIds[index];
107-
(
110+
)
111+
public
112+
view
113+
virtual
114+
returns (
115+
uint256 proposalId,
108116
address[] memory targets,
109117
uint256[] memory values,
110118
bytes[] memory calldatas,
111119
bytes32 descriptionHash
112-
) = proposalDetails(proposalId);
113-
return (proposalId, targets, values, calldatas, descriptionHash);
120+
)
121+
{
122+
proposalId = _proposalIds[index];
123+
(targets, values, calldatas, descriptionHash) = proposalDetails(proposalId);
114124
}
115125
}

contracts/governance/utils/Votes.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
232232
Checkpoints.Trace208 storage store,
233233
function(uint208, uint208) view returns (uint208) op,
234234
uint208 delta
235-
) private returns (uint208, uint208) {
235+
) private returns (uint208 oldValue, uint208 newValue) {
236236
return store.push(clock(), op(store.latest(), delta));
237237
}
238238

contracts/metatx/ERC2771Forwarder.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
218218
*/
219219
function _recoverForwardRequestSigner(
220220
ForwardRequestData calldata request
221-
) internal view virtual returns (bool, address) {
221+
) internal view virtual returns (bool isValid, address signer) {
222222
(address recovered, ECDSA.RecoverError err, ) = _hashTypedDataV4(
223223
keccak256(
224224
abi.encode(

contracts/token/ERC20/extensions/ERC4626.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ abstract contract ERC4626 is ERC20, IERC4626 {
8383
/**
8484
* @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
8585
*/
86-
function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
86+
function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool ok, uint8 assetDecimals) {
8787
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
8888
abi.encodeCall(IERC20Metadata.decimals, ())
8989
);

contracts/token/common/ERC2981.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ abstract contract ERC2981 is IERC2981, ERC165 {
5858
/**
5959
* @inheritdoc IERC2981
6060
*/
61-
function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual returns (address, uint256) {
61+
function royaltyInfo(
62+
uint256 tokenId,
63+
uint256 salePrice
64+
) public view virtual returns (address receiver, uint256 amount) {
6265
RoyaltyInfo storage _royaltyInfo = _tokenRoyaltyInfo[tokenId];
6366
address royaltyReceiver = _royaltyInfo.receiver;
6467
uint96 royaltyFraction = _royaltyInfo.royaltyFraction;

contracts/utils/cryptography/ECDSA.sol

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ library ECDSA {
5353
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
5454
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
5555
*/
56-
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
56+
function tryRecover(
57+
bytes32 hash,
58+
bytes memory signature
59+
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
5760
if (signature.length == 65) {
5861
bytes32 r;
5962
bytes32 s;
@@ -96,7 +99,11 @@ library ECDSA {
9699
*
97100
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
98101
*/
99-
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
102+
function tryRecover(
103+
bytes32 hash,
104+
bytes32 r,
105+
bytes32 vs
106+
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
100107
unchecked {
101108
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
102109
// We do not check for an overflow here since the shift operation results in 0 or 1.
@@ -123,7 +130,7 @@ library ECDSA {
123130
uint8 v,
124131
bytes32 r,
125132
bytes32 s
126-
) internal pure returns (address, RecoverError, bytes32) {
133+
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
127134
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
128135
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
129136
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most

contracts/utils/cryptography/P256.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ library P256 {
120120
* IMPORTANT: This function disallows signatures where the `s` value is above `N/2` to prevent malleability.
121121
* To flip the `s` value, compute `s = N - s` and `v = 1 - v` if (`v = 0 | 1`).
122122
*/
123-
function recovery(bytes32 h, uint8 v, bytes32 r, bytes32 s) internal view returns (bytes32, bytes32) {
123+
function recovery(bytes32 h, uint8 v, bytes32 r, bytes32 s) internal view returns (bytes32 x, bytes32 y) {
124124
if (!_isProperSignature(r, s) || v > 1) {
125125
return (0, 0);
126126
}
@@ -136,8 +136,8 @@ library P256 {
136136
uint256 w = Math.invModPrime(uint256(r), N);
137137
uint256 u1 = mulmod(N - (uint256(h) % N), w, N);
138138
uint256 u2 = mulmod(uint256(s), w, N);
139-
(uint256 x, uint256 y) = _jMultShamir(points, u1, u2);
140-
return (bytes32(x), bytes32(y));
139+
(uint256 xU, uint256 yU) = _jMultShamir(points, u1, u2);
140+
return (bytes32(xU), bytes32(yU));
141141
}
142142

143143
/**
@@ -247,7 +247,11 @@ library P256 {
247247
* The individual points for a single pass are precomputed.
248248
* Overall this reduces the number of additions while keeping the same number of doublings.
249249
*/
250-
function _jMultShamir(JPoint[16] memory points, uint256 u1, uint256 u2) private view returns (uint256, uint256) {
250+
function _jMultShamir(
251+
JPoint[16] memory points,
252+
uint256 u1,
253+
uint256 u2
254+
) private view returns (uint256 rx, uint256 ry) {
251255
uint256 x = 0;
252256
uint256 y = 0;
253257
uint256 z = 0;

contracts/utils/structs/Checkpoints.sol

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ library Checkpoints {
3636
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint32).max` key set will disable the
3737
* library.
3838
*/
39-
function push(Trace224 storage self, uint32 key, uint224 value) internal returns (uint224, uint224) {
39+
function push(
40+
Trace224 storage self,
41+
uint32 key,
42+
uint224 value
43+
) internal returns (uint224 oldValue, uint224 newValue) {
4044
return _insert(self._checkpoints, key, value);
4145
}
4246

@@ -127,7 +131,11 @@ library Checkpoints {
127131
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
128132
* or by updating the last one.
129133
*/
130-
function _insert(Checkpoint224[] storage self, uint32 key, uint224 value) private returns (uint224, uint224) {
134+
function _insert(
135+
Checkpoint224[] storage self,
136+
uint32 key,
137+
uint224 value
138+
) private returns (uint224 oldValue, uint224 newValue) {
131139
uint256 pos = self.length;
132140

133141
if (pos > 0) {
@@ -231,7 +239,11 @@ library Checkpoints {
231239
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint48).max` key set will disable the
232240
* library.
233241
*/
234-
function push(Trace208 storage self, uint48 key, uint208 value) internal returns (uint208, uint208) {
242+
function push(
243+
Trace208 storage self,
244+
uint48 key,
245+
uint208 value
246+
) internal returns (uint208 oldValue, uint208 newValue) {
235247
return _insert(self._checkpoints, key, value);
236248
}
237249

@@ -322,7 +334,11 @@ library Checkpoints {
322334
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
323335
* or by updating the last one.
324336
*/
325-
function _insert(Checkpoint208[] storage self, uint48 key, uint208 value) private returns (uint208, uint208) {
337+
function _insert(
338+
Checkpoint208[] storage self,
339+
uint48 key,
340+
uint208 value
341+
) private returns (uint208 oldValue, uint208 newValue) {
326342
uint256 pos = self.length;
327343

328344
if (pos > 0) {
@@ -426,7 +442,11 @@ library Checkpoints {
426442
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint96).max` key set will disable the
427443
* library.
428444
*/
429-
function push(Trace160 storage self, uint96 key, uint160 value) internal returns (uint160, uint160) {
445+
function push(
446+
Trace160 storage self,
447+
uint96 key,
448+
uint160 value
449+
) internal returns (uint160 oldValue, uint160 newValue) {
430450
return _insert(self._checkpoints, key, value);
431451
}
432452

@@ -517,7 +537,11 @@ library Checkpoints {
517537
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
518538
* or by updating the last one.
519539
*/
520-
function _insert(Checkpoint160[] storage self, uint96 key, uint160 value) private returns (uint160, uint160) {
540+
function _insert(
541+
Checkpoint160[] storage self,
542+
uint96 key,
543+
uint160 value
544+
) private returns (uint160 oldValue, uint160 newValue) {
521545
uint256 pos = self.length;
522546

523547
if (pos > 0) {

0 commit comments

Comments
 (0)