forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
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
swimalick
wants to merge
3
commits into
swim-v2
Choose a base branch
from
max_fee_validation
base: swim-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
if (payload.extraPayload.maxSwimUSDFee && payload.extraPayload.maxSwimUSDFee < 10000n) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. two thoughts:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.