@artblocks/contracts 1.5.0 → 1.7.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 (53) hide show
  1. package/artifacts/contracts/DependencyRegistryV0.sol/DependencyRegistryV0.json +61 -148
  2. package/artifacts/contracts/generator/GenArt721GeneratorV0.sol/GenArt721GeneratorV0.json +15 -2
  3. package/artifacts/contracts/generator/InPlaceDocument.sol/InPlaceDocument.json +10 -0
  4. package/artifacts/contracts/interfaces/v0.8.x/IAbxfsFileDataReader.sol/IAbxfsFileDataReader.json +109 -0
  5. package/artifacts/contracts/interfaces/v0.8.x/IAbxfsFileStore.sol/IAbxfsFileStore.json +86 -0
  6. package/artifacts/contracts/interfaces/v0.8.x/IDependencyRegistryV0.sol/IDependencyRegistryV0.json +41 -27
  7. package/artifacts/contracts/interfaces/v0.8.x/IFormPaletteBindingHooks.sol/IFormPaletteBindingHooks.json +723 -0
  8. package/artifacts/contracts/interfaces/v0.8.x/IPMPProjectViewsV0.sol/IPMPProjectViewsV0.json +126 -0
  9. package/artifacts/contracts/interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol/ISharedMinterRequiredPMPV0.json +36 -0
  10. package/artifacts/contracts/libs/v0.8.x/AbxfsCanonical.sol/AbxfsCanonical.json +10 -0
  11. package/artifacts/contracts/libs/v0.8.x/DependencyRegistryStorageLib.sol/DependencyRegistryStorageLib.json +2 -2
  12. package/artifacts/contracts/libs/v0.8.x/minter-libs/RequiredPMPLib.sol/RequiredPMPLib.json +10 -0
  13. package/artifacts/contracts/minter-suite/Minters/MinterSetPricePMPV0.sol/MinterSetPricePMPV0.json +613 -0
  14. package/artifacts/contracts/mock/CallProbeMock.sol/CallProbeMock.json +45 -0
  15. package/artifacts/contracts/mock/GasProbeMock.sol/GasProbeMock.json +45 -0
  16. package/artifacts/contracts/mock/GenArt721GeneratorV0ScriptyReferenceMock.sol/GenArt721GeneratorV0ScriptyReferenceMock.json +346 -0
  17. package/artifacts/contracts/mock/GenArt721GeneratorV0ScriptyReferenceMock.sol/ILegacyGenArt721CoreV2_PBAB_Flex.json +47 -0
  18. package/artifacts/contracts/mock/InPlaceDocumentHarnessMock.sol/InPlaceDocumentHarnessMock.json +161 -0
  19. package/artifacts/contracts/mock/MockAbxfsFileDataReader.sol/IMockFileStore.json +91 -0
  20. package/artifacts/contracts/mock/MockAbxfsFileDataReader.sol/MockAbxfsFileDataReader.json +183 -0
  21. package/artifacts/contracts/mock/MockAbxfsFileStore.sol/MockAbxfsFileStore.json +204 -0
  22. package/artifacts/contracts/mock/MockPMPMinterReentrantConfigureHook.sol/IMinterPMPPurchase.json +91 -0
  23. package/artifacts/contracts/mock/MockPMPMinterReentrantConfigureHook.sol/MockPMPMinterReentrantConfigureHook.json +180 -0
  24. package/artifacts/contracts/mock/MockPMPReentrantConfigureHook.sol/MockPMPReentrantConfigureHook.json +158 -0
  25. package/artifacts/contracts/mock/RawResponseMock.sol/RawResponseMock.json +61 -0
  26. package/artifacts/contracts/mock/ReentrancyPMPMockShared.sol/IMinterPurchaseWithPMPs.json +67 -0
  27. package/artifacts/contracts/mock/ReentrancyPMPMockShared.sol/ReentrancyPMPMockShared.json +154 -0
  28. package/artifacts/contracts/web3call/combined-hooks/FormPaletteBindingHooks.sol/FormPaletteBindingHooks.json +919 -0
  29. package/contracts/DependencyRegistryV0.sol +136 -226
  30. package/contracts/generator/GenArt721GeneratorV0.sol +541 -280
  31. package/contracts/generator/InPlaceDocument.sol +306 -0
  32. package/contracts/interfaces/v0.8.x/IAbxfsFileDataReader.sol +67 -0
  33. package/contracts/interfaces/v0.8.x/IAbxfsFileStore.sol +40 -0
  34. package/contracts/interfaces/v0.8.x/IDependencyRegistryV0.sol +33 -22
  35. package/contracts/interfaces/v0.8.x/IFormPaletteBindingHooks.sol +339 -0
  36. package/contracts/interfaces/v0.8.x/IPMPProjectViewsV0.sol +59 -0
  37. package/contracts/interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol +27 -0
  38. package/contracts/libs/v0.8.x/AbxfsCanonical.sol +23 -0
  39. package/contracts/libs/v0.8.x/DependencyRegistryStorageLib.sol +10 -4
  40. package/contracts/libs/v0.8.x/minter-libs/RequiredPMPLib.sol +336 -0
  41. package/contracts/minter-suite/Minters/MinterSetPricePMPV0.sol +664 -0
  42. package/contracts/mock/CallProbeMock.sol +20 -0
  43. package/contracts/mock/GasProbeMock.sol +21 -0
  44. package/contracts/mock/GenArt721GeneratorV0ScriptyReferenceMock.sol +1316 -0
  45. package/contracts/mock/InPlaceDocumentHarnessMock.sol +189 -0
  46. package/contracts/mock/MockAbxfsFileDataReader.sol +134 -0
  47. package/contracts/mock/MockAbxfsFileStore.sol +125 -0
  48. package/contracts/mock/MockPMPMinterReentrantConfigureHook.sol +85 -0
  49. package/contracts/mock/MockPMPReentrantConfigureHook.sol +59 -0
  50. package/contracts/mock/RawResponseMock.sol +58 -0
  51. package/contracts/mock/ReentrancyPMPMockShared.sol +81 -0
  52. package/contracts/web3call/combined-hooks/FormPaletteBindingHooks.sol +1392 -0
  53. package/package.json +1 -1
@@ -0,0 +1,336 @@
1
+ // SPDX-License-Identifier: LGPL-3.0-only
2
+ // Created By: Art Blocks Inc.
3
+
4
+ pragma solidity ^0.8.0;
5
+
6
+ import {IPMPV0} from "../../../interfaces/v0.8.x/IPMPV0.sol";
7
+ import {IPMPProjectViewsV0} from "../../../interfaces/v0.8.x/IPMPProjectViewsV0.sol";
8
+ import {ISharedMinterRequiredPMPV0} from "../../../interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol";
9
+
10
+ import {ImmutableStringArray} from "../ImmutableStringArray.sol";
11
+
12
+ /**
13
+ * @title Art Blocks Required PMP Library
14
+ * @notice This library manages the set of post-mint param (PMP) keys that a
15
+ * project requires to be configured during mint. It provides functionality to
16
+ * set a project's required keys, validated against the project's PMP
17
+ * configuration, and to enforce during mint that all required keys are being
18
+ * configured.
19
+ * @dev The validation performed when setting a project's required keys is a
20
+ * setup-time guardrail, not a durable guarantee. A project's artist may
21
+ * reconfigure the project on the PMP contract at any time afterwards, and this
22
+ * library has no hook into that. The guarantee that a token cannot be minted
23
+ * without its required params being set comes from combining the mint-time
24
+ * presence check in this library with the PMP contract's own validation, which
25
+ * reverts if a forwarded key is not part of the project's active config or does
26
+ * not authenticate the caller.
27
+ * @dev Consequently, an artist who invalidates a required key's PMP config
28
+ * after the fact will halt all minting on the project until either the PMP
29
+ * config or the project's required keys are corrected.
30
+ * @author Art Blocks Inc.
31
+ */
32
+ library RequiredPMPLib {
33
+ using ImmutableStringArray for ImmutableStringArray.StringArray;
34
+
35
+ // position of Required PMP Lib storage, using a diamond storage pattern
36
+ // for this library
37
+ bytes32 constant REQUIRED_PMP_LIB_STORAGE_POSITION =
38
+ keccak256("requiredpmplib.storage");
39
+
40
+ // @dev matches the PMP contract's own per-project config cap. Required keys
41
+ // must be a deduplicated subset of the project's configured keys, so in
42
+ // practice the project's key count is the binding constraint.
43
+ uint256 internal constant MAX_REQUIRED_PMP_KEYS = 256;
44
+
45
+ struct RequiredPMPProjectConfig {
46
+ // required keys, stored efficiently for introspection
47
+ ImmutableStringArray.StringArray requiredKeys; // slot 0: 32 bytes
48
+ // keccak256(abi.encode(key)) of each required key, aligned by index
49
+ // with requiredKeys. Stored so that the mint-time presence check does
50
+ // not need to load and hash the packed strings.
51
+ bytes32[] requiredKeyHashes; // slot 1: 32 bytes
52
+ }
53
+
54
+ // Diamond storage pattern is used in this library
55
+ struct RequiredPMPLibStorage {
56
+ mapping(address coreContract => mapping(uint256 projectId => RequiredPMPProjectConfig)) requiredPMPProjectConfigs;
57
+ }
58
+
59
+ /**
60
+ * @notice Sets the PMP keys that project `projectId` requires to be
61
+ * configured during mint, replacing any previously set keys.
62
+ * @dev Each key is validated against the project's configuration on
63
+ * `pmpContract`: it must be part of the project's active config, must
64
+ * authenticate `address(this)` as a configuring address, and must never
65
+ * lock. Duplicate keys are rejected.
66
+ * @dev An empty `requiredPMPKeys` array clears the project's required keys.
67
+ * @param projectId Project ID to set the required PMP keys for.
68
+ * @param coreContract Core contract address for the given project.
69
+ * @param pmpContract PMP contract the project's params are configured on.
70
+ * @param requiredPMPKeys PMP keys to require during mint.
71
+ */
72
+ function setRequiredPMPKeys(
73
+ uint256 projectId,
74
+ address coreContract,
75
+ address pmpContract,
76
+ string[] calldata requiredPMPKeys
77
+ ) internal {
78
+ uint256 numKeys = requiredPMPKeys.length;
79
+ require(numKeys <= MAX_REQUIRED_PMP_KEYS, "Only <= 256 req PMP keys");
80
+
81
+ // load the project's current PMP config nonce, used to verify that each
82
+ // required key is part of the project's active PMP config
83
+ // @dev loaded once here rather than per key
84
+ (, uint8 projectConfigNonce, , ) = IPMPProjectViewsV0(pmpContract)
85
+ .getProjectConfig({
86
+ coreContract: coreContract,
87
+ projectId: projectId
88
+ });
89
+
90
+ bytes32[] memory keyHashes = new bytes32[](numKeys);
91
+ for (uint256 i = 0; i < numKeys; i++) {
92
+ bytes32 keyHash = keccak256(abi.encode(requiredPMPKeys[i]));
93
+ // reject duplicate keys
94
+ for (uint256 j = 0; j < i; j++) {
95
+ require(keyHashes[j] != keyHash, "Duplicate req PMP key");
96
+ }
97
+ keyHashes[i] = keyHash;
98
+ _validateRequiredPMPKey({
99
+ projectId: projectId,
100
+ coreContract: coreContract,
101
+ pmpContract: pmpContract,
102
+ pmpKey: requiredPMPKeys[i],
103
+ projectConfigNonce: projectConfigNonce
104
+ });
105
+ }
106
+
107
+ RequiredPMPProjectConfig
108
+ storage requiredPMPProjectConfig = getRequiredPMPProjectConfig({
109
+ projectId: projectId,
110
+ coreContract: coreContract
111
+ });
112
+ ImmutableStringArray.store(
113
+ requiredPMPProjectConfig.requiredKeys,
114
+ requiredPMPKeys
115
+ );
116
+ requiredPMPProjectConfig.requiredKeyHashes = keyHashes;
117
+
118
+ emit ISharedMinterRequiredPMPV0.ProjectRequiredPMPKeysUpdated({
119
+ projectId: projectId,
120
+ coreContract: coreContract,
121
+ requiredPMPKeys: requiredPMPKeys
122
+ });
123
+ }
124
+
125
+ /**
126
+ * @notice Checks that `pmpInputs` contains no duplicate keys and that every
127
+ * PMP key required by project `projectId` is present in it.
128
+ * @dev Reverts if `pmpInputs` contains the same key more than once, if any
129
+ * required key is missing, or if a required string param is given an empty
130
+ * value, which the PMP contract would record as unconfigured. Additional
131
+ * non-required keys in `pmpInputs` are permitted.
132
+ * @dev Beyond the above, the PMP contract validates that each forwarded
133
+ * input is well-formed and authorized when it is configured.
134
+ * @param projectId Project ID being minted on.
135
+ * @param coreContract Core contract address for the given project.
136
+ * @param pmpInputs PMP inputs submitted with the purchase.
137
+ */
138
+ function preMintChecks(
139
+ uint256 projectId,
140
+ address coreContract,
141
+ IPMPV0.PMPInput[] calldata pmpInputs
142
+ ) internal view {
143
+ // hash each input key once, for comparison against every required key
144
+ // @dev done unconditionally, rather than only when the project has
145
+ // required keys, so that the no-duplicates guarantee below does not
146
+ // depend on the project's current configuration
147
+ uint256 numInputs = pmpInputs.length;
148
+ bytes32[] memory inputKeyHashes = new bytes32[](numInputs);
149
+ for (uint256 i = 0; i < numInputs; i++) {
150
+ bytes32 inputKeyHash = keccak256(abi.encode(pmpInputs[i].key));
151
+ // reject duplicate keys, for every param type. The PMP contract
152
+ // applies inputs in order with no duplicate guard, so the last
153
+ // input for a key is the one it persists. Were duplicates allowed,
154
+ // the checks below could pass on an earlier input while a later
155
+ // one overwrote it - for example a non-empty required string
156
+ // followed by the same key with an empty value, which the PMP
157
+ // contract stores and then reports as unconfigured.
158
+ for (uint256 j = 0; j < i; j++) {
159
+ require(
160
+ inputKeyHashes[j] != inputKeyHash,
161
+ "Duplicate PMP input key"
162
+ );
163
+ }
164
+ inputKeyHashes[i] = inputKeyHash;
165
+ }
166
+
167
+ bytes32[] storage requiredKeyHashes = getRequiredPMPProjectConfig({
168
+ projectId: projectId,
169
+ coreContract: coreContract
170
+ }).requiredKeyHashes;
171
+ uint256 numRequired = requiredKeyHashes.length;
172
+ for (uint256 i = 0; i < numRequired; i++) {
173
+ bytes32 requiredKeyHash = requiredKeyHashes[i];
174
+ bool isPresent = false;
175
+ for (uint256 j = 0; j < numInputs; j++) {
176
+ if (inputKeyHashes[j] == requiredKeyHash) {
177
+ // a required string param must be given a non-empty value.
178
+ // The PMP contract accepts an empty string, but then reports
179
+ // the param as unconfigured, which would let a required key
180
+ // be satisfied without actually being set.
181
+ // @dev the input's param type may be relied on here; the PMP
182
+ // contract reverts if it does not match the project's config
183
+ require(
184
+ pmpInputs[j].configuredParamType !=
185
+ IPMPV0.ParamType.String ||
186
+ bytes(pmpInputs[j].configuredValueString).length >
187
+ 0,
188
+ "Req PMP key empty string"
189
+ );
190
+ isPresent = true;
191
+ break;
192
+ }
193
+ }
194
+ require(isPresent, "Req PMP key not set");
195
+ }
196
+ }
197
+
198
+ /**
199
+ * @notice Checks that project `projectId` has no required PMP keys.
200
+ * @dev Used to gate purchase functions that do not accept PMP inputs, which
201
+ * would otherwise bypass a project's required keys entirely.
202
+ * @param projectId Project ID being minted on.
203
+ * @param coreContract Core contract address for the given project.
204
+ */
205
+ function requireNoRequiredPMPKeys(
206
+ uint256 projectId,
207
+ address coreContract
208
+ ) internal view {
209
+ require(
210
+ getRequiredPMPProjectConfig({
211
+ projectId: projectId,
212
+ coreContract: coreContract
213
+ }).requiredKeyHashes.length == 0,
214
+ "Project requires PMPs"
215
+ );
216
+ }
217
+
218
+ /**
219
+ * @notice Returns the PMP keys required to be configured during mint for
220
+ * project `projectId`.
221
+ * @param projectId Project ID to get the required PMP keys for.
222
+ * @param coreContract Core contract address for the given project.
223
+ * @return The project's required PMP keys. Empty if none are required.
224
+ */
225
+ function getRequiredPMPKeys(
226
+ uint256 projectId,
227
+ address coreContract
228
+ ) internal view returns (string[] memory) {
229
+ return
230
+ getRequiredPMPProjectConfig({
231
+ projectId: projectId,
232
+ coreContract: coreContract
233
+ }).requiredKeys.getAll();
234
+ }
235
+
236
+ /**
237
+ * Loads the RequiredPMPProjectConfig for a given project and core contract.
238
+ * @param projectId Project Id to get config for
239
+ * @param coreContract Core contract address to get config for
240
+ */
241
+ function getRequiredPMPProjectConfig(
242
+ uint256 projectId,
243
+ address coreContract
244
+ ) internal view returns (RequiredPMPProjectConfig storage) {
245
+ return s().requiredPMPProjectConfigs[coreContract][projectId];
246
+ }
247
+
248
+ /**
249
+ * @notice Validates that `pmpKey` may be required during mint for project
250
+ * `projectId`.
251
+ * @dev Reverts if the key is not part of the project's active PMP config,
252
+ * does not authenticate this contract as a configuring address, or could
253
+ * ever lock.
254
+ * @param projectId Project ID the key is being required for.
255
+ * @param coreContract Core contract address for the given project.
256
+ * @param pmpContract PMP contract the project's params are configured on.
257
+ * @param pmpKey PMP key to validate.
258
+ * @param projectConfigNonce The project's current PMP config nonce.
259
+ */
260
+ function _validateRequiredPMPKey(
261
+ uint256 projectId,
262
+ address coreContract,
263
+ address pmpContract,
264
+ string calldata pmpKey,
265
+ uint8 projectConfigNonce
266
+ ) private view {
267
+ IPMPV0.PMPConfigView memory pmpConfig = IPMPProjectViewsV0(pmpContract)
268
+ .getProjectPMPConfig({
269
+ coreContract: coreContract,
270
+ projectId: projectId,
271
+ pmpKey: pmpKey
272
+ });
273
+ // the key must be configured on the project
274
+ // @dev checked independently of the config nonce, because a project
275
+ // that has never been configured has a zero nonce that would otherwise
276
+ // trivially match an unconfigured key's zero highestConfigNonce
277
+ require(
278
+ pmpConfig.paramType != IPMPV0.ParamType.Unconfigured,
279
+ "Req PMP key unconfigured"
280
+ );
281
+ // ...and must be part of the project's most recently configured params
282
+ require(
283
+ pmpConfig.highestConfigNonce == projectConfigNonce,
284
+ "Req PMP key not in config"
285
+ );
286
+ // ...and must permit a configured address to set its value, since this
287
+ // contract is the caller when the key is configured at mint
288
+ require(
289
+ _authOptionIncludesAddress(pmpConfig.authOption),
290
+ "Req PMP key needs addr auth"
291
+ );
292
+ // ...and that configured address must be this contract
293
+ require(
294
+ pmpConfig.authAddress == address(this),
295
+ "Req PMP key must auth minter"
296
+ );
297
+ // ...and must never lock, because a locked key can no longer be
298
+ // configured by any party and would permanently halt minting
299
+ require(
300
+ pmpConfig.pmpLockedAfterTimestamp == 0,
301
+ "Req PMP key must never lock"
302
+ );
303
+ }
304
+
305
+ /**
306
+ * @notice Returns whether `authOption` permits a configured address to set
307
+ * a param's value.
308
+ * @param authOption The PMP auth option to check.
309
+ * @return bool True if the auth option includes address authentication.
310
+ */
311
+ function _authOptionIncludesAddress(
312
+ IPMPV0.AuthOption authOption
313
+ ) private pure returns (bool) {
314
+ return
315
+ authOption == IPMPV0.AuthOption.Address ||
316
+ authOption == IPMPV0.AuthOption.ArtistAndAddress ||
317
+ authOption == IPMPV0.AuthOption.TokenOwnerAndAddress ||
318
+ authOption == IPMPV0.AuthOption.ArtistAndTokenOwnerAndAddress;
319
+ }
320
+
321
+ /**
322
+ * @notice Return the storage struct for reading and writing. This library
323
+ * uses a diamond storage pattern when managing storage.
324
+ * @return storageStruct The RequiredPMPLibStorage struct.
325
+ */
326
+ function s()
327
+ internal
328
+ pure
329
+ returns (RequiredPMPLibStorage storage storageStruct)
330
+ {
331
+ bytes32 position = REQUIRED_PMP_LIB_STORAGE_POSITION;
332
+ assembly ("memory-safe") {
333
+ storageStruct.slot := position
334
+ }
335
+ }
336
+ }