Skip to content

Commit d03b214

Browse files
committed
refactor(contracts): use SafeCast
1 parent 7fe2905 commit d03b214

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

contracts/src/libs/MerkleTree.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity ^0.8.30;
33

44
import {Arrays} from "@openzeppelin-contracts-5.7.0/utils/Arrays.sol";
55
import {Math} from "@openzeppelin-contracts-5.7.0/utils/math/Math.sol";
6+
import {SafeCast} from "@openzeppelin-contracts-5.7.0/utils/math/SafeCast.sol";
67

78
import {SHA256} from "../libs/SHA256.sol";
89

@@ -13,6 +14,8 @@ import {SHA256} from "../libs/SHA256.sol";
1314
/// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.4.0/contracts/utils/structs/MerkleTree.sol).
1415
/// @custom:security-contact security@anoma.foundation
1516
library MerkleTree {
17+
using SafeCast for uint256;
18+
1619
struct Tree {
1720
uint256 _nextLeafIndex;
1821
bytes32[] _sides;
@@ -158,8 +161,6 @@ library MerkleTree {
158161
/// @param leavesCount The number of leaves.
159162
/// @return treeDepth The minimal required tree depth.
160163
function computeMinimalTreeDepth(uint256 leavesCount) internal pure returns (uint8 treeDepth) {
161-
// `leavesCount` is a memory array length, so its base-2 logarithm fits in a byte.
162-
// forge-lint: disable-next-line(unsafe-typecast)
163-
treeDepth = uint8(Math.log2({value: leavesCount, rounding: Math.Rounding.Ceil}));
164+
treeDepth = Math.log2({value: leavesCount, rounding: Math.Rounding.Ceil}).toUint8();
164165
}
165166
}

0 commit comments

Comments
 (0)