Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Duplicate Parent IPs When Registering Derivative IP #328

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ library Errors {
/// @notice Provided license template does not match the IP's current license template.
error LicenseRegistry__UnmatchedLicenseTemplate(address ipId, address licenseTemplate, address newLicenseTemplate);

/// @notice Provided license template and terms ID is a duplicate.
error LicenseRegistry__DuplicateLicense(address ipId, address licenseTemplate, uint256 licenseTermsId);

/// @notice Zero address provided for License Template.
error LicenseRegistry__ZeroLicenseTemplate();

Expand Down Expand Up @@ -283,6 +280,9 @@ library Errors {
/// @notice The IP has no attached the same license terms of Group IPA.
error LicenseRegistry__IpHasNoGroupLicenseTerms(address groupId, address licenseTemplate, uint256 licenseTermsId);

/// @notice The IP has already linked to the same parent IP.
error LicenseRegistry__DuplicateParentIp(address ipId, address parentIpId);

/// @notice When Set LicenseConfig the license template cannot be Zero address if royalty percentage is not Zero.
error LicensingModule__LicenseTemplateCannotBeZeroAddressToOverrideRoyaltyPercent();

Expand Down
8 changes: 4 additions & 4 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ contract LicenseRegistry is ILicenseRegistry, AccessManagedUpgradeable, UUPSUpgr
isUsingLicenseToken
);
$.childIps[parentIpIds[i]].add(childIpId);
// determine if duplicate license terms
// determine if duplicate parent IP
bool isNewParent = $.parentIps[childIpId].add(parentIpIds[i]);
bool isNewTerms = $.attachedLicenseTerms[childIpId].add(licenseTermsIds[i]);
if (!isNewParent && !isNewTerms) {
revert Errors.LicenseRegistry__DuplicateLicense(parentIpIds[i], licenseTemplate, licenseTermsIds[i]);
if (!isNewParent) {
revert Errors.LicenseRegistry__DuplicateParentIp(childIpId, parentIpIds[i]);
}
$.attachedLicenseTerms[childIpId].add(licenseTermsIds[i]);
// link child IP to parent IP with license terms
$.parentLicenseTerms[childIpId][parentIpIds[i]] = licenseTermsIds[i];
}
Expand Down
7 changes: 1 addition & 6 deletions test/foundry/integration/flows/royalty/Royalty.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ contract Flows_Integration_Disputes is BaseIntegration {
ipAcct[2] = registerIpAccount(address(mockNFT), 2, u.bob);

vm.expectRevert(
abi.encodeWithSelector(
Errors.LicenseRegistry__DuplicateLicense.selector,
ipAcct[1],
address(pilTemplate),
commRemixTermsId
)
abi.encodeWithSelector(Errors.LicenseRegistry__DuplicateParentIp.selector, ipAcct[2], ipAcct[1])
);
licensingModule.registerDerivativeWithLicenseTokens(ipAcct[2], licenseIds, "", 100e6);

Expand Down
18 changes: 10 additions & 8 deletions test/foundry/registries/LicenseRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,15 @@ contract LicenseRegistryTest is BaseTest {
});
}

function test_LicenseRegistry_registerDerivativeIp_revert_DuplicateLicense() public {
function test_LicenseRegistry_registerDerivativeIp_revert_DuplicateParents() public {
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing());
uint256 commRemixTermsId = pilTemplate.registerLicenseTerms(
PILFlavors.commercialRemix(0, 10, address(royaltyPolicyLAP), address(erc20))
);

vm.prank(ipOwner[1]);
licensingModule.attachLicenseTerms(ipAcct[1], address(pilTemplate), commRemixTermsId);

vm.prank(ipOwner[1]);
vm.expectRevert(
abi.encodeWithSelector(
Expand All @@ -427,14 +434,9 @@ contract LicenseRegistryTest is BaseTest {
parentIpIds[1] = ipAcct[1];
uint256[] memory licenseTermsIds = new uint256[](2);
licenseTermsIds[0] = socialRemixTermsId;
licenseTermsIds[1] = socialRemixTermsId;
licenseTermsIds[1] = commRemixTermsId;
vm.expectRevert(
abi.encodeWithSelector(
Errors.LicenseRegistry__DuplicateLicense.selector,
ipAcct[1],
address(pilTemplate),
socialRemixTermsId
)
abi.encodeWithSelector(Errors.LicenseRegistry__DuplicateParentIp.selector, ipAcct[2], ipAcct[1])
);
vm.prank(address(licensingModule));
licenseRegistry.registerDerivativeIp({
Expand Down
Loading