-
Notifications
You must be signed in to change notification settings - Fork 202
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
Remove sub() from gas() in SemaphoreVerifier.sol #871
Comments
@jimmychu0807 thanks 👍🏽 |
@saleel currently what is the simplest way to setup a test environment to trigger the issue that If this can't be done, I can't reliably know that I have solved this issue. Does this mean I should get back to setting up the smart-account-module? |
Yea, you would need to run the bundler and try to do a userOp with semaphore proof as the verifier. Basically, get the tests in https://github.com/saleel/semaphore-wallet pass with the original Semaphore contract (currently it uses the custom ones I have over there) |
@cedoor replying to your #345 (comment) To fix this issue, I want to be able to reproduce the error by running the test cases in https://github.com/saleel/semaphore-wallet . But the bundler component needed in the e2e test has updated since then and I have a hard time making all components connect together to trigger the error. The opcode restriction is outlined at [OP-012]: https://eips.ethereum.org/EIPS/eip-7562#opcode-rules An alternative is just that I make line from:
to
will that cause any security implication? |
Let me add some comments and explain. Here, In the proposed change, Typically, reserving gas helps prevent/reduce reentrancy attacks by ensuring that certain operations can always complete. However, in this specific context:
I suggest to proceed with the change. Replacing However, if future modifications introduce more gas-intensive operations after the Few more additional points:
|
@thogiti thank you for the explanation! With your comment, I take a deeper in the code. And I agree with what you said.
Let me make the change and check the difference in gas usage. Thank again for the helpful input! |
@jimmychu0807 |
@0xDatapunk thanks for the feedback. The issue is that we are in the yul assembly. If we call |
@jimmychu0807 do you minding experimenting calling gasleft() inside of assembly, and let me know what happens? thanks |
For the 0x06 precompile (
Similar logic exists for 0x07 and 0x08. Given this restriction preserving some gas seems necessary if we want to handle failure cases. That is, if when verifying an invalid proof we want to return Another approach could be hardcoding the gas sent to the precompile. The cost is dynamic based on the bit structure of the input so we could hardcode it to the upper bound of gas needed. |
Thanks for all the feedback! PR: #883 @jimmychu0807 Please, check the previous comment #871 (comment). The PR should include some other tests to be sure the function doesn't fail.
Cool, this should also work! |
A compiler error:
|
oops, then have to do something like:
which u don't like. |
the opcode rules disallow using |
I take another (deeper) look at the SemaphoreVerifier.sol. First on L#89 calling
Inside g1_mulAccC() function, L#62 will always NOT fail. This is because the first two parameters, Then This logic applies to three others Hmm... what I want to say is it may not be that straightforward to make L#62 and L#72 to revert. Let me ponder more on this. |
I looked at this a bit and it seems like you're right. If the codepath cannot revert then i think it's okay to not test the revert. e.g. we just remove the On a somewhat related note this looks like a good opportunity for optimization. We could remove a bunch of |
please refer to the updated #883. |
There are lines in SemaphoreVerifier.sol that make
gas()
calls. GAS opcode is restricted in validateUserOp (along with some other OPCODES). GAS is only allowed if immediately followed by CALL (and similar) opcodes. Semaphore doesstaticcall(sub(gas(), ...)
and there is aSUB
in between.So we need some other way to take the gas cost in consideration.
https://saleel.xyz/blog/zk-account-abstraction/
The text was updated successfully, but these errors were encountered: