Skip to content

fix(DK): no empty addresses after draw #2060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
bytes32 key = bytes32(uint256(courtID)); // Get the ID of the tree.

drawnAddress = sortitionModule.draw(key, _coreDisputeID, _nonce);
if (drawnAddress == address(0)) {
// Sortition can return 0 address if no one has staked yet.
return drawnAddress;
}

if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) {
round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false}));
Expand Down
20 changes: 20 additions & 0 deletions contracts/test/foundry/KlerosCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,26 @@ contract KlerosCoreTest is Test {
}
}

function test_draw_noEmptyAddresses() public {
uint256 disputeID = 0;
uint256 roundID = 0;

vm.prank(disputer);
arbitrable.createDispute{value: feeForJuror * DEFAULT_NB_OF_JURORS}("Action");
vm.warp(block.timestamp + minStakingTime);
sortitionModule.passPhase(); // Generating
vm.roll(block.number + rngLookahead + 1);
sortitionModule.passPhase(); // Drawing phase

core.draw(disputeID, DEFAULT_NB_OF_JURORS); // No one is staked so check that the empty addresses are not drawn.

KlerosCoreBase.Round memory round = core.getRoundInfo(disputeID, roundID);
assertEq(round.drawIterations, 3, "Wrong drawIterations number");

(, , , , uint256 nbVoters, ) = disputeKit.getRoundInfo(disputeID, roundID, 0);
assertEq(nbVoters, 0, "nbVoters should be 0");
}

function test_draw_parentCourts() public {
uint96 newCourtID = 2;
uint256 disputeID = 0;
Expand Down
Loading