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

fix: ledger vrs values + add support for type 0 and type 2 transactions #27966

Open
wants to merge 4 commits into
base: feat/9544
Choose a base branch
from

Conversation

seaona
Copy link
Contributor

@seaona seaona commented Oct 18, 2024

Description

Note: the jobs will fail in this branch, as we need to run lavamoat:auto, but I leave this for the base branch feat/9544 to do.
In case you want to try it locally you'll need to update the policies locally (see steps below).

Legacy Transactions support:

legacy-ledger.mp4

EIP1559 Transactions support:

eip1559-ledger.mp4

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

To run locally do:

  1. yarn lavamoat:auto -- this will update the policies (now this is failing in this PR, but I leave this to be done in the original branch from @Akaryatrh )
  2. yarn start:test
  3. yarn test:e2e:single test/e2e/tests/hardware-wallets/ledger.spec.ts --browser=chrome --leave-running=true

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@seaona seaona requested a review from a team as a code owner October 18, 2024 15:58
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

return Transaction.fromSerializedTx(txBuffer, {
const VALID_TYPES = [1, 2];
const txType = VALID_TYPES.includes(rawTx[0]) ? rawTx[0] : null;
const rlpData = txType === null ? txBuffer : txBuffer.slice(1, tx.length);
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, so why are we removing the transaction type of supported transactions?

What would happen here with a pre-EIP-1559 transaction, or a non-supported transaction type?

Copy link
Contributor Author

@seaona seaona Nov 5, 2024

Choose a reason for hiding this comment

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

hi @Gudahtt , so here we chose to implement this piece as close as what Ledger does

https://npmfs.com/package/@ledgerhq/hw-app-eth/6.12.2/src/Eth.ts#L206

mmm so with pre-EIP-1559's this piece of logic seems to work, since we are using a legacy tx type 0 in the spec 🤔

EDIT - I guess for the non-supported types, this would eventually fail somewhere? I'll try now manually to see what happens in a real device vs in this setup, and report back

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, thanks for sharing that link. It looks like Ledger uses the type to inform what it uses as its representation of the transaction to sign, here: https://npmfs.com/package/@ledgerhq/hw-app-eth/6.12.2/src/Eth.ts#L222

While it would be nice to just do what Ledger does, it's not entirely clear how to do that here because the linked code doesn't include the full picture. Reading further, it appears that Ledger sends the entire raw transaction to the device, only using the decoded data for fetching contract related metadata to send to the device alongside the transaction. Meaning that what we're doing here isn't really that similar after all.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like Transaction.fromValuesArray will only work for legacy transactions (the Transaction class we're using here is this one: https://github.com/ethereumjs/ethereumjs-monorepo/blob/%40ethereumjs/tx%404.2.0/packages/tx/src/legacyTransaction.ts#L33)

This change looks OK if that's all we want this mock to be used for. But it seems like it might fail for transactions of type 1 or 2. I'd recommend that we throw a more useful error for those types in the interim, or ensure they work correctly as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh thank you for these insights, and indeed the test is failing with type 2. I think I see what you mean, so possibly we'll need to handle each case differently in our logic 🤔
What would you think on doing: one case for type 0 (the current one that is working) one for type 2, and the rest of cases just handle it as failure? We could leave for the future the case of type 1 with access list? I'm not sure we currently have any test for type 0x1 nor support in the test dapp for testing it, so maybe adding 'testability' around this tx type first, would be better? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Leaving type 1 for later makes sense to me!

Copy link
Contributor

Choose a reason for hiding this comment

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

@Gudahtt @seaona can we merge this one and make new PRs for other cases? (this would allow me to clean up the destination branch)
Except if you see some blockers?

Copy link
Contributor Author

@seaona seaona Nov 19, 2024

Choose a reason for hiding this comment

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

I've added support for type 0 and type 2, and 2 specs, one for type 0 and another one for type2, which are now passing (see vids in the description).
Note: the jobs fail in ci, since this branch also needs to run lavamoat auto -> I leave this out of scope, so it can be done in the base branch from @Akaryatrh

KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
convertETHToHexGwei(2),
);
await driver.delay(2000);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ we can remove this delay if we seed the account from the beginning, using the ganache set balance method

fixtures: new FixtureBuilder().build(),
ganacheOptions: {
...defaultGanacheOptions,
hardfork: 'london',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ this makes our tx an EIP1559 (type 2 tx)

} else if (txType === 2) {
const rlpData = txBuffer.slice(1, tx.length);
const rlpTx = rlp.decode(rlpData);
return FeeMarketEIP1559Transaction.fromValuesArray(rlpTx, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for type 2 tx's, we need to use this other tx type (EIP1559)

@seaona seaona self-assigned this Nov 19, 2024
@seaona seaona added area-qa Relating to QA work (Quality Assurance) team-extension-platform Extension Platform team labels Nov 19, 2024
@seaona seaona changed the title fix: ledger vrs values fix: ledger vrs values + add support for type 0 and type 2 transactions Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-qa Relating to QA work (Quality Assurance) team-extension-platform Extension Platform team team-hardware-wallets
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

3 participants