ledger.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. // This file contains the implementation for interacting with the Ledger hardware
  17. // wallets. The wire protocol spec can be found in the Ledger Blue GitHub repo:
  18. // https://raw.githubusercontent.com/LedgerHQ/blue-app-eth/master/doc/ethapp.asc
  19. package usbwallet
  20. import (
  21. "encoding/binary"
  22. "encoding/hex"
  23. "errors"
  24. "fmt"
  25. "io"
  26. "math/big"
  27. "github.com/ethereum/go-ethereum/accounts"
  28. "github.com/ethereum/go-ethereum/common"
  29. "github.com/ethereum/go-ethereum/common/hexutil"
  30. "github.com/ethereum/go-ethereum/core/types"
  31. "github.com/ethereum/go-ethereum/crypto"
  32. "github.com/ethereum/go-ethereum/log"
  33. "github.com/ethereum/go-ethereum/rlp"
  34. )
  35. // ledgerOpcode is an enumeration encoding the supported Ledger opcodes.
  36. type ledgerOpcode byte
  37. // ledgerParam1 is an enumeration encoding the supported Ledger parameters for
  38. // specific opcodes. The same parameter values may be reused between opcodes.
  39. type ledgerParam1 byte
  40. // ledgerParam2 is an enumeration encoding the supported Ledger parameters for
  41. // specific opcodes. The same parameter values may be reused between opcodes.
  42. type ledgerParam2 byte
  43. const (
  44. ledgerOpRetrieveAddress ledgerOpcode = 0x02 // Returns the public key and Ethereum address for a given BIP 32 path
  45. ledgerOpSignTransaction ledgerOpcode = 0x04 // Signs an Ethereum transaction after having the user validate the parameters
  46. ledgerOpGetConfiguration ledgerOpcode = 0x06 // Returns specific wallet application configuration
  47. ledgerOpSignTypedMessage ledgerOpcode = 0x0c // Signs an Ethereum message following the EIP 712 specification
  48. ledgerP1DirectlyFetchAddress ledgerParam1 = 0x00 // Return address directly from the wallet
  49. ledgerP1InitTypedMessageData ledgerParam1 = 0x00 // First chunk of Typed Message data
  50. ledgerP1InitTransactionData ledgerParam1 = 0x00 // First transaction data block for signing
  51. ledgerP1ContTransactionData ledgerParam1 = 0x80 // Subsequent transaction data block for signing
  52. ledgerP2DiscardAddressChainCode ledgerParam2 = 0x00 // Do not return the chain code along with the address
  53. )
  54. // errLedgerReplyInvalidHeader is the error message returned by a Ledger data exchange
  55. // if the device replies with a mismatching header. This usually means the device
  56. // is in browser mode.
  57. var errLedgerReplyInvalidHeader = errors.New("ledger: invalid reply header")
  58. // errLedgerInvalidVersionReply is the error message returned by a Ledger version retrieval
  59. // when a response does arrive, but it does not contain the expected data.
  60. var errLedgerInvalidVersionReply = errors.New("ledger: invalid version reply")
  61. // ledgerDriver implements the communication with a Ledger hardware wallet.
  62. type ledgerDriver struct {
  63. device io.ReadWriter // USB device connection to communicate through
  64. version [3]byte // Current version of the Ledger firmware (zero if app is offline)
  65. browser bool // Flag whether the Ledger is in browser mode (reply channel mismatch)
  66. failure error // Any failure that would make the device unusable
  67. log log.Logger // Contextual logger to tag the ledger with its id
  68. }
  69. // newLedgerDriver creates a new instance of a Ledger USB protocol driver.
  70. func newLedgerDriver(logger log.Logger) driver {
  71. return &ledgerDriver{
  72. log: logger,
  73. }
  74. }
  75. // Status implements usbwallet.driver, returning various states the Ledger can
  76. // currently be in.
  77. func (w *ledgerDriver) Status() (string, error) {
  78. if w.failure != nil {
  79. return fmt.Sprintf("Failed: %v", w.failure), w.failure
  80. }
  81. if w.browser {
  82. return "Ethereum app in browser mode", w.failure
  83. }
  84. if w.offline() {
  85. return "Ethereum app offline", w.failure
  86. }
  87. return fmt.Sprintf("Ethereum app v%d.%d.%d online", w.version[0], w.version[1], w.version[2]), w.failure
  88. }
  89. // offline returns whether the wallet and the Ethereum app is offline or not.
  90. //
  91. // The method assumes that the state lock is held!
  92. func (w *ledgerDriver) offline() bool {
  93. return w.version == [3]byte{0, 0, 0}
  94. }
  95. // Open implements usbwallet.driver, attempting to initialize the connection to the
  96. // Ledger hardware wallet. The Ledger does not require a user passphrase, so that
  97. // parameter is silently discarded.
  98. func (w *ledgerDriver) Open(device io.ReadWriter, passphrase string) error {
  99. w.device, w.failure = device, nil
  100. _, err := w.ledgerDerive(accounts.DefaultBaseDerivationPath)
  101. if err != nil {
  102. // Ethereum app is not running or in browser mode, nothing more to do, return
  103. if err == errLedgerReplyInvalidHeader {
  104. w.browser = true
  105. }
  106. return nil
  107. }
  108. // Try to resolve the Ethereum app's version, will fail prior to v1.0.2
  109. if w.version, err = w.ledgerVersion(); err != nil {
  110. w.version = [3]byte{1, 0, 0} // Assume worst case, can't verify if v1.0.0 or v1.0.1
  111. }
  112. return nil
  113. }
  114. // Close implements usbwallet.driver, cleaning up and metadata maintained within
  115. // the Ledger driver.
  116. func (w *ledgerDriver) Close() error {
  117. w.browser, w.version = false, [3]byte{}
  118. return nil
  119. }
  120. // Heartbeat implements usbwallet.driver, performing a sanity check against the
  121. // Ledger to see if it's still online.
  122. func (w *ledgerDriver) Heartbeat() error {
  123. if _, err := w.ledgerVersion(); err != nil && err != errLedgerInvalidVersionReply {
  124. w.failure = err
  125. return err
  126. }
  127. return nil
  128. }
  129. // Derive implements usbwallet.driver, sending a derivation request to the Ledger
  130. // and returning the Ethereum address located on that derivation path.
  131. func (w *ledgerDriver) Derive(path accounts.DerivationPath) (common.Address, error) {
  132. return w.ledgerDerive(path)
  133. }
  134. // SignTx implements usbwallet.driver, sending the transaction to the Ledger and
  135. // waiting for the user to confirm or deny the transaction.
  136. //
  137. // Note, if the version of the Ethereum application running on the Ledger wallet is
  138. // too old to sign EIP-155 transactions, but such is requested nonetheless, an error
  139. // will be returned opposed to silently signing in Homestead mode.
  140. func (w *ledgerDriver) SignTx(path accounts.DerivationPath, tx *types.Transaction, chainID *big.Int) (common.Address, *types.Transaction, error) {
  141. // If the Ethereum app doesn't run, abort
  142. if w.offline() {
  143. return common.Address{}, nil, accounts.ErrWalletClosed
  144. }
  145. // Ensure the wallet is capable of signing the given transaction
  146. if chainID != nil && w.version[0] <= 1 && w.version[1] <= 0 && w.version[2] <= 2 {
  147. //lint:ignore ST1005 brand name displayed on the console
  148. return common.Address{}, nil, fmt.Errorf("Ledger v%d.%d.%d doesn't support signing this transaction, please update to v1.0.3 at least", w.version[0], w.version[1], w.version[2])
  149. }
  150. // All infos gathered and metadata checks out, request signing
  151. return w.ledgerSign(path, tx, chainID)
  152. }
  153. // SignTypedMessage implements usbwallet.driver, sending the message to the Ledger and
  154. // waiting for the user to sign or deny the transaction.
  155. //
  156. // Note: this was introduced in the ledger 1.5.0 firmware
  157. func (w *ledgerDriver) SignTypedMessage(path accounts.DerivationPath, domainHash []byte, messageHash []byte) ([]byte, error) {
  158. // If the Ethereum app doesn't run, abort
  159. if w.offline() {
  160. return nil, accounts.ErrWalletClosed
  161. }
  162. // Ensure the wallet is capable of signing the given transaction
  163. if w.version[0] < 1 && w.version[1] < 5 {
  164. //lint:ignore ST1005 brand name displayed on the console
  165. return nil, fmt.Errorf("Ledger version >= 1.5.0 required for EIP-712 signing (found version v%d.%d.%d)", w.version[0], w.version[1], w.version[2])
  166. }
  167. // All infos gathered and metadata checks out, request signing
  168. return w.ledgerSignTypedMessage(path, domainHash, messageHash)
  169. }
  170. // ledgerVersion retrieves the current version of the Ethereum wallet app running
  171. // on the Ledger wallet.
  172. //
  173. // The version retrieval protocol is defined as follows:
  174. //
  175. // CLA | INS | P1 | P2 | Lc | Le
  176. // ----+-----+----+----+----+---
  177. // E0 | 06 | 00 | 00 | 00 | 04
  178. //
  179. // With no input data, and the output data being:
  180. //
  181. // Description | Length
  182. // ---------------------------------------------------+--------
  183. // Flags 01: arbitrary data signature enabled by user | 1 byte
  184. // Application major version | 1 byte
  185. // Application minor version | 1 byte
  186. // Application patch version | 1 byte
  187. func (w *ledgerDriver) ledgerVersion() ([3]byte, error) {
  188. // Send the request and wait for the response
  189. reply, err := w.ledgerExchange(ledgerOpGetConfiguration, 0, 0, nil)
  190. if err != nil {
  191. return [3]byte{}, err
  192. }
  193. if len(reply) != 4 {
  194. return [3]byte{}, errLedgerInvalidVersionReply
  195. }
  196. // Cache the version for future reference
  197. var version [3]byte
  198. copy(version[:], reply[1:])
  199. return version, nil
  200. }
  201. // ledgerDerive retrieves the currently active Ethereum address from a Ledger
  202. // wallet at the specified derivation path.
  203. //
  204. // The address derivation protocol is defined as follows:
  205. //
  206. // CLA | INS | P1 | P2 | Lc | Le
  207. // ----+-----+----+----+-----+---
  208. // E0 | 02 | 00 return address
  209. // 01 display address and confirm before returning
  210. // | 00: do not return the chain code
  211. // | 01: return the chain code
  212. // | var | 00
  213. //
  214. // Where the input data is:
  215. //
  216. // Description | Length
  217. // -------------------------------------------------+--------
  218. // Number of BIP 32 derivations to perform (max 10) | 1 byte
  219. // First derivation index (big endian) | 4 bytes
  220. // ... | 4 bytes
  221. // Last derivation index (big endian) | 4 bytes
  222. //
  223. // And the output data is:
  224. //
  225. // Description | Length
  226. // ------------------------+-------------------
  227. // Public Key length | 1 byte
  228. // Uncompressed Public Key | arbitrary
  229. // Ethereum address length | 1 byte
  230. // Ethereum address | 40 bytes hex ascii
  231. // Chain code if requested | 32 bytes
  232. func (w *ledgerDriver) ledgerDerive(derivationPath []uint32) (common.Address, error) {
  233. // Flatten the derivation path into the Ledger request
  234. path := make([]byte, 1+4*len(derivationPath))
  235. path[0] = byte(len(derivationPath))
  236. for i, component := range derivationPath {
  237. binary.BigEndian.PutUint32(path[1+4*i:], component)
  238. }
  239. // Send the request and wait for the response
  240. reply, err := w.ledgerExchange(ledgerOpRetrieveAddress, ledgerP1DirectlyFetchAddress, ledgerP2DiscardAddressChainCode, path)
  241. if err != nil {
  242. return common.Address{}, err
  243. }
  244. // Discard the public key, we don't need that for now
  245. if len(reply) < 1 || len(reply) < 1+int(reply[0]) {
  246. return common.Address{}, errors.New("reply lacks public key entry")
  247. }
  248. reply = reply[1+int(reply[0]):]
  249. // Extract the Ethereum hex address string
  250. if len(reply) < 1 || len(reply) < 1+int(reply[0]) {
  251. return common.Address{}, errors.New("reply lacks address entry")
  252. }
  253. hexstr := reply[1 : 1+int(reply[0])]
  254. // Decode the hex sting into an Ethereum address and return
  255. var address common.Address
  256. if _, err = hex.Decode(address[:], hexstr); err != nil {
  257. return common.Address{}, err
  258. }
  259. return address, nil
  260. }
  261. // ledgerSign sends the transaction to the Ledger wallet, and waits for the user
  262. // to confirm or deny the transaction.
  263. //
  264. // The transaction signing protocol is defined as follows:
  265. //
  266. // CLA | INS | P1 | P2 | Lc | Le
  267. // ----+-----+----+----+-----+---
  268. // E0 | 04 | 00: first transaction data block
  269. // 80: subsequent transaction data block
  270. // | 00 | variable | variable
  271. //
  272. // Where the input for the first transaction block (first 255 bytes) is:
  273. //
  274. // Description | Length
  275. // -------------------------------------------------+----------
  276. // Number of BIP 32 derivations to perform (max 10) | 1 byte
  277. // First derivation index (big endian) | 4 bytes
  278. // ... | 4 bytes
  279. // Last derivation index (big endian) | 4 bytes
  280. // RLP transaction chunk | arbitrary
  281. //
  282. // And the input for subsequent transaction blocks (first 255 bytes) are:
  283. //
  284. // Description | Length
  285. // ----------------------+----------
  286. // RLP transaction chunk | arbitrary
  287. //
  288. // And the output data is:
  289. //
  290. // Description | Length
  291. // ------------+---------
  292. // signature V | 1 byte
  293. // signature R | 32 bytes
  294. // signature S | 32 bytes
  295. func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction, chainID *big.Int) (common.Address, *types.Transaction, error) {
  296. // Flatten the derivation path into the Ledger request
  297. path := make([]byte, 1+4*len(derivationPath))
  298. path[0] = byte(len(derivationPath))
  299. for i, component := range derivationPath {
  300. binary.BigEndian.PutUint32(path[1+4*i:], component)
  301. }
  302. // Create the transaction RLP based on whether legacy or EIP155 signing was requested
  303. var (
  304. txrlp []byte
  305. err error
  306. )
  307. if chainID == nil {
  308. if txrlp, err = rlp.EncodeToBytes([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}); err != nil {
  309. return common.Address{}, nil, err
  310. }
  311. } else {
  312. if txrlp, err = rlp.EncodeToBytes([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), chainID, big.NewInt(0), big.NewInt(0)}); err != nil {
  313. return common.Address{}, nil, err
  314. }
  315. }
  316. payload := append(path, txrlp...)
  317. // Send the request and wait for the response
  318. var (
  319. op = ledgerP1InitTransactionData
  320. reply []byte
  321. )
  322. for len(payload) > 0 {
  323. // Calculate the size of the next data chunk
  324. chunk := 255
  325. if chunk > len(payload) {
  326. chunk = len(payload)
  327. }
  328. // Send the chunk over, ensuring it's processed correctly
  329. reply, err = w.ledgerExchange(ledgerOpSignTransaction, op, 0, payload[:chunk])
  330. if err != nil {
  331. return common.Address{}, nil, err
  332. }
  333. // Shift the payload and ensure subsequent chunks are marked as such
  334. payload = payload[chunk:]
  335. op = ledgerP1ContTransactionData
  336. }
  337. // Extract the Ethereum signature and do a sanity validation
  338. if len(reply) != crypto.SignatureLength {
  339. return common.Address{}, nil, errors.New("reply lacks signature")
  340. }
  341. signature := append(reply[1:], reply[0])
  342. // Create the correct signer and signature transform based on the chain ID
  343. var signer types.Signer
  344. if chainID == nil {
  345. signer = new(types.HomesteadSigner)
  346. } else {
  347. signer = types.NewEIP155Signer(chainID)
  348. signature[64] -= byte(chainID.Uint64()*2 + 35)
  349. }
  350. signed, err := tx.WithSignature(signer, signature)
  351. if err != nil {
  352. return common.Address{}, nil, err
  353. }
  354. sender, err := types.Sender(signer, signed)
  355. if err != nil {
  356. return common.Address{}, nil, err
  357. }
  358. return sender, signed, nil
  359. }
  360. // ledgerSignTypedMessage sends the transaction to the Ledger wallet, and waits for the user
  361. // to confirm or deny the transaction.
  362. //
  363. // The signing protocol is defined as follows:
  364. //
  365. // CLA | INS | P1 | P2 | Lc | Le
  366. // ----+-----+----+-----------------------------+-----+---
  367. // E0 | 0C | 00 | implementation version : 00 | variable | variable
  368. //
  369. // Where the input is:
  370. //
  371. // Description | Length
  372. // -------------------------------------------------+----------
  373. // Number of BIP 32 derivations to perform (max 10) | 1 byte
  374. // First derivation index (big endian) | 4 bytes
  375. // ... | 4 bytes
  376. // Last derivation index (big endian) | 4 bytes
  377. // domain hash | 32 bytes
  378. // message hash | 32 bytes
  379. //
  380. //
  381. //
  382. // And the output data is:
  383. //
  384. // Description | Length
  385. // ------------+---------
  386. // signature V | 1 byte
  387. // signature R | 32 bytes
  388. // signature S | 32 bytes
  389. func (w *ledgerDriver) ledgerSignTypedMessage(derivationPath []uint32, domainHash []byte, messageHash []byte) ([]byte, error) {
  390. // Flatten the derivation path into the Ledger request
  391. path := make([]byte, 1+4*len(derivationPath))
  392. path[0] = byte(len(derivationPath))
  393. for i, component := range derivationPath {
  394. binary.BigEndian.PutUint32(path[1+4*i:], component)
  395. }
  396. // Create the 712 message
  397. payload := append(path, domainHash...)
  398. payload = append(payload, messageHash...)
  399. // Send the request and wait for the response
  400. var (
  401. op = ledgerP1InitTypedMessageData
  402. reply []byte
  403. err error
  404. )
  405. // Send the message over, ensuring it's processed correctly
  406. reply, err = w.ledgerExchange(ledgerOpSignTypedMessage, op, 0, payload)
  407. if err != nil {
  408. return nil, err
  409. }
  410. // Extract the Ethereum signature and do a sanity validation
  411. if len(reply) != crypto.SignatureLength {
  412. return nil, errors.New("reply lacks signature")
  413. }
  414. signature := append(reply[1:], reply[0])
  415. return signature, nil
  416. }
  417. // ledgerExchange performs a data exchange with the Ledger wallet, sending it a
  418. // message and retrieving the response.
  419. //
  420. // The common transport header is defined as follows:
  421. //
  422. // Description | Length
  423. // --------------------------------------+----------
  424. // Communication channel ID (big endian) | 2 bytes
  425. // Command tag | 1 byte
  426. // Packet sequence index (big endian) | 2 bytes
  427. // Payload | arbitrary
  428. //
  429. // The Communication channel ID allows commands multiplexing over the same
  430. // physical link. It is not used for the time being, and should be set to 0101
  431. // to avoid compatibility issues with implementations ignoring a leading 00 byte.
  432. //
  433. // The Command tag describes the message content. Use TAG_APDU (0x05) for standard
  434. // APDU payloads, or TAG_PING (0x02) for a simple link test.
  435. //
  436. // The Packet sequence index describes the current sequence for fragmented payloads.
  437. // The first fragment index is 0x00.
  438. //
  439. // APDU Command payloads are encoded as follows:
  440. //
  441. // Description | Length
  442. // -----------------------------------
  443. // APDU length (big endian) | 2 bytes
  444. // APDU CLA | 1 byte
  445. // APDU INS | 1 byte
  446. // APDU P1 | 1 byte
  447. // APDU P2 | 1 byte
  448. // APDU length | 1 byte
  449. // Optional APDU data | arbitrary
  450. func (w *ledgerDriver) ledgerExchange(opcode ledgerOpcode, p1 ledgerParam1, p2 ledgerParam2, data []byte) ([]byte, error) {
  451. // Construct the message payload, possibly split into multiple chunks
  452. apdu := make([]byte, 2, 7+len(data))
  453. binary.BigEndian.PutUint16(apdu, uint16(5+len(data)))
  454. apdu = append(apdu, []byte{0xe0, byte(opcode), byte(p1), byte(p2), byte(len(data))}...)
  455. apdu = append(apdu, data...)
  456. // Stream all the chunks to the device
  457. header := []byte{0x01, 0x01, 0x05, 0x00, 0x00} // Channel ID and command tag appended
  458. chunk := make([]byte, 64)
  459. space := len(chunk) - len(header)
  460. for i := 0; len(apdu) > 0; i++ {
  461. // Construct the new message to stream
  462. chunk = append(chunk[:0], header...)
  463. binary.BigEndian.PutUint16(chunk[3:], uint16(i))
  464. if len(apdu) > space {
  465. chunk = append(chunk, apdu[:space]...)
  466. apdu = apdu[space:]
  467. } else {
  468. chunk = append(chunk, apdu...)
  469. apdu = nil
  470. }
  471. // Send over to the device
  472. w.log.Trace("Data chunk sent to the Ledger", "chunk", hexutil.Bytes(chunk))
  473. if _, err := w.device.Write(chunk); err != nil {
  474. return nil, err
  475. }
  476. }
  477. // Stream the reply back from the wallet in 64 byte chunks
  478. var reply []byte
  479. chunk = chunk[:64] // Yeah, we surely have enough space
  480. for {
  481. // Read the next chunk from the Ledger wallet
  482. if _, err := io.ReadFull(w.device, chunk); err != nil {
  483. return nil, err
  484. }
  485. w.log.Trace("Data chunk received from the Ledger", "chunk", hexutil.Bytes(chunk))
  486. // Make sure the transport header matches
  487. if chunk[0] != 0x01 || chunk[1] != 0x01 || chunk[2] != 0x05 {
  488. return nil, errLedgerReplyInvalidHeader
  489. }
  490. // If it's the first chunk, retrieve the total message length
  491. var payload []byte
  492. if chunk[3] == 0x00 && chunk[4] == 0x00 {
  493. reply = make([]byte, 0, int(binary.BigEndian.Uint16(chunk[5:7])))
  494. payload = chunk[7:]
  495. } else {
  496. payload = chunk[5:]
  497. }
  498. // Append to the reply and stop when filled up
  499. if left := cap(reply) - len(reply); left > len(payload) {
  500. reply = append(reply, payload...)
  501. } else {
  502. reply = append(reply, payload[:left]...)
  503. break
  504. }
  505. }
  506. return reply[:len(reply)-2], nil
  507. }