@artblocks/contracts 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/artifacts/contracts/interfaces/v0.8.x/IFormPaletteBindingHooks.sol/IFormPaletteBindingHooks.json +723 -0
  2. package/artifacts/contracts/interfaces/v0.8.x/IPMPProjectViewsV0.sol/IPMPProjectViewsV0.json +126 -0
  3. package/artifacts/contracts/interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol/ISharedMinterRequiredPMPV0.json +36 -0
  4. package/artifacts/contracts/libs/v0.8.x/minter-libs/RequiredPMPLib.sol/RequiredPMPLib.json +10 -0
  5. package/artifacts/contracts/minter-suite/Minters/MinterSetPricePMPV0.sol/MinterSetPricePMPV0.json +613 -0
  6. package/artifacts/contracts/mock/MockPMPMinterReentrantConfigureHook.sol/IMinterPMPPurchase.json +91 -0
  7. package/artifacts/contracts/mock/MockPMPMinterReentrantConfigureHook.sol/MockPMPMinterReentrantConfigureHook.json +180 -0
  8. package/artifacts/contracts/mock/MockPMPReentrantConfigureHook.sol/MockPMPReentrantConfigureHook.json +158 -0
  9. package/artifacts/contracts/mock/ReentrancyPMPMockShared.sol/IMinterPurchaseWithPMPs.json +67 -0
  10. package/artifacts/contracts/mock/ReentrancyPMPMockShared.sol/ReentrancyPMPMockShared.json +154 -0
  11. package/artifacts/contracts/web3call/combined-hooks/FormPaletteBindingHooks.sol/FormPaletteBindingHooks.json +919 -0
  12. package/contracts/interfaces/v0.8.x/IFormPaletteBindingHooks.sol +339 -0
  13. package/contracts/interfaces/v0.8.x/IPMPProjectViewsV0.sol +59 -0
  14. package/contracts/interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol +27 -0
  15. package/contracts/libs/v0.8.x/minter-libs/RequiredPMPLib.sol +336 -0
  16. package/contracts/minter-suite/Minters/MinterSetPricePMPV0.sol +664 -0
  17. package/contracts/mock/MockPMPMinterReentrantConfigureHook.sol +85 -0
  18. package/contracts/mock/MockPMPReentrantConfigureHook.sol +59 -0
  19. package/contracts/mock/ReentrancyPMPMockShared.sol +81 -0
  20. package/contracts/web3call/combined-hooks/FormPaletteBindingHooks.sol +1392 -0
  21. package/package.json +1 -1
@@ -0,0 +1,85 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-only
2
+ pragma solidity 0.8.22;
3
+
4
+ import {IPMPConfigureHook} from "../interfaces/v0.8.x/IPMPConfigureHook.sol";
5
+ import {IPMPV0} from "../interfaces/v0.8.x/IPMPV0.sol";
6
+ import {ERC165} from "@openzeppelin-5.0/contracts/utils/introspection/ERC165.sol";
7
+ import {IERC165} from "@openzeppelin-5.0/contracts/interfaces/IERC165.sol";
8
+
9
+ interface IMinterPMPPurchase {
10
+ function purchase(
11
+ uint256 projectId,
12
+ address coreContract
13
+ ) external payable returns (uint256 tokenId);
14
+
15
+ function purchaseWithPMPs(
16
+ uint256 projectId,
17
+ address coreContract,
18
+ IPMPV0.PMPInput[] calldata pmpInputs
19
+ ) external payable returns (uint256 tokenId);
20
+ }
21
+
22
+ /**
23
+ * @title Mock minter-reentrant PMP configure hook
24
+ * @notice Configure hook that attempts to re-enter a purchase function on
25
+ * `MinterSetPricePMPV0` from inside `onTokenPMPConfigure`, which the PMP
26
+ * contract invokes while the minter's purchase is still in progress. Exists to
27
+ * prove that the minter's `nonReentrant` guard blocks an artist-configured
28
+ * hook from minting a second token in the same transaction.
29
+ * @dev Funded with ETH by the test so that the reentrant call is fully paid
30
+ * for, leaving the minter's reentrancy guard as the only thing that can stop
31
+ * it.
32
+ */
33
+ contract MockPMPMinterReentrantConfigureHook is IPMPConfigureHook, ERC165 {
34
+ address public immutable minter;
35
+ uint256 public immutable projectId;
36
+ address public immutable coreContract;
37
+ uint256 public immutable pricePerTokenInWei;
38
+ // when true, re-enters `purchaseWithPMPs` rather than `purchase`
39
+ bool public immutable reenterWithPMPs;
40
+
41
+ constructor(
42
+ address minter_,
43
+ uint256 projectId_,
44
+ address coreContract_,
45
+ uint256 pricePerTokenInWei_,
46
+ bool reenterWithPMPs_
47
+ ) {
48
+ minter = minter_;
49
+ projectId = projectId_;
50
+ coreContract = coreContract_;
51
+ pricePerTokenInWei = pricePerTokenInWei_;
52
+ reenterWithPMPs = reenterWithPMPs_;
53
+ }
54
+
55
+ function onTokenPMPConfigure(
56
+ address /* coreContract */,
57
+ uint256 /* tokenId */,
58
+ IPMPV0.PMPInput calldata pmpInput
59
+ ) external override {
60
+ if (reenterWithPMPs) {
61
+ // @dev forward the same input back through the PMP purchase path
62
+ IPMPV0.PMPInput[] memory pmpInputs = new IPMPV0.PMPInput[](1);
63
+ pmpInputs[0] = pmpInput;
64
+ IMinterPMPPurchase(minter).purchaseWithPMPs{
65
+ value: pricePerTokenInWei
66
+ }(projectId, coreContract, pmpInputs);
67
+ } else {
68
+ IMinterPMPPurchase(minter).purchase{value: pricePerTokenInWei}(
69
+ projectId,
70
+ coreContract
71
+ );
72
+ }
73
+ }
74
+
75
+ function supportsInterface(
76
+ bytes4 interfaceId
77
+ ) public view virtual override(ERC165, IERC165) returns (bool) {
78
+ return
79
+ interfaceId == type(IPMPConfigureHook).interfaceId ||
80
+ super.supportsInterface(interfaceId);
81
+ }
82
+
83
+ // @dev allows the test to fund the reentrant purchase
84
+ receive() external payable {}
85
+ }
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-only
2
+ pragma solidity 0.8.22;
3
+
4
+ import {IPMPConfigureHook} from "../interfaces/v0.8.x/IPMPConfigureHook.sol";
5
+ import {IPMPV0} from "../interfaces/v0.8.x/IPMPV0.sol";
6
+ import {ERC165} from "@openzeppelin-5.0/contracts/utils/introspection/ERC165.sol";
7
+ import {IERC165} from "@openzeppelin-5.0/contracts/interfaces/IERC165.sol";
8
+
9
+ /**
10
+ * @title Mock reentrant PMP configure hook
11
+ * @notice Configure hook that attempts to write a PostParam on another token
12
+ * from inside `onTokenPMPConfigure`. Exists to pin down the protocol behavior
13
+ * that `FormPaletteBindingHooks` is designed around: `configureTokenParams` is
14
+ * `nonReentrant`, so a configure hook can never write a PostParam, and a
15
+ * binding scheme cannot re-render a second token in one transaction.
16
+ */
17
+ contract MockPMPReentrantConfigureHook is IPMPConfigureHook, ERC165 {
18
+ IPMPV0 public immutable pmp;
19
+ address public immutable targetCoreContract;
20
+ uint256 public immutable targetTokenId;
21
+ string public targetKey;
22
+
23
+ constructor(
24
+ address pmp_,
25
+ address targetCoreContract_,
26
+ uint256 targetTokenId_,
27
+ string memory targetKey_
28
+ ) {
29
+ pmp = IPMPV0(pmp_);
30
+ targetCoreContract = targetCoreContract_;
31
+ targetTokenId = targetTokenId_;
32
+ targetKey = targetKey_;
33
+ }
34
+
35
+ function onTokenPMPConfigure(
36
+ address /* coreContract */,
37
+ uint256 /* tokenId */,
38
+ IPMPV0.PMPInput calldata /* pmpInput */
39
+ ) external override {
40
+ IPMPV0.PMPInput[] memory pmpInputs = new IPMPV0.PMPInput[](1);
41
+ pmpInputs[0] = IPMPV0.PMPInput({
42
+ key: targetKey,
43
+ configuredParamType: IPMPV0.ParamType.Uint256Range,
44
+ configuredValue: bytes32(uint256(0)),
45
+ configuringArtistString: false,
46
+ configuredValueString: ""
47
+ });
48
+ // @dev reverts with ReentrancyGuardReentrantCall
49
+ pmp.configureTokenParams(targetCoreContract, targetTokenId, pmpInputs);
50
+ }
51
+
52
+ function supportsInterface(
53
+ bytes4 interfaceId
54
+ ) public view virtual override(ERC165, IERC165) returns (bool) {
55
+ return
56
+ interfaceId == type(IPMPConfigureHook).interfaceId ||
57
+ super.supportsInterface(interfaceId);
58
+ }
59
+ }
@@ -0,0 +1,81 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-only
2
+ // Created By: Art Blocks Inc.
3
+
4
+ // @dev 0.8.22 required by the PMP interfaces, which depend on OpenZeppelin 5.0
5
+ pragma solidity 0.8.22;
6
+
7
+ import {IPMPV0} from "../interfaces/v0.8.x/IPMPV0.sol";
8
+
9
+ interface IMinterPurchaseWithPMPs {
10
+ function purchaseWithPMPs(
11
+ uint256 projectId,
12
+ address coreContract,
13
+ IPMPV0.PMPInput[] calldata pmpInputs
14
+ ) external payable returns (uint256 tokenId);
15
+ }
16
+
17
+ contract ReentrancyPMPMockShared {
18
+ uint256 public currentQtyToPurchase;
19
+ uint256 public currentProjectId;
20
+ address public currentCoreContract;
21
+ uint256 public currentPriceToPay;
22
+ string public currentPMPKey;
23
+ uint8 public currentPMPParamType;
24
+ bytes32 public currentPMPValue;
25
+
26
+ /**
27
+ @notice This function can be called to induce controlled reentrency attacks
28
+ on a shared AB minter's PMP-accepting purchase function.
29
+ Note that _priceToPay should be > project price per token to induce refund,
30
+ making reentrency possible via fallback function.
31
+ */
32
+ function attack(
33
+ uint256 _qtyToPurchase,
34
+ address _minterContractAddress,
35
+ uint256 _projectId,
36
+ address _coreContract,
37
+ uint256 _priceToPay,
38
+ string calldata _pmpKey,
39
+ uint8 _pmpParamType,
40
+ bytes32 _pmpValue
41
+ ) external payable {
42
+ // update state variables so that receive() knows what to do
43
+ currentQtyToPurchase = _qtyToPurchase;
44
+ currentProjectId = _projectId;
45
+ currentCoreContract = _coreContract;
46
+ currentPriceToPay = _priceToPay;
47
+ currentPMPKey = _pmpKey;
48
+ currentPMPParamType = _pmpParamType;
49
+ currentPMPValue = _pmpValue;
50
+ IMinterPurchaseWithPMPs(_minterContractAddress).purchaseWithPMPs{
51
+ value: _priceToPay
52
+ }(_projectId, _coreContract, _pmpInputs());
53
+ }
54
+
55
+ // receiver is called when minter sends refunded Ether to this contract.
56
+ receive() external payable {
57
+ // decrement num to be purchased
58
+ currentQtyToPurchase--;
59
+ if (currentQtyToPurchase > 0) {
60
+ // purchase again!
61
+ IMinterPurchaseWithPMPs(msg.sender).purchaseWithPMPs{
62
+ value: currentPriceToPay
63
+ }(currentProjectId, currentCoreContract, _pmpInputs());
64
+ }
65
+ }
66
+
67
+ function _pmpInputs()
68
+ internal
69
+ view
70
+ returns (IPMPV0.PMPInput[] memory pmpInputs)
71
+ {
72
+ pmpInputs = new IPMPV0.PMPInput[](1);
73
+ pmpInputs[0] = IPMPV0.PMPInput({
74
+ key: currentPMPKey,
75
+ configuredParamType: IPMPV0.ParamType(currentPMPParamType),
76
+ configuredValue: currentPMPValue,
77
+ configuringArtistString: false,
78
+ configuredValueString: ""
79
+ });
80
+ }
81
+ }