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

Add zero address check for asset issuer ID in erc20 gateway v4 #250

Merged
merged 7 commits into from
Aug 28, 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
5 changes: 5 additions & 0 deletions .changeset/witty-eyes-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-bridge/solidity-contracts': major
---

add zero address check for asset issuer id
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract FuelERC20GatewayV4 is
error GlobalDepositLimit();
error CannotDepositZero();
error CannotWithdrawZero();
error InvalidAssetIssuerID();
error InvalidSender();
error InvalidAmount();

Expand Down Expand Up @@ -145,6 +146,8 @@ contract FuelERC20GatewayV4 is
/// @param amount Amount of tokens to deposit
/// @dev Made payable to reduce gas costs
function deposit(bytes32 to, address tokenAddress, uint256 amount) external payable virtual whenNotPaused {
if (assetIssuerId == bytes32(0)) revert InvalidAssetIssuerID();

uint8 decimals = _getTokenDecimals(tokenAddress);
uint256 l2MintedAmount = _adjustDepositDecimals(decimals, amount);

Expand Down Expand Up @@ -173,6 +176,8 @@ contract FuelERC20GatewayV4 is
uint256 amount,
bytes calldata data
) external payable virtual whenNotPaused {
if (assetIssuerId == bytes32(0)) revert InvalidAssetIssuerID();

uint8 decimals = _getTokenDecimals(tokenAddress);
uint256 l2MintedAmount = _adjustDepositDecimals(decimals, amount);

Expand All @@ -191,6 +196,8 @@ contract FuelERC20GatewayV4 is
}

function sendMetadata(address tokenAddress) external payable virtual whenNotPaused {
if (assetIssuerId == bytes32(0)) revert InvalidAssetIssuerID();

bytes memory metadataMessage = abi.encodePacked(
assetIssuerId,
uint256(MessageType.METADATA),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,28 @@ export function behavesLikeErc20GatewayV4(fixture: () => Promise<Env>) {
);
});

it('reverts when asset issuer id is not set', async () => {
const {
erc20Gateway,
token,
signers: [deployer, user],
} = env;

const depositTo = randomBytes32();
const depositAmount = MaxUint256;

await erc20Gateway.connect(deployer).setAssetIssuerId(ZeroHash);

const tx = erc20Gateway
.connect(user)
.deposit(depositTo, token, depositAmount);

await expect(tx).to.be.revertedWithCustomError(
erc20Gateway,
'InvalidAssetIssuerID'
);
});

it('calls FuelMessagePortal', async () => {
const {
erc20Gateway,
Expand Down
Loading