Skip to content

Commit e43b335

Browse files
committed
chore: changelog, natspec decorators
1 parent 9d15604 commit e43b335

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

contracts/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The format is based on [Common Changelog](https://common-changelog.org/).
1616
- Make the primary VRF-based RNG fall back to `BlockhashRNG` if the VRF request is not fulfilled within a timeout ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
1717
- Authenticate the calls to the RNGs to prevent 3rd parties from depleting the Chainlink VRF subscription funds ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
1818
- Use `block.timestamp` rather than `block.number` for `BlockhashRNG` for better reliability on Arbitrum as block production is sporadic depending on network conditions. ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
19+
- Replace the `bytes32 _key` parameter in `SortitionTrees.createTree()` and `SortitionTrees.draw()` by `uint96 courtID` ([#2113](https://github.com/kleros/kleros-v2/issues/2113))
20+
- Extract the sortition sum trees logic into a library `SortitionTrees` ([#2113](https://github.com/kleros/kleros-v2/issues/2113))
1921
- Set the Hardhat Solidity version to v0.8.30 and enable the IR pipeline ([#2069](https://github.com/kleros/kleros-v2/issues/2069))
2022
- Set the Foundry Solidity version to v0.8.30 and enable the IR pipeline ([#2073](https://github.com/kleros/kleros-v2/issues/2073))
2123
- Widen the allowed solc version to any v0.8.x for the interfaces only ([#2083](https://github.com/kleros/kleros-v2/issues/2083))

contracts/src/libraries/SortitionTrees.sol

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ pragma solidity ^0.8.24;
55
type TreeKey is bytes32;
66
type CourtID is uint96;
77

8-
using {toTreeKey} for CourtID global;
9-
10-
function toTreeKey(CourtID _courtID) pure returns (TreeKey) {
11-
return TreeKey.wrap(bytes32(uint256(CourtID.unwrap(_courtID))));
12-
}
8+
using {SortitionTrees.toTreeKey} for CourtID global;
139

1410
library SortitionTrees {
11+
// ************************************* //
12+
// * Enums / Structs * //
13+
// ************************************* //
14+
1515
struct Tree {
1616
uint256 K; // The maximum number of children per node.
1717
uint256[] stack; // We use this to keep track of vacant positions in the tree after removing a leaf. This is for keeping the tree as balanced as possible without spending gas on moving nodes around.
@@ -21,6 +21,14 @@ library SortitionTrees {
2121
mapping(uint256 nodeIndex => bytes32 stakePathID) nodeIndexesToIDs;
2222
}
2323

24+
function toTreeKey(CourtID _courtID) internal pure returns (TreeKey) {
25+
return TreeKey.wrap(bytes32(uint256(CourtID.unwrap(_courtID))));
26+
}
27+
28+
// ************************************* //
29+
// * State Modifiers * //
30+
// ************************************* //
31+
2432
/// @dev Create a sortition sum tree at the specified key.
2533
/// @param _trees The mapping of sortition sum trees.
2634
/// @param _key The key of the new tree.
@@ -174,6 +182,10 @@ library SortitionTrees {
174182
}
175183
}
176184

185+
// ************************************* //
186+
// * Public Views * //
187+
// ************************************* //
188+
177189
/// @dev Get the stake of a juror in a court.
178190
/// @param _tree The sortition sum tree.
179191
/// @param _stakePathID The stake path ID, corresponding to a juror.
@@ -247,6 +259,10 @@ library SortitionTrees {
247259
}
248260
}
249261

262+
// ************************************* //
263+
// * Errors * //
264+
// ************************************* //
265+
250266
error TreeAlreadyExists();
251267
error KMustBeGreaterThanOne();
252268
}

0 commit comments

Comments
 (0)