Skip to content

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

Merged
merged 7 commits into from
May 13, 2025

Conversation

tejasbadadare
Copy link
Contributor

Summary

Introduces a strict parse mode for parsePriceUpdatesInternal named checkUpdateDataIsMinimal that reverts if the number of passed in updates in updateData is different than priceIds. 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

    • Any hints on things we can chop or refactor to satisfy the limit would be much appreciated! If we can't resolve the size issue, then we need to find a different way to solve this problem.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Copy link

vercel bot commented Apr 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:29pm

@tejasbadadare tejasbadadare changed the title feat(target_chains/ethereum/pyth): strict updatedata parsing feat(target_chains/ethereum/pyth): strict minimal updateData parsing Apr 29, 2025
@@ -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
Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will try 🙏

Copy link
Contributor Author

@tejasbadadare tejasbadadare Apr 30, 2025

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

Copy link
Collaborator

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.

@tejasbadadare tejasbadadare merged commit f01d4bd into main May 13, 2025
11 checks passed
@tejasbadadare tejasbadadare deleted the tb/pulse/strict-updatedata-parsing branch May 13, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants