Skip to content

Commit

Permalink
Merge pull request #336 from OriginTrail/fix/remove-kc-update
Browse files Browse the repository at this point in the history
Disable update in KC
  • Loading branch information
Mihajlo-Pavlovic authored Jan 24, 2025
2 parents ba6ce7a + 0dfb4b1 commit a31375c
Show file tree
Hide file tree
Showing 6 changed files with 665 additions and 755 deletions.
89 changes: 0 additions & 89 deletions abi/KnowledgeCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
}
],
"name": "CannotUpdateImmutableKnowledgeCollection",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -516,84 +505,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "string",
"name": "updateOperationId",
"type": "string"
},
{
"internalType": "bytes32",
"name": "merkleRoot",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "mintKnowledgeAssetsAmount",
"type": "uint256"
},
{
"internalType": "uint256[]",
"name": "knowledgeAssetsToBurn",
"type": "uint256[]"
},
{
"internalType": "uint88",
"name": "byteSize",
"type": "uint88"
},
{
"internalType": "uint96",
"name": "tokenAmount",
"type": "uint96"
},
{
"internalType": "address",
"name": "paymaster",
"type": "address"
},
{
"internalType": "uint72",
"name": "publisherNodeIdentityId",
"type": "uint72"
},
{
"internalType": "bytes32",
"name": "publisherNodeR",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "publisherNodeVS",
"type": "bytes32"
},
{
"internalType": "uint72[]",
"name": "identityIds",
"type": "uint72[]"
},
{
"internalType": "bytes32[]",
"name": "r",
"type": "bytes32[]"
},
{
"internalType": "bytes32[]",
"name": "vs",
"type": "bytes32[]"
}
],
"name": "updateKnowledgeCollection",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "version",
Expand Down
116 changes: 58 additions & 58 deletions contracts/KnowledgeCollection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,64 +110,64 @@ contract KnowledgeCollection is INamed, IVersioned, ContractStatus, IInitializab
return id;
}

function updateKnowledgeCollection(
uint256 id,
string calldata updateOperationId,
bytes32 merkleRoot,
uint256 mintKnowledgeAssetsAmount,
uint256[] calldata knowledgeAssetsToBurn,
uint88 byteSize,
uint96 tokenAmount,
address paymaster,
uint72 publisherNodeIdentityId,
bytes32 publisherNodeR,
bytes32 publisherNodeVS,
uint72[] calldata identityIds,
bytes32[] calldata r,
bytes32[] calldata vs
) external {
KnowledgeCollectionStorage kcs = knowledgeCollectionStorage;
EpochStorage es = epochStorage;

(, , , uint88 oldByteSize, , uint40 endEpoch, uint96 oldTokenAmount, bool isImmutable) = kcs
.getKnowledgeCollectionMetadata(id);

if (isImmutable) {
revert KnowledgeCollectionLib.CannotUpdateImmutableKnowledgeCollection(id);
}

_verifySignature(
publisherNodeIdentityId,
ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(publisherNodeIdentityId, merkleRoot))),
publisherNodeR,
publisherNodeVS
);

_verifySignatures(identityIds, ECDSA.toEthSignedMessageHash(merkleRoot), r, vs);

uint256 currentEpoch = chronos.getCurrentEpoch();
if (currentEpoch > endEpoch) {
revert KnowledgeCollectionLib.KnowledgeCollectionExpired(id, currentEpoch, endEpoch);
}

kcs.updateKnowledgeCollection(
msg.sender,
id,
updateOperationId,
merkleRoot,
mintKnowledgeAssetsAmount,
knowledgeAssetsToBurn,
oldByteSize + byteSize,
oldTokenAmount + tokenAmount
);

_validateTokenAmount(byteSize - oldByteSize, endEpoch - currentEpoch, tokenAmount, true);

es.addTokensToEpochRange(1, currentEpoch, endEpoch, tokenAmount);
es.addEpochProducedKnowledgeValue(publisherNodeIdentityId, currentEpoch, tokenAmount);

_addTokens(tokenAmount, paymaster);
}
// function updateKnowledgeCollection(
// uint256 id,
// string calldata updateOperationId,
// bytes32 merkleRoot,
// uint256 mintKnowledgeAssetsAmount,
// uint256[] calldata knowledgeAssetsToBurn,
// uint88 byteSize,
// uint96 tokenAmount,
// address paymaster,
// uint72 publisherNodeIdentityId,
// bytes32 publisherNodeR,
// bytes32 publisherNodeVS,
// uint72[] calldata identityIds,
// bytes32[] calldata r,
// bytes32[] calldata vs
// ) external {
// KnowledgeCollectionStorage kcs = knowledgeCollectionStorage;
// EpochStorage es = epochStorage;

// (, , , uint88 oldByteSize, , uint40 endEpoch, uint96 oldTokenAmount, bool isImmutable) = kcs
// .getKnowledgeCollectionMetadata(id);

// if (isImmutable) {
// revert KnowledgeCollectionLib.CannotUpdateImmutableKnowledgeCollection(id);
// }

// _verifySignature(
// publisherNodeIdentityId,
// ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(publisherNodeIdentityId, merkleRoot))),
// publisherNodeR,
// publisherNodeVS
// );

// _verifySignatures(identityIds, ECDSA.toEthSignedMessageHash(merkleRoot), r, vs);

// uint256 currentEpoch = chronos.getCurrentEpoch();
// if (currentEpoch > endEpoch) {
// revert KnowledgeCollectionLib.KnowledgeCollectionExpired(id, currentEpoch, endEpoch);
// }

// kcs.updateKnowledgeCollection(
// msg.sender,
// id,
// updateOperationId,
// merkleRoot,
// mintKnowledgeAssetsAmount,
// knowledgeAssetsToBurn,
// oldByteSize + byteSize,
// oldTokenAmount + tokenAmount
// );

// _validateTokenAmount(byteSize - oldByteSize, endEpoch - currentEpoch, tokenAmount, true);

// es.addTokensToEpochRange(1, currentEpoch, endEpoch, tokenAmount);
// es.addEpochProducedKnowledgeValue(publisherNodeIdentityId, currentEpoch, tokenAmount);

// _addTokens(tokenAmount, paymaster);
// }

function extendKnowledgeCollectionLifetime(
uint256 id,
Expand Down
Loading

0 comments on commit a31375c

Please sign in to comment.