From 259ecd5fc4c77d53915d8cc6395c100541ce6cd2 Mon Sep 17 00:00:00 2001 From: unknownunknown1 Date: Wed, 30 Jul 2025 19:20:56 +1000 Subject: [PATCH 1/2] fix(DK): no empty addresses after draw --- .../dispute-kits/DisputeKitClassicBase.sol | 13 +++++++----- contracts/test/foundry/KlerosCore.t.sol | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol b/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol index 5c2485a8c..7cab6ee35 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol @@ -230,11 +230,14 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi drawnAddress = sortitionModule.draw(key, _coreDisputeID, _nonce); - if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) { - round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false})); - alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true; - } else { - drawnAddress = address(0); + if (drawnAddress != address(0)) { + // Sortition can return 0 address if no one has staked yet. + if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) { + round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false})); + alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true; + } else { + drawnAddress = address(0); + } } } diff --git a/contracts/test/foundry/KlerosCore.t.sol b/contracts/test/foundry/KlerosCore.t.sol index e1f452da4..e91da1dad 100644 --- a/contracts/test/foundry/KlerosCore.t.sol +++ b/contracts/test/foundry/KlerosCore.t.sol @@ -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; From f0802642704b029923b535637f9476f39cadb22c Mon Sep 17 00:00:00 2001 From: jaybuidl Date: Fri, 1 Aug 2025 13:32:57 +0100 Subject: [PATCH 2/2] chore: minor tweak --- .../dispute-kits/DisputeKitClassicBase.sol | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol b/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol index 7cab6ee35..d0e7ddb95 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol @@ -229,15 +229,16 @@ 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)) { + if (drawnAddress == address(0)) { // Sortition can return 0 address if no one has staked yet. - if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) { - round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false})); - alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true; - } else { - drawnAddress = address(0); - } + return drawnAddress; + } + + if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) { + round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false})); + alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true; + } else { + drawnAddress = address(0); } }