Skip to content

Commit 607070b

Browse files
feat(dk): rng bug fix
1 parent 577d2fa commit 607070b

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,18 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence {
224224
returns (address drawnAddress)
225225
{
226226
require(phase == Phase.drawing, "Should be in drawing phase");
227+
228+
Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
229+
Round storage round = dispute.rounds[dispute.rounds.length - 1];
230+
227231
bytes32 key = bytes32(core.getSubcourtID(_coreDisputeID)); // Get the ID of the tree.
228-
uint256 drawnNumber = getRandomNumber();
232+
uint256 drawnNumber = uint256(keccak256(abi.encode(getRandomNumber(), _coreDisputeID, round.votes.length)));
229233

230234
uint256 K = core.getSortitionSumTreeK(key);
231235
uint256 nodesLength = core.getSortitionSumTreeNodesLength(key);
232236
uint256 treeIndex = 0;
233237
uint256 currentDrawnNumber = drawnNumber % core.getSortitionSumTreeNode(key, 0);
234238

235-
Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
236-
Round storage round = dispute.rounds[dispute.rounds.length - 1];
237-
238239
// TODO: Handle the situation when no one has staked yet.
239240

240241
// While it still has children

contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,25 +242,25 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence {
242242
returns (address drawnAddress)
243243
{
244244
require(phase == Phase.drawing, "Should be in drawing phase");
245-
bytes32 key = bytes32(core.getSubcourtID(_coreDisputeID)); // Get the ID of the tree.
246-
uint256 drawnNumber = getRandomNumber();
247-
248-
uint256 K = core.getSortitionSumTreeK(key);
249-
uint256 nodesLength = core.getSortitionSumTreeNodesLength(key);
250-
uint256 treeIndex = 0;
251-
uint256 currentDrawnNumber = drawnNumber % core.getSortitionSumTreeNode(key, 0);
252245

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

249+
bytes32 key = bytes32(core.getSubcourtID(_coreDisputeID)); // Get the ID of the tree.
250+
uint256 drawnNumber = uint256(keccak256(abi.encode(getRandomNumber(), _coreDisputeID, round.votes.length)));
251+
252+
(uint256 K, , uint256[] memory nodes) = core.getSortitionSumTree(key);
253+
uint256 treeIndex = 0;
254+
uint256 currentDrawnNumber = drawnNumber % nodes[0];
255+
256256
// TODO: Handle the situation when no one has staked yet.
257257

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

265265
if (currentDrawnNumber >= nodeValue) {
266266
// Go to the next child.

0 commit comments

Comments
 (0)