Compare commits
9 Commits
v4.7.3
...
release-v4
| Author | SHA1 | Date | |
|---|---|---|---|
| b438cb695a | |||
| 65dd47e8e2 | |||
| 376cef91ca | |||
| e968b56df4 | |||
| 3a64f471bf | |||
| 5ba94b2546 | |||
| 1f0d3db597 | |||
| 03ccb8ec33 | |||
| cefa52948a |
@ -17,6 +17,11 @@ import "./LibArbitrumL2.sol";
|
||||
* this specialization of {CrossChainEnabled} does not include a constructor.
|
||||
*
|
||||
* _Available since v4.6._
|
||||
*
|
||||
* WARNING: There is currently a bug in Arbitrum that causes this contract to
|
||||
* fail to detect cross-chain calls when deployed behind a proxy. This will be
|
||||
* fixed when the network is upgraded to Arbitrum Nitro, currently scheduled for
|
||||
* August 31st 2022.
|
||||
*/
|
||||
abstract contract CrossChainEnabledArbitrumL2 is CrossChainEnabled {
|
||||
/**
|
||||
|
||||
@ -12,6 +12,11 @@ import "../errors.sol";
|
||||
*
|
||||
* This version should only be used on L2 to process cross-chain messages
|
||||
* originating from L1. For the other side, use {LibArbitrumL1}.
|
||||
*
|
||||
* WARNING: There is currently a bug in Arbitrum that causes this contract to
|
||||
* fail to detect cross-chain calls when deployed behind a proxy. This will be
|
||||
* fixed when the network is upgraded to Arbitrum Nitro, currently scheduled for
|
||||
* August 31st 2022.
|
||||
*/
|
||||
library LibArbitrumL2 {
|
||||
/**
|
||||
|
||||
@ -81,7 +81,9 @@ interface IERC721 is IERC165 {
|
||||
/**
|
||||
* @dev Transfers `tokenId` token from `from` to `to`.
|
||||
*
|
||||
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
|
||||
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
|
||||
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
|
||||
* understand this adds an external call which potentially creates a reentrancy vulnerability.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
|
||||
@ -6,16 +6,16 @@ pragma solidity ^0.8.0;
|
||||
/**
|
||||
* @dev These functions deal with verification of Merkle Tree proofs.
|
||||
*
|
||||
* The proofs can be generated using the JavaScript library
|
||||
* https://github.com/miguelmota/merkletreejs[merkletreejs].
|
||||
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
|
||||
*
|
||||
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
|
||||
* The tree and the proofs can be generated using our
|
||||
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
|
||||
* You will find a quickstart guide in the readme.
|
||||
*
|
||||
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
|
||||
* hashing, or use a hash function other than keccak256 for hashing leaves.
|
||||
* This is because the concatenation of a sorted pair of internal nodes in
|
||||
* the merkle tree could be reinterpreted as a leaf value.
|
||||
* OpenZeppelin's JavaScript library generates merkle trees that are safe
|
||||
* against this attack out of the box.
|
||||
*/
|
||||
library MerkleProof {
|
||||
/**
|
||||
@ -75,9 +75,11 @@ library MerkleProof {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the `leaves` can be proved to be a part of a Merkle tree defined by
|
||||
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
|
||||
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
|
||||
*
|
||||
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
|
||||
*
|
||||
* _Available since v4.7._
|
||||
*/
|
||||
function multiProofVerify(
|
||||
@ -92,6 +94,8 @@ library MerkleProof {
|
||||
/**
|
||||
* @dev Calldata version of {multiProofVerify}
|
||||
*
|
||||
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
|
||||
*
|
||||
* _Available since v4.7._
|
||||
*/
|
||||
function multiProofVerifyCalldata(
|
||||
@ -104,9 +108,14 @@ library MerkleProof {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the root of a tree reconstructed from `leaves` and the sibling nodes in `proof`,
|
||||
* consuming from one or the other at each step according to the instructions given by
|
||||
* `proofFlags`.
|
||||
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
|
||||
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
|
||||
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
|
||||
* respectively.
|
||||
*
|
||||
* CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
|
||||
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
|
||||
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
|
||||
*
|
||||
* _Available since v4.7._
|
||||
*/
|
||||
@ -152,7 +161,9 @@ library MerkleProof {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Calldata version of {processMultiProof}
|
||||
* @dev Calldata version of {processMultiProof}.
|
||||
*
|
||||
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
|
||||
*
|
||||
* _Available since v4.7._
|
||||
*/
|
||||
|
||||
@ -36,10 +36,12 @@ import "./EnumerableSet.sol";
|
||||
*
|
||||
* [WARNING]
|
||||
* ====
|
||||
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
|
||||
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
|
||||
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
|
||||
* unusable.
|
||||
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
|
||||
*
|
||||
* In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an array of EnumerableMap.
|
||||
* In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
|
||||
* array of EnumerableMap.
|
||||
* ====
|
||||
*/
|
||||
library EnumerableMap {
|
||||
|
||||
@ -29,10 +29,12 @@ pragma solidity ^0.8.0;
|
||||
*
|
||||
* [WARNING]
|
||||
* ====
|
||||
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
|
||||
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
|
||||
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
|
||||
* unusable.
|
||||
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
|
||||
*
|
||||
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
|
||||
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
|
||||
* array of EnumerableSet.
|
||||
* ====
|
||||
*/
|
||||
library EnumerableSet {
|
||||
|
||||
@ -146,6 +146,8 @@ We can also implement more complex scenarios using the xref:api:token/ERC1155.ad
|
||||
|
||||
[[Presets]]
|
||||
== Preset ERC1155 contract
|
||||
A preset ERC1155 is available, xref:api:presets#ERC1155PresetMinterPauser[`ERC1155PresetMinterPauser`]. It is preset to allow for token minting (create) - including batch minting, stop all token transfers (pause) and allow holders to burn (destroy) their tokens. The contract uses xref:access-control.adoc[Access Control] to control access to the minting and pausing functionality. The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role.
|
||||
A preset ERC1155 is available, https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.7/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol[`ERC1155PresetMinterPauser`]. It is preset to allow for token minting (create) - including batch minting, stop all token transfers (pause) and allow holders to burn (destroy) their tokens. The contract uses xref:access-control.adoc[Access Control] to control access to the minting and pausing functionality. The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role.
|
||||
|
||||
This contract is ready to deploy without having to write any Solidity code. It can be used as-is for quick prototyping and testing, but is also suitable for production environments.
|
||||
|
||||
NOTE: Contract presets are now deprecated in favor of https://wizard.openzeppelin.com[Contracts Wizard] as a more powerful alternative.
|
||||
|
||||
@ -78,6 +78,8 @@ transfer(recipient, 5 * (10 ** 18));
|
||||
|
||||
[[Presets]]
|
||||
== Preset ERC20 contract
|
||||
A preset ERC20 is available, xref:api:presets#ERC20PresetMinterPauser[`ERC20PresetMinterPauser`]. It is preset to allow for token minting (create), stop all token transfers (pause) and allow holders to burn (destroy) their tokens. The contract uses xref:access-control.adoc[Access Control] to control access to the minting and pausing functionality. The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role.
|
||||
A preset ERC20 is available, https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.7/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol[`ERC20PresetMinterPauser`]. It is preset to allow for token minting (create), stop all token transfers (pause) and allow holders to burn (destroy) their tokens. The contract uses xref:access-control.adoc[Access Control] to control access to the minting and pausing functionality. The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role.
|
||||
|
||||
This contract is ready to deploy without having to write any Solidity code. It can be used as-is for quick prototyping and testing, but is also suitable for production environments.
|
||||
|
||||
NOTE: Contract presets are now deprecated in favor of https://wizard.openzeppelin.com[Contracts Wizard] as a more powerful alternative.
|
||||
|
||||
@ -83,6 +83,8 @@ TIP: If you'd like to put all item information on-chain, you can extend ERC721 t
|
||||
|
||||
[[Presets]]
|
||||
== Preset ERC721 contract
|
||||
A preset ERC721 is available, xref:api:presets#ERC721PresetMinterPauserAutoId[`ERC721PresetMinterPauserAutoId`]. It is preset to allow for token minting (create) with token ID and URI auto generation, stop all token transfers (pause) and allow holders to burn (destroy) their tokens. The contract uses xref:access-control.adoc[Access Control] to control access to the minting and pausing functionality. The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role.
|
||||
A preset ERC721 is available, https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.7/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol[`ERC721PresetMinterPauserAutoId`]. It is preconfigured with token minting (creation) with token ID and URI auto generation, the ability to stop all token transfers (pause), and it allows holders to burn (destroy) their tokens. The contract uses xref:access-control.adoc[Access Control] to control access to the minting and pausing functionality. The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role.
|
||||
|
||||
This contract is ready to deploy without having to write any Solidity code. It can be used as-is for quick prototyping and testing, but is also suitable for production environments.
|
||||
This contract is ready to deploy without having to write any Solidity code. It can be used as-is for quick prototyping and testing but is also suitable for production environments.
|
||||
|
||||
NOTE: Contract presets are now deprecated in favor of https://wizard.openzeppelin.com[Contracts Wizard] as a more powerful alternative.
|
||||
|
||||
@ -7,9 +7,9 @@ The OpenZeppelin Contracts provide a ton of useful utilities that you can use in
|
||||
|
||||
=== Checking Signatures On-Chain
|
||||
|
||||
xref:api:cryptography.adoc#ECDSA[`ECDSA`] provides functions for recovering and managing Ethereum account ECDSA signatures. These are often generated via https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#sign[`web3.eth.sign`], and are a 65 byte array (of type `bytes` in Solidity) arranged the following way: `[[v (1)], [r (32)], [s (32)]]`.
|
||||
xref:api:utils.adoc#ECDSA[`ECDSA`] provides functions for recovering and managing Ethereum account ECDSA signatures. These are often generated via https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#sign[`web3.eth.sign`], and are a 65 byte array (of type `bytes` in Solidity) arranged the following way: `[[v (1)], [r (32)], [s (32)]]`.
|
||||
|
||||
The data signer can be recovered with xref:api:cryptography.adoc#ECDSA-recover-bytes32-bytes-[`ECDSA.recover`], and its address compared to verify the signature. Most wallets will hash the data to sign and add the prefix '\x19Ethereum Signed Message:\n', so when attempting to recover the signer of an Ethereum signed message hash, you'll want to use xref:api:cryptography.adoc#ECDSA-toEthSignedMessageHash-bytes32-[`toEthSignedMessageHash`].
|
||||
The data signer can be recovered with xref:api:utils.adoc#ECDSA-recover-bytes32-bytes-[`ECDSA.recover`], and its address compared to verify the signature. Most wallets will hash the data to sign and add the prefix '\x19Ethereum Signed Message:\n', so when attempting to recover the signer of an Ethereum signed message hash, you'll want to use xref:api:utils.adoc#ECDSA-toEthSignedMessageHash-bytes32-[`toEthSignedMessageHash`].
|
||||
|
||||
[source,solidity]
|
||||
----
|
||||
@ -22,27 +22,27 @@ function _verify(bytes32 data, bytes memory signature, address account) internal
|
||||
}
|
||||
----
|
||||
|
||||
WARNING: Getting signature verification right is not trivial: make sure you fully read and understand xref:api:cryptography.adoc#ECDSA[`ECDSA`]'s documentation.
|
||||
WARNING: Getting signature verification right is not trivial: make sure you fully read and understand xref:api:utils.adoc#ECDSA[`ECDSA`]'s documentation.
|
||||
|
||||
=== Verifying Merkle Proofs
|
||||
|
||||
xref:api:cryptography.adoc#MerkleProof[`MerkleProof`] provides:
|
||||
xref:api:utils.adoc#MerkleProof[`MerkleProof`] provides:
|
||||
|
||||
* xref:api:cryptography.adoc#MerkleProof-verify-bytes32---bytes32-bytes32-[`verify`] - can prove that some value is part of a https://en.wikipedia.org/wiki/Merkle_tree[Merkle tree].
|
||||
* xref:api:utils.adoc#MerkleProof-verify-bytes32---bytes32-bytes32-[`verify`] - can prove that some value is part of a https://en.wikipedia.org/wiki/Merkle_tree[Merkle tree].
|
||||
|
||||
* xref:api:cryptography.adoc#MerkleProof-multiProofVerify-bytes32-bytes32---bytes32---bool---[`multiProofVerify`] - can prove multiple values are part of a Merkle tree.
|
||||
* xref:api:utils.adoc#MerkleProof-multiProofVerify-bytes32-bytes32---bytes32---bool---[`multiProofVerify`] - can prove multiple values are part of a Merkle tree.
|
||||
|
||||
[[introspection]]
|
||||
== Introspection
|
||||
|
||||
In Solidity, it's frequently helpful to know whether or not a contract supports an interface you'd like to use. ERC165 is a standard that helps do runtime interface detection. Contracts provide helpers both for implementing ERC165 in your contracts and querying other contracts:
|
||||
|
||||
* xref:api:introspection.adoc#IERC165[`IERC165`] — this is the ERC165 interface that defines xref:api:introspection.adoc#IERC165-supportsInterface-bytes4-[`supportsInterface`]. When implementing ERC165, you'll conform to this interface.
|
||||
* xref:api:introspection.adoc#ERC165[`ERC165`] — inherit this contract if you'd like to support interface detection using a lookup table in contract storage. You can register interfaces using xref:api:introspection.adoc#ERC165-_registerInterface-bytes4-[`_registerInterface(bytes4)`]: check out example usage as part of the ERC721 implementation.
|
||||
* xref:api:introspection.adoc#ERC165Checker[`ERC165Checker`] — ERC165Checker simplifies the process of checking whether or not a contract supports an interface you care about.
|
||||
* xref:api:utils.adoc#IERC165[`IERC165`] — this is the ERC165 interface that defines xref:api:utils.adoc#IERC165-supportsInterface-bytes4-[`supportsInterface`]. When implementing ERC165, you'll conform to this interface.
|
||||
* xref:api:utils.adoc#ERC165[`ERC165`] — inherit this contract if you'd like to support interface detection using a lookup table in contract storage. You can register interfaces using xref:api:utils.adoc#ERC165-_registerInterface-bytes4-[`_registerInterface(bytes4)`]: check out example usage as part of the ERC721 implementation.
|
||||
* xref:api:utils.adoc#ERC165Checker[`ERC165Checker`] — ERC165Checker simplifies the process of checking whether or not a contract supports an interface you care about.
|
||||
* include with `using ERC165Checker for address;`
|
||||
* xref:api:introspection.adoc#ERC165Checker-_supportsInterface-address-bytes4-[`myAddress._supportsInterface(bytes4)`]
|
||||
* xref:api:introspection.adoc#ERC165Checker-_supportsAllInterfaces-address-bytes4---[`myAddress._supportsAllInterfaces(bytes4[\])`]
|
||||
* xref:api:utils.adoc#ERC165Checker-_supportsInterface-address-bytes4-[`myAddress._supportsInterface(bytes4)`]
|
||||
* xref:api:utils.adoc#ERC165Checker-_supportsAllInterfaces-address-bytes4---[`myAddress._supportsAllInterfaces(bytes4[\])`]
|
||||
|
||||
[source,solidity]
|
||||
----
|
||||
@ -70,7 +70,7 @@ contract MyContract {
|
||||
[[math]]
|
||||
== Math
|
||||
|
||||
The most popular math related library OpenZeppelin Contracts provides is xref:api:math.adoc#SafeMath[`SafeMath`], which provides mathematical functions that protect your contract from overflows and underflows.
|
||||
The most popular math related library OpenZeppelin Contracts provides is xref:api:utils.adoc#SafeMath[`SafeMath`], which provides mathematical functions that protect your contract from overflows and underflows.
|
||||
|
||||
Include the contract with `using SafeMath for uint256;` and then call the functions:
|
||||
|
||||
@ -85,11 +85,11 @@ Easy!
|
||||
[[payment]]
|
||||
== Payment
|
||||
|
||||
Want to split some payments between multiple people? Maybe you have an app that sends 30% of art purchases to the original creator and 70% of the profits to the current owner; you can build that with xref:api:payment.adoc#PaymentSplitter[`PaymentSplitter`]!
|
||||
Want to split some payments between multiple people? Maybe you have an app that sends 30% of art purchases to the original creator and 70% of the profits to the current owner; you can build that with xref:api:finance.adoc#PaymentSplitter[`PaymentSplitter`]!
|
||||
|
||||
In Solidity, there are some security concerns with blindly sending money to accounts, since it allows them to execute arbitrary code. You can read up on these security concerns in the https://consensys.github.io/smart-contract-best-practices/[Ethereum Smart Contract Best Practices] website. One of the ways to fix reentrancy and stalling problems is, instead of immediately sending Ether to accounts that need it, you can use xref:api:payment.adoc#PullPayment[`PullPayment`], which offers an xref:api:payment.adoc#PullPayment-_asyncTransfer-address-uint256-[`_asyncTransfer`] function for sending money to something and requesting that they xref:api:payment.adoc#PullPayment-withdrawPayments-address-payable-[`withdrawPayments()`] it later.
|
||||
In Solidity, there are some security concerns with blindly sending money to accounts, since it allows them to execute arbitrary code. You can read up on these security concerns in the https://consensys.github.io/smart-contract-best-practices/[Ethereum Smart Contract Best Practices] website. One of the ways to fix reentrancy and stalling problems is, instead of immediately sending Ether to accounts that need it, you can use xref:api:security.adoc#PullPayment[`PullPayment`], which offers an xref:api:security.adoc#PullPayment-_asyncTransfer-address-uint256-[`_asyncTransfer`] function for sending money to something and requesting that they xref:api:security.adoc#PullPayment-withdrawPayments-address-payable-[`withdrawPayments()`] it later.
|
||||
|
||||
If you want to Escrow some funds, check out xref:api:payment.adoc#Escrow[`Escrow`] and xref:api:payment.adoc#ConditionalEscrow[`ConditionalEscrow`] for governing the release of some escrowed Ether.
|
||||
If you want to Escrow some funds, check out xref:api:utils.adoc#Escrow[`Escrow`] and xref:api:utils.adoc#ConditionalEscrow[`ConditionalEscrow`] for governing the release of some escrowed Ether.
|
||||
|
||||
[[collections]]
|
||||
== Collections
|
||||
|
||||
Reference in New Issue
Block a user