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: allow custom hash function in backends #873

Merged
merged 30 commits into from Oct 20, 2023
Merged

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Oct 19, 2023

Description

This PR implements:

  • changing the hash function for field-to-hash (used for mapping the commitment to witness in Groth16/PLONK)
  • changing the hash function for Fiat-Shamir challenge computation (in PLONK)
  • changing the hash function for KZG folding challenge computation (in PLONK)

For this, I added verifier and prover options for setting the hash functions. Additionally, I also added a way to modify verifier configuration using the assertion framework.

When the prover or verifier configuration is not modified then we are using exactly the same hash functions as before, so the proofs should be backwards compatible and most importantly, compatible with the Solidity verifer.

NB! Before merging we should get Consensys/gnark-crypto#464 merged and update the dependencies. Right now in go.mod I'm using the commit from the PR, but it would be better to use a commit from the master branch to avoid conflicts.

Related #847

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this been tested?

How has this been benchmarked?

Not benchmarked.

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

@github-actions
Copy link

📦 github.com/consensys/gnark/std/gkr
TestMiMCFullDepthNoDepSolve 0s

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb7588a]

goroutine 158597 [running]:
github.com/consensys/gnark-crypto/ecc/bn254/fr/iop.(*Polynomial).ToCanonical(0x0, 0xc000250c00?, {0xc00048b760?, 0xc0?, 0xfc2d00?})
	/home/runner/go/pkg/mod/github.com/consensys/gnark-crypto@v0.12.2-0.20231018181318-cdaa6aaee7a9/ecc/bn254/fr/iop/polynomial.go:338 +0x2a
github.com/consensys/gnark/backend/plonk/bn254.(*instance).computeNumerator.func6(0x0)
	/home/runner/work/gnark/gnark/backend/plonk/bn254/prove.go:1005 +0xc5
github.com/consensys/gnark/backend/plonk/bn254.batchApply.func1(0xc000014740?)
	/home/runner/work/gnark/gnark/backend/plonk/bn254/prove.go:1101 +0x31
created by github.com/consensys/gnark/backend/plonk/bn254.batchApply in goroutine 157232
	/home/runner/work/gnark/gnark/backend/plonk/bn254/prove.go:1100 +0x12b

@github-actions
Copy link

📦 github.com/consensys/gnark
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bls12-377
🛑 build failed

backend/groth16/bls12-377/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls12-377 [github.com/consensys/gnark.test]

backend/groth16/bls12-377/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls12-377/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bls12-381
🛑 build failed

backend/groth16/bls12-381/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls12-381 [github.com/consensys/gnark.test]

backend/groth16/bls12-381/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls12-381/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bls24-315
🛑 build failed

backend/groth16/bls24-315/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls24-315 [github.com/consensys/gnark.test]

backend/groth16/bls24-315/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls24-315/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bls24-317
🛑 build failed

backend/groth16/bls24-317/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls24-317 [github.com/consensys/gnark.test]

backend/groth16/bls24-317/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bls24-317/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bn254
🛑 build failed

backend/groth16/bn254/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bn254 [github.com/consensys/gnark.test]

backend/groth16/bn254/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bn254/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bw6-633
🛑 build failed

backend/groth16/bw6-633/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bw6-633 [github.com/consensys/gnark.test]

backend/groth16/bw6-633/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bw6-633/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/groth16/bw6-761
🛑 build failed

backend/groth16/bw6-761/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bw6-761 [github.com/consensys/gnark.test]

backend/groth16/bw6-761/prove.go:63:15: undefined: fmt

📦 github.com/consensys/gnark/backend/groth16/bw6-761/mpcsetup
🛑 build failed

📦 github.com/consensys/gnark/backend/plonk
🛑 build failed

📦 github.com/consensys/gnark/constraint
🛑 build failed

📦 github.com/consensys/gnark/examples/cubic
🛑 build failed

📦 github.com/consensys/gnark/examples/emulated
🛑 build failed

📦 github.com/consensys/gnark/examples/exponentiate
🛑 build failed

📦 github.com/consensys/gnark/examples/mimc
🛑 build failed

📦 github.com/consensys/gnark/examples/rollup
🛑 build failed

📦 github.com/consensys/gnark/frontend/cs/scs
🛑 build failed

📦 github.com/consensys/gnark/internal/regression_tests
🛑 build failed

📦 github.com/consensys/gnark/std/accumulator/merkle
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/fields_bls12381
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/fields_bn254
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/fields_bw6761
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/sw_bls12381
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/sw_bn254
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/sw_bw6761
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/emulated/sw_emulated
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/native/fields_bls12377
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/native/fields_bls24315
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/native/sw_bls12377
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/native/sw_bls24315
🛑 build failed

📦 github.com/consensys/gnark/std/algebra/native/twistededwards
🛑 build failed

📦 github.com/consensys/gnark/std/commitments/fri
🛑 build failed

📦 github.com/consensys/gnark/std/commitments/kzg
🛑 build failed

📦 github.com/consensys/gnark/std/evmprecompiles
🛑 build failed

📦 github.com/consensys/gnark/std/fiat-shamir
🛑 build failed

📦 github.com/consensys/gnark/std/gkr
🛑 build failed

📦 github.com/consensys/gnark/std/hash/mimc
🛑 build failed

📦 github.com/consensys/gnark/std/hash/sha2
🛑 build failed

📦 github.com/consensys/gnark/std/hash/sha3
🛑 build failed

📦 github.com/consensys/gnark/std/internal/logderivprecomp
🛑 build failed

📦 github.com/consensys/gnark/std/lookup/logderivlookup
🛑 build failed

📦 github.com/consensys/gnark/std/math/bits
🛑 build failed

📦 github.com/consensys/gnark/std/math/bitslice
🛑 build failed

📦 github.com/consensys/gnark/std/math/cmp
🛑 build failed

📦 github.com/consensys/gnark/std/math/emulated
🛑 build failed

📦 github.com/consensys/gnark/std/math/uints
🛑 build failed

📦 github.com/consensys/gnark/std/multicommit
🛑 build failed

📦 github.com/consensys/gnark/std/permutation/keccakf
🛑 build failed

📦 github.com/consensys/gnark/std/permutation/sha2
🛑 build failed

📦 github.com/consensys/gnark/std/polynomial
🛑 build failed

📦 github.com/consensys/gnark/std/rangecheck
🛑 build failed

📦 github.com/consensys/gnark/std/recursion/groth16
🛑 build failed

📦 github.com/consensys/gnark/std/selector
🛑 build failed

📦 github.com/consensys/gnark/std/signature/ecdsa
🛑 build failed

📦 github.com/consensys/gnark/std/signature/eddsa
🛑 build failed

📦 github.com/consensys/gnark/std/utils/test_vectors_utils
🛑 build failed

📦 github.com/consensys/gnark/test
🛑 build failed

@ivokub ivokub changed the title feat: allow custom hash-to-field function in backends feat: allow custom functions function in backends Oct 19, 2023
@ivokub ivokub marked this pull request as ready for review October 19, 2023 23:05
@ivokub ivokub self-assigned this Oct 19, 2023
@ivokub ivokub added consolidate strengthen an existing feature P1: High Issue priority: high labels Oct 19, 2023
@ivokub ivokub changed the title feat: allow custom functions function in backends feat: allow custom hash function in backends Oct 20, 2023
@ivokub ivokub added the zk-evm label Oct 20, 2023
@ivokub ivokub merged commit 653506f into master Oct 20, 2023
7 checks passed
@ivokub ivokub deleted the feat/custom-hashtofield branch October 20, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consolidate strengthen an existing feature P1: High Issue priority: high zk-evm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants