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

fixing a bug for rescue/solidity transcript #70

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zhenfeizhang
Copy link
Contributor

Description

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (main)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@CLAassistant
Copy link

CLAassistant commented Jun 29, 2022

CLA assistant check
All committers have signed the CLA.

@alxiong alxiong added this to the Release 0.2.0 milestone Dec 13, 2022
@alxiong
Copy link
Contributor

alxiong commented Dec 13, 2022

this is a stale PR. iirc, the original motivation was just defense in depth in the light of trailofbits' disclosure on FrozenHeart where some FS transcripts forget taking in all the public inputs (especially the vk), but our library has always hashed all PI into our transcript, and adding a domain separator (the label) for each field may not have a security impact, just good-to-have.

Adding this to SolidityTranscript will increase the gas cost for PlonkVerifier.

I personally don't find this necessary from security perspective, am I missing anything?

Just want to bring this out for discussion. @EspressoSystems/jellyfish

@mrain
Copy link
Contributor

mrain commented Dec 16, 2022

Is there any reference for old discussion about this issue?

Also is the gas cost increase going to be significant if we add those domain separators? @alxiong

@alxiong
Copy link
Contributor

alxiong commented Dec 19, 2022

Is there any reference for old discussion about this issue?

Sorry, I can't recall. @chancharles92 do you have anything to add beyond my comments above?

Also is the gas cost increase going to be significant if we add those domain separators?

yes, it's non-neglible cuz we are hashing using rescue which is expensive in Solidity (in absolute gas cost, but somewhat manageable in relative gas cost), the more pressing problem is the contract bytecode size will increase. I remember we have a lots of trouble trying to keep CAPE contract under size limit.

@alxiong alxiong self-assigned this Dec 19, 2022
@chancharles92
Copy link
Contributor

Is there any reference for old discussion about this issue?

Sorry, I can't recall. @chancharles92 do you have anything to add beyond my comments above?

My impression is that Zhenfei mentioned that our SNARK/Circuit transcript implementations are secure, but I don't remember clearly whether the solidity transcript is correct or not.

@chancharles92
Copy link
Contributor

chancharles92 commented Jan 17, 2023

Found the context here: https://www.notion.so/espressosys/Potential-vulnerability-on-Jellyfish-s-transcript-91e810dd59c849aba7bab4ef9baaffb9 @mrain @alxiong

TL; DR: it's not a bug in Jellyfish because Jellyfish code has an implicit data length field. But for general usage (e.g. if some external users want to use it and want to support dynamic data length fields), it'll be better to patch this PR.

@alxiong
Copy link
Contributor

alxiong commented Jan 18, 2023

Thanks for finding the notion page. I have a question, so it's probably a good idea to fix "rescue transcript". But is it necessary to also add label to "solidity transcript"? The scenario described where 3 BN254 points turn out to be identical to 2 BLS12-381 points are not possible in our CAPE contract.

Also I remember Aztec's plonk verifier contract doesn't add label, neither does matter-lab.

@chancharles92
Copy link
Contributor

Thanks for finding the notion page. I have a question, so it's probably a good idea to fix "rescue transcript". But is it necessary to also add label to "solidity transcript"? The scenario described where 3 BN254 points turn out to be identical to 2 BLS12-381 points are not possible in our CAPE contract.

Also I remember Aztec's plonk verifier contract doesn't add label, neither does matter-lab.

Yes, check TL; DR. We didn't need to merge this PR now. OTOH, fixing the "rescue transcript" also has some costs because the SNARK circuit will have more constraints.

@mrain mrain changed the title fixing a bug for solidity transcript fixing a bug for rescue/solidity transcript Jan 18, 2023
@mrain
Copy link
Contributor

mrain commented Jan 18, 2023

Thanks for finding the notion page. I have a question, so it's probably a good idea to fix "rescue transcript". But is it necessary to also add label to "solidity transcript"? The scenario described where 3 BN254 points turn out to be identical to 2 BLS12-381 points are not possible in our CAPE contract.
Also I remember Aztec's plonk verifier contract doesn't add label, neither does matter-lab.

Yes, check TL; DR. We didn't need to merge this PR now. OTOH, fixing the "rescue transcript" also has some costs because the SNARK circuit will have more constraints.

I pushed a commit for fixing the rescue transcript. Please check @alxiong @chancharles92

@chancharles92
Copy link
Contributor

chancharles92 commented Jan 18, 2023

Thanks for finding the notion page. I have a question, so it's probably a good idea to fix "rescue transcript". But is it necessary to also add label to "solidity transcript"? The scenario described where 3 BN254 points turn out to be identical to 2 BLS12-381 points are not possible in our CAPE contract.
Also I remember Aztec's plonk verifier contract doesn't add label, neither does matter-lab.

Yes, check TL; DR. We didn't need to merge this PR now. OTOH, fixing the "rescue transcript" also has some costs because the SNARK circuit will have more constraints.

I pushed a commit for fixing the rescue transcript. Please check @alxiong @chancharles92

If we fix the rescue transcript, should we also sync the change in the circuit? E.g., in append_variable(), we should also append the label constant.
https://github.com/EspressoSystems/jellyfish/blob/main/plonk/src/circuit/transcript.rs#L84

(It's strange that the tests didn't fail after the changes.)

@mrain
Copy link
Contributor

mrain commented Jan 18, 2023

Thanks for finding the notion page. I have a question, so it's probably a good idea to fix "rescue transcript". But is it necessary to also add label to "solidity transcript"? The scenario described where 3 BN254 points turn out to be identical to 2 BLS12-381 points are not possible in our CAPE contract.
Also I remember Aztec's plonk verifier contract doesn't add label, neither does matter-lab.

Yes, check TL; DR. We didn't need to merge this PR now. OTOH, fixing the "rescue transcript" also has some costs because the SNARK circuit will have more constraints.

I pushed a commit for fixing the rescue transcript. Please check @alxiong @chancharles92

If we fix the rescue transcript, should we also sync the change in the circuit? E.g., in append_variable(), we should also append the label constant. https://github.com/EspressoSystems/jellyfish/blob/main/plonk/src/circuit/transcript.rs#L84

(It's strange that the tests didn't fail after the changes.)

Sure we should. But it's not easy in the current gadget design. I'll try to do it today.

@chancharles92
Copy link
Contributor

Sure we should. But it's not easy in the current gadget design. I'll try to do it today.

Thanks, it's not in a hurry as we do not plan to merge this PR very soon.

COULD NOT PASS THE TESTS.
Details are described in the comments. Pls search for "TODO".
let mut f = bytes_to_field_elements(&msg);
self.transcript.append(&mut f);
/// Append the message to the transcript.
/// TODO(Chengyu): fix the bug here, current design brings trouble to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the gadget implementation for rescue transcript. However, I encountered trouble passing the tests. The reason is described here.
I would also suggest remove this from the current release plan.
@alxiong @chancharles92

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we can include this change in a patch release afterwards.

@mrain mrain removed this from the Release 0.2.0 milestone Jan 19, 2023
@mrain
Copy link
Contributor

mrain commented Jan 19, 2023

Also could someone check the CI here? It failed test on my local computer. But CI passed.

@chancharles92
Copy link
Contributor

Also could someone check the CI here? It failed test on my local computer. But CI passed.

@Ancient123 Can we do similar changes in Jellyfish as we did to the HyperPlonk repo?

@Ancient123
Copy link
Member

Also could someone check the CI here? It failed test on my local computer. But CI passed.

@Ancient123 Can we do similar changes in Jellyfish as we did to the HyperPlonk repo?

This is part of the reason I consider it bad practice to call testing scripts versus having them embedded in the github build.yml.

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.

6 participants