High-Performance secp256k1 Implementation Discussion

20 replies 284 views
ericgasFull Member
Posts: 15 · Reputation: 567
#1Mar 21, 2019, 03:40 AM
Hey folks, I've been coding a super fast version of secp256k1 from scratch using C++ and CUDA. It’s got optional optimizations for x86-64 and RISC-V. Main goal? Max out performance and keep things efficient. Not about breaking cryptography or recovering keys.
6 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#2Mar 21, 2019, 04:50 AM
Totally with you on that! Your take on Fermat-based inversion and side-channel risks is spot on. Right now, this library is all about performance research. Some of the optimization paths aim for speed, not constant-time execution, especially in controlled setups. But yeah, we’re planning for side-channel resistance next.
3 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#3Mar 21, 2019, 07:19 AM
Just added OpenCL support for ESP32 and optimized a few more parts.
0 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#4Mar 21, 2019, 01:17 PM
🔥 Here’s what UltrafastSecp256k1 is all about: A zero-dependency, multi-platform secp256k1 stack that covers everything in the Bitcoin and EVM space, from basic arithmetic to complex multi-party protocols.
3 Reply Quote Share
falcon2019Full Member
Posts: 90 · Reputation: 425
#5Mar 21, 2019, 04:02 PM
The core engine includes: - Field and point arithmetic - GLV endomorphism acceleration - Precomputation tables - Deterministic nonces - Low-S normalization.
0 Reply Quote Share
0xNodeMember
Posts: 671 · Reputation: 80
#6Mar 22, 2019, 11:57 AM
For assembly and SIMD, we’ve got: - x64 assembly - ARM64 inline assembly - RISC-V + RVV - Batch inversion - AVX2 / AVX-512 operations.
3 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#7Mar 22, 2019, 03:20 PM
Your repo looks solid! I noticed your block batch inversion is something I’ve never seen in public code before. Took me weeks to get something similar sorted out, and debugging those sync issues was a nightmare.
3 Reply Quote Share
Posts: 185 · Reputation: 37
#8Mar 22, 2019, 06:16 PM
What hardware did you use for testing the RISC-V version? And can this run on Metal for Apple silicon? That'd be a first for a secp256k1 library.
1 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#9Mar 22, 2019, 09:20 PM
I’ve been using the Milk-V Mars device for testing. I also plan to port it to the ESP32 RISC-V version I ordered. I’ve tested on various platforms like STM32 and Android too. It just works everywhere without extra libraries.
3 Reply Quote Share
serHero Member
Posts: 580 · Reputation: 2321
#10Mar 23, 2019, 06:47 AM
Your multiple consecutive posts are kinda annoying and against the rules here. Just edit your last post instead. Your topic is cool, don’t mess it up with spam.
1 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#11Mar 23, 2019, 08:09 AM
Thanks for the heads up, I’ll keep that in mind.
3 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#12Mar 23, 2019, 02:10 PM
This project sounds super intriguing! Just curious, what AI tools are you using to help speed up development?
4 Reply Quote Share
the_chainFull Member
Posts: 6 · Reputation: 385
#13Mar 25, 2019, 01:12 PM
I’m relying on my 20 years of experience and various models to quickly analyze and find performance bottlenecks. Makes it easier to create platform-specific assembly code.
2 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#14Mar 25, 2019, 01:21 PM
Benchmark results against libsecp256k1 for BIP-352 pipeline are up.
4 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#15Mar 25, 2019, 02:34 PM
Hey, I checked your CUDA code, but it seems like you’re not using precomputed tables for ECMULT. With those, you could speed up the k.G process significantly. Just a thought.
4 Reply Quote Share
the_chainFull Member
Posts: 6 · Reputation: 385
#16Mar 25, 2019, 05:06 PM
Appreciate the tip! I’m focused on optimizing the CPU and MCU side first. GPU optimizations are next, and I’m wrapping up a self-audit system for code quality.
5 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#17Mar 25, 2019, 10:11 PM
UltrafastSecp256k1 v3.21 just dropped! Key updates include: - Constant-time SafeGCD scalar inverse - Quicker constant-time ECDSA signing - Stricter BIP-340 parsing - Improved audit infrastructure.
0 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#18Mar 25, 2019, 11:25 PM
You’re welcome! Glad I could help you achieve that 13x speedup.
4 Reply Quote Share
ericgasFull Member
Posts: 15 · Reputation: 567
#19Mar 26, 2019, 04:52 AM
Latest on UltrafastSecp256k1 v3.3: - Implemented GPU CABI across all languages - Added Ethereum ZK layer - 17-67x speedup for batch ops - OpenCL optimizations - Security updates and bug fixes.
1 Reply Quote Share
Posts: 3523 · Reputation: 35
#20Mar 26, 2019, 05:48 AM
Update on the Continuous Adversarial Audit Standard: Instead of a costly third-party audit, I’ve set up a continuous system that runs on every commit with tons of assertions and security tests.
1 Reply Quote Share

Related topics