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

Implementation of tx circuit (shortcut 1) #484

Merged
merged 15 commits into from May 31, 2022
Merged

Implementation of tx circuit (shortcut 1) #484

merged 15 commits into from May 31, 2022

Conversation

ed255
Copy link
Member

@ed255 ed255 commented May 2, 2022

This is the implementation of the Transaction Circuit as specified in https://github.com/appliedzkp/zkevm-specs/blob/master/specs/transactions-proof.md#circuit-behaviour-shortcut-1

Depends on:


New dependencies to the zkevm-circuits subcrate:

  • halo2wrong subcrates. This is where the ECDSA verification chip is implemented. This dependency uses halo2 and this means that we'll require the version of halo2 used in halo2wrong and zkevm-circuits to match.
  • group: Required for field and curve traits
  • libsecp256k1: Requiered to perform the ECDSA public key recovery with access to the public key coordinates.
  • rlp: Required to calculate the RLP of the transaction to get the transaction hash (to sign)
  • num-bigint: Used to hold an integer bigger than the field, to latter apply mod Fq (this is required for the message hash in the ECDSA signature operation)
  • subtle: Used to map CtOption to Result

The added tests for tx_circuit use k=19, which use a lot of memory even using the MockProver. Rust tests run in parallel by default, which may make the tests run out of memory when the tx_circuit tests are run concurrently with other tests. For this reason I've split the tests into "light" (which are all the test declared previously), and "heavy" which are marked with ignore and start with "serial_" and are run in a different step in serial both in the github actions and Makefile.


Notes on current implementation:

  • Columns used: ~205
  • Rows per tx: ~170k

@ed255 ed255 requested a review from a team as a code owner May 2, 2022 10:30
@ed255 ed255 requested review from ChihChengLiang and removed request for a team May 2, 2022 10:30
@ed255 ed255 marked this pull request as draft May 2, 2022 10:30
@github-actions github-actions bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label May 2, 2022
@ed255 ed255 marked this pull request as ready for review May 16, 2022 09:38
@github-actions github-actions bot added the CI Issues related to the Continuous Integration mechanisms of the repository. label May 16, 2022
@ed255 ed255 force-pushed the feature/tx-circuit branch 3 times, most recently from 5042e3c to 914c2bd Compare May 16, 2022 17:30
@ed255 ed255 changed the title [WIP] Implementation of tx circuit (shortcut 1) Implementation of tx circuit (shortcut 1) May 17, 2022
@ed255 ed255 requested a review from adria0 May 17, 2022 09:49
Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

Looking fine so far. Amazing work.

Haven't checked everything, as I want to do a second review once the first comments are discussed/addressed :)

Comment on lines +32 to +36
ecdsa = { git = "https://github.com/appliedzkp/halo2wrong", rev = "92b96893b5699ff40723e201a2416313aeafd267", features = ["kzg"] }
secp256k1 = { git = "https://github.com/appliedzkp/halo2wrong", rev = "92b96893b5699ff40723e201a2416313aeafd267", features = ["kzg"] }
ecc = { git = "https://github.com/appliedzkp/halo2wrong", rev = "92b96893b5699ff40723e201a2416313aeafd267", features = ["kzg"] }
maingate = { git = "https://github.com/appliedzkp/halo2wrong", rev = "92b96893b5699ff40723e201a2416313aeafd267", features = ["kzg"] }
integer = { git = "https://github.com/appliedzkp/halo2wrong", rev = "92b96893b5699ff40723e201a2416313aeafd267", features = ["kzg"] }
Copy link
Member

Choose a reason for hiding this comment

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

We should release a tag as we do for halo2_proofs. Otherways this might be hard to track in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree!

zkevm-circuits/src/tx_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit.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
eth-types/src/geth_types.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit/sign_verify.rs Show resolved Hide resolved
zkevm-circuits/src/tx_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/tx_circuit.rs Outdated 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
// by keccak table lookup, where pub_key_bytes is built from the pub_key
// in the ecdsa_chip
// keccak lookup
meta.lookup_any("keccak", |meta| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just thinking out loud to @CPerezz. Wondering what interface can we add to keccak config to simplify this gate.

Copy link
Member

Choose a reason for hiding this comment

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

I thought the same! ahhahah

That's why I wanted to meet with you. Since we can do a proxy-table to simplify the API (at a cost obviously). And I thought that once the state_tag stuff is handled (I'm working on it), We should meet with @miha-stopar and @ed255 to see what are they expecting exactly as API.

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
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 overall

ed255 added 14 commits May 27, 2022 12:40
Implement the Tx Circuit as specified in
https://github.com/appliedzkp/zkevm-specs/blob/master/specs/transactions-proof.md#circuit-behaviour-shortcut-1

This implementation uses ~205 columns and ~170k rows per transaction.

New dependencies to the zkevm-circuits subcrate:
- `halo2wrong` subcrates.  This is where the ECDSA verification chip is
  implemented.  This dependency uses `halo2` and this means that we'll
  require the version of `halo2` used in `halo2wrong` and
  `zkevm-circuits` to match.
- `group`: Required for field and curve traits
- `libsecp256k1`: Requiered to perform the ECDSA public key recovery
  with access to the public key coordinates.
- `rlp`: Required to calculate the RLP of the transaction to get the
  transaction hash (to sign)
- `num-bigint`: Used to hold an integer bigger than the field, to latter
  apply mod Fq (this is required for the message hash in the ECDSA
  signature operation)
- `subtle`: Used to map `CtOption` to `Result`
Copy link
Member

@adria0 adria0 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 @ed255 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Issues related to the Continuous Integration mechanisms of the repository. crate-eth-types Issues related to the eth-types workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants