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

Fix foreign EC add soundness #1545

Merged
merged 6 commits into from
Apr 9, 2024
Merged

Fix foreign EC add soundness #1545

merged 6 commits into from
Apr 9, 2024

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Apr 9, 2024

closes #1531

The foreign EC addition gadget is modified to assert $x_1 \ne x_2$. We do this by first computing $\Delta := x_1 - x_2$ (which is needed subsequently) and checking that $\Delta$ can take none of the values $0$, $f$ and $2f$ -- which are those values equal to 0 modulo $f$ which can't be excluded due to range checks on $x_1$ and $x_2$.

Since $\Delta$ consists of 3 limbs $(\Delta_0, \Delta_1, \Delta_2)$, checking that it doesn't equal $0 = (0,0,0)$ entails checking that not all of the limbs equal 0. We make this more efficient by combining the lower two limbs into one field element (safe, because they are < 2^88), and using a new specialized assertNotVectorEquals() gadget which is suitable to check a vector inequality like $(\Delta_{01}, \Delta_2) \ne (0, 0)$.

Results. The EC add gadget increases from 63 to 69 rows. To me, this seems like a reasonable trade-off given that EC add becomes much less scary to use and analyzing soundness of the higher-level gadgets like scalar mul and ECDSA does not have to reason about degenerate addition cases.

@mitschabaude mitschabaude changed the base branch from main to release/0.18.0 April 9, 2024 08:27
Base automatically changed from release/0.18.0 to main April 9, 2024 14:06
@mitschabaude mitschabaude merged commit 88822f9 into main Apr 9, 2024
11 checks passed
@mitschabaude mitschabaude deleted the feature/safe-foreign-add branch April 9, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-native EC addition should constrain x1 != x2
2 participants