Skip to content

Commit 59ca8e1

Browse files
fix: update storage layout
1 parent 36a2455 commit 59ca8e1

File tree

5 files changed

+44
-87
lines changed

5 files changed

+44
-87
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
4141
mapping(address account => mapping(uint256 choiceId => uint256)) contributions; // Maps contributors to their contributions for each choice.
4242
uint256 feeRewards; // Sum of reimbursable appeal fees available to the parties that made contributions to the ruling that ultimately wins a dispute.
4343
uint256[] fundedChoices; // Stores the choices that are fully funded.
44-
uint256 nbVotes; // Maximal number of votes this dispute can get.
44+
mapping(address drawnAddress => bool) alreadyDrawn; // True if the address has already been drawn, false by default.
4545
}
4646

4747
struct Vote {
@@ -64,12 +64,11 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
6464
Dispute[] public disputes; // Array of the locally created disputes.
6565
mapping(uint256 => uint256) public coreDisputeIDToLocal; // Maps the dispute ID in Kleros Core to the local dispute ID.
6666
bool public singleDrawPerJuror; // Whether each juror can only draw once per dispute, false by default.
67-
mapping(uint256 localDisputeID => mapping(uint256 localRoundID => mapping(address drawnAddress => bool)))
68-
public alreadyDrawn; // True if the address has already been drawn, false by default. To be added to the Round struct when fully redeploying rather than upgrading.
6967
mapping(uint256 coreDisputeID => bool) public coreDisputeIDToActive; // True if this dispute kit is active for this core dispute ID.
7068
address public wNative; // The wrapped native token for safeSend().
7169
uint256 public jumpDisputeKitID; // The ID of the dispute kit in Kleros Core disputeKits array that the dispute should switch to after the court jump, in case the new court doesn't support this dispute kit.
7270

71+
uint256[50] private __gap; // Reserved slots for future upgrades.
7372
// ************************************* //
7473
// * Events * //
7574
// ************************************* //
@@ -201,12 +200,11 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
201200
/// @param _coreDisputeID The ID of the dispute in Kleros Core.
202201
/// @param _numberOfChoices Number of choices of the dispute
203202
/// @param _extraData Additional info about the dispute, for possible use in future dispute kits.
204-
/// @param _nbVotes Number of votes for this dispute.
205203
function createDispute(
206204
uint256 _coreDisputeID,
207205
uint256 _numberOfChoices,
208206
bytes calldata _extraData,
209-
uint256 _nbVotes
207+
uint256 /*_nbVotes*/
210208
) external override onlyByCore {
211209
uint256 localDisputeID = disputes.length;
212210
Dispute storage dispute = disputes.push();
@@ -218,7 +216,6 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
218216
dispute.coreRoundIDToLocal[core.getNumberOfRounds(_coreDisputeID) - 1] = dispute.rounds.length;
219217

220218
Round storage round = dispute.rounds.push();
221-
round.nbVotes = _nbVotes;
222219
round.tied = true;
223220

224221
coreDisputeIDToLocal[_coreDisputeID] = localDisputeID;
@@ -250,7 +247,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
250247

251248
if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) {
252249
round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false}));
253-
alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true;
250+
round.alreadyDrawn[drawnAddress] = true;
254251
} else {
255252
drawnAddress = address(0);
256253
}
@@ -422,7 +419,6 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
422419
dispute.coreRoundIDToLocal[coreRoundID + 1] = dispute.rounds.length;
423420

424421
Round storage newRound = dispute.rounds.push();
425-
newRound.nbVotes = core.getNumberOfVotes(_coreDisputeID);
426422
newRound.tied = true;
427423
}
428424
core.appeal{value: appealCost}(_coreDisputeID, dispute.numberOfChoices, dispute.extraData);
@@ -768,8 +764,8 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
768764
if (singleDrawPerJuror) {
769765
uint256 localDisputeID = coreDisputeIDToLocal[_coreDisputeID];
770766
Dispute storage dispute = disputes[localDisputeID];
771-
uint256 localRoundID = dispute.rounds.length - 1;
772-
result = !alreadyDrawn[localDisputeID][localRoundID][_juror];
767+
Round storage round = dispute.rounds[dispute.rounds.length - 1];
768+
result = !round.alreadyDrawn[_juror];
773769
} else {
774770
result = true;
775771
}

contracts/src/arbitration/interfaces/IDisputeKit.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface IDisputeKit {
3535
/// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
3636
/// @param _numberOfChoices Number of choices of the dispute
3737
/// @param _extraData Additional info about the dispute, for possible use in future dispute kits.
38-
/// @param _nbVotes Maximal number of votes this dispute can get. DEPRECATED as we don't need to pass it now. KC handles the count.
38+
/// @param _nbVotes Maximal number of votes this dispute can get. Added for future-proofing.
3939
function createDispute(
4040
uint256 _coreDisputeID,
4141
uint256 _numberOfChoices,

contracts/test/arbitration/staking-neo.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ describe("Staking", async () => {
469469
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
470470
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
471471
await pnk.approve(core.target, PNK(1000));
472-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
473472
await expect(core.setStake(2, PNK(3000)))
474473
.to.emit(sortition, "StakeDelayed")
475474
.withArgs(deployer, 2, PNK(3000));
@@ -481,10 +480,9 @@ describe("Staking", async () => {
481480
});
482481

483482
it("Should store the delayed stake for later", async () => {
484-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
485483
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
486484
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
487-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000), false]);
485+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000)]);
488486
});
489487
});
490488

@@ -507,9 +505,8 @@ describe("Staking", async () => {
507505
]); // stake unchanged, delayed
508506
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
509507
expect(await sortition.delayedStakeReadIndex()).to.be.equal(2);
510-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
511-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
512-
expect(await sortition.latestDelayedStakeIndex(deployer, 1)).to.be.equal(0); // Deprecated. Always 0
508+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
509+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
513510
});
514511

515512
it("Should transfer PNK after delayed stake execution", async () => {
@@ -535,7 +532,6 @@ describe("Staking", async () => {
535532
it("Should delay the stake decrease", async () => {
536533
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
537534
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
538-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
539535
await expect(core.setStake(2, PNK(1000)))
540536
.to.emit(sortition, "StakeDelayed")
541537
.withArgs(deployer, 2, PNK(1000));
@@ -547,10 +543,9 @@ describe("Staking", async () => {
547543
});
548544

549545
it("Should store the delayed stake for later", async () => {
550-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
551546
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
552547
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
553-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000), false]);
548+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000)]);
554549
});
555550
});
556551

@@ -572,9 +567,8 @@ describe("Staking", async () => {
572567
]); // stake unchanged, delayed
573568
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
574569
expect(await sortition.delayedStakeReadIndex()).to.be.equal(2);
575-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
576-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
577-
expect(await sortition.latestDelayedStakeIndex(deployer, 1)).to.be.equal(0); // Deprecated. Always 0
570+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
571+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
578572
});
579573

580574
it("Should withdraw some PNK", async () => {
@@ -600,7 +594,6 @@ describe("Staking", async () => {
600594
it("Should delay the stake decrease", async () => {
601595
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
602596
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
603-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
604597
await expect(core.setStake(2, PNK(1000)))
605598
.to.emit(sortition, "StakeDelayed")
606599
.withArgs(deployer, 2, PNK(1000));
@@ -612,17 +605,15 @@ describe("Staking", async () => {
612605
});
613606

614607
it("Should store the delayed stake for later", async () => {
615-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
616608
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
617609
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
618-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000), false]);
610+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000)]);
619611
});
620612
});
621613

622614
describe("When stake is increased back to the previous amount", () => {
623615
it("Should delay the stake increase", async () => {
624616
balanceBefore = await pnk.balanceOf(deployer);
625-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
626617
await expect(core.setStake(2, PNK(2000)))
627618
.to.emit(sortition, "StakeDelayed")
628619
.withArgs(deployer, 2, PNK(2000));
@@ -634,11 +625,10 @@ describe("Staking", async () => {
634625
});
635626

636627
it("Should store the delayed stake for later", async () => {
637-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
638628
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
639629
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
640-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000), false]);
641-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000), false]);
630+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000)]);
631+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000)]);
642632
});
643633
});
644634

@@ -663,9 +653,8 @@ describe("Staking", async () => {
663653
]); // stake unchanged, delayed
664654
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
665655
expect(await sortition.delayedStakeReadIndex()).to.be.equal(3);
666-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
667-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
668-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
656+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
657+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
669658
});
670659

671660
it("Should not transfer any PNK", async () => {
@@ -692,7 +681,6 @@ describe("Staking", async () => {
692681
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
693682
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
694683
await pnk.approve(core.target, PNK(1000));
695-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
696684
await expect(core.setStake(2, PNK(3000)))
697685
.to.emit(sortition, "StakeDelayed")
698686
.withArgs(deployer, 2, PNK(3000));
@@ -704,17 +692,15 @@ describe("Staking", async () => {
704692
});
705693

706694
it("Should store the delayed stake for later", async () => {
707-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
708695
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
709696
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
710-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000), false]);
697+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000)]);
711698
});
712699
});
713700

714701
describe("When stake is decreased back to the previous amount", () => {
715702
it("Should cancel out the stake decrease back", async () => {
716703
balanceBefore = await pnk.balanceOf(deployer);
717-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
718704
await expect(core.setStake(2, PNK(2000)))
719705
.to.emit(sortition, "StakeDelayed")
720706
.withArgs(deployer, 2, PNK(2000));
@@ -726,11 +712,10 @@ describe("Staking", async () => {
726712
});
727713

728714
it("Should store the delayed stake for later", async () => {
729-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
730715
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
731716
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
732-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000), false]);
733-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000), false]);
717+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000)]);
718+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000)]);
734719
});
735720
});
736721

@@ -753,9 +738,8 @@ describe("Staking", async () => {
753738
]); // stake unchanged, delayed
754739
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
755740
expect(await sortition.delayedStakeReadIndex()).to.be.equal(3);
756-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
757-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
758-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
741+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
742+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
759743
});
760744

761745
it("Should not transfer any PNK", async () => {

0 commit comments

Comments
 (0)