Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion 4: Adding checks for newVal == oldVal #393

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading