Skip to content

Commit

Permalink
Only signing with contract address, we don't need the full contract i…
Browse files Browse the repository at this point in the history
…nformation to hash

Since we now know that the erc1155 is the one that is validating the sig, we can know
that the hash is equiv to the contract address
  • Loading branch information
oveddan committed Aug 15, 2023
1 parent 85c8dc3 commit 34f9be8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 94 deletions.
22 changes: 2 additions & 20 deletions src/premint/ZoraCreator1155Attribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ struct TokenCreationConfig {
}

struct PremintConfig {
// The config for the contract to be created
ContractCreationConfig contractConfig;
// The config for the token to be created
TokenCreationConfig tokenConfig;
// Unique id of the token, used to ensure that multiple signatures can't be used to create the same intended token.
Expand Down Expand Up @@ -121,20 +119,13 @@ library ZoraCreator1155Attribution {

bytes32 constant CONTRACT_AND_TOKEN_DOMAIN =
keccak256(
"Premint(ContractCreationConfig contractConfig,TokenCreationConfig tokenConfig,uint32 uid,uint32 version,bool deleted)ContractCreationConfig(address contractAdmin,string contractURI,string contractName)TokenCreationConfig(string tokenURI,uint256 maxSupply,uint64 maxTokensPerAddress,uint96 pricePerToken,uint64 mintStart,uint64 mintDuration,uint32 royaltyMintSchedule,uint32 royaltyBPS,address royaltyRecipient)"
"Premint(TokenCreationConfig tokenConfig,uint32 uid,uint32 version,bool deleted)ContractCreationConfig(address contractAdmin,string contractURI,string contractName)TokenCreationConfig(string tokenURI,uint256 maxSupply,uint64 maxTokensPerAddress,uint96 pricePerToken,uint64 mintStart,uint64 mintDuration,uint32 royaltyMintSchedule,uint32 royaltyBPS,address royaltyRecipient)"
);

function hashPremint(PremintConfig calldata premintConfig) public pure returns (bytes32) {
return
keccak256(
abi.encode(
CONTRACT_AND_TOKEN_DOMAIN,
_hashContract(premintConfig.contractConfig),
_hashToken(premintConfig.tokenConfig),
premintConfig.uid,
premintConfig.version,
premintConfig.deleted
)
abi.encode(CONTRACT_AND_TOKEN_DOMAIN, _hashToken(premintConfig.tokenConfig), premintConfig.uid, premintConfig.version, premintConfig.deleted)
);
}

Expand All @@ -161,15 +152,6 @@ library ZoraCreator1155Attribution {
);
}

bytes32 constant CONTRACT_DOMAIN = keccak256("ContractCreationConfig(address contractAdmin,string contractURI,string contractName)");

function _hashContract(ContractCreationConfig calldata contractConfig) private pure returns (bytes32) {
return
keccak256(
abi.encode(CONTRACT_DOMAIN, contractConfig.contractAdmin, _stringHash(contractConfig.contractURI), _stringHash(contractConfig.contractName))
);
}

function _stringHash(string calldata value) private pure returns (bytes32) {
return keccak256(bytes(value));
}
Expand Down
18 changes: 5 additions & 13 deletions src/premint/ZoraCreator1155PremintExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract ZoraCreator1155PremintExecutor {
// so it is unaware of order, it just takes the token uri and creates the next token with it
// this could include creating the contract.
function premint(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature,
uint256 quantityToMint,
Expand All @@ -61,25 +62,13 @@ contract ZoraCreator1155PremintExecutor {
// 6. Future: First minter gets rewards

// get or create the contract with the given params
(IZoraCreator1155 tokenContract, bool isNewContract) = _getOrCreateContract(premintConfig.contractConfig);
(IZoraCreator1155 tokenContract, bool isNewContract) = _getOrCreateContract(contractConfig);
address contractAddress = address(tokenContract);

// have the address setup the new token. The signer must have permission to do this.
// (that role enforcement is expected to be in the tokenContract).
// the token contract will:

// emit event early to have a cleaner log
emit Preminted(
contractAddress,
newTokenId,
isNewContract,
premintConfig.uid,
premintConfig.contractConfig,
premintConfig.tokenConfig,
msg.sender,
quantityToMint
);

// * setup the token with the signer as the creator, and follow the creator rewards standard.
// * will revert if the token in the contract with the same uid already exists.
// * will make sure creator has admin rights to the token.
Expand All @@ -96,6 +85,9 @@ contract ZoraCreator1155PremintExecutor {
quantityToMint,
abi.encode(tokenRecipient, mintComment)
);

// emit Preminted event
emit Preminted(contractAddress, newTokenId, isNewContract, premintConfig.uid, contractConfig, premintConfig.tokenConfig, msg.sender, quantityToMint);
}

function _getOrCreateContract(ContractCreationConfig calldata contractConfig) private returns (IZoraCreator1155 tokenContract, bool isNewContract) {
Expand Down
Loading

0 comments on commit 34f9be8

Please sign in to comment.