-
Notifications
You must be signed in to change notification settings - Fork 250
Cleanup Verifier.sol and make error handling consistent #96
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
Cleanup Verifier.sol and make error handling consistent #96
Conversation
My next move would be to remove the return value from Personally I prefer to revert on invalid proofs. This prevents errors where the result is accidentally ignored. (See for example also |
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.
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.
Hi! After the next Semaphore ceremony we will have more verifiers (> 10). Since this code is regenerated every time from SnarkJS templates I think it is better to create a new verifier_groth16.sol.ejs
template with your changes.
@kobigurk Looks like you are partially right: field elements are verified, but scalars are not considered field elements. |
Ah yes, exactly the distinction I was looking for. Super dangerous :) |
Ok, so let's be conservative here and reject proofs where the input is not reduced. I'll add a commit. |
Thanks! Btw, it's not only conservative, it's a direct attack vector - a16z/zkdrops#2 |
I made all the functions in I don't know if this removes all proof malleability for people other than the prover. (i.e. given a valid proof but not the private inputs, can I compute a different also valid proof) |
@cedoor I suspected there was some template involved, despite the usual warning comment missing. Thanks for the link, I will submit a PR there too. I think we can still merge it here, the only thing that changes with a new ceremony is the contents of the |
It removes "public input" malleability, which is the dangerous part. Proofs can still be modified, because Groth16 is randomizable. |
contracts/base/SemaphoreCore.sol
Outdated
[root, nullifierHash, signalHash, externalNullifier] | ||
); | ||
|
||
return true; // TODO: This is redundant |
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.
Can't we remove this line? Updating the extension contracts should be sufficient to make this change compatible
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.
Happy to do so! I left it to limit the scope of changes.
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.
Seems you need to run yarn prettier:fix
to pass tests.
Pull request checklist
Please check if your PR fulfills the following requirements:
yarn compile
) was run locally and any changes were pushedyarn lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Currently when provided with an invalid proof, the verifier will either:
false
,invalid()
opcode,verifier-gte-snark-scalar-field
pairing-add-failed
,This makes handling invalid proofs hard. Returning
false
is especially dangerous because it puts the burden on the caller.What is the new behavior?
When provided with an invalid proof, the verifier will:
InvalidProof()
In the unlikely event that the caller desires different behaviour, the caller can use a Solidity try/catch statement.
Does this introduce a breaking change?
The revert error message for an invalid proof changes.
Other information