Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

LicenseRegistry verifier conditions check #8

Merged
merged 3 commits into from
Jan 20, 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
2 changes: 2 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ library Errors {
error LicenseRegistry__NotLicensee();
error LicenseRegistry__ParentIdEqualThanChild();
error LicenseRegistry__LicensorDoesntHaveThisPolicy();
error LicenseRegistry__MintParamFailed();
error LicenseRegistry__LinkParentParamFailed();

////////////////////////////////////////////////////////////////////////////
// ModuleRegistry //
Expand Down
30 changes: 26 additions & 4 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,17 @@ contract LicenseRegistry is ERC1155 {

Licensing.Policy memory pol = policy(policyId);

// TODO: execute minting params to check if they are valid
Licensing.Parameter[] memory mintParams = _frameworks[pol.frameworkId].mintingParams;
bytes[] memory mintParamValues = pol.mintingParamValues;
for (uint256 i=0; i < mintParams.length; i++) {
Licensing.Parameter memory param = mintParams[i];
// Empty bytes => use default value specified in license framework creation params.
bytes memory callValue = mintParamValues[i].length == 0 ? param.defaultValue : mintParamValues[i];
// TODO: is `caller` param `msg.sender` or `receiver` or something else?
if (!param.verifier.verifyParam(receiver, callValue)) {
revert Errors.LicenseRegistry__MintParamFailed();
}
}

(uint256 lId, bool isNew) = _addIdOrGetExisting(abi.encode(licenseData), _hashedLicenses, _totalLicenses);
licenseId = lId;
Expand Down Expand Up @@ -269,11 +279,23 @@ contract LicenseRegistry is ERC1155 {
// TODO: check licensor exist
// TODO: check licensor part of a bad tag branch
}
Licensing.Policy memory policy = policy(licenseData.policyId);
// TODO: check linking conditions

Licensing.Policy memory pol = policy(licenseData.policyId);

// TODO: verify the mechanism for checking linking conditions
Licensing.Parameter[] memory linkParams = _frameworks[pol.frameworkId].linkParentParams;
jdubpark marked this conversation as resolved.
Show resolved Hide resolved
bytes[] memory linkParamValues = pol.linkParentParamValues;
for (uint256 i=0; i < linkParams.length; i++) {
Licensing.Parameter memory param = linkParams[i];
// Empty bytes => use default value specified in license framework creation params.
bytes memory callValue = linkParamValues[i].length == 0 ? param.defaultValue : linkParamValues[i];
if (!param.verifier.verifyParam(holder, callValue)) {
revert Errors.LicenseRegistry__LinkParentParamFailed();
}
}

// Add policy to kid
addPolicy(childIpId, policy);
addPolicy(childIpId, pol);
// Set parent
for (uint256 i=0; i < parents.length; i++) {
// We don't care if it was already a parent, because there might be a case such as:
Expand Down
24 changes: 12 additions & 12 deletions test/foundry/LicenseRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ contract LicenseRegistryTest is Test {
needsActivation: false,
linkParentParamValues: new bytes[](1)
});
policy.mintingParamValues[0] = abi.encode("test");
policy.activationParamValues[0] = abi.encode("test");
policy.linkParentParamValues[0] = abi.encode("test");
policy.mintingParamValues[0] = abi.encode(true);
policy.activationParamValues[0] = abi.encode(true);
policy.linkParentParamValues[0] = abi.encode(true);
(uint256 policyId, uint256 indexOnIpId) = registry.addPolicy(ipId1, policy);
assertEq(policyId, 1, "policyId not 1");
assertEq(indexOnIpId, 0, "indexOnIpId not 0");
Expand All @@ -98,9 +98,9 @@ contract LicenseRegistryTest is Test {
needsActivation: false,
linkParentParamValues: new bytes[](1)
});
policy.mintingParamValues[0] = abi.encode("test");
policy.activationParamValues[0] = abi.encode("test");
policy.linkParentParamValues[0] = abi.encode("test");
policy.mintingParamValues[0] = abi.encode(true);
policy.activationParamValues[0] = abi.encode(true);
policy.linkParentParamValues[0] = abi.encode(true);
(uint256 policyId, uint256 indexOnIpId) = registry.addPolicy(ipId1, policy);
(uint256 policyId2, uint256 indexOnIpId2) = registry.addPolicy(ipId2, policy);
assertEq(policyId, policyId2, "policyId not reused");
Expand All @@ -118,9 +118,9 @@ contract LicenseRegistryTest is Test {
needsActivation: false,
linkParentParamValues: new bytes[](1)
});
policy.mintingParamValues[0] = abi.encode("test");
policy.activationParamValues[0] = abi.encode("test");
policy.linkParentParamValues[0] = abi.encode("test");
policy.mintingParamValues[0] = abi.encode(true);
policy.activationParamValues[0] = abi.encode(true);
policy.linkParentParamValues[0] = abi.encode(true);

// First time adding a policy
(uint256 policyId, uint256 indexOnIpId) = registry.addPolicy(ipId1, policy);
Expand Down Expand Up @@ -148,9 +148,9 @@ contract LicenseRegistryTest is Test {
needsActivation: false,
linkParentParamValues: new bytes[](1)
});
policy.mintingParamValues[0] = abi.encode("test");
policy.activationParamValues[0] = abi.encode("test");
policy.linkParentParamValues[0] = abi.encode("test");
policy.mintingParamValues[0] = abi.encode(true);
policy.activationParamValues[0] = abi.encode(true);
policy.linkParentParamValues[0] = abi.encode(true);
(uint256 policyId, uint256 indexOnIpId) = registry.addPolicy(ipId1, policy);
assertEq(policyId, 1);
Licensing.License memory licenseData = Licensing.License({
Expand Down