Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions contracts/src/arbitration/KlerosCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ contract KlerosCore is IArbitrator {
// * Public Views for Dispute Kits * //
// ************************************* //

function getSortitionSumTreeK(bytes32 _key) public view returns (uint256) {
return sortitionSumTrees.sortitionSumTrees[_key].K;
}

function getSortitionSumTreeNode(bytes32 _key, uint256 _index) public view returns (uint256) {
return sortitionSumTrees.sortitionSumTrees[_key].nodes[_index];
}

function getSortitionSumTreeNodesLength(bytes32 _key) public view returns (uint256) {
return sortitionSumTrees.sortitionSumTrees[_key].nodes.length;
}

function getSortitionSumTree(bytes32 _key)
public
view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,22 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence {
bytes32 key = bytes32(core.getSubcourtID(_coreDisputeID)); // Get the ID of the tree.
uint256 drawnNumber = getRandomNumber();

(uint256 K, , uint256[] memory nodes) = core.getSortitionSumTree(key);
uint256 K = core.getSortitionSumTreeK(key);
uint256 nodesLength = core.getSortitionSumTreeNodesLength(key);
uint256 treeIndex = 0;
uint256 currentDrawnNumber = drawnNumber % nodes[0];
uint256 currentDrawnNumber = drawnNumber % core.getSortitionSumTreeNode(key, 0);

Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
Round storage round = dispute.rounds[dispute.rounds.length - 1];

// TODO: Handle the situation when no one has staked yet.

// While it still has children
while ((K * treeIndex) + 1 < nodes.length) {
while ((K * treeIndex) + 1 < nodesLength) {
for (uint256 i = 1; i <= K; i++) {
// Loop over children.
uint256 nodeIndex = (K * treeIndex) + i;
uint256 nodeValue = nodes[nodeIndex];
uint256 nodeValue = core.getSortitionSumTreeNode(key, nodeIndex);

if (currentDrawnNumber >= nodeValue) {
// Go to the next child.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,22 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence {
bytes32 key = bytes32(core.getSubcourtID(_coreDisputeID)); // Get the ID of the tree.
uint256 drawnNumber = getRandomNumber();

(uint256 K, , uint256[] memory nodes) = core.getSortitionSumTree(key);
uint256 K = core.getSortitionSumTreeK(key);
uint256 nodesLength = core.getSortitionSumTreeNodesLength(key);
uint256 treeIndex = 0;
uint256 currentDrawnNumber = drawnNumber % nodes[0];
uint256 currentDrawnNumber = drawnNumber % core.getSortitionSumTreeNode(key, 0);

Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
Round storage round = dispute.rounds[dispute.rounds.length - 1];

// TODO: Handle the situation when no one has staked yet.

// While it still has children
while ((K * treeIndex) + 1 < nodes.length) {
while ((K * treeIndex) + 1 < nodesLength) {
for (uint256 i = 1; i <= K; i++) {
// Loop over children.
uint256 nodeIndex = (K * treeIndex) + i;
uint256 nodeValue = nodes[nodeIndex];
uint256 nodeValue = core.getSortitionSumTreeNode(key, nodeIndex);

if (currentDrawnNumber >= nodeValue) {
// Go to the next child.
Expand Down