Skip to content

Commit b714c12

Browse files
committed
fix: accounting of round.drawIterations
1 parent 7d90db7 commit b714c12

File tree

4 files changed

+21
-45
lines changed

4 files changed

+21
-45
lines changed

contracts/src/arbitration/KlerosCore.sol

+7-36
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,10 @@ contract KlerosCore is IArbitratorV2 {
610610

611611
IDisputeKit disputeKit = disputeKitNodes[round.disputeKitID].disputeKit;
612612

613-
uint256 startIndex = round.drawIterations;
614-
for (uint256 i = startIndex; i < startIndex + _iterations && round.drawnJurors.length < round.nbVotes; i++) {
615-
address drawnAddress = disputeKit.draw(_disputeID, i);
613+
uint256 startIndex = round.drawIterations; // for gas: less storage reads
614+
uint256 i;
615+
while (i < _iterations && round.drawnJurors.length < round.nbVotes) {
616+
address drawnAddress = disputeKit.draw(_disputeID, startIndex + i++);
616617
if (drawnAddress == address(0)) {
617618
continue;
618619
}
@@ -623,7 +624,7 @@ contract KlerosCore is IArbitratorV2 {
623624
sortitionModule.postDrawHook(_disputeID, currentRound);
624625
}
625626
}
626-
round.drawIterations += _iterations;
627+
round.drawIterations += i;
627628
}
628629

629630
/// @dev Appeals the ruling of a specified dispute.
@@ -972,38 +973,8 @@ contract KlerosCore is IArbitratorV2 {
972973
(ruling, tied, overridden) = disputeKit.currentRuling(_disputeID);
973974
}
974975

975-
function getRoundInfo(
976-
uint256 _disputeID,
977-
uint256 _round
978-
)
979-
external
980-
view
981-
returns (
982-
uint256 disputeKitID,
983-
uint256 pnkAtStakePerJuror,
984-
uint256 totalFeesForJurors,
985-
uint256 nbVotes,
986-
uint256 repartitions,
987-
uint256 pnkPenalties,
988-
address[] memory drawnJurors,
989-
uint256 sumFeeRewardPaid,
990-
uint256 sumPnkRewardPaid,
991-
IERC20 feeToken
992-
)
993-
{
994-
Round storage round = disputes[_disputeID].rounds[_round];
995-
return (
996-
round.disputeKitID,
997-
round.pnkAtStakePerJuror,
998-
round.totalFeesForJurors,
999-
round.nbVotes,
1000-
round.repartitions,
1001-
round.pnkPenalties,
1002-
round.drawnJurors,
1003-
round.sumFeeRewardPaid,
1004-
round.sumPnkRewardPaid,
1005-
round.feeToken
1006-
);
976+
function getRoundInfo(uint256 _disputeID, uint256 _round) external view returns (Round memory) {
977+
return disputes[_disputeID].rounds[_round];
1007978
}
1008979

1009980
function getNumberOfRounds(uint256 _disputeID) external view returns (uint256) {

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,9 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence {
562562
/// @inheritdoc BaseDisputeKit
563563
function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) {
564564
(uint96 courtID, , , , ) = core.disputes(_coreDisputeID);
565-
(, uint256 lockedAmountPerJuror, , , , , , , , ) = core.getRoundInfo(
566-
_coreDisputeID,
567-
core.getNumberOfRounds(_coreDisputeID) - 1
568-
);
565+
uint256 lockedAmountPerJuror = core
566+
.getRoundInfo(_coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1)
567+
.pnkAtStakePerJuror;
569568
(uint256 totalStaked, uint256 totalLocked, , ) = core.getJurorBalance(_juror, courtID);
570569
return totalStaked >= totalLocked + lockedAmountPerJuror;
571570
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,9 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence {
585585
/// @return Whether the address can be drawn or not.
586586
function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) {
587587
(uint96 courtID, , , , ) = core.disputes(_coreDisputeID);
588-
(, uint256 lockedAmountPerJuror, , , , , , , , ) = core.getRoundInfo(
589-
_coreDisputeID,
590-
core.getNumberOfRounds(_coreDisputeID) - 1
591-
);
588+
uint256 lockedAmountPerJuror = core
589+
.getRoundInfo(_coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1)
590+
.pnkAtStakePerJuror;
592591
(uint256 totalStaked, uint256 totalLocked, , ) = core.getJurorBalance(_juror, courtID);
593592
if (totalStaked < totalLocked + lockedAmountPerJuror) {
594593
return false;

contracts/test/arbitration/draw.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ describe("Draw Benchmark", async () => {
203203
};
204204
let countedDraws: CountedDraws;
205205
const expectFromDraw = async (drawTx: Promise<ContractTransaction>) => {
206+
expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);
207+
206208
const tx = await (await drawTx).wait();
207209
expect(tx)
208210
.to.emit(core, "Draw")
@@ -261,7 +263,8 @@ describe("Draw Benchmark", async () => {
261263
};
262264

263265
const expectFromDraw = async (drawTx: Promise<ContractTransaction>) => {
264-
await expect(drawTx).to.not.emit(core, "Draw");
266+
expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(20);
267+
expect(await drawTx).to.not.emit(core, "Draw");
265268
};
266269

267270
const unstake = async (wallet: Wallet) => {
@@ -295,6 +298,8 @@ describe("Draw Benchmark", async () => {
295298
};
296299
let countedDraws: CountedDraws;
297300
const expectFromDraw = async (drawTx: Promise<ContractTransaction>) => {
301+
expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);
302+
298303
const tx = await (await drawTx).wait();
299304
expect(tx)
300305
.to.emit(core, "Draw")
@@ -353,6 +358,8 @@ describe("Draw Benchmark", async () => {
353358
};
354359
let countedDraws: CountedDraws;
355360
const expectFromDraw = async (drawTx: Promise<ContractTransaction>) => {
361+
expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);
362+
356363
const tx = await (await drawTx).wait();
357364
expect(tx)
358365
.to.emit(core, "Draw")

0 commit comments

Comments
 (0)