Skip to content

Commit

Permalink
fix premint v2 struct hash and creator attribution (#384)
Browse files Browse the repository at this point in the history
fix v2 of domain setting

fix premint encoding and creator attribution event

added changeset
  • Loading branch information
oveddan authored Nov 27, 2023
2 parents 994773a + 1d58cd1 commit 3c1351e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-poems-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoralabs/zora-1155-contracts": patch
---

fixed bug where premint config v2 did not have correct eip-712 domain. fixed bug in CreatorAttribution event where structHash was not included in it
5 changes: 5 additions & 0 deletions .changeset/mighty-peaches-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoralabs/protocol-deployments": patch
---

Deployed 2.5.2 to zora sepolia and zora goerli
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ library ZoraCreator1155Attribution {

bytes32 constant ATTRIBUTION_DOMAIN_V2 =
keccak256(
"CreatorAttribution(TokenCreationConfig tokenConfig,uint32 uid,uint32 version,bool deleted)TokenCreationConfig(string tokenURI,uint256 maxSupply,uint64 maxTokensPerAddress,uint96 pricePerToken,uint64 mintStart,uint64 mintDuration,uint32 royaltyBPS,address royaltyRecipient,address fixedPriceMinter,address createReferral)"
"CreatorAttribution(TokenCreationConfig tokenConfig,uint32 uid,uint32 version,bool deleted)TokenCreationConfig(string tokenURI,uint256 maxSupply,uint64 maxTokensPerAddress,uint96 pricePerToken,uint64 mintStart,uint64 mintDuration,uint32 royaltyBPS,address payoutRecipient,address fixedPriceMinter,address createReferral)"
);

function hashPremint(PremintConfigV2 memory premintConfig) internal pure returns (bytes32) {
Expand Down Expand Up @@ -208,7 +208,7 @@ library ZoraCreator1155Attribution {
return
keccak256(
abi.encode(
TOKEN_DOMAIN_V1,
TOKEN_DOMAIN_V2,
_stringHash(tokenConfig.tokenURI),
tokenConfig.maxSupply,
tokenConfig.maxTokensPerAddress,
Expand Down Expand Up @@ -390,7 +390,7 @@ library DelegatedTokenCreation {
if (premintVersion == ZoraCreator1155Attribution.HASHED_VERSION_1) {
PremintConfig memory premintConfig = abi.decode(premintConfigEncoded, (PremintConfig));

creatorAttribution = _recoverCreatorAttribution(
creatorAttribution = recoverCreatorAttribution(
ZoraCreator1155Attribution.VERSION_1,
ZoraCreator1155Attribution.hashPremint(premintConfig),
tokenContract,
Expand All @@ -401,7 +401,7 @@ library DelegatedTokenCreation {
} else {
PremintConfigV2 memory premintConfig = abi.decode(premintConfigEncoded, (PremintConfigV2));

creatorAttribution = _recoverCreatorAttribution(
creatorAttribution = recoverCreatorAttribution(
ZoraCreator1155Attribution.VERSION_2,
ZoraCreator1155Attribution.hashPremint(premintConfig),
tokenContract,
Expand All @@ -422,12 +422,13 @@ library DelegatedTokenCreation {
versions[1] = ZoraCreator1155Attribution.VERSION_2;
}

function _recoverCreatorAttribution(
function recoverCreatorAttribution(
string memory version,
bytes32 structHash,
address tokenContract,
bytes calldata signature
) private view returns (DecodedCreatorAttribution memory attribution) {
) internal view returns (DecodedCreatorAttribution memory attribution) {
attribution.structHash = structHash;
attribution.version = version;

attribution.creator = ZoraCreator1155Attribution.recoverSignerHashed(structHash, signature, tokenContract, keccak256(bytes(version)), block.chainid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract ZoraCreator1155PreminterTest is Test {
return factory.defaultMinters()[0];
}

function makeDefaultPremintConfig() internal view returns (PremintConfigV2 memory) {
function makeDefaultPremintConfigV2() internal view returns (PremintConfigV2 memory) {
return
PremintConfigV2({
tokenConfig: Zora1155PremintFixtures.makeDefaultTokenCreationConfigV2(getFixedPriceMinter(), creator),
Expand All @@ -87,6 +87,10 @@ contract ZoraCreator1155PreminterTest is Test {
});
}

function makeDefaultPremintConfigV1() internal view returns (PremintConfig memory) {
return Zora1155PremintFixtures.makeDefaultV1PremintConfig(getFixedPriceMinter(), creator);
}

function makePremintConfigWithCreateReferral(address createReferral) internal view returns (PremintConfigV2 memory) {
return
PremintConfigV2({
Expand Down Expand Up @@ -151,7 +155,7 @@ contract ZoraCreator1155PreminterTest is Test {

// configuration of contract to create
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// how many tokens are minted to the executor
uint256 quantityToMint = 4;
Expand Down Expand Up @@ -208,7 +212,7 @@ contract ZoraCreator1155PreminterTest is Test {

// configuration of contract to create
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// how many tokens are minted to the executor
uint256 chainId = block.chainid;
Expand Down Expand Up @@ -242,10 +246,43 @@ contract ZoraCreator1155PreminterTest is Test {

event CreatorAttribution(bytes32 structHash, string domainName, string version, address creator, bytes signature);

function test_premint_emitsCreatorAttribution_fromErc1155Contract() external {
function test_premintV1_emitsCreatorAttribution_fromErc1155Contract() external {
// build a premint
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfig memory premintConfig = makeDefaultPremintConfigV1();

// sign and execute premint
uint256 chainId = block.chainid;

address deterministicAddress = preminter.getContractAddress(contractConfig);
bytes32 structHash = ZoraCreator1155Attribution.hashPremint(premintConfig);
bytes32 digest = ZoraCreator1155Attribution.premintHashedTypeDataV4(
structHash,
deterministicAddress,
ZoraCreator1155Attribution.HASHED_VERSION_1,
chainId
);
bytes memory signature = _sign(creatorPrivateKey, digest);

uint256 quantityToMint = 4;
uint256 mintCost = mintFeeAmount * quantityToMint;
// this account will be used to execute the premint, and should result in a contract being created
vm.deal(collector, mintCost);

vm.prank(collector);

// verify CreatorAttribution was emitted from the erc1155 contract
vm.expectEmit(true, true, true, true, deterministicAddress);
emit CreatorAttribution(structHash, ZoraCreator1155Attribution.NAME, ZoraCreator1155Attribution.VERSION_1, creator, signature);

// create contract and token via premint
preminter.premintV1{value: mintCost}(contractConfig, premintConfig, signature, quantityToMint, defaultMintArguments);
}

function test_premintV2_emitsCreatorAttribution_fromErc1155Contract() external {
// build a premint
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// sign and execute premint
uint256 chainId = block.chainid;
Expand All @@ -268,7 +305,7 @@ contract ZoraCreator1155PreminterTest is Test {
vm.prank(collector);

// verify CreatorAttribution was emitted from the erc1155 contract
vm.expectEmit(true, false, false, false, deterministicAddress);
vm.expectEmit(true, true, true, true, deterministicAddress);
emit CreatorAttribution(structHash, ZoraCreator1155Attribution.NAME, ZoraCreator1155Attribution.VERSION_2, creator, signature);

// create contract and token via premint
Expand All @@ -280,7 +317,7 @@ contract ZoraCreator1155PreminterTest is Test {

// configuration of contract to create
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// how many tokens are minted to the executor
uint256 quantityToMint = 4;
Expand Down Expand Up @@ -321,7 +358,7 @@ contract ZoraCreator1155PreminterTest is Test {

// configuration of contract to create
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// how many tokens are minted to the executor
uint256 quantityToMint = 2;
Expand Down Expand Up @@ -375,7 +412,7 @@ contract ZoraCreator1155PreminterTest is Test {

function testCreateTokenPerUid() public {
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

uint256 quantityToMint = 2;
uint256 chainId = block.chainid;
Expand All @@ -402,7 +439,7 @@ contract ZoraCreator1155PreminterTest is Test {

function test_deleted_preventsTokenFromBeingMinted() external {
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

premintConfig.deleted = true;
uint chainId = block.chainid;
Expand All @@ -426,7 +463,7 @@ contract ZoraCreator1155PreminterTest is Test {

function test_emitsPremint_whenNewContract() external {
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();
address contractAddress = preminter.getContractAddress(contractConfig);

// how many tokens are minted to the executor
Expand All @@ -452,7 +489,7 @@ contract ZoraCreator1155PreminterTest is Test {

function test_onlyOwner_hasAdminRights_onCreatedToken() public {
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// how many tokens are minted to the executor
uint256 quantityToMint = 4;
Expand Down Expand Up @@ -520,7 +557,7 @@ contract ZoraCreator1155PreminterTest is Test {
}

function test_premintStatus_getsStatus() external {
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// how many tokens are minted to the executor
uint256 quantityToMint = 4;
Expand Down Expand Up @@ -564,7 +601,7 @@ contract ZoraCreator1155PreminterTest is Test {
vm.warp(currentTime);

ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();
premintConfig.tokenConfig.mintStart = startDate;

uint256 quantityToMint = 4;
Expand Down Expand Up @@ -598,7 +635,7 @@ contract ZoraCreator1155PreminterTest is Test {

// build a premint with a token that has the given start date and duration
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();
address contractAddress = preminter.getContractAddress(contractConfig);

premintConfig.tokenConfig.mintStart = startDate;
Expand Down Expand Up @@ -637,7 +674,7 @@ contract ZoraCreator1155PreminterTest is Test {
function test_premintStatus_getsIfContractHasBeenCreatedAndTokenIdForPremint() external {
// build a premint
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// get premint status
(bool contractCreated, uint256 tokenId) = preminter.premintStatus(preminter.getContractAddress(contractConfig), premintConfig.uid);
Expand All @@ -664,7 +701,7 @@ contract ZoraCreator1155PreminterTest is Test {
function test_premint_whenContractCreated_premintCanOnlyBeExecutedByPermissionBitMinter() external {
// build a premint
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

address contractAddress = preminter.getContractAddress(contractConfig);

Expand Down Expand Up @@ -760,7 +797,7 @@ contract ZoraCreator1155PreminterTest is Test {
function test_premintVersion_whenCreated_returnsAllVersion() external {
// build a premint
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

// sign and execute premint
address deterministicAddress = preminter.getContractAddress(contractConfig);
Expand Down Expand Up @@ -791,7 +828,7 @@ contract ZoraCreator1155PreminterTest is Test {

function test_premintWithNoMintRecipient_reverts() public {
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfig();
PremintConfigV2 memory premintConfig = makeDefaultPremintConfigV2();

address contractAddress = preminter.getContractAddress(contractConfig);

Expand Down
12 changes: 6 additions & 6 deletions packages/protocol-deployments/addresses/999.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"CONTRACT_1155_IMPL": "0xa2669e686fa4192166daEa69F269b262636eE198",
"CONTRACT_1155_IMPL_VERSION": "2.5.1",
"FACTORY_IMPL": "0x30ed75ffaDF6215A3190d43ec505750a70B29fAc",
"CONTRACT_1155_IMPL": "0x928279Bf32E3E5318123fD9E936E51c30Be9eE6f",
"CONTRACT_1155_IMPL_VERSION": "2.5.2",
"FACTORY_IMPL": "0x6329e54bcdb44117732a06087f7E485F8943C9AF",
"FACTORY_PROXY": "0x777777C338d93e2C7adf08D102d45CA7CC4Ed021",
"FIXED_PRICE_SALE_STRATEGY": "0x04E2516A2c207E84a1839755675dfd8eF6302F0a",
"MERKLE_MINT_SALE_STRATEGY": "0xf48172CA3B6068B20eE4917Eb27b5472f1f272C7",
"PREMINTER_IMPL": "0x37A7c717c3EDA58e4ec7F424B2A46934Fd8f8468",
"PREMINTER_IMPL": "0x6D3b29A851d595c4d85A3214f1245e74b6Fb8bBb",
"PREMINTER_PROXY": "0x7777773606e7e46C8Ba8B98C08f5cD218e31d340",
"REDEEM_MINTER_FACTORY": "0x78964965cF77850224513a367f899435C5B69174",
"UPGRADE_GATE": "0xbC50029836A59A4E5e1Bb8988272F46ebA0F9900",
"timestamp": 1700533625,
"commit": "8c57238e"
"timestamp": 1700611870,
"commit": "d5eef7cb"
}
12 changes: 6 additions & 6 deletions packages/protocol-deployments/addresses/999999999.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"CONTRACT_1155_IMPL": "0xF3a46845548bE811Ce37e65153563f4a0AaEbe31",
"CONTRACT_1155_IMPL_VERSION": "2.5.1",
"FACTORY_IMPL": "0xF7e49F97E82cc38ACd82E303F37Fe046f5a190B5",
"CONTRACT_1155_IMPL": "0x073ef87C54c192c21ddEf881fE18064b6161fAC9",
"CONTRACT_1155_IMPL_VERSION": "2.5.2",
"FACTORY_IMPL": "0x7316777F0cBe4da5a52cd5e68d1C50af8E466AC1",
"FACTORY_PROXY": "0x777777C338d93e2C7adf08D102d45CA7CC4Ed021",
"FIXED_PRICE_SALE_STRATEGY": "0x6d28164C3CE04A190D5F9f0f8881fc807EAD975A",
"MERKLE_MINT_SALE_STRATEGY": "0x5e5fD4b758076BAD940db0284b711A67E8a3B88c",
"PREMINTER_IMPL": "0x37A7c717c3EDA58e4ec7F424B2A46934Fd8f8468",
"PREMINTER_IMPL": "0x6D3b29A851d595c4d85A3214f1245e74b6Fb8bBb",
"PREMINTER_PROXY": "0x7777773606e7e46C8Ba8B98C08f5cD218e31d340",
"REDEEM_MINTER_FACTORY": "0x25cFb6dd9cDE8425e781d6718a29Ccbca3F038d6",
"UPGRADE_GATE": "0x0000000000000000000000000000000000000000",
"timestamp": 1700531325,
"commit": "fdd3d044"
"timestamp": 1700610104,
"commit": "134b44da"
}

0 comments on commit 3c1351e

Please sign in to comment.