diff --git a/abi/CommitManagerV2.json b/abi/CommitManagerV2.json index 856de1f7..4b9788b9 100644 --- a/abi/CommitManagerV2.json +++ b/abi/CommitManagerV2.json @@ -513,19 +513,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "hashingProxy", - "outputs": [ - { - "internalType": "contract HashingProxy", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "hub", @@ -724,19 +711,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "stakingContract", - "outputs": [ - { - "internalType": "contract StakingV2", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "stakingStorage", diff --git a/abi/CommitManagerV2U1.json b/abi/CommitManagerV2U1.json index d6a0df49..eb79b779 100644 --- a/abi/CommitManagerV2U1.json +++ b/abi/CommitManagerV2U1.json @@ -453,13 +453,13 @@ "anonymous": false, "inputs": [ { - "indexed": true, + "indexed": false, "internalType": "address", "name": "assetContract", "type": "address" }, { - "indexed": true, + "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" @@ -489,7 +489,7 @@ "type": "uint256" }, { - "indexed": true, + "indexed": false, "internalType": "uint72", "name": "identityId", "type": "uint72" @@ -508,13 +508,13 @@ "anonymous": false, "inputs": [ { - "indexed": true, + "indexed": false, "internalType": "address", "name": "assetContract", "type": "address" }, { - "indexed": true, + "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" @@ -617,19 +617,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "hashingProxy", - "outputs": [ - { - "internalType": "contract HashingProxy", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "hub", @@ -857,19 +844,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "stakingContract", - "outputs": [ - { - "internalType": "contract StakingV2", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "stakingStorage", diff --git a/abi/ShardingTableStorageV2.json b/abi/ShardingTableStorageV2.json index c595f88d..31b9d1b1 100644 --- a/abi/ShardingTableStorageV2.json +++ b/abi/ShardingTableStorageV2.json @@ -17,6 +17,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "identityId", @@ -150,6 +155,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "index", @@ -196,6 +206,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "index", @@ -218,6 +233,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "index", @@ -240,6 +260,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "index", @@ -276,6 +301,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "index", @@ -312,6 +342,11 @@ "name": "hashRingPosition", "type": "uint256" }, + { + "internalType": "bytes", + "name": "nodeId", + "type": "bytes" + }, { "internalType": "uint72", "name": "index", diff --git a/contracts/v2/CommitManagerV1.sol b/contracts/v2/CommitManagerV1.sol index 7c531180..93e74558 100644 --- a/contracts/v2/CommitManagerV1.sol +++ b/contracts/v2/CommitManagerV1.sol @@ -2,11 +2,8 @@ pragma solidity ^0.8.16; -import {HashingProxy} from "../v1/HashingProxy.sol"; import {Log2PLDSF} from "../v1/scoring/log2pldsf.sol"; import {LinearSum} from "./scoring/LinearSum.sol"; -import {ProximityScoringProxy} from "./ProximityScoringProxy.sol"; -import {StakingV2} from "./Staking.sol"; import {IdentityStorageV2} from "./storage/IdentityStorage.sol"; import {ParametersStorage} from "../v1/storage/ParametersStorage.sol"; import {ProfileStorage} from "../v1/storage/ProfileStorage.sol"; @@ -21,11 +18,8 @@ import {ServiceAgreementStructsV1} from "../v1/structs/ServiceAgreementStructsV1 import {ServiceAgreementStructsV2} from "./structs/ServiceAgreementStructsV2.sol"; import {ShardingTableStructsV2} from "../v2/structs/ShardingTableStructsV2.sol"; import {CommitManagerErrorsV2} from "./errors/CommitManagerErrorsV2.sol"; -import {ContentAssetErrors} from "./errors/assets/ContentAssetErrors.sol"; -import {GeneralErrors} from "../v1/errors/GeneralErrors.sol"; import {ServiceAgreementErrorsV1} from "../v1/errors/ServiceAgreementErrorsV1.sol"; import {ServiceAgreementErrorsV2} from "./errors/ServiceAgreementErrorsV2.sol"; -import {NULL} from "../v1/constants/ShardingTableConstants.sol"; contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { event CommitSubmitted( @@ -46,11 +40,8 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { bool[4] public reqs = [false, false, false, false]; - HashingProxy public hashingProxy; - Log2PLDSF public log2pldsf; LinearSum public linearSum; - StakingV2 public stakingContract; IdentityStorageV2 public identityStorage; ParametersStorage public parametersStorage; ProfileStorage public profileStorage; @@ -64,16 +55,8 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { constructor(address hubAddress) ContractStatus(hubAddress) {} function initialize() public onlyHubOwner { - hashingProxy = HashingProxy(hub.getContractAddress("HashingProxy")); - log2pldsf = Log2PLDSF( - ProximityScoringProxy(hub.getContractAddress("ScoringProxy")).getScoreFunctionContractAddress(_LOG2PLDSF_ID) - ); - linearSum = LinearSum( - ProximityScoringProxy(hub.getContractAddress("ScoringProxy")).getScoreFunctionContractAddress( - _LINEAR_SUM_ID - ) - ); - stakingContract = StakingV2(hub.getContractAddress("Staking")); + log2pldsf = Log2PLDSF(hub.getContractAddress("Log2PLDSF")); + linearSum = LinearSum(hub.getContractAddress("LinearSum")); identityStorage = IdentityStorageV2(hub.getContractAddress("IdentityStorage")); parametersStorage = ParametersStorage(hub.getContractAddress("ParametersStorage")); profileStorage = ProfileStorage(hub.getContractAddress("ProfileStorage")); @@ -165,10 +148,7 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { function submitCommit(ServiceAgreementStructsV1.CommitInputArgs calldata args) external { ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy; - bytes32 agreementId = hashingProxy.callHashFunction( - args.hashFunctionId, - abi.encodePacked(args.assetContract, args.tokenId, args.keyword) - ); + bytes32 agreementId = sha256(abi.encodePacked(args.assetContract, args.tokenId, args.keyword)); if (!sasProxy.agreementV1Exists(agreementId)) revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId); @@ -183,7 +163,6 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { if (!reqs[0] && !isCommitWindowOpen(agreementId, args.epoch)) { uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId); - uint256 actualCommitWindowStart = (sasProxy.getAgreementStartTime(agreementId) + args.epoch * epochLength); revert ServiceAgreementErrorsV1.CommitWindowClosed( @@ -231,10 +210,7 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { function submitCommit(ServiceAgreementStructsV2.CommitInputArgs calldata args) external { ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy; - bytes32 agreementId = hashingProxy.callHashFunction( - args.hashFunctionId, - abi.encodePacked(args.assetContract, args.tokenId, args.keyword) - ); + bytes32 agreementId = sha256(abi.encodePacked(args.assetContract, args.tokenId, args.keyword)); if (!sasProxy.agreementV1Exists(agreementId)) revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId); @@ -249,7 +225,6 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { if (!reqs[0] && !isCommitWindowOpen(agreementId, args.epoch)) { uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId); - uint256 actualCommitWindowStart = (sasProxy.getAgreementStartTime(agreementId) + args.epoch * epochLength); revert ServiceAgreementErrorsV1.CommitWindowClosed( @@ -354,9 +329,9 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { (uint256 leftEdgeDistance, uint256 closestDistance, uint256 rightEdgeDistance) = ls .calculateNeighborhoodBoundaryDistances( hashFunctionId, - ps.getNodeId(leftEdgeNode.identityId), - ps.getNodeId(closestNode.identityId), - ps.getNodeId(rightEdgeNode.identityId), + leftEdgeNode.nodeId, + closestNode.nodeId, + rightEdgeNode.nodeId, keyword ); @@ -386,40 +361,40 @@ contract CommitManagerV2 is Named, Versioned, ContractStatus, Initializable { // Verify that closestNode is indeed closest if ( - closestDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestPrevIdentityId)) || - closestDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestNextIdentityId)) + closestDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(closestPrevIdentityId), keyword) || + closestDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(closestNextIdentityId), keyword) ) revert CommitManagerErrorsV2.InvalidClosestNode( agreementId, epoch, closestNodeIndex, closestDistance, - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestPrevIdentityId)), - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestNextIdentityId)), + ls.calculateDistance(hashFunctionId, ps.getNodeId(closestPrevIdentityId), keyword), + ls.calculateDistance(hashFunctionId, ps.getNodeId(closestNextIdentityId), keyword), block.timestamp ); // Verify that leftNode is indeed the left edge of the Neighborhood - if (leftEdgeDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(rightEdgeNextIdentityId))) + if (leftEdgeDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(rightEdgeNextIdentityId), keyword)) revert CommitManagerErrorsV2.InvalidLeftEdgeNode( agreementId, epoch, leftEdgeNodeIndex, rightEdgeNodeIndex != nodesCount - 1 ? rightEdgeNodeIndex + 1 : 0, leftEdgeDistance, - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(rightEdgeNextIdentityId)), + ls.calculateDistance(hashFunctionId, ps.getNodeId(rightEdgeNextIdentityId), keyword), block.timestamp ); // Verify that rightNode is indeed the right edge of the Neighborhood - if (rightEdgeDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(leftEdgePrevIdentityId))) + if (rightEdgeDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(leftEdgePrevIdentityId), keyword)) revert CommitManagerErrorsV2.InvalidRightEdgeNode( agreementId, epoch, rightEdgeNodeIndex, leftEdgeNodeIndex != 0 ? leftEdgeNodeIndex - 1 : nodesCount - 1, rightEdgeDistance, - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(leftEdgePrevIdentityId)), + ls.calculateDistance(hashFunctionId, ps.getNodeId(leftEdgePrevIdentityId), keyword), block.timestamp ); diff --git a/contracts/v2/CommitManagerV1U1.sol b/contracts/v2/CommitManagerV1U1.sol index b85e6172..99ca4be0 100644 --- a/contracts/v2/CommitManagerV1U1.sol +++ b/contracts/v2/CommitManagerV1U1.sol @@ -2,11 +2,8 @@ pragma solidity ^0.8.16; -import {HashingProxy} from "../v1/HashingProxy.sol"; import {Log2PLDSF} from "../v1/scoring/log2pldsf.sol"; import {LinearSum} from "./scoring/LinearSum.sol"; -import {ProximityScoringProxy} from "./ProximityScoringProxy.sol"; -import {StakingV2} from "./Staking.sol"; import {ContentAssetStorage} from "../v1/storage/assets/ContentAssetStorage.sol"; import {ContentAssetStorageV2} from "./storage/assets/ContentAssetStorage.sol"; import {IdentityStorageV2} from "./storage/IdentityStorage.sol"; @@ -25,27 +22,24 @@ import {ServiceAgreementStructsV1} from "../v1/structs/ServiceAgreementStructsV1 import {ServiceAgreementStructsV2} from "./structs/ServiceAgreementStructsV2.sol"; import {ShardingTableStructsV2} from "./structs/ShardingTableStructsV2.sol"; import {CommitManagerErrorsV2} from "./errors/CommitManagerErrorsV2.sol"; -import {ContentAssetErrors} from "./errors/assets/ContentAssetErrors.sol"; -import {GeneralErrors} from "../v1/errors/GeneralErrors.sol"; import {ServiceAgreementErrorsV1} from "../v1/errors/ServiceAgreementErrorsV1.sol"; import {ServiceAgreementErrorsV1U1} from "../v1/errors/ServiceAgreementErrorsV1U1.sol"; import {ServiceAgreementErrorsV2} from "./errors/ServiceAgreementErrorsV2.sol"; -import {NULL} from "../v1/constants/ShardingTableConstants.sol"; contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { event CommitSubmitted( - address indexed assetContract, - uint256 indexed tokenId, + address assetContract, + uint256 tokenId, bytes keyword, uint8 hashFunctionId, uint16 epoch, uint256 stateIndex, - uint72 indexed identityId, + uint72 identityId, uint40 score ); event StateFinalized( - address indexed assetContract, - uint256 indexed tokenId, + address assetContract, + uint256 tokenId, bytes keyword, uint8 hashFunctionId, uint16 epoch, @@ -61,10 +55,8 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { bool[6] public reqs = [false, false, false, false, false, false]; - HashingProxy public hashingProxy; Log2PLDSF public log2pldsf; LinearSum public linearSum; - StakingV2 public stakingContract; ContentAssetStorageV2 public contentAssetStorage; IdentityStorageV2 public identityStorage; ParametersStorage public parametersStorage; @@ -78,16 +70,8 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { constructor(address hubAddress) ContractStatus(hubAddress) {} function initialize() public onlyHubOwner { - hashingProxy = HashingProxy(hub.getContractAddress("HashingProxy")); - log2pldsf = Log2PLDSF( - ProximityScoringProxy(hub.getContractAddress("ScoringProxy")).getScoreFunctionContractAddress(_LOG2PLDSF_ID) - ); - linearSum = LinearSum( - ProximityScoringProxy(hub.getContractAddress("ScoringProxy")).getScoreFunctionContractAddress( - _LINEAR_SUM_ID - ) - ); - stakingContract = StakingV2(hub.getContractAddress("Staking")); + log2pldsf = Log2PLDSF(hub.getContractAddress("Log2PLDSF")); + linearSum = LinearSum(hub.getContractAddress("LinearSum")); contentAssetStorage = ContentAssetStorageV2(hub.getAssetStorageAddress("ContentAssetStorage")); identityStorage = IdentityStorageV2(hub.getContractAddress("IdentityStorage")); parametersStorage = ParametersStorage(hub.getContractAddress("ParametersStorage")); @@ -209,10 +193,7 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy; Log2PLDSF l2p = log2pldsf; - bytes32 agreementId = hashingProxy.callHashFunction( - args.hashFunctionId, - abi.encodePacked(args.assetContract, args.tokenId, args.keyword) - ); + bytes32 agreementId = sha256(abi.encodePacked(args.assetContract, args.tokenId, args.keyword)); if (sasProxy.agreementV1Exists(agreementId) || !sasProxy.agreementV1U1Exists(agreementId)) revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId); @@ -229,7 +210,6 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { if (!reqs[0] && !isCommitWindowOpen(agreementId, args.epoch)) { uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId); - uint256 actualCommitWindowStart = (sasProxy.getAgreementStartTime(agreementId) + args.epoch * epochLength); revert ServiceAgreementErrorsV1U1.CommitWindowClosed( @@ -278,10 +258,7 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy; LinearSum ls = linearSum; - bytes32 agreementId = hashingProxy.callHashFunction( - args.hashFunctionId, - abi.encodePacked(args.assetContract, args.tokenId, args.keyword) - ); + bytes32 agreementId = sha256(abi.encodePacked(args.assetContract, args.tokenId, args.keyword)); if (sasProxy.agreementV1Exists(agreementId) || !sasProxy.agreementV1U1Exists(agreementId)) revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId); @@ -298,7 +275,6 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { if (!reqs[0] && !isCommitWindowOpen(agreementId, args.epoch)) { uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId); - uint256 actualCommitWindowStart = (sasProxy.getAgreementStartTime(agreementId) + args.epoch * epochLength); revert ServiceAgreementErrorsV1U1.CommitWindowClosed( @@ -335,7 +311,7 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { ); uint40 score = ls.calculateScore( - ls.calculateDistance(args.hashFunctionId, args.keyword, profileStorage.getNodeId(identityId)), + ls.calculateDistance(args.hashFunctionId, profileStorage.getNodeId(identityId), args.keyword), maxDistance, nodesCount, stakingStorage.totalStakes(identityId) @@ -367,10 +343,7 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { if (uss.getUnfinalizedState(args.tokenId) == bytes32(0)) revert ServiceAgreementErrorsV1U1.NoPendingUpdate(args.assetContract, args.tokenId); - bytes32 agreementId = hashingProxy.callHashFunction( - args.hashFunctionId, - abi.encodePacked(args.assetContract, args.tokenId, args.keyword) - ); + bytes32 agreementId = sha256(abi.encodePacked(args.assetContract, args.tokenId, args.keyword)); if (!sasProxy.agreementV1U1Exists(agreementId)) revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId); @@ -472,10 +445,7 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { if (uss.getUnfinalizedState(args.tokenId) == bytes32(0)) revert ServiceAgreementErrorsV1U1.NoPendingUpdate(args.assetContract, args.tokenId); - bytes32 agreementId = hashingProxy.callHashFunction( - args.hashFunctionId, - abi.encodePacked(args.assetContract, args.tokenId, args.keyword) - ); + bytes32 agreementId = sha256(abi.encodePacked(args.assetContract, args.tokenId, args.keyword)); if (!sasProxy.agreementV1U1Exists(agreementId)) revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId); @@ -624,9 +594,9 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { (uint256 leftEdgeDistance, uint256 closestDistance, uint256 rightEdgeDistance) = linearSum .calculateNeighborhoodBoundaryDistances( hashFunctionId, - ps.getNodeId(leftEdgeNode.identityId), - ps.getNodeId(closestNode.identityId), - ps.getNodeId(rightEdgeNode.identityId), + leftEdgeNode.nodeId, + closestNode.nodeId, + rightEdgeNode.nodeId, keyword ); @@ -656,40 +626,40 @@ contract CommitManagerV2U1 is Named, Versioned, ContractStatus, Initializable { // Verify that closestNode is indeed closest if ( - closestDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestPrevIdentityId)) || - closestDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestNextIdentityId)) + closestDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(closestPrevIdentityId), keyword) || + closestDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(closestNextIdentityId), keyword) ) revert CommitManagerErrorsV2.InvalidClosestNode( agreementId, epoch, closestNodeIndex, closestDistance, - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestPrevIdentityId)), - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(closestNextIdentityId)), + ls.calculateDistance(hashFunctionId, ps.getNodeId(closestPrevIdentityId), keyword), + ls.calculateDistance(hashFunctionId, ps.getNodeId(closestNextIdentityId), keyword), block.timestamp ); // Verify that leftNode is indeed the left edge of the Neighborhood - if (leftEdgeDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(rightEdgeNextIdentityId))) + if (leftEdgeDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(rightEdgeNextIdentityId), keyword)) revert CommitManagerErrorsV2.InvalidLeftEdgeNode( agreementId, epoch, leftEdgeNodeIndex, rightEdgeNodeIndex != nodesCount - 1 ? rightEdgeNodeIndex + 1 : 0, leftEdgeDistance, - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(rightEdgeNextIdentityId)), + ls.calculateDistance(hashFunctionId, ps.getNodeId(rightEdgeNextIdentityId), keyword), block.timestamp ); // Verify that rightNode is indeed the right edge of the Neighborhood - if (rightEdgeDistance > ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(leftEdgePrevIdentityId))) + if (rightEdgeDistance > ls.calculateDistance(hashFunctionId, ps.getNodeId(leftEdgePrevIdentityId), keyword)) revert CommitManagerErrorsV2.InvalidRightEdgeNode( agreementId, epoch, rightEdgeNodeIndex, leftEdgeNodeIndex != 0 ? leftEdgeNodeIndex - 1 : nodesCount - 1, rightEdgeDistance, - ls.calculateDistance(hashFunctionId, keyword, ps.getNodeId(leftEdgePrevIdentityId)), + ls.calculateDistance(hashFunctionId, ps.getNodeId(leftEdgePrevIdentityId), keyword), block.timestamp ); diff --git a/contracts/v2/ShardingTable.sol b/contracts/v2/ShardingTable.sol index 9295ad44..fa37778e 100644 --- a/contracts/v2/ShardingTable.sol +++ b/contracts/v2/ShardingTable.sol @@ -157,7 +157,7 @@ contract ShardingTableV2 is Named, Versioned, ContractStatus, Initializable { ); // Create node object + set index pointer to new identityId + increment total nodes count - sts.createNodeObject(newNodeHashRingPosition, identityId, index); + sts.createNodeObject(newNodeHashRingPosition, ps.getNodeId(identityId), identityId, index); sts.setIdentityId(index, identityId); sts.incrementNodesCount(); diff --git a/contracts/v2/scoring/LinearSum.sol b/contracts/v2/scoring/LinearSum.sol index 1a90126d..6f74785d 100644 --- a/contracts/v2/scoring/LinearSum.sol +++ b/contracts/v2/scoring/LinearSum.sol @@ -59,10 +59,10 @@ contract LinearSum is IProximityScoreFunctionsPair, Indexable, Named, HubDepende } else { uint64 proximityScore = (normalizedDistance - 1e18) * w1; uint64 stakeScore = normalizeStake(stake) * w2; - if (stakeScore > proximityScore) { + if (stakeScore <= proximityScore) { return 0; } - return uint40(proximityScore - stakeScore); + return uint40(stakeScore - proximityScore); } } diff --git a/contracts/v2/storage/ShardingTableStorage.sol b/contracts/v2/storage/ShardingTableStorage.sol index e97b53b5..ada90cdf 100644 --- a/contracts/v2/storage/ShardingTableStorage.sol +++ b/contracts/v2/storage/ShardingTableStorage.sol @@ -38,10 +38,16 @@ contract ShardingTableStorageV2 is Named, Versioned, HubDependent { nodesCount--; } - function createNodeObject(uint256 hashRingPosition, uint72 identityId, uint72 index) external onlyContracts { + function createNodeObject( + uint256 hashRingPosition, + bytes calldata nodeId, + uint72 identityId, + uint72 index + ) external onlyContracts { nodes[identityId] = ShardingTableStructsV2.Node({ hashRingPosition: hashRingPosition, index: index, + nodeId: nodeId, identityId: identityId }); } diff --git a/contracts/v2/structs/ShardingTableStructsV2.sol b/contracts/v2/structs/ShardingTableStructsV2.sol index 50802dc5..c6012f3f 100644 --- a/contracts/v2/structs/ShardingTableStructsV2.sol +++ b/contracts/v2/structs/ShardingTableStructsV2.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.16; library ShardingTableStructsV2 { struct Node { uint256 hashRingPosition; + bytes nodeId; uint72 index; uint72 identityId; } diff --git a/test/v2/unit/CommitManagerV2.test.ts b/test/v2/unit/CommitManagerV2.test.ts index 04b919bd..b668feca 100644 --- a/test/v2/unit/CommitManagerV2.test.ts +++ b/test/v2/unit/CommitManagerV2.test.ts @@ -395,9 +395,26 @@ describe('@v2 @unit CommitManagerV2 contract', function () { rightEdgeNodeIndex: rightEdgeNode.index, }; + const r2 = await ParametersStorage.r2(); + const minStake = await ParametersStorage.minimumStake(); + const maxStake = await ParametersStorage.maximumStake(); + const score = await calculateScore( + closestNode.distance, + closestNode.stake, + neighborhood[neighborhood.length - 1].distance, + r2, + nodes.length, + minStake, + maxStake, + ); + await expect( - CommitManagerV2['submitCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))'](commitV2InputArgs), - ).to.emit(CommitManagerV2, 'CommitSubmitted'); + CommitManagerV2.connect(closestNode.account)[ + 'submitCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))' + ](commitV2InputArgs), + ) + .to.emit(CommitManagerV2, 'CommitSubmitted') + .withArgs(ContentAssetStorageV2.address, tokenId, keyword, 1, 0, closestNode.identityId, score); }); it('Create new asset with scoreFunction 1, submit R0 V1 commits, expect R0 V1 commits to be returned', async () => { @@ -459,17 +476,9 @@ describe('@v2 @unit CommitManagerV2 contract', function () { rightEdgeNodeIndex: rightEdgeNode.index, }; - for (const node of neighborhood.slice(0, 3).reverse()) { - await expect( - CommitManagerV2.connect(node.account)[ - 'submitCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))' - ](commitV2InputArgs), - ).to.emit(CommitManagerV2, 'CommitSubmitted'); - } - - const topCommits = await CommitManagerV2.getTopCommitSubmissions(agreementId, 0); const scoredNeighborhood = await Promise.all( neighborhood.map(async (node) => ({ + account: node.account, identityId: node.identityId, score: ( await calculateScore( @@ -484,7 +493,22 @@ describe('@v2 @unit CommitManagerV2 contract', function () { ).toNumber(), })), ); - const expectedWinners = scoredNeighborhood.sort((a, b) => b.score - a.score).slice(0, r0); + + scoredNeighborhood.sort((a, b) => b.score - a.score); + + for (const node of [...scoredNeighborhood].reverse()) { + await expect( + CommitManagerV2.connect(node.account)[ + 'submitCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))' + ](commitV2InputArgs), + ) + .to.emit(CommitManagerV2, 'CommitSubmitted') + .withArgs(ContentAssetStorageV2.address, tokenId, keyword, 1, 0, node.identityId, node.score); + } + + const topCommits = await CommitManagerV2.getTopCommitSubmissions(agreementId, 0); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const expectedWinners = scoredNeighborhood.map(({ account, ...rest }) => rest).slice(0, r0); expect( topCommits.map((commit) => ({ identityId: commit.identityId.toNumber(), score: commit.score })),