Skip to content

Commit 05c3f28

Browse files
authored
Merge pull request #2060 from kleros/fix/draw-empty-address-bug
fix(DK): no empty addresses after draw
2 parents e9ed4ba + f080264 commit 05c3f28

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
229229
bytes32 key = bytes32(uint256(courtID)); // Get the ID of the tree.
230230

231231
drawnAddress = sortitionModule.draw(key, _coreDisputeID, _nonce);
232+
if (drawnAddress == address(0)) {
233+
// Sortition can return 0 address if no one has staked yet.
234+
return drawnAddress;
235+
}
232236

233237
if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) {
234238
round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false}));

contracts/test/foundry/KlerosCore.t.sol

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,26 @@ contract KlerosCoreTest is Test {
14471447
}
14481448
}
14491449

1450+
function test_draw_noEmptyAddresses() public {
1451+
uint256 disputeID = 0;
1452+
uint256 roundID = 0;
1453+
1454+
vm.prank(disputer);
1455+
arbitrable.createDispute{value: feeForJuror * DEFAULT_NB_OF_JURORS}("Action");
1456+
vm.warp(block.timestamp + minStakingTime);
1457+
sortitionModule.passPhase(); // Generating
1458+
vm.roll(block.number + rngLookahead + 1);
1459+
sortitionModule.passPhase(); // Drawing phase
1460+
1461+
core.draw(disputeID, DEFAULT_NB_OF_JURORS); // No one is staked so check that the empty addresses are not drawn.
1462+
1463+
KlerosCoreBase.Round memory round = core.getRoundInfo(disputeID, roundID);
1464+
assertEq(round.drawIterations, 3, "Wrong drawIterations number");
1465+
1466+
(, , , , uint256 nbVoters, ) = disputeKit.getRoundInfo(disputeID, roundID, 0);
1467+
assertEq(nbVoters, 0, "nbVoters should be 0");
1468+
}
1469+
14501470
function test_draw_parentCourts() public {
14511471
uint96 newCourtID = 2;
14521472
uint256 disputeID = 0;

0 commit comments

Comments
 (0)