-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
base: feat/9544
Are you sure you want to change the base?
Conversation
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. |
test/stub/keyring-bridge.js
Outdated
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
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)
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
Related issues
Fixes:
Manual testing steps
To run locally do:
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 )yarn start:test
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