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

Optimize bn254/groth16 solidity verifier. #376

Conversation

citizen-stig
Copy link
Contributor

Problem

Existing implementation of Pairing library allocated additional memory on each addition and multiplication, which can quadratically increase gas cost with larger public input.

This PR addresses several things:

  1. Allocates single array for each operation and reuses them between
  2. Changes declaration of input from memory to calldata. Ideally public input should be constructed off-chain and remain only in call data. It is important to notice, that caller smart contract might already do it, but EVM implicitly copy call data to memory, which is not needed in this case.

tinywell and others added 3 commits July 29, 2022 12:39
* fix  misspelled ("decsribes" ->  "describes")

* fix  misspelled ("decsribes" ->  "describes") from tmpl file and regenerate

Co-authored-by: tinywell <tinywell@tinywell.com>
@gbotrel gbotrel changed the base branch from master to develop October 4, 2022 14:23
@citizen-stig citizen-stig marked this pull request as ready for review October 4, 2022 19:08
add_input[3] = uint256({{$ki.Y.String}});
Pairing.plus_raw(add_input, add_return);
{{- end -}}
{{- end }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

test were failing because; vk_x is used in the pairing computation, while the result from add_return is not.
Will merge and do the quick fix on develop

@gbotrel gbotrel merged commit 1a93ec8 into Consensys:develop Oct 6, 2022
AlexandreBelling pushed a commit to AlexandreBelling/gnark that referenced this pull request Nov 24, 2022
* fix: misspelled ("decsribes" ->  "describes") (Consensys#339)

* fix  misspelled ("decsribes" ->  "describes")

* fix  misspelled ("decsribes" ->  "describes") from tmpl file and regenerate

Co-authored-by: tinywell <tinywell@tinywell.com>

* Fix: minor typo (Consensys#360)

Fix: minor typo

* Use shared array for input

* Fixes in the template

Co-authored-by: tinywell <zfh-zyw@163.com>
Co-authored-by: tinywell <tinywell@tinywell.com>
Co-authored-by: omahs <73983677+omahs@users.noreply.github.com>
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.

None yet

4 participants