All Projects → ConsenSys → goff

ConsenSys / goff

Licence: Apache-2.0 License
goff (go finite field) is a unix-like tool that generates fast field arithmetic in Go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to goff

galois
A performant NumPy extension for Galois fields and their applications
Stars: ✭ 106 (+49.3%)
Mutual labels:  finite-fields
evm-bn
Convert fixed-point numbers to ethers big numbers and vice-versa.
Stars: ✭ 33 (-53.52%)
Mutual labels:  bignumber
Euler
The open-source computational framework for the Swift language
Stars: ✭ 37 (-47.89%)
Mutual labels:  bignumber
fflas-ffpack
FFLAS-FFPACK - Finite Field Linear Algebra Subroutines / Package
Stars: ✭ 44 (-38.03%)
Mutual labels:  finite-fields
SimpleTypes
The universal PHP library to convert any values and measures (money, weight, currency converter, length, etc.).
Stars: ✭ 56 (-21.13%)
Mutual labels:  arithmetic
BigNumber
A really long long long long long long number in C++
Stars: ✭ 37 (-47.89%)
Mutual labels:  bignumber
JavaBase
📝 Java Base Learning
Stars: ✭ 13 (-81.69%)
Mutual labels:  arithmetic
EllipticCurve
An elliptic curve library written in Swift 4
Stars: ✭ 18 (-74.65%)
Mutual labels:  finite-fields
BigInteger
Be limited not by the size of your register but by the bulk of your RAM.
Stars: ✭ 13 (-81.69%)
Mutual labels:  bignumber
klibcpp
kedixa's Cplusplus Library(timer, multiarray, unsigned_bigint, bigint, rational)
Stars: ✭ 17 (-76.06%)
Mutual labels:  bignumber
ToolGood.Algorithm
Support four arithmetic operations, Excel formulas, and support custom parameters. 支持四则运算、Excel公式语法,并支持自定义参数。
Stars: ✭ 77 (+8.45%)
Mutual labels:  arithmetic
rekenaar
Idris tactics for (commutative) monoids
Stars: ✭ 21 (-70.42%)
Mutual labels:  arithmetic
bcmath-extended
Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions.
Stars: ✭ 59 (-16.9%)
Mutual labels:  bignumber
hebimath
arbitrary precision arithmetic library
Stars: ✭ 37 (-47.89%)
Mutual labels:  bignumber
BhimIntegers
BhimIntegers🚀 is a C++ library that is useful when we are dealing with BigIntegers💥💥. We can handle big integers (integers having a size bigger than the long long int data type) and we can perform arithmetic operations📘 like addition, multiplication, subtraction, division, equality check, etc📐📐. Also, there are several functions like factorial, …
Stars: ✭ 43 (-39.44%)
Mutual labels:  bignumber
fp256
An efficient library for 256 bit integer arithmetic
Stars: ✭ 21 (-70.42%)
Mutual labels:  bignum-library
givaro
Givaro - C++ library for arithmetic and algebraic computations
Stars: ✭ 41 (-42.25%)
Mutual labels:  arithmetic
js-big-decimal
Work with large numbers on the client side with high precision.
Stars: ✭ 41 (-42.25%)
Mutual labels:  arithmetic
evoapproxlib
Library of approximate arithmetic circuits
Stars: ✭ 23 (-67.61%)
Mutual labels:  arithmetic
chop
Round matrix elements to lower precision in MATLAB
Stars: ✭ 21 (-70.42%)
Mutual labels:  arithmetic

Fast finite field arithmetic in Golang

License Go Report Card

goff (go finite field) is a unix-like tool that generates fast field arithmetic in Go.

We introduced goff in this article: the project came from the need to have performant field operations in Go. For most moduli, goff outperforms math/big and optimized libraries written in C++ or Rust.

In particular, goff modular multiplication is blazingly fast. "Faster big-integer modular multiplication for most moduli" explains the algorithmic optimization we discovered and implemented, and presents some benchmarks.

Actively developed and maintained by the team ([email protected]) behind:

Warning

goff has not been audited and is provided as-is, use at your own risk. In particular, goff makes no security guarantees such as constant time implementation or side-channel attack resistance.

goff generates code optimized for 64bits architectures. It generates optimized assembly for moduli matching the NoCarry condition on amd64 which support ADX/MULX instructions. Other targets have a fallback generic Go code.

Since v0.4.0, goff's code has been migrated into gnark-crypto. This repo contains the unix-like tool only.

Getting started

Go version

goff is tested with the last 2 major releases of Go (1.15 and 1.16).

Install goff

# dependencies
go get golang.org/x/tools/cmd/goimports
go get github.com/klauspost/asmfmt/cmd/asmfmt

# goff
go get github.com/consensys/goff

Usage

Generated API

Example API doc

API -- go.mod (recommended)

At the root of your repo:

# note that code has been migrated in gnark-crypto since v0.4.0
go get github.com/consensys/gnark-crypto

then in a main.go (that can be called using a go:generate workflow):

import (
  "github.com/consensys/gnark-crypto/field/generator"
  "github.com/consensys/gnark-crypto/field"

fp, _ = field.NewField("fp", "Element", fpModulus)

generator.GenerateFF(fp, "fp"))

Command line interface

goff

running goff version v0.4.0

Usage:
  goff [flags]

Flags:
  -e, --element string   name of the generated struct and file
  -h, --help             help for goff
  -m, --modulus string   field modulus (base 10)
  -o, --output string    destination path to create output files
  -p, --package string   package name in generated files
  -v, --version          version for goff

goff -- a short example

Running

goff -m 21888242871946452262085832188824287194645226208583 -o ./bn256/ -p bn256 -e Element

outputs the .go and .s files in ./bn256/

The generated type has an API that's similar with big.Int

Example API signature

// Mul z = x * y mod q
func (z *Element) Mul(x, y *Element) *Element 

and can be used like so:

var a, b Element
a.SetUint64(2)
b.SetString("984896738")

a.Mul(a, b)

a.Sub(a, a)
 .Add(a, b)
 .Inv(a)
 
b.Exp(b, 42)
b.Neg(b)

Build tags

goff generate optimized assembly for amd64 target.

For the Mul operation, using ADX instructions and ADOX/ADCX result in a significant performance gain.

The "default" target amd64 checks if the running architecture supports these instruction, and reverts to generic path if not. This check adds a branch and forces the function to reserve some bytes on the frame to store the argument to call _mulGeneric .

goff output can be compiled with amd64_adx flag which omits this check. Will crash if the platform running the binary doesn't support the ADX instructions (roughly, before 2016).

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. Get in touch: [email protected]

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the Apache 2 License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].