btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.23k stars 2.36k forks source link

Question: Secp256k1 it's written from scratch in go? #1570

Closed tiero closed 4 years ago

tiero commented 4 years ago

Hello!

I'm right saying that the secp256k1 curve has been implemented from scratch in go, isn't a cgo binding of the C library in bitcoin-core one right?

Someone knows what the reason for this choice? Easier to cross-compile?

Thanks

jcvernaleo commented 4 years ago

cgo is great if you absolutely need to link to c code (for example, if you need to link to CUDA or opencl libraries) but if you aren't absolutely stuck doing it, there are big advantages to pure go. The cross compiling bit you mentioned is one. The race detector is another. Being able to use the various go linters is also a big plus for pure go over cgo.

Also, at least for most people, go is easier to read than C so having things in go is a plus on that front.

Does that answer what you are asking, or am I missing some part of the question?

tiero commented 4 years ago

That's great! All of these points resonate well with me, just that you know...people every time repeat never "roll your own crypto".

I want to port to native Go also secp256k1-zkp. Would you suggest to start of from this implementation?

jrick commented 4 years ago

never "roll your own crypto"

someone has to roll it.

in this case, these aren't new bespoke algorithms being written, but well known ones simply being implemented in another language.

jcvernaleo commented 4 years ago

Yeah, agree with @jrick, 'never roll your own' mostly means don't come up with your own crypto algorithm unless you really know what you are doing. Reimplimenting is a much safer task than that.

Roasbeef commented 4 years ago

Closing as the question seems to be answered.