on master help sign in
Manually follow EIP-155 in certain circumstances.

Ledger does not seem to handle EIP-155 automatically. When using a Ledger, if the block number is at least FORK_BLKNUM = 2675000, one needs to pre-set the ECDSA signature parameters with r = 0, s = 0, and v = chainId prior to signing. The easiest way to handle this on our end is to just branch on the network type, since mainnet and Ropsten have obviously passed FORK_BLKNUM. This is somewhat awkward when dealing with offline transactions, since we might want to test them on a local network as well. For now we can assume that users generating offline transactions wish to later submit them to mainnet, but the best thing to do is probably to add an 'advanced' tab to offline transaction generation where one can disable the defaulted-on EIP-155 settings in this case. See: See https://github.com/LedgerHQ/ledgerjs/issues/43#issuecomment-366984725 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md

commit8184c25823e378701fcef451d3ad0496945fe074 authorJared Tobin <jared@jtobin.io> dateWed 30 Jan 2019, 07:16 (8 years ago) parent483c410
9 files changed+60−1
src/components/StatelessTransaction.js+1 src/lib/txn.js+49−1 src/views/AcceptTransfer.js+1 src/views/CancelTransfer.js+1 src/views/CreateGalaxy.js+1 src/views/IssueChild.js+2 src/views/SetKeys.js+1 src/views/SetProxy.js+2 src/views/Transfer.js+2
src/components/StatelessTransaction.js+1
@@ -114,6 +114,7 @@ const StatelessTransaction = props => {
114114 wallet: props.wallet,
115115 walletType: props.walletType,
116116 walletHdPath: props.walletHdPath,
117+ networkType: props.networkType,
117118 txn: props.txn,
118119 setStx: props.setStx,
119120 nonce: props.nonce,
src/lib/txn.js+49−1
@@ -5,6 +5,7 @@ import Tx from 'ethereumjs-tx'
55import Web3 from 'web3'
66
77import { BRIDGE_ERROR } from '../lib/error'
8+import { NETWORK_NAMES } from '../lib/network'
89import { ledgerSignTransaction } from '../lib/ledger'
910import { trezorSignTransaction } from '../lib/trezor'
1011import {
@@ -48,6 +49,7 @@ const signTransaction = async config => {
4849 wallet,
4950 walletType,
5051 walletHdPath,
52+ networkType,
5153 txn,
5254 setStx,
5355 nonce,
@@ -61,6 +63,52 @@ const signTransaction = async config => {
6163 gasPrice = toHex(toWei(gasPrice, 'gwei'))
6264 gasLimit = toHex(gasLimit)
6365
66+ const txParams = { nonce, chainId, gasPrice, gasLimit }
67+
68+ // NB (jtobin)
69+ //
70+ // Ledger does not seem to handle EIP-155 automatically. When using a Ledger,
71+ // if the block number is at least FORK_BLKNUM = 2675000, one needs to
72+ // pre-set the ECDSA signature parameters with r = 0, s = 0, and v = chainId
73+ // prior to signing.
74+ //
75+ // The easiest way to handle this is to just branch on the network, since
76+ // mainnet and Ropsten have obviously passed FORK_BLKNUM. This is somewhat
77+ // awkward when dealing with offline transactions, since we might want to
78+ // test them on a local network as well.
79+ //
80+ // The best thing to do is probably to add an 'advanced' tab to offline
81+ // transaction generation where one can disable the defaulted-on EIP-155
82+ // settings in this case. This is pretty low-priority, but is a
83+ // comprehensive solution.
84+ //
85+ // See:
86+ //
87+ // See https://github.com/LedgerHQ/ledgerjs/issues/43#issuecomment-366984725
88+ //
89+ // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
90+
91+ const eip155Params = {
92+ r: '0x00',
93+ s: '0x00',
94+ v: chainId
95+ }
96+
97+ const defaultEip155Networks = [
98+ NETWORK_NAMES.MAINNET,
99+ NETWORK_NAMES.ROPSTEN,
100+ NETWORK_NAMES.OFFLINE
101+ ]
102+
103+ const needEip155Params =
104+ walletType === WALLET_NAMES.LEDGER &&
105+ defaultEip155Networks.includes(networkType)
106+
107+ const signingParams =
108+ needEip155Params
109+ ? Object.assign(txParams, eip155Params)
110+ : txParams
111+
64112 const wal = wallet.matchWith({
65113 Just: (w) => w.value,
66114 Nothing: () => { throw BRIDGE_ERROR.MISSING_WALLET }
@@ -70,7 +118,7 @@ const signTransaction = async config => {
70118
71119 const utx = txn.matchWith({
72120 Just: (tx) =>
73− Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
121+ Object.assign(tx.value, signingParams),
74122 Nothing: () => {
75123 throw BRIDGE_ERROR.MISSING_TXN
76124 }
src/views/AcceptTransfer.js+1
@@ -303,6 +303,7 @@ class AcceptTransfer extends React.Component {
303303 wallet={props.wallet}
304304 walletType={props.walletType}
305305 walletHdPath={props.walletHdPath}
306+ networkType={props.networkType}
306307 // Tx
307308 txn={state.txn}
308309 stx={state.stx}
src/views/CancelTransfer.js+1
@@ -234,6 +234,7 @@ class CancelTransfer extends React.Component {
234234 wallet={props.wallet}
235235 walletType={props.walletType}
236236 walletHdPath={props.walletHdPath}
237+ networkType={props.networkType}
237238 // Tx
238239 txn={state.txn}
239240 stx={state.stx}
src/views/CreateGalaxy.js+1
@@ -249,6 +249,7 @@ class CreateGalaxy extends React.Component {
249249 wallet={props.wallet}
250250 walletType={props.walletType}
251251 walletHdPath={props.walletHdPath}
252+ networkType={props.networkType}
252253 // Tx
253254 txApproval={state.txApproval}
254255 txn={state.txn}
src/views/IssueChild.js+2
@@ -461,6 +461,7 @@ class IssueChild extends React.Component {
461461 wallet={props.wallet}
462462 walletType={props.walletType}
463463 walletHdPath={props.walletHdPath}
464+ networkType={props.networkType}
464465 // Tx
465466 txn={state.txn}
466467 stx={state.stx}
@@ -498,6 +499,7 @@ class IssueChild extends React.Component {
498499 { state.txError.value }
499500 </Warning>
500501 }
502+
501503 </Col>
502504 </Row>
503505 )
src/views/SetKeys.js+1
@@ -329,6 +329,7 @@ class SetKeys extends React.Component {
329329 contracts={props.contracts}
330330 wallet={props.wallet}
331331 walletType={props.walletType}
332+ networkType={props.networkType}
332333 // Tx
333334 txn={state.txn}
334335 stx={state.stx}
src/views/SetProxy.js+2
@@ -293,6 +293,7 @@ class SetProxy extends React.Component {
293293 'Generator to generate a keypair.'
294294 }
295295 </P>
296+
296297 <AddressInput
297298 className='mono mt-8'
298299 prop-size='lg'
@@ -320,6 +321,7 @@ class SetProxy extends React.Component {
320321 wallet={props.wallet}
321322 walletType={props.walletType}
322323 walletHdPath={props.walletHdPath}
324+ networkType={props.networkType}
323325 // Tx
324326 txn={state.txn}
325327 stx={state.stx}
src/views/Transfer.js+2
@@ -265,6 +265,7 @@ class Transfer extends React.Component {
265265 You may cancel the transfer until the transfer is accepted.`
266266 }
267267 </P>
268+
268269 <AddressInput
269270 className={'mono mt-8'}
270271 prop-size='lg'
@@ -292,6 +293,7 @@ class Transfer extends React.Component {
292293 wallet={props.wallet}
293294 walletType={props.walletType}
294295 walletHdPath={props.walletHdPath}
296+ networkType={props.networkType}
295297 // Tx
296298 txn={state.txn}
297299 stx={state.stx}