README.md

August 29, 2019 ยท View on GitHub

Oliver: efficient Baby-JubJub point arithmetic for smart contracts

Oliver (full name: Oliver Twisted Edwards) is a smart contract that performs elliptic curve point multiplication on the Baby-JubJub curve.

It can multiply up to 15 points (with up to 15 distinct scalars) at once.

Optimisations

Oliver is written in Huff, a low-level language that compiles to Ethereum Virtual Machine opcodes. It also uses many of the same optimisations employed by weierstrudel:

  • Shamir's trick, which combines multiple scalar multiplications into a single double-and-add loop, fixing the number of 'point doubling' operations to ~254
  • Sliding Window Non-Adjacent Form, a representation of scalar multipliers which reduces the number of 'point addition' operations to ~50 per point
  • Using the difference between the Baby-JubJub curve's 254-bit field modulus and the EVM's 256 word size to defer modular reductions until absolutely necessary

Because Baby-JubJub is a Twisted Edwards curve, a couple of optimisations from weierstrudel could not be used, namely the curve endomorphism which halved the number of point doubling operations required, and the trick whereby one could pretend points in projective coordinates had a Z value of 1. For these reasons, it's a bit less efficient than weierstrudel.

Benchmarks

Gas estimates can be obtained by running yarn benchmark.

Number of pointsApproximate gas cost (average of 25 runs)Cost per point
182,20982,209
2107,06053,530
3132,01744,006
4157,47939,370
5183,35136,670
6210,33135,055
7236,71533,816
8265,05033,131
9292,18632,465
10321,40432,140
11349,13731,740
12379,09831,592
13408,15931,397
14439,31031,379
15469,64631,310

Usage

  1. Run Oliver tests with yarn test
  2. Run Oliver benchmarks with yarn benchmark