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

fix(protocol): be more strict with changeBridgedToken #17333

Merged
merged 1 commit into from
May 25, 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
12 changes: 11 additions & 1 deletion packages/protocol/contracts/tokenvault/ERC20Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.24;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "../bridge/IQuotaManager.sol";
import "../common/LibStrings.sol";
import "../libs/LibAddress.sol";
Expand All @@ -17,6 +18,7 @@ import "./BaseVault.sol";
/// @dev Labeled in AddressResolver as "erc20_vault".
/// @custom:security-contact [email protected]
contract ERC20Vault is BaseVault {
using Address for address;
using LibAddress for address;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -143,6 +145,7 @@ contract ERC20Vault is BaseVault {
error VAULT_CTOKEN_MISMATCH();
error VAULT_INVALID_TOKEN();
error VAULT_INVALID_AMOUNT();
error VAULT_INVALID_CTOKEN();
error VAULT_INVALID_NEW_BTOKEN();
error VAULT_LAST_MIGRATION_TOO_CLOSE();

Expand All @@ -166,10 +169,17 @@ contract ERC20Vault is BaseVault {
nonReentrant
returns (address btokenOld_)
{
if (_btokenNew == address(0) || bridgedToCanonical[_btokenNew].addr != address(0)) {
if (
_btokenNew == address(0) || bridgedToCanonical[_btokenNew].addr != address(0)
|| !_btokenNew.isContract()
) {
revert VAULT_INVALID_NEW_BTOKEN();
}

if (_ctoken.addr == address(0) || _ctoken.chainId == block.chainid) {
revert VAULT_INVALID_CTOKEN();
}

if (btokenBlacklist[_btokenNew]) revert VAULT_BTOKEN_BLACKLISTED();

uint256 _lastMigrationStart = lastMigrationStart[_ctoken.chainId][_ctoken.addr];
Expand Down
13 changes: 13 additions & 0 deletions packages/protocol/test/tokenvault/ERC20Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,19 @@ contract TestERC20Vault is TaikoTest {
address(usdc)
);

// invalid btoken
vm.expectRevert(ERC20Vault.VAULT_INVALID_CTOKEN.selector);
erc20Vault.changeBridgedToken(
ERC20Vault.CanonicalERC20({
chainId: uint64(block.chainid),
addr: address(erc20),
decimals: 18,
symbol: "ERC20TT",
name: "ERC20 Test token"
}),
address(usdc)
);

// We cannot use stETH for erc20 (as it is used in connection with another token)
vm.expectRevert(ERC20Vault.VAULT_INVALID_NEW_BTOKEN.selector);
erc20Vault.changeBridgedToken(
Expand Down