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 basic maxSwimUSDFee validation, fix rate limit bug #18

Open
wants to merge 3 commits into
base: swim-v2
Choose a base branch
from
Open
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions relayer/spy_relayer/src/backends/swim/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ export class SwimListener implements Listener {
return currentNumRequests >= 0 ? currentNumRequests < env.requestLimit : false;
}

/**
* Sanity check the maxSwimUSDFee field.
* To prevent exploits, we automatically reject any payload with a maxSwimUSDFee that is less than 0.01 swimUSD (10000)
*/
verifyMaxSwimUSDFeeIsValid(payload: ParsedTransferWithArbDataPayload<ParsedSwimData>): boolean {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1/ Should we log anything if we reject an invalid maxSwimUSDFee?
2/ Can you add a TODO here that vaguely denotes all the conditions we wanna check (doesn't have to be super specific or anything). In an ideal world, we'll want to test this method for all conditions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I can add a debug log
  2. Yeah i'll add a TODO

if (payload.extraPayload.maxSwimUSDFee && payload.extraPayload.maxSwimUSDFee < 10000n) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two thoughts:

  1. why not just return <condition>
  2. if the extraPayload has no maxSwimUSDFee it should default to 0 and so you should also reject the transaction

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

I wasn't sure how to handle the default 0 case when I initially wrote this, synced with Andrew to figure it out

return false;
}

return true;
}

/** Parses a raw VAA byte array
*
* @throws when unable to parse the VAA
Expand Down Expand Up @@ -208,6 +220,7 @@ export class SwimListener implements Listener {
!this.verifyIsApprovedToken(parsedPayload) ||
!this.verifyToSwimContracts(parsedPayload) ||
!this.verifyIsPropellerEnabled(parsedPayload) ||
!this.verifyMaxSwimUSDFeeIsValid(parsedPayload) ||
!(await this.verifyIsRateLimited(parsedPayload))
) {
return "Validation failed for VAA sequence " + parsedVaa.sequence + " from chainId " + parsedVaa.emitterChain;
Expand Down