electora-vote / electora-app

Decentralized Voting Application - leveraging the power of zk-proofs, conditions based decryption, and decentralized storage
https://app.electora.eu/
8 stars 2 forks source link

Sweep: when using an invalid sismo id, the redirect from sismo causes the error `LookupError: 'vote/choose/<ID>' does not exist` #96

Open theref opened 1 year ago

theref commented 1 year ago

Details

suppose a ballot is created with an invalid sismo group id. When a user goes to vote, they are sent to sismo to create a zk proof, but this fails because the group does not exist. Sismo then redirects back to electora app, but you get the error:

LookupError: 'vote/choose/<ID>' does not exist

instead, on a failed proof generation (either due to invalid group id or failure to produce a valid proof) the user should be redirected to the ballot page at #ballot_id=<BALLOT_ID>

Checklist - [X] `client_code/services/proof.py` > • Modify the `prove_eligibility` function to catch any exceptions when trying to connect to Sismo. If an exception is caught, redirect to the ballot page using the ballot's UUID. - [X] `client_code/forms/routes/vote/ChooseCandidate/__init__.py` > • In the `__init__` method of the `ChooseCandidate` class, add a check to see if the proof is valid. If it is not, redirect to the ballot page using the ballot's UUID.
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/electora-vote/electora-app/pull/98.

💎 Sweep Pro: I used GPT-4 to create this ticket. You have unlimited GPT-4 tickets. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/electora-vote/electora-app/blob/e2e1e0ca55f8ca8cd9a8135a17f28404cbc576ce/client_code/services/proof.py#L1-L17 https://github.com/electora-vote/electora-app/blob/e2e1e0ca55f8ca8cd9a8135a17f28404cbc576ce/client_code/forms/routes/vote/ChooseCandidate/__init__.py#L1-L34 https://github.com/electora-vote/electora-app/blob/e2e1e0ca55f8ca8cd9a8135a17f28404cbc576ce/client_code/model.py#L1-L40 https://github.com/electora-vote/electora-app/blob/e2e1e0ca55f8ca8cd9a8135a17f28404cbc576ce/client_code/services/storage.py#L1-L105 https://github.com/electora-vote/electora-app/blob/e2e1e0ca55f8ca8cd9a8135a17f28404cbc576ce/client_code/forms/routes/ballot/Create/__init__.py#L1-L43

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
client_code/services/proof.py Modify client_code/services/proof.py with contents:
• Modify the prove_eligibility function to catch any exceptions when trying to connect to Sismo. If an exception is caught, redirect to the ballot page using the ballot's UUID.
client_code/forms/routes/vote/ChooseCandidate/__init__.py Modify client_code/forms/routes/vote/ChooseCandidate/init.py with contents:
• In the __init__ method of the ChooseCandidate class, add a check to see if the proof is valid. If it is not, redirect to the ballot page using the ballot's UUID.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Fix redirect error when using invalid Sismo group ID sweep/fix-redirect-error

Description

This PR fixes the issue where, when a user tries to vote on a ballot with an invalid Sismo group ID, the application throws a LookupError when redirecting back from Sismo. The error message is 'vote/choose/<ID>' does not exist. This PR modifies the code to handle this error and redirect the user to the correct ballot page.

Summary

  • Modified the prove_eligibility function in client_code/services/proof.py to catch any exceptions when connecting to Sismo. If an exception is caught, the user is redirected to the ballot page using the ballot's UUID.
  • Modified the ChooseCandidate class in client_code/forms/routes/vote/ChooseCandidate/__init__.py to check if the proof is valid. If it is not, the user is redirected to the ballot page using the ballot's UUID.

This PR ensures that users are redirected to the correct ballot page when there is an error with the Sismo proof generation process.


Step 4: ⌨️ Coding

File Instructions Progress Error logs
client_code/services/proof.py Modify client_code/services/proof.py with contents:
• Modify the prove_eligibility function to catch any exceptions when trying to connect to Sismo. If an exception is caught, redirect to the ballot page using the ballot's UUID.
✅ Commit cdb6293 No errors.
client_code/forms/routes/vote/ChooseCandidate/__init__.py Modify client_code/forms/routes/vote/ChooseCandidate/init.py with contents:
• In the __init__ method of the ChooseCandidate class, add a check to see if the proof is valid. If it is not, redirect to the ballot page using the ballot's UUID.
✅ Commit 9cce0b2 No errors. I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/fix-redirect-error.

Here is the 1st review

No changes required. The added code correctly addresses the issue by checking if the proof is not present and redirecting the user to the ballot page if it's not. It also handles exceptions that might occur while connecting to the Sismo client and redirects the user to the ballot page in such cases. Good job!

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. Join Our Discord