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(Relayer): Protect against invalid evm addresses #2072

Merged
merged 12 commits into from
Feb 8, 2025
Merged
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
30 changes: 28 additions & 2 deletions src/relayer/Relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@ export class Relayer {
return false;
}

const badAddress = [
deposit.depositor,
deposit.recipient,
deposit.exclusiveRelayer,
deposit.inputToken,
deposit.outputToken,
].some((address) => {
try {
ethersUtils.getAddress(address);
} catch {
return true;
}
});

if (badAddress) {
this.logger.debug({
at: "Relayer::filterDeposit",
message: `Skipping ${srcChain} deposit due to invalid address.`,
deposit,
});
return false;
}

// Ensure that the individual deposit meets the minimum deposit confirmation requirements for its value.
const fillAmountUsd = profitClient.getFillAmountInUsd(deposit);
if (!isDefined(fillAmountUsd)) {
Expand Down Expand Up @@ -477,7 +500,7 @@ export class Relayer {
}

const fillAmount = profitClient.getFillAmountInUsd(deposit);
return acc.add(fillAmount);
return acc.add(fillAmount ?? bnZero);
}, bnZero);

return commitment;
Expand Down Expand Up @@ -570,7 +593,7 @@ export class Relayer {
.filter((deposit) => tokenClient.hasBalanceForFill(deposit))
.reduce((agg, deposit) => {
const unfilledAmountUsd = profitClient.getFillAmountInUsd(deposit);
agg[deposit.originChainId] = (agg[deposit.originChainId] ?? bnZero).add(unfilledAmountUsd);
agg[deposit.originChainId] = (agg[deposit.originChainId] ?? bnZero).add(unfilledAmountUsd ?? bnZero);
return agg;
}, {});

Expand Down Expand Up @@ -694,6 +717,9 @@ export class Relayer {
} else {
const { blockNumber, outputToken, outputAmount } = deposit;
const fillAmountUsd = profitClient.getFillAmountInUsd(deposit);
if (!isDefined(fillAmountUsd)) {
return;
}
const limitIdx = this.findOriginChainLimitIdx(originChainId, blockNumber);

// Ensure that a limit was identified, and that no upper thresholds would be breached by filling this deposit.
Expand Down