maci icon indicating copy to clipboard operation
maci copied to clipboard

Generate keypair: "TypeError: Invalid hex string"

Open xuhcc opened this issue 3 years ago • 8 comments

Sometimes when I call new Keypair() it fails with TypeError: Invalid hex string error. It started to happen after upgrading to 0.7.1. The error occurs at this line: https://github.com/appliedzkp/maci/blob/0a4f7cc0e355a191cc69f7b9fedb4440370a2abb/crypto/ts/index.ts#L56

I tried to debug it and noticed that Buffer.from throws type error when i.toString(16) is a 63-character string, for example:

18582ee20a67742c1a065b14b057dd78f79e9f885518a347e7956a7e6a442e1

but it doesn't throw error if i.toString(16) consists of 64 characters:

177df0660a150cdeb60d19f9383dfeb664bdd681ff2a1f990d4d84efb8347792

The error occurs only in browser environment, I can't reproduce it with node.js.

xuhcc avatar May 04 '21 10:05 xuhcc

Hi! Could you try 0.7.2 and see if it works?

weijiekoh avatar May 05 '21 11:05 weijiekoh

Nope, it still throws TypeError from time to time

xuhcc avatar May 05 '21 14:05 xuhcc

Ah, my bad, 0.7.2 didn't contain the correct build/index.js file. 0.7.3 should work instead.

weijiekoh avatar May 07 '21 11:05 weijiekoh

0.7.3 is not working at all, even MACI contract deployment fails.

xuhcc avatar May 09 '21 15:05 xuhcc

0.7.4 is working fine

xuhcc avatar May 10 '21 09:05 xuhcc

Hmmm I appear to still occasionally hit this issue using 0.7.4 - see https://github.com/ethereum/clrfund/issues/99

@weijiekoh @xuhcc - any idea how this might still be occurring? I can't seem to reproduce it consistently.

samajammin avatar Jun 20 '21 20:06 samajammin

Seems I'm not able to re-open this issue. Should I create a new one?

Thanks.

samajammin avatar Jun 20 '21 20:06 samajammin

I'm investigating now, will ping when done!

weijiekoh avatar Jun 20 '21 20:06 weijiekoh

Closing this, clr.fund confirmed they haven't had any more issues with this lately, and the error likely stemmed from passing an un-even hex value to Buffer.from, as .toString(16) may produce uneven results. Please re open if this is still an issue

ctrlc03 avatar Jan 20 '24 12:01 ctrlc03