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

Safe property access / allow transaction with undefined to fields, in signTransaction #98

Merged
merged 3 commits into from
Aug 27, 2021

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Aug 27, 2021

With #68, we started directly accessing a .buf property on tx.to in signTransaction. This was necessary given changes in ethereumjs-tx

The problem is that the to field can be undefined. This is necessary for deploying contracts. Currently, in prod, if you attempt to create a contract deployment transaction with ledger in metamask, you will see an error because of tx.to.buf and tx.to being undefined.

This PR fixes that.

@danjm danjm requested a review from a team as a code owner August 27, 2021 12:53
index.js Outdated
@@ -255,8 +255,7 @@ class LedgerBridgeKeyring extends EventEmitter {
rawTxHex = tx.type === 0 || !tx.type
? ethUtil.rlp.encode(tx.getMessageToSign(false)).toString('hex')
: tx.getMessageToSign(false).toString('hex')

return this._signTransaction(address, rawTxHex, tx.to.buf, (payload) => {
return this._signTransaction(address, rawTxHex, tx.to && tx.to.buf, (payload) => {
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 to me like passing in nothing for toAddress will result in the to field passed to the Ledger device being set to 0x0. That doesn't seem right 🤔 . Should _signTransaction omit the to field instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

Actually, after merging #95, the to field isn't even needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have simply removed the to parameter in 8f2195c

Copy link
Member

Choose a reason for hiding this comment

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

That works! Though if you wanted to remove the dependency on #95, I think this would also be safe to merge if to was omitted for contract deployments, but passed in otherwise.

@danjm
Copy link
Contributor Author

danjm commented Aug 27, 2021

Adding a DO NOT MERGE label, as this now depends on #95

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@danjm danjm merged commit 3c22af7 into main Aug 27, 2021
@danjm danjm deleted the fix-contract-deployments branch August 27, 2021 17:16
@adonesky1 adonesky1 mentioned this pull request Aug 31, 2021
julianariel pushed a commit to block-wallet/eth-ledger-bridge-keyring that referenced this pull request Apr 27, 2022
… signTransaction (MetaMask#98)

* Safe property access / allow transaction with undefined to fields, in signTransaction

* Revert "Safe property access / allow transaction with undefined to fields, in signTransaction"

This reverts commit 3c148ba.

* Remove passage of to param to ledger bridge, which will not be needed after PR MetaMask#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants