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

feat: differentiate ecrecover with strict and lax check for s #656

Merged
merged 2 commits into from
May 25, 2023

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Apr 21, 2023

Ethereum Yellow paper defines two initial conditions for ECRecover:

  • in case of checking transaction signatures, s should be s < N+2 + 1
  • in case of ECREC precompile, s should be s < N.

This PR updates the current precompile method which takes additional variable which defines the upper bound to compare s against. Also added test cases (strict check, lax check, assumed failure).

This is based on top of fix/ecdsa-v which depends on update in gnark-crypto. So have to wait for other PRs being merged before can merge this one.

CC: @AlexandreBelling, @OlivierBBB -- can you confirm this behaviour is good?

@ivokub ivokub added consolidate strengthen an existing feature zk-evm P1: High Issue priority: high labels Apr 21, 2023
@ivokub ivokub added this to the v0.9.0 milestone Apr 21, 2023
@ivokub ivokub requested a review from yelhousni April 21, 2023 11:14
@ivokub ivokub self-assigned this Apr 21, 2023
@ivokub ivokub force-pushed the feat/ecdsa-stricts branch from 78539d4 to 6c01cd0 Compare April 25, 2023 17:41
@yelhousni
Copy link
Contributor

  • in case of checking transaction signatures, s should be s < N+2 + 1

I assume you mean s < N/2 + 1?

@ivokub
Copy link
Collaborator Author

ivokub commented Apr 26, 2023

  • in case of checking transaction signatures, s should be s < N+2 + 1

I assume you mean s < N/2 + 1?

Yes! Sorry, my typo.

@yelhousni
Copy link
Contributor

I think 01-ecrecover.go should exclude the bounds checks on s and r as these are done on the zkEVM arithmetization side to avoid junk calls https://github.com/ConsenSys/zkevm-spec/issues/50

@ivokub
Copy link
Collaborator Author

ivokub commented Apr 26, 2023

I think 01-ecrecover.go should exclude the bounds checks on s and r as these are done on the zkEVM arithmetization side to avoid junk calls ConsenSys/zkevm-spec#50

I would also avoid, but there is a gotcha. This primitive is used in two places - first by the arithmetization when ECRECOVER precompile is called and second to verify the validity of the transaction.

For the first case it is obvious that it would be better to perform the check on the arithmetization side to avoid calling the circuit. But for the second case the check is done by the prover directly on the block data without passing to arithmetization. And there it may be better if we do the check on our side (I'm not fully sure, @AlexandreBelling can confirm?).

Now, we have two options - either implement two different circuits where in one we do not check s (for calling precompile in arithmetization) and in the second one we do (for prover verifying transaction signature). Or we have only a single circuit with a selector to select the bound we check s against. For simplicity I went for a single-circuit route.

@ivokub ivokub force-pushed the feat/ecdsa-stricts branch from 6c01cd0 to b38a6b9 Compare April 26, 2023 10:34
@ivokub
Copy link
Collaborator Author

ivokub commented Apr 27, 2023

So, I asked @AlexandreBelling, and as far as I understood then there is a fixed amount of ECRecover calls within a block. Having a single circuit allows to allocate these calls more efficiently between transaction verification and calling ECREC precompile. So the recommendation was to have a single circuit, even if when calling precompile we perform additional check on s.

Copy link
Contributor

@yelhousni yelhousni left a comment

Choose a reason for hiding this comment

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

Ok single-circuit then! Now either we'll duplicate arithmetization checks on s or remove them from the arithmetization side. I would choose the duplication option (cc @OlivierBBB).

@ivokub ivokub merged commit cb0c4d2 into develop May 25, 2023
@ivokub ivokub deleted the feat/ecdsa-stricts branch May 25, 2023 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consolidate strengthen an existing feature P1: High Issue priority: high zk-evm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants