Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is mining a pubkey maybe cryptographically dubious? #33

Open
gwillen opened this issue Sep 13, 2023 · 10 comments
Open

Why is mining a pubkey maybe cryptographically dubious? #33

gwillen opened this issue Sep 13, 2023 · 10 comments

Comments

@gwillen
Copy link

gwillen commented Sep 13, 2023

I had trouble finding where the note to this effect was originally added to the documentation. I was hoping for some kind of explanation of just how dubious.

@jb55
Copy link
Owner

jb55 commented Sep 15, 2023 via email

@gwillen
Copy link
Author

gwillen commented Sep 15, 2023

Well, I was specifically wondering what would make it more dubious than just regular key generation. After reading the source, I'm assuming it's about the fast trick for generating the next candidate, at the bottom of the loop?

@jb55
Copy link
Owner

jb55 commented Sep 16, 2023 via email

@gwillen
Copy link
Author

gwillen commented Sep 16, 2023

I am also not a cryptographer but I have worked with a few. I'm pretty sure grinding itself is fine, I'm pretty sure I had cryptographically-knowledgeable ex-coworkers who used bitcoin vanity addresses (which are ground like this.)

The xor thing is kind of sus to me, in the way of "I'm pretty sure it's fine; I couldn't come up with anything wrong with it in 5 minutes of thinking, which was enough for me to use it; but I would run it by a cryptographer to be sure."

I can try to get one of of my Blockstream ex-coworkers to look at it if you like.

@jb55
Copy link
Owner

jb55 commented Sep 16, 2023 via email

@apoelstra
Copy link

apoelstra commented Sep 17, 2023

There is no problem grinding a secret key to get some property of the public key, as long as the only thing you're filtering for is a pubkey property. (If this were a problem, then an attacker could e.g. scan the Bitcoin blockchain for public keys that naturally had a lot of 0s, and then apply whatever attack your grinding supposedly enabled, and normal non-grinding public key cryptography would be vulnerable. At least in a world where there were lots of public keys. But it is not, so you are fine.)

But this xor thing does seem super weird, and this tactic of repeatedly generating fresh independent keys is extremely slow. You should be able to get a multiple-hundred-times speedup by using e.g. bitcoin-core/secp256k1#507

@apoelstra
Copy link

Because it is not otherwise linked here, the grinding code is at

static int generate_key(secp256k1_context *ctx, struct key *key, int *difficulty)

@jb55
Copy link
Owner

jb55 commented Sep 17, 2023 via email

@apoelstra
Copy link

@jb55 even if the patch does not apply, you can get a speedup by using the public API to repeatedly call pubkey_tweak_add and seckey_tweak_add with the same fixed value (say, 1). This should still give you a massive speedup, though it will still leave a lot of performance on the table.

@jb55
Copy link
Owner

jb55 commented Sep 18, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants