Skip to content

Commit 259ecd5

Browse files
fix(DK): no empty addresses after draw
1 parent e9ed4ba commit 259ecd5

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,14 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
230230

231231
drawnAddress = sortitionModule.draw(key, _coreDisputeID, _nonce);
232232

233-
if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) {
234-
round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false}));
235-
alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true;
236-
} else {
237-
drawnAddress = address(0);
233+
if (drawnAddress != address(0)) {
234+
// Sortition can return 0 address if no one has staked yet.
235+
if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) {
236+
round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false}));
237+
alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true;
238+
} else {
239+
drawnAddress = address(0);
240+
}
238241
}
239242
}
240243

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)