Skip to content

Commit

Permalink
add checks to dictionary updates
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig committed Jan 24, 2025
1 parent 6ef1aab commit 76de69a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
19 changes: 6 additions & 13 deletions src/clients/BundleDataClient/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
bnUint32Max,
isZeroValueDeposit,
chainIsEvm,
isAddressBytes32,
} from "../../utils";
import winston from "winston";
import {
Expand Down Expand Up @@ -90,6 +89,10 @@ function updateBundleFillsV3(
repaymentChainId: number,
repaymentToken: string
): void {
// It is impossible to refund a deposit if the repayment chain is EVM and the relayer is a non-evm address.
if (chainIsEvm(fill.repaymentChainId) && !utils.isAddress(fill.relayer)) {
return;
}
if (!dict?.[repaymentChainId]?.[repaymentToken]) {
assign(dict, [repaymentChainId, repaymentToken], {
fills: [],
Expand Down Expand Up @@ -930,15 +933,11 @@ export class BundleDataClient {
return;
}
// If the fill's repayment address is not a valid EVM address and the repayment chain is an EVM chain, the fill is invalid.
if (chainIsEvm(fill.repaymentChainId) && isAddressBytes32(fill.relayer)) {
if (chainIsEvm(fill.repaymentChainId) && !utils.isAddress(fill.relayer)) {
const fillTransaction = await originClient.spokePool.provider.getTransaction(fill.transactionHash);
const originRelayer = fillTransaction.from;
this.logger.debug({
at: "BundleDataClient#loadData",
message: `${fill.relayer} is not a valid address on chain ${fill.repaymentChainId}. Falling back to ${originRelayer}.`,
});
// Repayment chain is still an EVM chain, but the msg.sender is a bytes32 address, so the fill is invalid.
if (isAddressBytes32(originRelayer)) {
if (!utils.isAddress(originRelayer)) {
bundleInvalidFillsV3.push(fill);
return;
}
Expand All @@ -949,12 +948,6 @@ export class BundleDataClient {
// algorithm will not work.
const historicalDeposit = await queryHistoricalDepositForFill(originClient, fill);
if (!historicalDeposit.found) {
this.logger.debug({
at: "BundleDataClient#loadData",
message: "Could not binary search a historical deposit for fill.",
fill,
reason: historicalDeposit.reason,
});
bundleInvalidFillsV3.push(fill);
} else {
const matchedDeposit = historicalDeposit.deposit;
Expand Down
26 changes: 0 additions & 26 deletions src/utils/AddressUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,3 @@ export function compareAddressesSimple(addressA?: string, addressB?: string): bo
}
return addressA.toLowerCase() === addressB.toLowerCase();
}

// Converts an input hex data string into a bytes32 string. Note that the output bytes will be lowercase
// so that it naturally matches with ethers event data.
// Throws an error if the input string is already greater than 32 bytes.
export function toBytes32(address: string): string {
return utils.hexZeroPad(address, 32).toLowerCase();
}

// Converts an input (assumed to be) bytes32 string into a bytes20 string.
// If the input is not a bytes32 but is less than type(uint160).max, then this function
// will still succeed.
// Throws an error if the string as an unsigned integer is greater than type(uint160).max.
export function toAddress(bytes32: string): string {
// rawAddress is the address which is not properly checksummed.
const rawAddress = utils.hexZeroPad(utils.hexStripZeros(bytes32), 20);
return utils.getAddress(rawAddress);
}

// Checks if an input address is a 32-byte address or not.
export function isAddressBytes32(address: string): boolean {
// If the address is not 32 bytes, then don't check.
if (utils.hexDataLength(address) !== 32) return false;

const strippedAddress = utils.hexStripZeros(address);
return utils.isBytes(strippedAddress) && utils.hexDataLength(strippedAddress) > 20;
}

0 comments on commit 76de69a

Please sign in to comment.