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

E2E Test For Hook-Enabled ERC-1271 Signatures #1832

Merged
merged 2 commits into from
Sep 6, 2023
Merged

Conversation

nlordell
Copy link
Contributor

Now, thanks to #1831, we no longer depend on eth_call with state override support for simulating ERC-1271 signature validation for orders with pre-hooks. This means that we can finally write an E2E test for this!

This PR does just that - it executes an order on behalf of a Safe that is created just-in-time for the settlement as part of a pre-hook. Note that we assert that the ERC-1271 order is created for a Safe with no code!

Test Plan

This is the test!

@nlordell nlordell requested a review from a team as a code owner August 31, 2023 22:56
@nlordell nlordell force-pushed the e2e-eip1271-pre-hook branch from ffcce9e to 57948a0 Compare August 31, 2023 22:56
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.

Very cool. This allows for some very nice use cases, where users can e.g. bridge funds to a specific mainnet address and sign an order in the name of that address in which the safe is deployed in a pre-hook and proceeds are swapped back to their address on the original chain in a post hook.

fn domain_separator(&self) -> DomainSeparator {
let mut buffer = [0_u8; 96];
buffer[0..32].copy_from_slice(&hex!(
"47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218"
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these magic numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry - meant to include links to code but forgot. Will update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some documentation with links to the code that was ported and where the magic numbers come from.

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.

Nice test and easy to understand. 👍

Base automatically changed from reader-magic to main September 6, 2023 07:47
nlordell pushed a commit that referenced this pull request Sep 6, 2023
Follow up to
#1827 (comment)
- thanks @fleupold for the wonderful idea!

This PR changes instances of `eth_call` with state override simulations
**where we are only overriding the Settlement contract code** to make
use of `StorageAccessible`. It does this with an additional support
`Reader` contract in order to avoid needing to manage deployments
on-chain for the `StorageAccessible` target (i.e. the reader logic). See
the comment in the `Reader.sol` file for more details on how this works.

Specifically, we changed the following two simulations to no longer
require state overrides (i.e. we do not need a special node to handle
those requests, and it will Just Work™ on Gnosis Chain):
* Account balance simulations with pre-hooks
* ERC-1271 signature validation with pre-hooks

In a follow up PRs I will:
1. #1832
2. Remove the redundant `Web3` strategy for both account balance and
signature verification simulation

### Release notes

Hooks E2E test continues to pass **without the nasty
`----account-balances-optimistic-pre-interaction-handling=true` hack**
which used to disable balance checks for orders with pre-hooks. This
means that not only are we E2E testing that executing orders with
pre-hooks are working, we are also checking that balance simulations
work 🎉.

You can double check this is actually doing something by applying a
patch like this:

```diff
diff --git a/crates/e2e/tests/e2e/hooks.rs b/crates/e2e/tests/e2e/hooks.rs
index 42d8d072..84d978b5 100644
--- a/crates/e2e/tests/e2e/hooks.rs
+++ b/crates/e2e/tests/e2e/hooks.rs
@@ -66,7 +66,7 @@ async fn test(web3: Web3) {
             full: json!({
                 "metadata": {
                     "hooks": {
-                        "pre": [permit, steal_cow],
+                        "pre": [/*permit, */steal_cow],
                         "post": [steal_weth],
                     },
                 },
```

And see the E2E test fail as expected with:

```
thread 'hooks::local_node_test' panicked at 'called `Result::unwrap()` on an `Err` value: (400, "{\"errorType\":\"InsufficientAllowance\",\"description\":\"order owner must give allowance to VaultRelayer\"}")', crates/e2e/tests/e2e/hooks.rs:83:41
```

I also ran the `cargo test -p shared -- --nocapture --ignored
account_balances::simulation` manual test which continues to work.
@nlordell nlordell force-pushed the e2e-eip1271-pre-hook branch from 04549bf to 27b0509 Compare September 6, 2023 08:13
@nlordell nlordell enabled auto-merge (squash) September 6, 2023 08:18
@nlordell nlordell merged commit df0f7b4 into main Sep 6, 2023
7 checks passed
@nlordell nlordell deleted the e2e-eip1271-pre-hook branch September 6, 2023 08:20
@github-actions github-actions bot locked and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants