Skip to content

Commit

Permalink
fix(Relayer): Protect against invalid evm addresses (#2072)
Browse files Browse the repository at this point in the history
* fix(Relayer): Protect against undefined fill amount
  • Loading branch information
pxrl authored Feb 8, 2025
1 parent 795040a commit e8c3865
Showing 1 changed file with 28 additions and 2 deletions.
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

0 comments on commit e8c3865

Please sign in to comment.