Skip to content

performance improvements#1307

Merged
adecaro merged 8 commits into
mainfrom
f-perf-dlog-prover
Feb 5, 2026
Merged

performance improvements#1307
adecaro merged 8 commits into
mainfrom
f-perf-dlog-prover

Conversation

@adecaro

@adecaro adecaro commented Jan 31, 2026

Copy link
Copy Markdown
Contributor

This PR introduces the following improvements:

  • use of MultiScalarMul for the computation of the commitment
  • pre-computation of powers of 2, sums of powers of 2, and Zr elements from 0 to 64
  • better use of mathlib where possible.

This PR depends on IBM/mathlib#42

@adecaro adecaro force-pushed the f-perf-dlog-prover branch from 8a18e60 to bd2c21d Compare February 2, 2026 15:09
@adecaro adecaro self-assigned this Feb 2, 2026
@adecaro adecaro added this to the Q1/26 milestone Feb 2, 2026
@adecaro adecaro changed the title use MultiScalarMul performance improvements Feb 2, 2026
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>

# Conflicts:
#	go.mod
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
@adecaro adecaro force-pushed the f-perf-dlog-prover branch from a99ac22 to 2e1fcbd Compare February 5, 2026 06:32
Comment on lines +48 to +62
func Zero(c *math.Curve) *math.Zr {
return NewCachedZrFromInt(c, 0)
}

// One returns the curve element representing 1 in Zr. It prefers the
// cached value when present.
func One(c *math.Curve) *math.Zr {
return NewCachedZrFromInt(c, 1)
}

// Two returns the curve element representing 2 in Zr. It prefers the
// cached value when present.
func Two(c *math.Curve) *math.Zr {
return NewCachedZrFromInt(c, 2)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't a small number X simply correspond to (0,0,...,X) in math.Zr? How much does caching these values save?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero, one, and two were instantiated multiple times in the code. Having them pre-generated once and for all saves a lot of allocations in the long run.

if !ok {
logger.Warnf("no hit for [%d:%d]", c.ID(), i)
two := c.NewZrFromUint64(2)
return two.PowMod(c.NewZrFromUint64(i))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should this happen after you have populated the cache?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this happens a lot, maybe find a high power of 2 that is in the cache and multiply it by the factor that it is missing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there's Exp(Element, Big.Int) I think this will be faster than converting to Zr

@AkramBitar AkramBitar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok for me

@adecaro adecaro merged commit a415902 into main Feb 5, 2026
54 checks passed
@adecaro adecaro deleted the f-perf-dlog-prover branch February 5, 2026 09:05
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.

3 participants