Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

feat: verify ciphertext #32

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

feat: verify ciphertext #32

wants to merge 6 commits into from

Conversation

lovenoble
Copy link

No description provided.

}

ct := new(tfhe.TfheCiphertext)
ct.Serialization = ctBytes

Choose a reason for hiding this comment

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

@lovenoble this make sense. but we should try deserialize the ciphertext in order to ensure it is valid format like tfhe does? I guess we need to add TODO comments.

Copy link
Author

Choose a reason for hiding this comment

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

So I check the format after decrypting it in the following lines of codes.

Copy link
Author

Choose a reason for hiding this comment

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

So I check the format after decrypting it in the following lines of codes.

Choose a reason for hiding this comment

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

@lovenoble Got it. But i see that the tfhe uses deserializecompact function which produces non-compact ciphertext serialization from compacted one. Guess like the original meaning of verifyCipherTextRun function gets changed in this implementation. I think its original purpose was to deserialize the compacted cipher text and returns hash of it.

Copy link
Author

@lovenoble lovenoble Jun 3, 2024

Choose a reason for hiding this comment

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

I'm not sure how to implement compact serialization. Do you have any idea about it? And do we need a compact serialization for TEE case, @amaury1093 , @kenta-mori3322 ?

Choose a reason for hiding this comment

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

@lovenoble yeah actually was trying to decode rust code to golang.

Choose a reason for hiding this comment

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

Hi @lovenoble we have actually agreed on the fact that we won't use compacted ciphertext for TEE as it won't be so long. I think I can approve your PR.

Copy link

@kenta-mori3322 kenta-mori3322 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -118,3 +120,89 @@ func Decrypt(ct *tfhe.TfheCiphertext) (TeePlaintext, error) {

return plaintext, nil
}

func GetTeeCiphertextSize(t tfhe.FheUintType) (size uint, found bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lovenoble Are you 100% sure that if I do:

tee.Encrypt(NewTeePlaintext(1, tfhe.Uint64))
tee.Encrypt(NewTeePlaintext(2, tfhe.Uint64))

the two ciphertexts will have the same length? Does that hold true for all elliptic curve signatures?


another question:

tee.Encrypt(NewTeePlaintext(1, tfhe.Uint64))
tee.Encrypt(NewTeePlaintext(1, tfhe.Uint32))

Are the 2 ciphertext lengths still the same?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, I'd like to see in this PR the teeCiphertextSize table, what sizes we have.

For now we chose ECIES. This might change though, I would like to know if this table is still useful if we change to something else.

Copy link
Author

@lovenoble lovenoble Jun 6, 2024

Choose a reason for hiding this comment

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

The result will have the same length as long as the input length and the type are the same.
https://github.com/Inco-fhevm/zbc-go-ethereum/blob/master/crypto/ecies/ecies.go#L232
The output lenght is ct = make([]byte, len(Rb)+len(em)+len(d)), where

	em, err := symEncrypt(rand, params, Ke, m)
	d := messageTag(params.Hash, Km, em, s2)
	Rb := elliptic.Marshal(pub.Curve, R.PublicKey.X, R.PublicKey.Y)

When we look into these functions, we can get to know that they will return the constant length for the input of same length.

As for the second question, it will usually have different lengths.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants