Skip to content

Conversation

@ali-behjati
Copy link
Collaborator

@ali-behjati ali-behjati commented Apr 21, 2023

This PR adds the support WormholeMerkle accumulator message to the ethereum contract while still supporting the old message format. The code is not optimized yet and with more optimizations we can achieve a better gas usage. Currently based on the gas benchmark below it has a 18% improvement with a single price feed. Although the cost of updating 5 feeds in the same batch is higher than the current approach but in reality the chances that all 5 feeds be in the same batch is very low.

In the future when the migration to the Merkle Accumulator is over we can break the backward compatibility and remove the old code.

This is the result of the benchmark:

testBenchmarkGetEmaPrice() (gas: 25525)
testBenchmarkGetPrice() (gas: 23386)
testBenchmarkGetUpdateFee() (gas: 133310)
testBenchmarkParsePriceFeedUpdatesForOnePriceFeed() (gas: 310765)
testBenchmarkParsePriceFeedUpdatesForOnePriceFeedNotWithinRange() (gas: 311840)
testBenchmarkParsePriceFeedUpdatesForTwoPriceFeed() (gas: 317491)
testBenchmarkUpdatePriceFeedsIfNecessaryWhBatchFresh() (gas: 378912)
testBenchmarkUpdatePriceFeedsIfNecessaryWhBatchNotFresh() (gas: 175765)
testBenchmarkUpdatePriceFeedsWhBatchFresh() (gas: 357741)
testBenchmarkUpdatePriceFeedsWhBatchNotFresh() (gas: 316172)
testBenchmarkUpdatePriceFeedsWhMerkle1FeedFresh() (gas: 293517)
testBenchmarkUpdatePriceFeedsWhMerkle1FeedNotFresh() (gas: 283079)
testBenchmarkUpdatePriceFeedsWhMerkle2FeedsFresh() (gas: 333020)
testBenchmarkUpdatePriceFeedsWhMerkle2FeedsNotFresh() (gas: 312169)
testBenchmarkUpdatePriceFeedsWhMerkle3FeedsFresh() (gas: 359739)
testBenchmarkUpdatePriceFeedsWhMerkle3FeedsNotFresh() (gas: 339052)
testBenchmarkUpdatePriceFeedsWhMerkle4FeedNotFresh() (gas: 366044)
testBenchmarkUpdatePriceFeedsWhMerkle4FeedsFresh() (gas: 397336)
testBenchmarkUpdatePriceFeedsWhMerkle5FeedsFresh() (gas: 434540)
testBenchmarkUpdatePriceFeedsWhMerkle5FeedsNotFresh() (gas: 393001)

Note: This change set adds an overhead of 1k gas to the batch attestations.
Note 2: Gas benchmark here does not include the initial input size cost and that will be lower too. So I can say the gas saving would be slightly more than 20%.

@vercel
Copy link

vercel bot commented Apr 21, 2023

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

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) May 3, 2023 1:52pm
xc-admin-frontend ⬜️ Ignored (Inspect) May 3, 2023 1:52pm

@ali-behjati ali-behjati requested review from Reisen and jayantk April 26, 2023 15:45
@ali-behjati ali-behjati marked this pull request as ready for review April 26, 2023 15:46
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

message looks good except this one minor thing

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

in general, this looks great. Nice job on very thorough testing. I left a couple minor comments

if (i < messages.length) {
tree[(1 << depth) + i] = leafHash(messages[i]);
} else {
tree[(1 << depth) + i] = leafHash("");
Copy link
Contributor

Choose a reason for hiding this comment

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

will have to update this for the empty node prefix as well

function updatePriceFeeds(
bytes[] calldata updateData
) public payable override {
// TODO: Is this fee model still good for accumulator?
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm yeah maybe we should charge on a per-feed basis, though doing that gas efficiently may be tricky. we may be able to do something a little too clever by using the number of bytes in an update as a proxy....

Copy link
Collaborator Author

@ali-behjati ali-behjati May 3, 2023

Choose a reason for hiding this comment

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

I think we should do it per price and i like the idea of using number of bytes. What's wrong if i say len(update) * baseFee? 🤔

@ali-behjati
Copy link
Collaborator Author

Merging this PR. There are two outstanding TODOs for the future: (1) update fee (2) whether to emit an accumulator update or not.

@ali-behjati ali-behjati merged commit f94dceb into main May 3, 2023
@ali-behjati ali-behjati deleted the eth/add-acumulator branch May 3, 2023 14:08
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.

3 participants