Skip to content

Commit

Permalink
Adding checks for newVal == oldVal
Browse files Browse the repository at this point in the history
Verified that a new val is not the same as the old one during parameter
updates.
  • Loading branch information
dimpar committed May 3, 2024
1 parent a2e6113 commit fcd7596
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions solidity/contracts/PausableOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ abstract contract PausableOwnable is
/// mechanism.
error PausableUnauthorizedAccount(address account);

/// @notice Reverts when the new pause admin address is the same as the
/// current pause admin address.
error SamePauseAdmin();

/// @notice Reverts if called by any account other than the pause admin
/// or the contract owner.
modifier onlyPauseAdminOrOwner() {
Expand Down Expand Up @@ -95,6 +99,9 @@ abstract contract PausableOwnable is
if (newPauseAdmin == address(0)) {
revert ZeroAddress();
}
if (newPauseAdmin == pauseAdmin) {
revert SamePauseAdmin();
}

emit PauseAdminUpdated(newPauseAdmin, pauseAdmin);

Expand Down
12 changes: 12 additions & 0 deletions solidity/contracts/stBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ contract stBTC is ERC4626Fees, PausableOwnable {
/// Reverts if the address is disallowed.
error DisallowedAddress();

/// Reverts if the treasury address is the same.
error SameTreasury();

/// Reverts if the dispatcher address is the same.
error SameDispatcher();

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand Down Expand Up @@ -104,6 +110,9 @@ contract stBTC is ERC4626Fees, PausableOwnable {
if (newTreasury == address(this)) {
revert DisallowedAddress();
}
if (newTreasury == treasury) {
revert SameTreasury();
}

emit TreasuryUpdated(treasury, newTreasury);

Expand All @@ -128,6 +137,9 @@ contract stBTC is ERC4626Fees, PausableOwnable {
if (address(newDispatcher) == address(0)) {
revert ZeroAddress();
}
if (address(newDispatcher) == address(dispatcher)) {
revert SameDispatcher();
}

address oldDispatcher = address(dispatcher);

Expand Down
26 changes: 26 additions & 0 deletions solidity/test/stBTC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,14 @@ describe("stBTC", () => {
})
})

context("when a new dispatcher is the same as the old one", () => {
it("should revert", async () => {
await expect(
stbtc.connect(governance).updateDispatcher(mezoAllocator),
).to.be.revertedWithCustomError(stbtc, "SameDispatcher")
})
})

context("when a new dispatcher is non-zero address", () => {
let newDispatcher: string
let stbtcAddress: string
Expand Down Expand Up @@ -1616,6 +1624,14 @@ describe("stBTC", () => {
})
})

context("when a new treasury is same as the old one", () => {
it("should revert", async () => {
await expect(
stbtc.connect(governance).updateTreasury(treasury),
).to.be.revertedWithCustomError(stbtc, "SameTreasury")
})
})

context("when a new treasury is Acre address", () => {
it("should revert", async () => {
await expect(
Expand Down Expand Up @@ -1693,6 +1709,16 @@ describe("stBTC", () => {
.withArgs(pauseAdmin.address)
})
})

context("when updating pause admin to the same address", () => {
beforeAfterSnapshotWrapper()

it("should revert", async () => {
await expect(
stbtc.connect(governance).updatePauseAdmin(pauseAdmin.address),
).to.be.revertedWithCustomError(stbtc, "SamePauseAdmin")
})
})
})

context("when the unauthorized account tries to pause contract", () => {
Expand Down

0 comments on commit fcd7596

Please sign in to comment.