Skip to content

fix: use custom address recovery for fake signature #4890

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 3 commits into from
Feb 22, 2024

Conversation

agostbiro
Copy link
Member

@agostbiro agostbiro commented Feb 19, 2024

Make sure we're not trying to recover the address from fake signatures. Fixes NomicFoundation/edr#294

Copy link

changeset-bot bot commented Feb 19, 2024

⚠️ No Changeset found

Latest commit: f481801

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Feb 19, 2024

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

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 19, 2024 7:41pm

Copy link
Member

@Wodann Wodann left a comment

Choose a reason for hiding this comment

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

I think I would have solved this differently, but this fixes the issue for now.

The function transaction_from_block can return the ExecutableTransaction which includes the from-address, voiding the need for recovery. This PR shows my intended solution.

Something we should wonder is whether the concept of faking a transaction should be incorporated in the raw transaction type? This PR does so now, which I'm not a fan of.
A limiting factor atm is that we don't have a way of expressing that an Address is a valid Ethereum address.

E.g. it's currently still possible that someone uses a JSON-RPC client with fake transactions for testing, which would result in the recovery of an invalid Ethereum address.

I'll approve to expedite the merging process, but if you agree with the above, I'd prefer a minimal change to use the ExecutionTransaction (which already contains the correct address) and to revisit this discussion when we deal with NomicFoundation/edr#260

@fvictorio
Copy link
Member

fvictorio commented Feb 22, 2024

Something we should wonder is whether the concept of faking a transaction should be incorporated in the raw transaction type?

I don't think it should.

A limiting factor atm is that we don't have a way of expressing that an Address is a valid Ethereum address.
E.g. it's currently still possible that someone uses a JSON-RPC client with fake transactions for testing, which would result in the recovery of an invalid Ethereum address.

I'm not sure I understand this. Could you elaborate?

@agostbiro
Copy link
Member Author

Thanks for thinking deeply about this @Wodann! I'm answering between the lines below.

Something we should wonder is whether the concept of faking a transaction should be incorporated in the raw transaction type? This PR does so now, which I'm not a fan of.

Faking a transaction is already incorporated into the raw transaction type:

pub fn fake_sign(self, sender: &Address) -> SignedTransaction {

The source of the bug is that this is not taken into account when doing recovery which this PR fixes.

A limiting factor atm is that we don't have a way of expressing that an Address is a valid Ethereum address.

E.g. it's currently still possible that someone uses a JSON-RPC client with fake transactions for testing, which would result in the recovery of an invalid Ethereum address.

I don't follow either, sorry. Please elaborate :)

The function transaction_from_block can return the ExecutableTransaction which includes the from-address, voiding the need for recovery. #4911 shows my intended solution.

That's a good idea, but it still leaves SignedTransaction::recover in a broken state, so this bug is bound to reoccur in the future unless we fix that.

I'll approve to expedite the merging process, but if you agree with the above, I'd prefer a minimal change to use the ExecutionTransaction (which already contains the correct address) and to revisit this discussion when we deal with NomicFoundation/edr#260

The right way to handle this imo would be to have two signed transaction types: SignedTransaction and FakeSignedTransaction (or possibly a SignedTransaction<SignatureType>), as that'd ensure at compile time (instead of the runtime check solution in this PR) that the recovery logic is appropriate for the signature method.

But moving the check to compile time is a bigger change, hence the approach in this PR.

All in all, I'd prefer the solution in this PR over #4911 as while the latter fixes the immediate problem, it doesn't prevent it from reoccurring.

@Wodann
Copy link
Member

Wodann commented Feb 22, 2024

The right way to handle this imo would be to have two signed transaction types: SignedTransaction and FakeSignedTransaction (or possibly a SignedTransaction), as that'd ensure at compile time (instead of the runtime check solution in this PR) that the recovery logic is appropriate for the signature method.

I agree with this. The SignedTransaction<SignatureType> would allow us to re-use as much of the data as possible. Could you create an issue for that, @agostbiro?

All in all, I'd prefer the solution in this PR over #4911 as while the latter fixes the immediate problem, it doesn't prevent it from reoccurring.

It's unnecessary to use recover() given that we already know the Address when we call it. So at the very least we should merge both solutions; given that they solve different things.

@Wodann Wodann merged commit 5aab752 into main Feb 22, 2024
@Wodann Wodann deleted the edr/fix/get-tx-with-impersonated-account branch February 22, 2024 15:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:edr no changeset needed This PR doesn't require a changeset
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make hardhat_impersonateAccount work with all addresses
4 participants