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

doc: include number of squares and multiplications in results #54

Open
kevaundray opened this issue May 22, 2020 · 6 comments
Open

doc: include number of squares and multiplications in results #54

kevaundray opened this issue May 22, 2020 · 6 comments
Labels
doc Improvements or additions to documentation

Comments

@kevaundray
Copy link

Perhaps add the number of squares and multiplications or doublings and additions alongside the chain length?

@mmcloughlin
Copy link
Owner

To clarify, are you talking about the results lists (readme and full results page)?

@kevaundray
Copy link
Author

kevaundray commented May 22, 2020 via email

@mmcloughlin mmcloughlin changed the title Number of squares and multiplications doc: include number of squares and multiplications in results May 23, 2020
@mmcloughlin mmcloughlin added the doc Improvements or additions to documentation label May 23, 2020
@mmcloughlin
Copy link
Owner

Yes, I agree with you on showing the add/double counts (equivalent to multiplication/square). It's common for other work on the subject to present it that way too, for example https://eprint.iacr.org/2018/1038.

When you say incorporate, do you mean use a weighting when selecting the best chain from a bunch of results?

@kevaundray
Copy link
Author

kevaundray commented May 23, 2020 via email

@mmcloughlin
Copy link
Owner

mmcloughlin commented May 23, 2020

Yep, I mean to use a weighting. For example, setting the weighting of a squaring operation to be 0.85 the weighting of a multiplication operation.

Right. I considered this a while back and forgot about it, so it didn't make it into the initial release, but I agree this would be a good feature. The fact that squares are cheaper is accounted for to some extent here:

// Find the best.
best := []exec.Result{rs[0]}
for _, r := range rs[1:] {
if len(r.Program) == len(best[0].Program) {
best = append(best, r)
} else if len(r.Program) < len(best[0].Program) {
best = []exec.Result{r}
}
}
sort.Slice(best, func(i, j int) bool {
ai := best[i].Program.Adds()
aj := best[j].Program.Adds()
ni := best[i].Algorithm.String()
nj := best[j].Algorithm.String()
return ai < aj || (ai == aj && ni < nj)
})

That is, among the shortest chains it picks the one with the fewest adds (equivalently the most doubles). After that it sorts by algorithm name... that was just a way to ensure the result was deterministic!

One possible drawback, if it has utility, is that the  actual weighting is implementation specific, so a blanket ratio may not be suitable.

Yes, agreed the exact weightings would need to be configurable.

I think there's an interesting question about what other heuristics you would use to choose the best chain, even among those that have the exact same number of adds and doubles. @briansmith in some private communication suggested both maximum number of live variables and pipeline stalls (dependencies between variables) as factors you might want to consider.

As long as you have some coarse score to narrow down to the top candidates, then you could just code generate the actual exponentiation function and benchmark it. I thought I remembered a paper that took this approach, maybe it was https://eprint.iacr.org/2019/403 but skimming it now I'm not sure.

@kevaundray
Copy link
Author

kevaundray commented May 23, 2020 via email

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

No branches or pull requests

2 participants