Skip to content

Commit

Permalink
Suggestion 3: Adding missing check for ownership of tBTC token (#415)
Browse files Browse the repository at this point in the history
Added a missing check for ownership of tBTC token when updating the
tbtcVault address.
  • Loading branch information
nkuba authored May 10, 2024
2 parents d9cfc07 + 7f8ccdb commit 330b37c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions solidity/contracts/BitcoinRedeemer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ contract BitcoinRedeemer is Ownable2StepUpgradeable, IReceiveApproval {
/// Reverts when approveAndCall to tBTC contract fails.
error ApproveAndCallFailed();

/// Reverts if the new TBTCVault contract is not tBTC token owner.
error NotTbtcTokenOwner();

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand Down Expand Up @@ -118,6 +121,10 @@ contract BitcoinRedeemer is Ownable2StepUpgradeable, IReceiveApproval {
revert ZeroAddress();
}

if (newTbtcVault != tbtcToken.owner()) {
revert NotTbtcTokenOwner();
}

emit TbtcVaultUpdated(tbtcVault, newTbtcVault);

tbtcVault = newTbtcVault;
Expand Down
12 changes: 11 additions & 1 deletion solidity/test/BitcoinRedeemer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,24 @@ describe("BitcoinRedeemer", () => {
})
})

context("when a new treasury is an allowed address", () => {
context("when a new tbtc vault is not tBTC token owner", () => {
it("should revert", async () => {
const newTbtcVault = await ethers.Wallet.createRandom().getAddress()
await expect(
bitcoinRedeemer.connect(governance).updateTbtcVault(newTbtcVault),
).to.be.revertedWithCustomError(bitcoinRedeemer, "NotTbtcTokenOwner")
})
})

context("when a new tbtc vault is an allowed address", () => {
let oldTbtcVault: string
let newTbtcVault: string
let tx: ContractTransactionResponse

before(async () => {
oldTbtcVault = await bitcoinRedeemer.tbtcVault()
newTbtcVault = await ethers.Wallet.createRandom().getAddress()
await tbtc.setOwner(newTbtcVault)

tx = await bitcoinRedeemer
.connect(governance)
Expand Down

0 comments on commit 330b37c

Please sign in to comment.