Skip to content

Commit

Permalink
Detect and Revert Duplicate License Terms (storyprotocol#75)
Browse files Browse the repository at this point in the history
* Duplicate licenses revert
  • Loading branch information
kingster-will authored and jdubpark committed Apr 14, 2024
1 parent db5de1e commit 910119a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ library Errors {
error LicenseRegistry__IndexOutOfBounds(address ipId, uint256 index, uint256 length);
error LicenseRegistry__LicenseTermsAlreadyAttached(address ipId, address licenseTemplate, uint256 licenseTermsId);
error LicenseRegistry__UnmatchedLicenseTemplate(address ipId, address licenseTemplate, address newLicenseTemplate);

error LicenseRegistry__DuplicateLicense(address ipId, address licenseTemplate, uint256 licenseTermsId);
////////////////////////////////////////////////////////////////////////////
// LicenseToken //
////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 6 additions & 2 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ contract LicenseRegistry is ILicenseRegistry, AccessManagedUpgradeable, UUPSUpgr

for (uint256 i = 0; i < parentIpIds.length; i++) {
_verifyDerivativeFromParent(parentIpIds[i], childIpId, licenseTemplate, licenseTermsIds[i]);
$.parentIps[childIpId].add(parentIpIds[i]);
$.childIps[parentIpIds[i]].add(childIpId);
$.attachedLicenseTerms[childIpId].add(licenseTermsIds[i]);
// determine if duplicate license terms
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]);
}
}

$.licenseTemplates[childIpId] = licenseTemplate;
Expand Down
9 changes: 8 additions & 1 deletion test/foundry/integration/flows/royalty/Royalty.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ contract Flows_Integration_Disputes is BaseIntegration {

ipAcct[2] = registerIpAccount(address(mockNFT), 2, u.bob);

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

// can link max two
Expand Down
40 changes: 40 additions & 0 deletions test/foundry/registries/LicenseRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,46 @@ contract LicenseRegistryTest is BaseTest {
licenseRegistry.getParentIp(ipId2, 1);
}

function test_LicenseRegistry_registerDerivativeIp() public {
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing());
vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), socialRemixTermsId);
vm.prank(ipOwner2);
licensingModule.attachLicenseTerms(ipId2, address(pilTemplate), socialRemixTermsId);

address[] memory parentIpIds = new address[](2);
parentIpIds[0] = ipId1;
parentIpIds[1] = ipId2;
uint256[] memory licenseTermsIds = new uint256[](2);
licenseTermsIds[0] = socialRemixTermsId;
licenseTermsIds[1] = socialRemixTermsId;
vm.prank(address(licensingModule));
licenseRegistry.registerDerivativeIp(ipId3, parentIpIds, address(pilTemplate), licenseTermsIds);
}

function test_LicenseRegistry_registerDerivativeIp_revert_DuplicateLicense() public {
uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing());
vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), socialRemixTermsId);

address[] memory parentIpIds = new address[](2);
parentIpIds[0] = ipId1;
parentIpIds[1] = ipId1;
uint256[] memory licenseTermsIds = new uint256[](2);
licenseTermsIds[0] = socialRemixTermsId;
licenseTermsIds[1] = socialRemixTermsId;
vm.expectRevert(
abi.encodeWithSelector(
Errors.LicenseRegistry__DuplicateLicense.selector,
ipId1,
address(pilTemplate),
socialRemixTermsId
)
);
vm.prank(address(licensingModule));
licenseRegistry.registerDerivativeIp(ipId2, parentIpIds, address(pilTemplate), licenseTermsIds);
}

function onERC721Received(address, address, uint256, bytes memory) public pure returns (bytes4) {
return this.onERC721Received.selector;
}
Expand Down

0 comments on commit 910119a

Please sign in to comment.