-
Notifications
You must be signed in to change notification settings - Fork 260
feat(target_chains/ethereum/pyth): strict minimal updateData parsing #2637
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -299,6 +299,24 @@ abstract contract Pyth is | |||
if (msg.value < requiredFee) revert PythErrors.InsufficientFee(); | |||
} | |||
|
|||
// In minimal update data mode, revert if we have more or less updates than price IDs |
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.
Can you try out doing it on the fly instead of parsing again to save gas (and hopefully contract size)
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.
will try 🙏
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.
We calculate on the fly now and inlined ParseConfig to chop a struct to save space (see commits after your review,) but we are still 372 bytes short 😭
Any idea if there's something unused that we can remove? Otherwise i'll abandon this approach and just use a heuristic check in Pulse.updatePriceFeeds
to check that the updatedata isn't too large
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.
i recommend you reduce the optimizer runs a bit to match it. the optimizer inlines things to reduce jump costs.
…b/pulse/strict-updatedata-parsing
…b/pulse/strict-updatedata-parsing
…b/pulse/strict-updatedata-parsing
Summary
Introduces a strict parse mode for
parsePriceUpdatesInternal
namedcheckUpdateDataIsMinimal
that reverts if the number of passed in updates inupdateData
is different thanpriceIds
. If the update data is minimal and sufficient to satisfy the requested priceIds, parsing succeeds.Rationale
There is a potential attack vector for Pulse where a bad keeper could provide huge updatedata that contains many more price IDs than requested. This doesn't affect correctness, but it could burn more gas than intended during parsing, which the manager pays for. This could be used to drain manager wallets. Using this new strict parsing mode in Pulse prevents that.
Gas benchmark delta looks good, <0.5% difference: https://app.warp.dev/block/XCs2XtRCKZ1FhQ7StYoYb7
Unfortunately this change causes the contract size to exceed the limit by 666 bytes 👿: https://app.warp.dev/block/x6K9sJRtbLRVMdb4aM212C
How has this been tested?