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

Refactor Tx circuit and use challenge api #803

Conversation

han0110
Copy link
Collaborator

@han0110 han0110 commented Sep 27, 2022

This PR aims to refactor Tx circuit with challenge API.

It reuses MainGate's advice columns to create an extra random linear combination gate to get rid of 130 columns in SignVerifyChip, with the cost of few more rows to do SignVerifyChip::assign_signature_verify than previous approach. So now tests and benchmark of Tx circuit can be ran locally.

In respect to more rows (76 rows precisely) to verify a single signature, I think it should be negligible cause ecdsa verification already costs ~70k, and is still the bottleneck. Also even we have reached our bottleneck on ecdsa verification, we can actually just allocate another MainGate to double our capacity (each MainGate with RangeChip costs ~60 msm) without too much change to current code.

There is also a caveat about multi-phase: The AssignedCell will have value: Value::unknown in any phase that is not equal to current one, because we need to follow the principle that the function to of assign_{fixed,advice} will only be called once (it's a FnMut so we need to guarantee that). So it's a little bit awkward to calculate later phase witness with previous phase's AssignedCell, we need to pass the Cell and Value separately to make sure we can do the calculation and at the same time enforce the copy constraint.

And currently this behavior is not shown in MockProver, so it takes me some time to find this issue, I have also created an issue privacy-scaling-explorations/halo2#102 to propose to make MockProver to do multi-phsae synthesis just like real prover.

Todo

@github-actions github-actions bot added crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-integration-tests Issues related to the integration-tests workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements labels Sep 27, 2022
@han0110 han0110 force-pushed the feature/challenge-api-for-tx-circuit branch from e716130 to fe61a14 Compare September 27, 2022 12:39
@han0110 han0110 marked this pull request as ready for review September 27, 2022 15:18
@han0110 han0110 requested a review from a team as a code owner September 27, 2022 15:18
@han0110 han0110 requested review from CPerezz and ed255 and removed request for a team and CPerezz September 27, 2022 15:18
@ed255 ed255 linked an issue Sep 28, 2022 that may be closed by this pull request
Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

LGTM! Amazing work! Not only you updated the circuit to use the challenge API, but also optimized it removing many rows, and also cleaned up some stuff :D

I've left some questions (so that I make sure i understood everything) and a suggestion, please take a look :)

zkevm-circuits/src/tx_circuit.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Outdated Show resolved Hide resolved
@han0110 han0110 force-pushed the feature/challenge-api-for-tx-circuit branch from 885034b to ab7a796 Compare September 29, 2022 07:28
@han0110 han0110 force-pushed the feature/challenge-api-for-tx-circuit branch from ab7a796 to bf7e44d Compare September 30, 2022 05:46
@han0110 han0110 mentioned this pull request Oct 3, 2022
1 task
Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM. I did only a light review so that this pr can be merged to unblock other prs. Added a comment.

zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Outdated Show resolved Hide resolved
@han0110 han0110 force-pushed the feature/challenge-api-for-tx-circuit branch from bf7e44d to bbb5921 Compare October 4, 2022 09:55
@han0110
Copy link
Collaborator Author

han0110 commented Oct 4, 2022

Although the spec has not been merged, but since privacy-scaling-explorations/zkevm-specs#292 only adds some more description to Tx circuit, so I think we can merge this first to unblock #816.

@han0110 han0110 merged commit f0a8302 into privacy-scaling-explorations:main Oct 4, 2022
@han0110 han0110 deleted the feature/challenge-api-for-tx-circuit branch October 4, 2022 10:26
StefanosChaliasos referenced this pull request in Veridise/zkevm-circuits Oct 7, 2022
* feat: refactor tx circuit and use challenge api for it

* feat: remove `#[ignore]` for tests of tx circuit

* fix: apply suggestion and clean up

* fix: apply suggestion from @ChihChengLiang
GopherJ pushed a commit to dompute/zkevm-circuits that referenced this pull request Sep 13, 2023
* support max snark upto 16

* more tests

* fix bug in data input len

* merge required features from max_snark=29

* clean up
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-integration-tests Issues related to the integration-tests workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Tx circuit with challenge API
3 participants