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

feat: verify ciphertext#32

Open
lovenoble wants to merge 6 commits into
mainfrom
el/verify-ciphertext
Open

feat: verify ciphertext#32
lovenoble wants to merge 6 commits into
mainfrom
el/verify-ciphertext

Conversation

@lovenoble

Copy link
Copy Markdown

No description provided.

Comment thread fhevm/tee_crypto.go
}

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

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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.

@lovenoble lovenoble Jun 3, 2024

Copy link
Copy Markdown
Author

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 ?

Copy link
Copy Markdown

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.

Copy link
Copy Markdown

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.

@KentaMori115 KentaMori115 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment thread tee/tee_mock.go
return plaintext, nil
}

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

Copy link
Copy Markdown
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
Copy Markdown
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.

@lovenoble lovenoble Jun 6, 2024

Copy link
Copy Markdown
Author

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