trufflesuite / ganache-ui

Personal blockchain for Ethereum development
https://www.trufflesuite.com/ganache
MIT License
4.65k stars 795 forks source link

Error: Number can only safely store up to 53 bits #1079

Open ish3lan opened 5 years ago

ish3lan commented 5 years ago

I tried to sign a transaction using the sender private key, I got private key length error. I tried to sign it using the receiver private key it worked. The I signed another transaction using another receiving and sending addresses and it worked as expected (signing transaction using the sender private key).

Then I went again to send a transaction from the the first account to the second and I got this error.

screen shot 2019-01-15 at 6 20 07 pm

Error: Number can only safely store up to 53 bits
    at assert (/node_modules/ganache-core/node_modules/bn.js/lib/bn.js:6:21)
    at BN.toNumber (/node_modules/ganache-core/node_modules/bn.js/lib/bn.js:506:7)
    at Object.exports.bufferToInt (/node_modules/ganache-core/node_modules/ethereumjs-util/dist/index.js:196:40)
    at Object.number (/node_modules/ganache-core/lib/utils/to.js:112:18)
    at validateNonce (/node_modules/ganache-core/lib/statemanager.js:927:27)
    at blockchain.getQueuedNonce (/node_modules/ganache-core/lib/statemanager.js:938:7)
    at /node_modules/ganache-core/lib/blockchain_double.js:414:5
    at /node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:77:5
    at /node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:461:14
    at Object.return (/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:485:9)
    at processNode (/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:285:30)
    at processNode (/node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:521:5)
    at /node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:516:13
    at /node_modules/ganache-core/node_modules/merkle-patricia-tree/baseTrie.js:180:7
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
davidmurdoch commented 5 years ago

Thanks for reporting, @ish3lan. What version of Ganache are you using?

davidmurdoch commented 5 years ago

It looks like the nonce in the signed transaction may be too large; that is: greater than 9007199254740991 (Number.MAX_SAFE_INTEGER). Is it possible that the nonce in your signed transaction is incorrect?

ish3lan commented 5 years ago

That is right I mistakenly put the sending address in the nonce field

however the problem still exists with private keys of first and second account swapped .

On Tue, 15 Jan 2019 at 7:08 PM David Murdoch notifications@github.com wrote:

It looks like the nonce in the signed transaction may be too large; that is: greater than 9007199254740991 (Number.MAX_SAFE_INTEGER). Is it possible that the nonce in your signed transaction is incorrect?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/trufflesuite/ganache/issues/1079#issuecomment-454448386, or mute the thread https://github.com/notifications/unsubscribe-auth/AHE5fDw2EeXtDRKRRyjJRdS7eDGZvl9Wks5vDfzrgaJpZM4aBMG4

davidmurdoch commented 5 years ago

Can you paste the private key length error here?

ccowell commented 5 years ago

@ish3lan Did you make any progress on this issue? If not, please provide the error message.

Related to https://github.com/trufflesuite/ganache/issues/847

ish3lan commented 5 years ago

@davidmurdoch @ccowell This is a bit late, I am not able to regenerate the claimed scenario (swapping private keys thing), however I can confirm when I paste the full private key of the sending address I get from ganache-cli e.g. 0xc5c7e13cfd7a269be287aa6f9f1f70d225ef60dedde297068c8748d8e8f06981 I get this error:

/Udacity/Block Chain/Project 5/node_modules/ethereumjs-util/dist/index.js:369
  var sig = secp256k1.sign(msgHash, privateKey);
                      ^

RangeError: private key length is invalid
    at Object.exports.ecsign (/Udacity/Block Chain/Project 5/node_modules/ethereumjs-util/dist/index.js:369:23)
    at Transaction.sign (/Udacity/Block Chain/Project 5/node_modules/ethereumjs-tx/es5/index.js:252:23)
    at Object.<anonymous> (/Udacity/Block Chain/Project 5/index.js:42:13)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
    at startup (internal/bootstrap/node.js:300:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)

I was able to avoid this by deleting the 0x at the beginning of private key

davidmurdoch commented 5 years ago

@ish3lan Just so I understand, this last error you gave us isn't coming from Ganache, is it? Are you just saying that the format Ganache gives you for the private key (JSON-RPC UNFORMATTTED DATA; hex encoded with leading 0x) isn't what you expected?

ghost commented 5 years ago

In many blogs I've found it was a Truffle version problem. Truffle v5 would make problems of this type. They suggest to downgrade to truffle@4.1.15.

This has not been so for me. I have continue to use truffle v5. I've resolved by checking my gas limit when I sent a transaction. gasLimit: web3.utils.toHex( gas_limit ),//The maximum gas provided for this transaction (gas limit)