Skip to content

perf:import the optimized aries-bbs module into idemix#67

Closed
neetance wants to merge 1 commit into
IBM:mainfrom
neetance:perf/aries-bbs-optimizations
Closed

perf:import the optimized aries-bbs module into idemix#67
neetance wants to merge 1 commit into
IBM:mainfrom
neetance:perf/aries-bbs-optimizations

Conversation

@neetance
Copy link
Copy Markdown
Contributor

Summary

Replaces the aries-bbs-go dependency with an optimized fork that eliminates the primary performance bottlenecks in BBS+ signing, verification, and proof operations. The optimized implementation is imported as an independent Go module
via a replace directive, as suggested by @adecaro.

Changes in the Optimized Fork

1. MSM Batching (bbs.go)

Replaced sequential Mul + Add calls in sumOfG1Products with Mul2 pairing to process pairs in batches, reducing the number of individual scalar multiplication calls.

2. Generator Cache (keys.go)

Introduced publicKeyGeneratorCache, a struct owned by BBSLib whose lifecycle is tied to the BBSLib instance rather than the process.

type publicKeyGeneratorCache struct {
    generators sync.Map
}

func newPublicKeyGeneratorCache() *publicKeyGeneratorCache {
    return &publicKeyGeneratorCache{}
}

func (c *publicKeyGeneratorCache) get(data []byte, curve *ml.Curve) *ml.G1 {
    if c == nil {
        return hashToG1(data, curve)
    }

    key := string(data)
    if cached, ok := c.generators.Load(key); ok {
        return cached.(*ml.G1)
    }

    generator := hashToG1(data, curve)
    cached, _ := c.generators.LoadOrStore(key, generator)

    return cached.(*ml.G1)
}

The full changes in the forked repo can be found here

Benchmark results for Idemix

I ran Benchmark_SignVerify for both before and after the changes and here are the results:

  • Before

goos: linux
goarch: amd64
pkg: github.com/IBM/idemix/bccsp
cpu: 13th Gen Intel(R) Core(TM) i5-13450HX
Benchmark_SignVerify/sign-legacy-16         	    2456	    463296 ns/op
Benchmark_SignVerify/sign-legacy-16         	    2284	    459566 ns/op
Benchmark_SignVerify/sign-legacy-16         	    2557	    451071 ns/op
Benchmark_SignVerify/sign-legacy-16         	    2367	    481330 ns/op
Benchmark_SignVerify/sign-legacy-16         	    2768	    445788 ns/op
Benchmark_SignVerify/verify-legacy-16       	    1522	    741913 ns/op
Benchmark_SignVerify/verify-legacy-16       	    1669	    729083 ns/op
Benchmark_SignVerify/verify-legacy-16       	    1592	    707307 ns/op
Benchmark_SignVerify/verify-legacy-16       	    1572	    752862 ns/op
Benchmark_SignVerify/verify-legacy-16       	    1621	    754706 ns/op
Benchmark_SignVerify/sign-aries-16          	    1614	    680451 ns/op
Benchmark_SignVerify/sign-aries-16          	    1814	    676492 ns/op
Benchmark_SignVerify/sign-aries-16          	    1867	    677873 ns/op
Benchmark_SignVerify/sign-aries-16          	    1658	    667028 ns/op
Benchmark_SignVerify/sign-aries-16          	    1694	    697726 ns/op
Benchmark_SignVerify/verify-aries-16        	    1772	    592744 ns/op
Benchmark_SignVerify/verify-aries-16        	    1852	    611659 ns/op
Benchmark_SignVerify/verify-aries-16        	    1954	    595495 ns/op
Benchmark_SignVerify/verify-aries-16        	    1888	    585800 ns/op
Benchmark_SignVerify/verify-aries-16        	    1855	    589481 ns/op
PASS
ok  	github.com/IBM/idemix/bccsp	26.345s
  • After

goos: linux
goarch: amd64
pkg: github.com/IBM/idemix/bccsp
cpu: 13th Gen Intel(R) Core(TM) i5-13450HX
Benchmark_SignVerify/sign-legacy-16                 2818            468805 ns/op
Benchmark_SignVerify/sign-legacy-16                 2437            461810 ns/op
Benchmark_SignVerify/sign-legacy-16                 2230            463701 ns/op
Benchmark_SignVerify/sign-legacy-16                 2791            425753 ns/op
Benchmark_SignVerify/sign-legacy-16                 2512            429629 ns/op
Benchmark_SignVerify/verify-legacy-16               1713            701312 ns/op
Benchmark_SignVerify/verify-legacy-16               1760            704013 ns/op
Benchmark_SignVerify/verify-legacy-16               1616            693058 ns/op
Benchmark_SignVerify/verify-legacy-16               1773            699480 ns/op
Benchmark_SignVerify/verify-legacy-16               1533            706496 ns/op
Benchmark_SignVerify/sign-aries-16                  2060            579442 ns/op
Benchmark_SignVerify/sign-aries-16                  2089            573992 ns/op
Benchmark_SignVerify/sign-aries-16                  1911            566363 ns/op
Benchmark_SignVerify/sign-aries-16                  2109            571912 ns/op
Benchmark_SignVerify/sign-aries-16                  2034            570187 ns/op
Benchmark_SignVerify/verify-aries-16                2180            554506 ns/op
Benchmark_SignVerify/verify-aries-16                1863            546916 ns/op
Benchmark_SignVerify/verify-aries-16                2268            564125 ns/op
Benchmark_SignVerify/verify-aries-16                1960            571819 ns/op
Benchmark_SignVerify/verify-aries-16                2232            556930 ns/op
PASS
ok      github.com/IBM/idemix/bccsp     26.478s
  • Comparison using benchstat

goos: linux
goarch: amd64
pkg: github.com/IBM/idemix/bccsp
cpu: 13th Gen Intel(R) Core(TM) i5-13450HX
                             │ original_bench.txt │         optimized_bench.txt         │
                             │       sec/op       │    sec/op     vs base               │
_SignVerify/sign-legacy-16           459.6µ ± ∞ ¹   461.8µ ± ∞ ¹        ~ (p=0.841 n=5)
_SignVerify/verify-legacy-16         741.9µ ± ∞ ¹   701.3µ ± ∞ ¹   -5.47% (p=0.008 n=5)
_SignVerify/sign-aries-16            677.9µ ± ∞ ¹   571.9µ ± ∞ ¹  -15.63% (p=0.008 n=5)
_SignVerify/verify-aries-16          592.7µ ± ∞ ¹   556.9µ ± ∞ ¹   -6.04% (p=0.008 n=5)
geomean                              608.4µ         566.7µ         -6.85%

We can see that aries-signing shows an improvement of 15.63% and verification an improvement of 6%

Testing

All existing tests pass with make unit-tests and make unit-tests-race

Let me know if this is good 🙏

Signed-off-by: Ankit Basu <ankitbasu14@gmail.com>
@adecaro adecaro self-requested a review May 24, 2026 06:52
@adecaro adecaro self-assigned this May 24, 2026
@adecaro
Copy link
Copy Markdown
Member

adecaro commented May 24, 2026

Hi @neetance , sorry for misleading. I meant to have aries-bbs implementation directly inside the Idemix repo as an independent go modulo. The code will be maintained in the context of Idemix so we make sure it does not become stale. Sorry for the misunderstanding 🙏

@neetance
Copy link
Copy Markdown
Contributor Author

Hi @adecaro, sorry for misunderstanding
I'll close this pr and raise another clean pr with the aries-bbs code inside a separate module inside idemix itself under bbs/
Thanks for clearing things up 🙏

@neetance neetance closed this May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants