Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Implement and benchmark windowing point multiplication ops #94

Merged
merged 36 commits into from
Dec 14, 2019
Merged

Conversation

CPerezz
Copy link
Contributor

@CPerezz CPerezz commented Dec 14, 2019

Update benches to Criterion v0.3.

Implemented:

  • into_bits() for Scalar.
  • mod_4() for Scalar.
  • NAF and WINDOW_NAF computation algorithms for Scalar.
  • Refactor and optimize Half, Pow and legendre_symbol() for FieldElement and Scalar.
  • Shr implementation for Scalar.

Implemented and benchmarked

  • w - NAF Point mul.
  • Binary NAF Point mul.
  • LRSB

Closes #93 & #94 & #92

This operation is needed in order to implement
high-speed Point multiplication algorithms.

- Refactored `two_pow_k` impl for `Scalar` which wasn't
working propperly.
It gives the bit-representation of the given `Scalar`
as an array of 256 bits represented as u8's.

This method is useful in order to implement other
algorithms that require binary decomposition of a
given `Scalar`.
This is required by `BenchmarkId::new()` in order
to print the blackboxed inputs.

Also added `Panic` docs of the `inverse` function.
This algorithm performs point multiplication in with
an estimated cost of: `(t*A/2)+tD.

This may improve the status of #93
Implemented benchmarks for `FieldElement` ops and
blackboxed the inputs.
Also compared lrbs method against the double_and_add.
It performs slightly better so it's good news for #93
This finished the benchmarking refactor.
This op is a requirement for computing the
Not Adjacent Form of a number.
Which is used on the most performant Point
mul algorithms.
It does not even need to turn the `Scalar` into
bytes. We just apply & 0b0000_0011 to the first
limb.
- Implemented Non-Adjacent transformation algorithm.
- Implemented conversions from `i8` into `Scalar`.
- Add tests for both.
The benchmarks implemented show an improvement over
the `double_and_add` method currently used.
Now the function takes not just the `Scalar` but also
a the exponent of a power of 2.
Then it computes `Scalar (mod 2^exponent)`.

The exponent has to be <= 256.
This computes the width-wNAF of a positive integer.
- profile.release section created in Cargo.toml
with optimizations.
The algorithm now is working so it should be the
base for the Window-W NAF Point Mul method.
Also:
- refactored benchmarks.
- removed related tests.
- Bench all of the point ops benchmarks with
`RistrettoPoint` inputs.
We got rid of them both and applyed a simple pre-computed
constant which is `1/2 (mod l)` so we just need to
multiply the `FieldElement` by the constant and we
directly get it's half.

Everything has been reduced to the `Half` implementation now.
- `fast_even_half` should be used for even `FieldElements` only
and performs almost 4x faster than the `Half` trait impl.
- `Half` trait should be used when we don't know if the
`FieldElement` will be even or not.
- Implemented benchmarks for both functions that implement the
same operation.
- Modified `mod_sqrt()` implementation to work with the fast
`half` implementation.
- Defined `MINUS_ONE_HALF` on constants in order to not
perform an operation for which we know the result
previously on every `legendre_symbol` call.

- Refactored the function with the constant usage.

- Refactored some doc-comments on `FieldElement` functions.
Since the algorithm allows you to just divide by two
even numbers but it also manages to get always even
numbers, we can apply `fast_even_half` every iteration.
CPerezz and others added 6 commits October 22, 2019 02:43
Applied the same changes that were done in 13d484f
but for `Scalar`.

Also left `fast_half_without_modulo` for point mul
implementations.
This is the inital
draft of Sonny.
Merge branch 'windowing' of https://github.com/dusk-network/dusk-zerocaf into windowing
@CPerezz CPerezz added enhancement New feature or request testing This feature requires to be tested. speed_improvement New implementation or changes that speed up existing processes. labels Dec 14, 2019
@CPerezz CPerezz added this to the Ristretto Release milestone Dec 14, 2019
@CPerezz CPerezz self-assigned this Dec 14, 2019
@codecov
Copy link

codecov bot commented Dec 14, 2019

Codecov Report

Merging #94 into master will increase coverage by 0.73%.
The diff coverage is 99.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #94      +/-   ##
==========================================
+ Coverage   98.82%   99.55%   +0.73%     
==========================================
  Files           5        5              
  Lines        3476     4082     +606     
==========================================
+ Hits         3435     4064     +629     
+ Misses         41       18      -23
Impacted Files Coverage Δ
src/backend/u64/scalar.rs 99.89% <100%> (+0.32%) ⬆️
src/ristretto.rs 98.83% <100%> (+0.57%) ⬆️
src/edwards.rs 99.18% <100%> (+1.8%) ⬆️
src/backend/u64/field.rs 99.79% <98.18%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb39d27...dbd5b70. Read the comment docs.

@CPerezz CPerezz merged commit 0cfb242 into master Dec 14, 2019
@CPerezz CPerezz deleted the windowing branch December 14, 2019 23:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request speed_improvement New implementation or changes that speed up existing processes. testing This feature requires to be tested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#ITEM 2 - Implement windowing/sliding-window point mul operation.
2 participants