Skip to content

Commit 1863aef

Browse files
authored
Merge pull request #54 from lidofinance/fix/distributor-root
weakening the check
2 parents c4c4bae + c108ec3 commit 1863aef

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/Distributor.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ contract Distributor is AccessControlEnumerable {
8585
*/
8686
function setMerkleRoot(bytes32 _root, string calldata _cid) external {
8787
_checkRole(MANAGER_ROLE, msg.sender);
88-
if (_root == root || keccak256(bytes(_cid)) == keccak256(bytes(cid))) revert AlreadyProcessed();
88+
if (_root == root && keccak256(bytes(_cid)) == keccak256(bytes(cid))) revert AlreadyProcessed();
8989

9090
emit MerkleRootUpdated(root, _root, cid, _cid, lastProcessedBlock, block.number);
9191

test/unit/distributor/MerkleRoot.test.sol

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,33 @@ contract MerkleRootTest is Test, SetupDistributor {
2626
distributor.setMerkleRoot(newRoot, newCid);
2727
}
2828

29-
function test_SetMerkleRoot_RevertsOnSameRoot() public {
30-
bytes32 newRoot = keccak256("testRoot");
31-
string memory cid1 = "QmTestCID1";
32-
33-
vm.prank(manager);
34-
distributor.setMerkleRoot(newRoot, cid1);
29+
function test_SetMerkleRoot_RevertsWhenNoChanges() public {
30+
bytes32 initialRoot = keccak256("root");
31+
string memory initialCid = "QmCID";
3532

36-
// Try to set the same root with different CID
37-
string memory cid2 = "QmTestCID2";
33+
vm.startPrank(manager);
34+
distributor.setMerkleRoot(initialRoot, initialCid);
3835

39-
vm.prank(manager);
4036
vm.expectRevert(Distributor.AlreadyProcessed.selector);
41-
distributor.setMerkleRoot(newRoot, cid2);
37+
distributor.setMerkleRoot(initialRoot, initialCid);
38+
vm.stopPrank();
4239
}
4340

44-
function test_SetMerkleRoot_RevertsOnSameCid() public {
41+
function test_SetMerkleRoot_AllowsPartialUpdates() public {
4542
bytes32 root1 = keccak256("root1");
46-
string memory sameCid = "QmTestCID";
43+
bytes32 root2 = keccak256("root2");
44+
string memory cid1 = "QmCid1";
45+
string memory cid2 = "QmCid2";
4746

48-
vm.prank(manager);
49-
distributor.setMerkleRoot(root1, sameCid);
47+
vm.startPrank(manager);
48+
distributor.setMerkleRoot(root1, cid1);
5049

51-
// Try to set different root with same CID
52-
bytes32 root2 = keccak256("root2");
50+
// Same root, new cid
51+
distributor.setMerkleRoot(root1, cid2);
5352

54-
vm.prank(manager);
55-
vm.expectRevert(Distributor.AlreadyProcessed.selector);
56-
distributor.setMerkleRoot(root2, sameCid);
53+
// Same cid, new root
54+
distributor.setMerkleRoot(root2, cid2);
55+
vm.stopPrank();
5756
}
5857

5958
// ==================== Successful Merkle Root Setting ====================

0 commit comments

Comments
 (0)