got "0xNaN" when rlp decode number field
eiTT-01 opened this issue · 0 comments
eiTT-01 commented
Description
When I try to decode a raw tx and then retrive its transaction id or singer, I just got null. After that I found it's caused by rlp decode.
Actual behavior
let clauses = [{
to: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed',
value: 0,
data: '0x'
}]
let body = {
chainTag: 0x9a,
blockRef: '0x0000000000000000',
expiration: 32,
clauses: clauses,
gasPriceCoef: 0,
gas: 21000,
dependsOn: null,
nonce: 12345678
}
let tx = new Transaction(body)
let signingHash = cry.blake2b256(tx.encode())
tx.signature = cry.secp256k1.sign(signingHash, /* private key here */)
let raw = tx.encode()
let decoded = Transaction.decode(raw)
Decoded Transactin:
{
"body": {
"chainTag": 154,
"blockRef": "0x0000000000000000",
"expiration": 32,
"clauses": [
{
"to": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed",
"value": "0xNaN", // wrong
"data": "0x"
}
],
"gasPriceCoef": "0xNaN", // wrong
"gas": 21000,
"dependsOn": null,
"nonce": 12345678,
"reserved": []
},
"signature": / * sig buffer */
}
}
Suggestion
update rlp.ts
file:
#89 const bn = new BigNumber('0x' + buf.toString('hex'))
to:
#89 const bn = new BigNumber(buf.toString('hex'), 16)