Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

BN254 precompiles design #386

Closed
han0110 opened this issue Feb 14, 2023 · 2 comments
Closed

BN254 precompiles design #386

han0110 opened this issue Feb 14, 2023 · 2 comments
Assignees

Comments

@han0110
Copy link
Contributor

han0110 commented Feb 14, 2023

In our current EVM circuit strategy, implementing BN254 precomiles inline seems to be impractical (probably fine to do add but definitely not fine for scalar mul or pairing), so we could delegate the computation to another sub-circuit BN254 circuit built from halo2wrong, then communicate the input by bn254_table. First we need to estimate how many different input could happen inside a single block (30M gas):

Operation Worst Case Gas Cost Maximum Different Input Row Cost 1
BN254Add ≥ 100 + 150 ≤ 120000 ≈ 216.87 257 ≈ 28.01
BN254SalarMul ≥ 100 + 6000 ≤ 4919 ≈ 212.26 41880 ≈ 215.35
BN254Pairing ≥ 100 + 45000 ≤ 666 ≈ 29.38 ?

The maximum different input seems small enough to be packed into a single table.

But there is a problem, the pairing input could be variable size, for the table we could simply use RLC the sync the bytes, but for the BN254 circuit it needs to be able to handle variable size input.

So we could follow the Keccak circuit design, to repeat the region add_gt_and_pairing, which also checks if the output is identity, but the row cost of this region will be much more expensive than other 2 operations so it could be an easy thing to exploit (e.g. a transaction with 30M gas repeating calling pairing).

Footnotes

  1. Row cost is estimated using https://github.com/privacy-scaling-explorations/halo2wrong/tree/v2 and the could be easily reduced by allocating more advice columns (but for sure more cost on prover/verifier).

@aguzmant103 aguzmant103 moved this to 📋 Refined Backlog in zkEVM Community Edition Feb 16, 2023
@aguzmant103 aguzmant103 moved this from 📋 Refined Backlog to 🏗 In progress in zkEVM Community Edition Mar 2, 2023
@ChihChengLiang ChihChengLiang linked a pull request Jun 14, 2023 that will close this issue
@ChihChengLiang ChihChengLiang moved this from 🏗 In progress to Milestone Tasks in zkEVM Community Edition Jun 20, 2023
@ed255 ed255 moved this from Milestone Tasks to 🆕 Product Backlog Items in zkEVM Community Edition Jun 29, 2023
@ChihChengLiang ChihChengLiang moved this from 🆕 Product Backlog Items to Milestone Tasks in zkEVM Community Edition Jul 3, 2023
@KimiWu123 KimiWu123 self-assigned this Oct 27, 2023
@KimiWu123
Copy link
Contributor

HI @han0110, I think this issue was addressed by #500 and we could close this. What do you think?

@han0110
Copy link
Contributor Author

han0110 commented Nov 27, 2023

Sounds good to me

@han0110 han0110 closed this as completed Nov 27, 2023
@KimiWu123 KimiWu123 moved this from Milestone Tasks to ✅ Done in zkEVM Community Edition Nov 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants