Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v5.1 updates #5139

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a726d5d
Create a ERC1363Utils helper similar to existing ERC721Utils and ERC1…
Amxx Aug 2, 2024
0af6561
Get leaves from memory in processMultiProofCalldata (#5140)
Amxx Aug 2, 2024
b10df77
Make explicit the validity of the empty set in MerkleProof.sol (#5142)
ernestognw Aug 7, 2024
4fb8987
Remove double declaration of `P` in P256 (#5159)
cairoeth Aug 21, 2024
c8b4529
Update declaration of memory safe assembly blocks (#5172)
Amxx Aug 29, 2024
56c27d2
Remove redundant array access in Checkpoints (#5169)
Amxx Aug 29, 2024
e995abf
Remove unused import in IAccessManaged (#5170)
Amxx Aug 29, 2024
c51cc4d
Fix typographical errors (#5171)
Amxx Aug 29, 2024
58a1147
Add missing docstrings (#5168)
Amxx Aug 29, 2024
7048533
Update MerkleProof note clarifying empty set definition (#5144)
ernestognw Aug 9, 2024
90afffc
Add memory side effects notes when using function pointers (#5174)
ernestognw Aug 30, 2024
67ea678
Revert "Remove double declaration of `P` in P256 (#5159)" (#5180)
Amxx Aug 30, 2024
6af500b
Optimizations to P256 operations (#5181)
cairoeth Sep 3, 2024
6aac3f9
Add note about 100% royalty in IERC2981 (#5173)
ernestognw Sep 3, 2024
444c65e
Make padding skip clear in Base64URL encoding (#5176)
ernestognw Sep 3, 2024
56c61cc
Clarify Governor events' lack of indexed parameters (#5175)
ernestognw Sep 5, 2024
fe3c344
Fix typographical errors (#5194)
cairoeth Sep 13, 2024
0698da4
Update to match Solidity pragma (#5198)
cairoeth Sep 17, 2024
d521fe7
Remove redundant modulo operation in P256 (#5200)
cairoeth Sep 17, 2024
21046a7
Clean dirty addresses and booleans (#5195)
cairoeth Sep 18, 2024
ecb562a
Clarify reference commits and licenses (#5205)
cairoeth Sep 19, 2024
fa0d643
Clarify mapping named parameters (#5204)
cairoeth Sep 19, 2024
13672e0
Update documentation of helper interface (#5179)
Amxx Sep 19, 2024
2c2e522
Add note about memory manipulation in MerkleTree (#5213)
ernestognw Sep 19, 2024
aa536ca
Disallow empty CircularBuffer setup (#5214)
ernestognw Sep 19, 2024
1d425c3
Update and clarify documentation comments (#5206)
cairoeth Sep 23, 2024
28cb012
Add P256 and RSA documentation sections (#5227)
ericglau Sep 25, 2024
d9bad96
Refactor Heap.sol to remove `index` and `lookup` (#5190)
Amxx Oct 1, 2024
d240bde
Implement 5.1 Full Audit Naming Suggestions (#5215)
ernestognw Sep 25, 2024
4a9e581
Consistently name multiple returned values (#5177)
ernestognw Sep 25, 2024
d681671
Improve VestingWallet's constructor and RSA.pkcs1Sha256 documentation…
Amxx Sep 27, 2024
ad8e94e
Add introduction tag for v5.1 contracts (#5228)
cairoeth Sep 27, 2024
00c85e6
Fix invalid link and typos (#5232)
Amxx Oct 1, 2024
6709a08
Fix P256 corner cases (#5218)
cairoeth Sep 30, 2024
e24c155
Add warning about low public key exponent (#5234)
Amxx Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-bats-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC1363Utils`: Add helper similar to the existing `ERC721Utils` and `ERC1155Utils`
8 changes: 8 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ module.exports = {
fgrep: '[skip-on-coverage]',
invert: true,
},
// Work around stack too deep for coverage
configureYulOptimizer: true,
solcOptimizerDetails: {
yul: true,
yulDetails: {
optimizerSteps: '',
},
},
};
10 changes: 9 additions & 1 deletion contracts/access/manager/AccessManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ contract AccessManager is Context, Multicall, IAccessManager {
uint32 nonce;
}

/**
* @dev The identifier of the admin role. Required to perform most configuration operations including
* other roles' management and target restrictions.
*/
uint64 public constant ADMIN_ROLE = type(uint64).min; // 0

/**
* @dev The identifier of the public role. Automatically granted to all addresses with no delay.
*/
uint64 public constant PUBLIC_ROLE = type(uint64).max; // 2**64-1

mapping(address target => TargetConfig mode) private _targets;
Expand Down Expand Up @@ -687,7 +695,7 @@ contract AccessManager is Context, Multicall, IAccessManager {

(bool adminRestricted, uint64 roleId, uint32 operationDelay) = _getAdminRestrictions(data);

// isTragetClosed apply to non-admin-restricted function
// isTargetClosed apply to non-admin-restricted function
if (!adminRestricted && isTargetClosed(address(this))) {
return (false, 0);
}
Expand Down
1 change: 0 additions & 1 deletion contracts/access/manager/IAccessManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

pragma solidity ^0.8.20;

import {IAccessManaged} from "./IAccessManaged.sol";
import {Time} from "../../utils/types/Time.sol";

interface IAccessManager {
Expand Down
4 changes: 2 additions & 2 deletions contracts/finance/VestingWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ contract VestingWallet is Context, Ownable {
uint64 private immutable _duration;

/**
* @dev Sets the sender as the initial owner, the beneficiary as the pending owner, the start timestamp and the
* vesting duration of the vesting wallet.
* @dev Sets the beneficiary (owner), the start timestamp and the vesting duration (in seconds) of the vesting
* wallet.
*/
constructor(address beneficiary, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(beneficiary) {
_start = startTimestamp;
Expand Down
6 changes: 4 additions & 2 deletions contracts/finance/VestingWalletCliff.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {VestingWallet} from "./VestingWallet.sol";

/**
* @dev Extension of {VestingWallet} that adds a cliff to the vesting schedule.
*
* _Available since v5.1._
*/
abstract contract VestingWalletCliff is VestingWallet {
using SafeCast for *;
Expand All @@ -17,8 +19,8 @@ abstract contract VestingWalletCliff is VestingWallet {
error InvalidCliffDuration(uint64 cliffSeconds, uint64 durationSeconds);

/**
* @dev Sets the sender as the initial owner, the beneficiary as the pending owner, the start timestamp, the
* vesting duration and the duration of the cliff of the vesting wallet.
* @dev Set the duration of the cliff, in seconds. The cliff starts vesting schedule (see {VestingWallet}'s
* constructor) and ends `cliffSeconds` later.
*/
constructor(uint64 cliffSeconds) {
if (cliffSeconds > duration()) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
* @dev Try to parse a character from a string as a hex value. Returns `(true, value)` if the char is in
* `[0-9a-fA-F]` and `(false, 0)` otherwise. Value is guaranteed to be in the range `0 <= value < 16`
*/
function _tryHexToUint(bytes1 char) private pure returns (bool, uint8) {
function _tryHexToUint(bytes1 char) private pure returns (bool isHex, uint8 value) {
uint8 c = uint8(char);
unchecked {
// Case 0-9
Expand Down
3 changes: 3 additions & 0 deletions contracts/governance/IGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {IERC6372} from "../interfaces/IERC6372.sol";

/**
* @dev Interface of the {Governor} core.
*
* NOTE: Event parameters lack the `indexed` keyword for compatibility with GovernorBravo events.
* Making event parameters `indexed` affects how events are decoded, potentially breaking existing indexers.
*/
interface IGovernor is IERC165, IERC6372 {
enum ProposalState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {Math} from "../../utils/math/Math.sol";
* * Voting privately from a shielded pool using zero knowledge proofs.
*
* Based on ScopeLift's GovernorCountingFractional[https://github.com/ScopeLift/flexible-voting/blob/e5de2efd1368387b840931f19f3c184c85842761/src/GovernorCountingFractional.sol]
*
* _Available since v5.1._
*/
abstract contract GovernorCountingFractional is Governor {
using Math for *;
Expand All @@ -43,7 +45,7 @@ abstract contract GovernorCountingFractional is Governor {
/**
* @dev Mapping from proposal ID to vote tallies for that proposal.
*/
mapping(uint256 => ProposalVote) private _proposalVotes;
mapping(uint256 proposalId => ProposalVote) private _proposalVotes;

/**
* @dev A fractional vote params uses more votes than are available for that user.
Expand Down Expand Up @@ -145,7 +147,7 @@ abstract contract GovernorCountingFractional is Governor {
uint256 againstVotes = 0;
uint256 forVotes = 0;
uint256 abstainVotes = 0;
uint256 usedWeight;
uint256 usedWeight = 0;

// For clarity of event indexing, fractional voting must be clearly advertised in the "support" field.
//
Expand Down
22 changes: 16 additions & 6 deletions contracts/governance/extensions/GovernorStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ abstract contract GovernorStorage is Governor {
*/
function proposalDetails(
uint256 proposalId
) public view virtual returns (address[] memory, uint256[] memory, bytes[] memory, bytes32) {
)
public
view
virtual
returns (address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
{
// here, using memory is more efficient than storage
ProposalDetails memory details = _proposalDetails[proposalId];
if (details.descriptionHash == 0) {
Expand All @@ -102,14 +107,19 @@ abstract contract GovernorStorage is Governor {
*/
function proposalDetailsAt(
uint256 index
) public view virtual returns (uint256, address[] memory, uint256[] memory, bytes[] memory, bytes32) {
uint256 proposalId = _proposalIds[index];
(
)
public
view
virtual
returns (
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) = proposalDetails(proposalId);
return (proposalId, targets, values, calldatas, descriptionHash);
)
{
proposalId = _proposalIds[index];
(targets, values, calldatas, descriptionHash) = proposalDetails(proposalId);
}
}
2 changes: 1 addition & 1 deletion contracts/governance/utils/Votes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
Checkpoints.Trace208 storage store,
function(uint208, uint208) view returns (uint208) op,
uint208 delta
) private returns (uint208, uint208) {
) private returns (uint208 oldValue, uint208 newValue) {
return store.push(clock(), op(store.latest(), delta));
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC1363Receiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IERC1363Receiver {
* (i.e. 0x88a7ca5c, or its own function selector).
*
* @param operator The address which called `transferAndCall` or `transferFromAndCall` function.
* @param from The address which are tokens transferred from.
* @param from The address which the tokens are transferred from.
* @param value The amount of tokens transferred.
* @param data Additional data with no specified format.
* @return `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))` if transfer is allowed unless throwing.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC1363Spender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pragma solidity ^0.8.20;

/**
* @title ERC1363Spender
* @title IERC1363Spender
* @dev Interface for any contract that wants to support `approveAndCall`
* from ERC-1363 token contracts.
*/
Expand Down
3 changes: 3 additions & 0 deletions contracts/interfaces/IERC2981.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ interface IERC2981 is IERC165 {
/**
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
*
* NOTE: ERC-2981 allows setting the royalty to 100% of the price. In that case all the price would be sent to the
* royalty receiver and 0 tokens to the seller. Contracts dealing with royalty should consider empty transfers.
*/
function royaltyInfo(
uint256 tokenId,
Expand Down
8 changes: 3 additions & 5 deletions contracts/metatx/ERC2771Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
*/
function _recoverForwardRequestSigner(
ForwardRequestData calldata request
) internal view virtual returns (bool, address) {
) internal view virtual returns (bool isValid, address signer) {
(address recovered, ECDSA.RecoverError err, ) = _hashTypedDataV4(
keccak256(
abi.encode(
Expand Down Expand Up @@ -309,8 +309,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
bool success;
uint256 returnSize;
uint256 returnValue;
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
// Perform the staticcall and save the result in the scratch space.
// | Location | Content | Content (Hex) |
// |-----------|----------|--------------------------------------------------------------------|
Expand Down Expand Up @@ -362,8 +361,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
// neither revert or assert consume all gas since Solidity 0.8.20
// https://docs.soliditylang.org/en/v0.8.20/control-structures.html#panic-via-assert-and-error-via-require
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
invalid()
}
}
Expand Down
9 changes: 3 additions & 6 deletions contracts/proxy/Clones.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ library Clones {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
Expand Down Expand Up @@ -77,8 +76,7 @@ library Clones {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
Expand All @@ -99,8 +97,7 @@ library Clones {
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
Expand Down
2 changes: 1 addition & 1 deletion contracts/proxy/ERC1967/ERC1967Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
* @dev This abstract contract provides getters and event emitting update functions for
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
Expand Down
3 changes: 2 additions & 1 deletion contracts/proxy/transparent/TransparentUpgradeableProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {ProxyAdmin} from "./ProxyAdmin.sol";
* include them in the ABI so this interface must be used to interact with it.
*/
interface ITransparentUpgradeableProxy is IERC1967 {
function upgradeToAndCall(address, bytes calldata) external payable;
/// @dev See {UUPSUpgradeable-upgradeToAndCall}
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions contracts/token/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER
uint256 element1,
uint256 element2
) private pure returns (uint256[] memory array1, uint256[] memory array2) {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
// Load the free memory pointer
array1 := mload(0x40)
// Set array length to 1
Expand Down
2 changes: 2 additions & 0 deletions contracts/token/ERC1155/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel
== Utilities

{{ERC1155Holder}}

{{ERC1155Utils}}
12 changes: 6 additions & 6 deletions contracts/token/ERC1155/utils/ERC1155Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {IERC1155Errors} from "../../../interfaces/draft-IERC6093.sol";
* @dev Library that provide common ERC-1155 utility functions.
*
* See https://eips.ethereum.org/EIPS/eip-1155[ERC-1155].
*
* _Available since v5.1._
*/
library ERC1155Utils {
/**
* @dev Performs an acceptance check for the provided `operator` by calling {IERC1155-onERC1155Received}
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
*
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA).
* The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).
* Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept
* the transfer.
*/
Expand All @@ -38,8 +40,7 @@ library ERC1155Utils {
// non-IERC1155Receiver implementer
revert IERC1155Errors.ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
revert(add(32, reason), mload(reason))
}
}
Expand All @@ -51,7 +52,7 @@ library ERC1155Utils {
* @dev Performs a batch acceptance check for the provided `operator` by calling {IERC1155-onERC1155BatchReceived}
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
*
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA).
* The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).
* Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept
* the transfer.
*/
Expand All @@ -76,8 +77,7 @@ library ERC1155Utils {
// non-IERC1155Receiver implementer
revert IERC1155Errors.ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
revert(add(32, reason), mload(reason))
}
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/token/ERC20/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel
== Utilities

{{SafeERC20}}

{{ERC1363Utils}}
Loading
Loading