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

Sepolia fix for Cow AMMs #3110

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Sepolia fix for Cow AMMs #3110

wants to merge 6 commits into from

Conversation

sunce86
Copy link
Contributor

@sunce86 sunce86 commented Nov 5, 2024

Description

Signature verification is now part of order creation for cow amm orders.

Changes

  • isValidSignature call is executed as part of creating the cow amm order

How to test

Cow amm e2e test should confirm no new issues are introduced.

Fixes #
#3102

@sunce86 sunce86 self-assigned this Nov 5, 2024
@sunce86 sunce86 requested a review from a team as a code owner November 5, 2024 12:19
Copy link
Contributor

@MartinquaXD MartinquaXD left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this. 👍
Looks good, just a few nits.

@@ -86,6 +90,26 @@ impl Amm {
let raw_signature = signature.0.into_iter().skip(20).collect();
let signature = Signature::Eip1271(raw_signature);

// Cow AMM pools can have specific requirements for the signature validity.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The underlying issue is not that specific cow amms might have special requirements but rather that the helper contract might produce invalid signatures at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it's still Cow AMM specific EIP1271 signature check implementation causing the invalidity right... I mean, the order is good and signature is good, it's only bad in context of using that signature/order on cow amm pool.

Anyway, your statement is true as well. I think git blame can be used here to give more context in not clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

But it's still Cow AMM specific EIP1271 signature check implementation causing the invalidity right.

The meaning of the signature is entirely implementation specific. If it doesn't work for the only thing it's supposed to work it's not really a good signature is it? 😅
The correct behavior would be that the helper contract refuses to create the signature in the first place because it's supposed to be aware of the implementation details of the cow amms it's supposed to work for.
It's not the case that there is a catch all implementation of the helper contract which happens to be incompatible with the balancer cow amm. The helper was specifically written for the balancer version so we should be able to expect that it works.
But it's also true that by now there is enough context on the matter to be found with git blame.

crates/cow-amm/src/amm.rs Outdated Show resolved Hide resolved
crates/cow-amm/src/amm.rs Show resolved Hide resolved
Copy link
Contributor

@fleupold fleupold left a comment

Choose a reason for hiding this comment

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

Thanks for taking a stab at it. I'd be a bit more comfortable if we could better test this (test plan reads a bit like 🤞), but I guess adding an e2e test is more work than testing in staging.

For this however, we need to disable cow amms in sepolia prod and enable it in staging to see it fixes the issue.

@@ -48,12 +51,13 @@ impl Amm {
let (order, pre_interactions, post_interactions, signature) =
self.helper.order(self.address, prices).call().await?;
self.convert_orders_reponse(order, signature, pre_interactions, post_interactions)
.await
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: check validity would make sense between fetching the order and converting it (ie only convert "valid" orders).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but the whole convert_orders_reponse functionality is already needed to check the signature (order hash building and signature building), so it makes it really convenient to be part of it.

crates/cow-amm/src/amm.rs Outdated Show resolved Hide resolved
@MartinquaXD
Copy link
Contributor

MartinquaXD commented Nov 5, 2024

I'd be a bit more comfortable if we could better test this (test plan reads a bit like 🤞), but I guess adding an e2e test is more work than testing in staging.

Given that this issue is easily reproducable on sepolia at the moment we could just create a forked e2e test for the problematic pool and assert that we are not able to generate the bad order.

Comment on lines +95 to +99
if !self
.helper
.is_legacy(self.contract.address())
.call()
.await?
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to only check the non-legacy pools?
IMO this is the correct thing to do anyway and we don't really gain anything from omitting very very few RPC requests with this check.
Also I think the actual helper interface doesn't even have this function.

Copy link

This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed.

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.

4 participants