-
Notifications
You must be signed in to change notification settings - Fork 420
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
Conversation
78539d4
to
6c01cd0
Compare
I assume you mean |
Yes! Sorry, my typo. |
I think |
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. |
6c01cd0
to
b38a6b9
Compare
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 |
There was a problem hiding this 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).
Ethereum Yellow paper defines two initial conditions for ECRecover:
s
should bes < N+2 + 1
s
should bes < 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?