Consensys / eth-lightwallet

Lightweight JS Wallet for Node and the browser
MIT License
1.47k stars 504 forks source link

Infinite loop in signing.signTx() #118

Open JMLX42 opened 8 years ago

JMLX42 commented 8 years ago

Hi,

the browser (Chrome, Firefox) hangs when I call signing.signTx(). The process takes 100% CPU and never ends. Thus, I'm thinking there is an infinite loop somewhere.

Here is how I create my Keystore:

    _createKeystore: function(voteId, callback) {
        var password = 'password'; // FIXME

        lightwallet.keystore.createVault(
            { password: password },
            (err, ks) => {
                ks.keyFromPassword(password, (err, pwDerivedKey) => {
                    ks.passwordProvider = (cb) => password;

                    console.log('BlockchainAccountStore: created new keystore');
                    callback(err, ks, pwDerivedKey);
                });
            }
        );
    }

and how I create an account:

    _createAccount: function(voteId) {
        this._getKeystore(voteId, (err, ks, pwDerivedKey) => {
            if (err) {
                console.error(err);
                return;
            }

            this._keystore[voteId] = ks;
            this._pwDerivedKey[voteId] = pwDerivedKey;

            ks.generateNewAddress(pwDerivedKey);

            var addresses = ks.getAddresses();
            var address = addresses[addresses.length - 1];

            this._voterCard[voteId] = this._generateVoterCard(ks);

            this.trigger(this);
        });
    }

and here is how I create and sign the transaction:

    _getVoteTransaction: function(keystore,
                                  pwDerivedKey,
                                  address,
                                  voteContractAddress,
                                  voteContractABI,
                                  value)
    {
        var tx = lightwallet.txutils.functionTx(
            JSON.parse(voteContractABI),
            'vote',
            [value],
            {
                to: voteContractAddress,
                gasLimit: 999999,
                gasPrice: 20000000000,
                nonce: 0
            }
        );

        var signedTx = '0x' + lightwallet.signing.signTx(
            keystore,
            pwDerivedKey,
            tx,
            address
        );

        return signedTx;
    }

But the call to signing.signTx never ends. In Firefox, here is the timeout callstack:

Error: Script terminated by timeout at:
[768]</n.prototype._initArray@https://cocorico.cc/app.js:1984:3929
[768]</n.prototype._init@https://cocorico.cc/app.js:1984:3131
n@https://cocorico.cc/app.js:1984:349
[783]</Point.prototype.mul@https://cocorico.cc/app.js:2033:6288
[785]</EC.prototype.sign@https://cocorico.cc/app.js:2037:1751
[775]</</exports.sign@https://cocorico.cc/app.js:2012:3993
[776]</</module.exports/<.sign@https://cocorico.cc/app.js:2017:6745
[767]</</exports.ecsign@https://cocorico.cc/app.js:1980:4103
[764]</</Transaction.prototype.sign@https://cocorico.cc/app.js:1971:1823
[547]</</signTx@https://cocorico.cc/app.js:1372:338
[1464]</module.exports<._getVoteTransaction@https://cocorico.cc/app.js:3482:1333
[1464]</module.exports<._vote@https://cocorico.cc/app.js:3482:1445
[1403]</module.exports.listen/e@https://cocorico.cc/app.js:3360:160
[1399]</EventEmitter.prototype.emit@https://cocorico.cc/app.js:3352:708
[1403]</module.exports.trigger@https://cocorico.cc/app.js:3360:438
[1403]</module.exports.triggerAsync/<@https://cocorico.cc/app.js:3360:545
app.js:1984:3929

How can we investigate and solve this?

Thanks,

JMLX42 commented 8 years ago

Sometimes, the timeout is somewhere else:

Error: Script terminated by timeout at:
[374]</SHA256.prototype._update@https://cocorico.cc/app.js:824:6055
[371]</BlockHash.prototype.update@https://cocorico.cc/app.js:818:810
[372]</Hmac.prototype._init@https://cocorico.cc/app.js:820:528
Hmac@https://cocorico.cc/app.js:820:154
[366]</HmacDRBG.prototype._hmac@https://cocorico.cc/app.js:808:937
[366]</HmacDRBG.prototype._update@https://cocorico.cc/app.js:808:1099
[366]</HmacDRBG.prototype.generate@https://cocorico.cc/app.js:808:1829
[785]</EC.prototype.sign@https://cocorico.cc/app.js:2037:1653
[775]</</exports.sign@https://cocorico.cc/app.js:2012:3993
[776]</</module.exports/<.sign@https://cocorico.cc/app.js:2017:6745
[767]</</exports.ecsign@https://cocorico.cc/app.js:1980:4103
[764]</</Transaction.prototype.sign@https://cocorico.cc/app.js:1971:1823
[547]</</signTx@https://cocorico.cc/app.js:1372:338
[1464]</module.exports<._getVoteTransaction@https://cocorico.cc/app.js:3482:1333
[1464]</module.exports<._vote@https://cocorico.cc/app.js:3482:1445
[1403]</module.exports.listen/e@https://cocorico.cc/app.js:3360:160
[1399]</EventEmitter.prototype.emit@https://cocorico.cc/app.js:3352:708
[1403]</module.exports.trigger@https://cocorico.cc/app.js:3360:438
[1403]</module.exports.triggerAsync/<@https://cocorico.cc/app.js:3360:545
JMLX42 commented 8 years ago
npm cache clear
rm -rf node_modules
npm install

and then rebuilding my app seams to have fixed the problem. I'm letting this open just in case it's not really fixed/someone else can reproduce this.

Will close in a few days if I can't reproduce.

Cheers,

Pris17 commented 7 years ago

I am using eth-lightwallet to generate accounts and then sign and create contract. I am able to create a contract and send raw transaction to blockchain node. Now i want to call one of the contract function which accepts 4-5 arguements and sets those arguements in variables. But I am not able to do this. Getting error as "Cannot read property 'inputs' of undefined".. Any help appreciated