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

feat: support for external libs (DO NOT MERGE) #5417

Closed
wants to merge 13 commits into from
37 changes: 37 additions & 0 deletions .github/workflows/mirror-external_libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# We push using git subrepo (https://github.com/ingydotnet/git-subrepo)
# with some logic to recover from squashed parent commits
# We first identify ourselves, needed to commit.
# Then push to subrepo, commit to master. The commit is needed
# to continue to replay. If we still hit issues such as this
# action failing due to upstream changes, a manual resolution
# PR with ./scripts/git_subrepo.sh pull will be needed.
name: Mirror Repositories
on:
schedule:
# Run the workflow every night at 2:00 AM UTC.
- cron: "0 2 * * *"
workflow_dispatch: {}

jobs:
mirror-to-noir-edwards-lib:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
guipublic marked this conversation as resolved.
Show resolved Hide resolved
- name: Push to external libs repo
run: |
SUBREPO_PATH=external_libs/noir-edwards
git config --global user.name AztecBot
git config --global user.email [email protected]
guipublic marked this conversation as resolved.
Show resolved Hide resolved

if ./scripts/git_subrepo.sh push $SUBREPO_PATH --branch=master; then
git fetch # in case a commit came after this
git rebase origin/master
git commit --amend -m "$(git log -1 --pretty=%B) [skip ci]"
git push
fi


1 change: 1 addition & 0 deletions external_libs/noir-edwards/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
12 changes: 12 additions & 0 deletions external_libs/noir-edwards/.gitrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme
;
[subrepo]
remote = https://github.com/zac-williamson/noir-edwards.git
branch = main
commit = 0016ce82cd58b6ebb0c43c271725590bcff4e755
parent = e1bcb73f8c2e2c6786faeb18b8ce070a2400635d
method = merge
cmdver = 0.4.6
7 changes: 7 additions & 0 deletions external_libs/noir-edwards/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "edwards"
type = "lib"
authors = [""]
compiler_version = ">=0.30.0"

[dependencies]
20 changes: 20 additions & 0 deletions external_libs/noir-edwards/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# noir-edwards

Optimized implementation of Twisted Edwards curves.

Uses lookup tables and maximally efficient representations of group operations (for width-4 noir) to efficiently implement scalar multiplication and multiscalar multiplication.

Cost of 1 scalar mul = 2232 gates. Marginal cost of additional muls in an msm = 972 gates.

For example usage see `test.nr`

List of potential optimizations to improve performance:

1. update barretenberg backend to identify when memory lookups always come in pairs. e.g. two MEM operations, different ids, read index is the same. backend can convert into 1 memory table with 2 values instead of 2 memory tables with 1 value

```
MEM (id: 1, read at: x1, value: x125)
MEM (id: 2, read at: x1, value: x126)
```

2. fix barretenberg bug where range checks for values <2^{14} create an unneccessary addition gate.
1 change: 1 addition & 0 deletions external_libs/noir-edwards/info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nargo compile --force && bb gates -b ./target/edwards.json
10 changes: 10 additions & 0 deletions external_libs/noir-edwards/src/bjj.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::TECurveParameterTrait;
use crate::Curve;

struct BabyJubJubParams {}
impl TECurveParameterTrait for BabyJubJubParams {
fn a() -> Field { 168700 }
fn d() -> Field { 168696 }
fn gen() -> (Field, Field) { (0x0bb77a6ad63e739b4eacb2e09d6277c12ab8d8010534e0b62893f3f6bb957051, 0x25797203f7a0b24925572e1cd16bf9edfce0051fb9e133774b3c257a872d7d8b)}
}
type BabyJubJub = Curve<BabyJubJubParams>;
Loading