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 hashing Fiat-Shamir transcript challenge without hashing to field first #474

Merged
merged 19 commits into from
Dec 21, 2023

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Dec 19, 2023

Description

Fixes #467.

This PR allows to avoid hashing to field before we hash the challenge name into the transcript. The problem with the current approach was that it wasn't that well compatible with gnark counterpart when doing recursion in-circuit.

The obvious solution was to add options to conditionally allow altering the behaviour of Fiat-Shamir instance, but this created another problem as currently the challenge names were already given as variadic arguments and we cannot have multiple.

So, I removed mandatory challenge name fixing when initializing transcript and added an option to optionally fix them. Now, if the challenge names are not given then we can bind to new challenges on the go.

This allowed to add the option for avoiding the hash to field before hashing the challenge name into the transcript. Added edge case check where if hash to field is requested but we do not have the method.

This fix breaks usage of Fiat-Shamir transcript, but it is fixed in gnark-crypto and I'm also pushing changes to gnark. See Consensys/gnark#974

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

Tests work. Also checked that fixes the issue in zkevm.

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

@ivokub ivokub added consolidate strengthen an existing feature zk-evm P1: High Issue priority: high labels Dec 19, 2023
@ivokub ivokub requested a review from gbotrel December 19, 2023 00:55
@ivokub ivokub self-assigned this Dec 19, 2023
@ivokub
Copy link
Collaborator Author

ivokub commented Dec 19, 2023

Seems there is some incompatibility with gnark still.

@ivokub ivokub marked this pull request as draft December 19, 2023 08:44
Copy link

📦 github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc
TestMiMCFiatShamir 0s

panic: runtime error: slice bounds out of range [:32] with capacity 31 [recovered]
	panic: runtime error: slice bounds out of range [:32] with capacity 31

goroutine 19 [running]:
testing.tRunner.func1.2({0x5ca380, 0xc0001c0168})
	/opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1548 +0x397
panic({0x5ca380?, 0xc0001c0168?})
	/opt/hostedtoolcache/go/1.21.5/x64/src/runtime/panic.go:914 +0x21f
github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc.(*digest).Write(0xc0001b7cc0, {0xc0001de400, 0x1f, 0x1f})
	/home/runner/work/gnark-crypto/gnark-crypto/ecc/bn254/fr/mimc/mimc.go:106 +0x1b7
github.com/consensys/gnark-crypto/fiat-shamir.(*Transcript).ComputeChallenge(0xc000187710, {0x5de0cb, 0x2})
	/home/runner/work/gnark-crypto/gnark-crypto/fiat-shamir/transcript.go:132 +0x555
github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc_test.TestMiMCFiatShamir(0x0?)
	/home/runner/work/gnark-crypto/gnark-crypto/ecc/bn254/fr/mimc/mimc_test.go:16 +0x45e
testing.tRunner(0xc0001976c0, 0x6209f8)
	/opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 1
	/opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1648 +0x3ad

@ivokub ivokub marked this pull request as ready for review December 20, 2023 00:15
@ivokub ivokub merged commit 1db1afb into master Dec 21, 2023
7 checks passed
@ivokub ivokub deleted the feat/raw-fs-transcript branch December 21, 2023 13:16
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.

refactor: make applying domain separation optional in Fiat-Shamir Transcript
2 participants