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

Improve root calculation for KZG setup() #211

Merged
merged 3 commits into from
Sep 21, 2023

Conversation

chiro-hiro
Copy link

Hi guys, I'm learning KZG so I checked halo2 source code. Found some minor issues and can be improved.

                let mut root = <Bn256 as Engine>::Scalar::ROOT_OF_UNITY_INV
                    .invert()
                    .unwrap();
                for _ in k..<Bn256 as Engine>::Scalar::S {
                    root = root.square();
                }

Is equivalent to

                let root = <Bn256 as Engine>::Scalar::ROOT_OF_UNITY
                    .pow_vartime([1 << (<Bn256 as Engine>::Scalar::S - k)]);

Result:

                        root-of-unity time:   [1.4413 µs 1.4443 µs 1.4473 µs]                           
                        change: [-89.921% -89.897% -89.873%] (p = 0.00 < 0.05)
                        Performance has improved.

@chiro-hiro
Copy link
Author

@CPerezz Could you please check this?

Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

Thanks for catching this!

halo2_proofs/src/poly/kzg/commitment.rs Outdated Show resolved Hide resolved
@chiro-hiro chiro-hiro requested a review from han0110 September 20, 2023 09:27
@kilic kilic self-requested a review September 20, 2023 17:08
@han0110 han0110 merged commit 4455c2f into privacy-scaling-explorations:main Sep 21, 2023
12 checks passed
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.

3 participants