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

feat/#1665 Precompile ECRECOVER #1720

Merged
merged 28 commits into from
Feb 19, 2024
Merged

feat/#1665 Precompile ECRECOVER #1720

merged 28 commits into from
Feb 19, 2024

Conversation

KimiWu123
Copy link
Contributor

@KimiWu123 KimiWu123 commented Dec 25, 2023

closed #1665

This PR was ported from

which manly includes,

  1. the main logic in ecrecover gadget (ecrecover.rs)
  2. signature verifcation circuiit (sig_circuit.rs). What I did is to change rlc to word lo/hi.
  3. a new table, sig_table.rs
  4. ecc circuit (ecc_circuit.rs). It's not be used in ecRecover, but it was implemented in Scroll's PR. If I removed ecc_circuit, it would be inconvienent for people porting ecAdd, ecMul or ecPairing. That's why I keep it here.
  5. dependencies update, using halo2lib (includes halo2-base and halo2-ecc)

@github-actions github-actions bot added crate-bus-mapping Issues related to the bus-mapping workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member crate-eth-types Issues related to the eth-types workspace member labels Dec 25, 2023
@KimiWu123 KimiWu123 force-pushed the feat/#1665-ecrecover branch 3 times, most recently from 4b80960 to 99d2b1c Compare December 28, 2023 04:41
@KimiWu123 KimiWu123 marked this pull request as ready for review January 8, 2024 03:06
@KimiWu123 KimiWu123 marked this pull request as draft January 8, 2024 03:40
@github-actions github-actions bot added crate-mock Issues related to the mock workspace member crate-integration-tests Issues related to the integration-tests workspace member labels Jan 10, 2024
roynalnaruto and others added 14 commits January 26, 2024 11:35
* feat: preliminary work

* wip

* finish assignment to ecrecover

* fix: input length may be different than call data length (for precompiles)

* fix: input bytes to ecrecover

* minor edits

* Fix ecrecover input rlc comparison (right-padding zeroes) (#585)

* potential approach (pow of rand lookup)

* add lookup for pow of rand

* fix: right pad only if needed

* fix: missing constraint on padded_rlc

* constrain pow of rand table

* Update step.rs

* fix: sig_v sanity check (remove assertions to allow garbage input)

* fix: calldata length == 0 handled

* chore: renaming precompile_* and parallel iter for tests

---------

Co-authored-by: Zhang Zhuo <[email protected]>

Precompile ECRECOVER (#529)

* feat: preliminary work

* wip

* finish assignment to ecrecover

* fix: input length may be different than call data length (for precompiles)

* fix: input bytes to ecrecover

* minor edits

* Fix ecrecover input rlc comparison (right-padding zeroes) (#585)

* potential approach (pow of rand lookup)

* add lookup for pow of rand

* fix: right pad only if needed

* fix: missing constraint on padded_rlc

* constrain pow of rand table

* Update step.rs

* fix: sig_v sanity check (remove assertions to allow garbage input)

* fix: calldata length == 0 handled

* chore: renaming precompile_* and parallel iter for tests

---------

Co-authored-by: Zhang Zhuo <[email protected]>
* wip: preliminary work sig circuit/lookp

* feat: handle panics and edge cases in sig circuit

* fix: handle v not boolean

* fix: fq modulus not assigned and bus-mapping handle overflowing r/s

* fix: sig_v handle invalid values (lookup) and is_valid dev_load fix

* refactor (review comment)

* fix: no sig table lookup for invalid sig_v

* remove wrong test case (assertion fail)
@github-actions github-actions bot removed the crate-mock Issues related to the mock workspace member label Jan 26, 2024
@KimiWu123 KimiWu123 force-pushed the feat/#1665-ecrecover branch 4 times, most recently from afd1526 to be813d0 Compare January 29, 2024 11:39
@KimiWu123 KimiWu123 changed the title [WIP] feat/#1665 Precompile ECRECOVER feat/#1665 Precompile ECRECOVER Jan 30, 2024
@miha-stopar miha-stopar self-requested a review January 30, 2024 08:56
Copy link
Collaborator

@miha-stopar miha-stopar left a comment

Choose a reason for hiding this comment

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

Added some nitpicks and questions. Looks great to me, but I have yet to read ECC circuit more carefully.

// - limb_bits: 88
// - num_limbs: 3
//
// TODO: make those parameters tunable from a config file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this to be done in a new PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in aed502b

},
)?;

layouter.assign_region(
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are some TODOs in the Scroll version, like // TODO: is this correct? before assign_region function. I guess it's a leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I believe so. So, I removed it.

powers_of_256: &[QuantumCell<F>],
op: &EcAddOp,
) -> EcAddDecomposed<F> {
log::trace!("[ECC] ==> EcAdd Assignmnet START:");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Assignmnet -> Assignment


ecc_chip.assert_equal(ctx, &rand_point, &sum3);

log::trace!("[ECC] EcAdd Assignmnet END:");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Assignment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! fixed in 4d5070f

powers_of_256: &[QuantumCell<F>],
op: &EcMulOp,
) -> EcMulDecomposed<F> {
log::trace!("[ECC] ==> EcMul Assignmnet START:");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Assignment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 4d5070f

powers_of_256: &[QuantumCell<F>],
op: &EcPairingOp,
) -> EcPairingDecomposed<F> {
log::trace!("[ECC] ==> EcPairing Assignment START:");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 4d5070f

Copy link
Collaborator

@miha-stopar miha-stopar left a comment

Choose a reason for hiding this comment

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

It seems all good to me. I would need some more time to check every detail of the ecc_circuit, but there are tests covering all edge cases and it was peer reviewed by Scroll people, so I think it should be all right.

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.

First pass.

zkevm-circuits/src/lib.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.

@KimiWu123 KimiWu123 added this pull request to the merge queue Feb 19, 2024
Merged via the queue into main with commit e19d163 Feb 19, 2024
15 checks passed
@KimiWu123 KimiWu123 deleted the feat/#1665-ecrecover branch February 19, 2024 10:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CI Issues related to the Continuous Integration mechanisms of the repository. crate-bus-mapping Issues related to the bus-mapping workspace member crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-eth-types Issues related to the eth-types 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.

Precompile: 0x01 ecRecover
4 participants