From 172cacb121f8316af5d4693a8b54a9d5eb891b36 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Fri, 10 May 2024 11:16:22 +0200 Subject: [PATCH] Added check if KA is already part of other Paranet during submission --- abi/Paranet.json | 21 ++++++++++++++++ .../v2/errors/paranets/ParanetErrors.sol | 5 ++++ contracts/v2/paranets/Paranet.sol | 24 ++++++++++++++----- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/abi/Paranet.json b/abi/Paranet.json index 0b1e3df7..b94c3a25 100644 --- a/abi/Paranet.json +++ b/abi/Paranet.json @@ -10,6 +10,27 @@ "stateMutability": "nonpayable", "type": "constructor" }, + { + "inputs": [ + { + "internalType": "address", + "name": "paranetKnowledgeAssetStorageContract", + "type": "address" + }, + { + "internalType": "uint256", + "name": "paranetTokenId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "paranetId", + "type": "bytes32" + } + ], + "name": "KnowledgeAssetIsAPartOfOtherParanet", + "type": "error" + }, { "inputs": [ { diff --git a/contracts/v2/errors/paranets/ParanetErrors.sol b/contracts/v2/errors/paranets/ParanetErrors.sol index ce4b4bf2..5263c1cc 100644 --- a/contracts/v2/errors/paranets/ParanetErrors.sol +++ b/contracts/v2/errors/paranets/ParanetErrors.sol @@ -13,6 +13,11 @@ library ParanetErrors { address knowledgeAssetStorageContract, uint256 knowledgeAssetTokenId ); + error KnowledgeAssetIsAPartOfOtherParanet( + address paranetKnowledgeAssetStorageContract, + uint256 paranetTokenId, + bytes32 paranetId + ); error NoOperatorRewardAvailable(bytes32 paranetId); error NoEarnedReward(bytes32 paranetId, address miner); error TracTargetExceeded(bytes32 paranetId, uint96 tracTarget, uint96 tracRewarded, uint96 tracSpent); diff --git a/contracts/v2/paranets/Paranet.sol b/contracts/v2/paranets/Paranet.sol index e5199671..49d343d0 100644 --- a/contracts/v2/paranets/Paranet.sol +++ b/contracts/v2/paranets/Paranet.sol @@ -559,8 +559,8 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { ParanetKnowledgeMinersRegistry pkmr = paranetKnowledgeMinersRegistry; ParanetKnowledgeAssetsRegistry pkar = paranetKnowledgeAssetsRegistry; - if (!pr.paranetExists(keccak256(abi.encodePacked(knowledgeAssetStorageContract, paranetKATokenId)))) { - revert ParanetErrors.ParanetDoesntExist(knowledgeAssetStorageContract, paranetKATokenId); + if (!pr.paranetExists(keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)))) { + revert ParanetErrors.ParanetDoesntExist(paranetKAStorageContract, paranetKATokenId); } if (IERC721(knowledgeAssetStorageContract).ownerOf(knowledgeAssetTokenId) != msg.sender) { @@ -572,6 +572,18 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { ); } + if ( + pkar.isParanetKnowledgeAsset( + keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId)) + ) + ) { + revert ParanetErrors.KnowledgeAssetIsAPartOfOtherParanet( + knowledgeAssetStorageContract, + knowledgeAssetTokenId, + pkar.getParanetId(keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId))) + ); + } + uint96 remainingTokenAmount = serviceAgreementStorageProxy.getAgreementTokenAmount( hashingProxy.callHashFunction( HASH_FUNCTION_ID, @@ -596,7 +608,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { // Add Knowledge Asset to the KnowledgeAssetsRegistry pkar.addKnowledgeAsset( keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)), - address(contentAssetStorage), + knowledgeAssetStorageContract, knowledgeAssetTokenId, msg.sender, bytes("") @@ -605,7 +617,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { // Add Knowledge Asset Metadata to the ParanetsRegistry pr.addKnowledgeAsset( keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)), - keccak256(abi.encodePacked(address(contentAssetStorage), knowledgeAssetTokenId)) + keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId)) ); pr.addCumulativeKnowledgeValue( keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)), @@ -616,7 +628,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { pkmr.addSubmittedKnowledgeAsset( msg.sender, keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)), - keccak256(abi.encodePacked(address(contentAssetStorage), knowledgeAssetTokenId)) + keccak256(abi.encodePacked(knowledgeAssetStorageContract, knowledgeAssetTokenId)) ); pkmr.addCumulativeTracSpent( msg.sender, @@ -629,7 +641,7 @@ contract Paranet is Named, Versioned, ContractStatusV2, Initializable { emit KnowledgeAssetSubmittedToParanet( paranetKAStorageContract, paranetKATokenId, - address(contentAssetStorage), + knowledgeAssetStorageContract, knowledgeAssetTokenId ); }