Git Product home page Git Product logo

noir-bigint's Introduction

Noir BigInt

CI MIT License

DEPRECATION NOTICE: With native bigint opcodes added in Noir v0.24.0, this repository is no longer required. Use the native bigint abstractions instead of this library.

Packages

This library provides three crates:

  • biguint - custom unsigned big integer type implemented using u56 limbs
  • primefield - wrapper around biguint that implements prime field operations
  • curves - example elliptic curve libraries built using the primefield type

biguint

This crate provides a custom BigUint56 data type, allowing for computations on large unsigned integers. The integers are represented with a fixed number of limbs, each of which is a 56-bit unsigned integer.

We utilize u56 limbs for two primary reasons:

  1. 56 is divisible by 8, simplifying conversions to/from bytes.
  2. Multiplication requires a double-width intermediate value and u112 is the maximum double-width value that can be represented in Noir.

This provides various functionalities such as arithmetic operations (addition, subtraction, multiplication, division), bitwise operations (left shift, right shift), comparisons and conversions (to bytes, to bits).

primefield

This contains the PrimeField data type, which allows for efficient operations on prime field elements. This is implemented as a wrapper around the BigUint56 type and stores the values in the Montgomery form for efficient modular multiplication/reduction.

curves

This crate contains examples of the secp256k1 and the ed25519 curves implemented using the PrimeField type.

Installation

In your Nargo.toml file, add the following dependency:

[dependencies]
noir_bigint_curves = { tag = "v0.2.0", git = "https://github.com/shuklaayush/noir-bigint", directory="crates/curves" }
noir_biguint = { tag = "v0.2.0", git = "https://github.com/shuklaayush/noir-bigint", directory="crates/biguint" }
noir_bigint_primefield = { tag = "v0.2.0", git = "https://github.com/shuklaayush/noir-bigint", directory="crates/primefield" }

Testing

Tests are run using nargo:

nargo test

All tests are run as part of the CI pipeline test.yaml.

Contributing

Contributions are welcome! Please adhere to the following guidelines:

  • Open a pull request with a clear description of your changes.
  • Changes should aim to improve code efficiency or readability.
  • Add appropriate tests, ensuring all pass before submission.

Acknowledgements

Disclaimer

This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base.

noir-bigint's People

Contributors

okuyiga avatar pavlovdog avatar shuklaayush avatar skaunov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

noir-bigint's Issues

Make `BigUint` struct take generic arguments

BigUint currently defaults to 5 u56 limbs. Explore if there are ways to make it generic in <BITS_PER_LIMB, NUM_LIMBS> or <T, NUM_LIMBS> within the limitations of what is currently supported by Noir

Test case cannot be run.

I pulled the code and ran the test case in the root directory with an error message
`
Error: Nargo.toml is badly formed, could not parse.

data did not match any variant of untagged enum Manifest

Caused by:
data did not match any variant of untagged enum Manifest

Location:
crates/nargo_cli/src/cli/mod.rs:74:5
`

I am using Nargo version 0.9.0
nargo 0.9.0 (git version hash: 970c18ee29e37d35e39169005e629deed8b30b6e, is dirty: false)

Implement faster non-native modular multiplication

PrimeField currently uses the montgomery method for doing modular multiplication

// Multiplies `rhs` by `self`, returning the result.
fn mul(self: Self, other: Self) -> Self {
let (lo, hi) = self.val.mul(other.val);
PrimeField::montgomery_reduce(lo, hi)
}

This is a bottleneck right now. Explore if there are faster ways to do this

One idea is to use unconstrained functions/brillig to optimize - https://github.com/noir-lang/acvm-docs/blob/main/docs/brillig/00_intro.md

Links:

  1. https://eprint.iacr.org/2022/1470
  2. https://github.com/okuyiga/noir-mul-mod-non-determinstic/blob/master/circuits/src/main.nr
  3. https://hackmd.io/@arielg/B13JoihA8
  4. https://github.com/axiom-crypto/halo2-lib/blob/4060f2a703ca5ca3ed03fd869cfdf0c778aae240/halo2-ecc/src/bigint/carry_mod.rs

can't find crate when import subdir of git url

i try to import this lib by the readme instruction but get Error: cannot find src directory in path /home/<user>/nargo/github.com/shuklaayush/noir-bigintv0.1.0, think there's something wrong with subdir search or is there any integration test been done on this?

here, think should search for all folder with nargo.toml in multiple crate case: https://github.com/noir-lang/noir/blob/fd291971f2060438c4b529e4cb5b5911a9939418/crates/nargo/src/lib.rs#L34-L42

nargo --version output
nargo 0.7.1 (git version hash: d0110e27e225290af05134be4c9e490c79e3cb9a, is dirty: false)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.