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

gkr_nonnative intial review #1162

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Conversation

amit0365
Copy link

@amit0365 amit0365 commented Jun 12, 2024

Description

Initial draft of GKR nonnative prover and verifier functions. This can handle arbitrary fields, the variable.go file contains functions like FromBits which takes a variable and casts it as an element to perform necessary computation.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

  • TestLoadCircuit
  • TestTopSortTrivial
  • TestTopSortSingleGate
  • TestTopSortDeep
  • TestGkrVectorsEmulated

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@CLAassistant
Copy link

CLAassistant commented Jun 12, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ amit0365
❌ TheDarkMatters


amit0365 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@amit0365 amit0365 assigned amit0365 and unassigned amit0365 Jun 12, 2024
std/gkr/gkr.go Show resolved Hide resolved
std/math/emulated/element.go Outdated Show resolved Hide resolved
std/polynomial/polynomial.go Show resolved Hide resolved
Copy link
Author

@amit0365 amit0365 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emulated.Field.FromBits already does this

removed was not using these

amit0365 added 7 commits June 13, 2024 16:25
…ted it in verify -m using emulated.assertequal in verify -m removed unused frombits in element as @arya pointed -m
… popoulated it in verify -m using emulated.assertequal in verify -m removed unused frombits in element as @arya pointed -m"

This reverts commit 6cbdc74.
…ager and populated it in verify" -m "Removed unused fromBits in Element"
Added verifier in ClaimsManager and populated it in verify

Using emulated.Assertequal in verify

Removed unused fromBits in Element
Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a partial look at it (not files gkr_nonnative.go and gkr_nonnative_test.go yet). I think in general there may be a confusion what we have meant previously by "native" implementation (which I agree hasn't been the best definition).

Essentially we have been using the term "native" both for the "circuit native field element" and "machine native field element". In the context of GKR, the prover runs completely outside of the circuit working directly with field elements and we do not need to use frontend.Variable and frontend.API at all. Only when we start defining the circuit we need to use frontend.API and frontend.Variable (alternatively, emulated.Field and emulated.Element when working in circuit non-native field).

So, for defining the prover and prover data structures, we shouldn't be needing circuit variables and circuit API at all.

@@ -25,6 +32,521 @@ import (
// The only purpose of putting this definition here is to avoid the import cycles (cs/plonk <-> frontend) and (cs/r1cs <-> frontend)
type Variable interface{}

type Element [4]uint64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the implementation? Usually, when you want to perform witness assignment in gnark then it is sufficient to just assign whatever type you have:

type Circuit struct {
    A frontend.Variable
}

func Test(t *testing.T) {
    ....
    assignment := Circuit{A: 10} // also Circuit{A: fr.NewElement(10)} would work etc.
}

Maybe I have misunderstood why you have the implementation here?

std/fiat-shamir/settings.go Outdated Show resolved Hide resolved
@@ -51,6 +51,7 @@ func deriveChallengeProver(fs *cryptofiatshamir.Transcript, challengeNames []str
return challenge, challengeNames[1:], nil
}

// todo change this bind as limbs instead of bits, ask @arya if necessary
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but can leave out of scope right now. It would be better to consider it for general case (field and group elements), but group element marshalling is more complicated which we would have to change.

std/recursion/sumcheck/arithengine.go Outdated Show resolved Hide resolved
@@ -88,6 +97,10 @@ func (ee *emuEngine[FR]) Const(i *big.Int) *emulated.Element[FR] {
return ee.f.NewElement(i)
}

func (ee *emuEngine[FR]) AssertIsEqual(a, b *emulated.Element[FR]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove, does not make sense to have it in ArithEngine which is used for gate evaluation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -0,0 +1,203 @@
// Copyright 2020 Consensys Software Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you need pools.

std/polynomial/polynomial.go Outdated Show resolved Hide resolved
std/polynomial/polynomial.go Outdated Show resolved Hide resolved
std/polynomial/polynomial.go Show resolved Hide resolved
@@ -51,6 +116,43 @@ func (m MultiLin) fold(api frontend.API, at frontend.Variable) {
}
}

func (m *MultiLin) FoldParallel(api frontend.API, r frontend.Variable) utils.Task {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need it - circuit compilation happen sequentially anyway and you cannot parallelize it.

@amit0365 amit0365 self-assigned this Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants