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

chore: add re-encrypt#28

Open
KentaMori115 wants to merge 3 commits into
mainfrom
feat/re-encrypt
Open

chore: add re-encrypt#28
KentaMori115 wants to merge 3 commits into
mainfrom
feat/re-encrypt

Conversation

@KentaMori115

@KentaMori115 KentaMori115 commented May 27, 2024

Copy link
Copy Markdown
  • Adds re-encrypt operator for TEE.
  • Adds custom evm mock with EthCall enabled.
  • Adds custom Decrypt function that returns in big.Int type.
  • Unit test

@lovenoble lovenoble deleted the branch main May 28, 2024 13:31
@lovenoble lovenoble closed this May 28, 2024
@lovenoble lovenoble reopened this May 28, 2024
@lovenoble lovenoble changed the base branch from main1 to main May 28, 2024 13:47
Comment thread fhevm/tee_crypto.go Outdated
Comment on lines +109 to +113
decryptedValue, err := tee.DecryptToBigInt(ct.ciphertext)

if err != nil {
logger.Error("reencrypt decryption failed", "err", err)
return nil, err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How about removing the DecryptToBigInt function and using the following lines?

		plaintext, err := tee.Decrypt(ct.ciphertext)
		if err != nil {
			logger.Error("reencrypt decryption failed", "err", err)
			return nil, err
		}
		decryptedValue := big.NewInt(0).SetBytes(plaintext.Value)

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.

Okay

Comment thread fhevm/params.go
Comment on lines +313 to +318
TeeReencrypt: map[tfhe.FheUintType]uint64{
tfhe.FheBool: 1000,
tfhe.FheUint4: 1000,
tfhe.FheUint8: 1000,
tfhe.FheUint16: 1100,
tfhe.FheUint32: 1200,

@lovenoble lovenoble May 28, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These values are much larger than the ones for other TEE operations.

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.

Basically copy & pasted code from tfhe reencrypt.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@amaury1093 Do you have any chance to look into this?

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.

Agreed. Maybe we can do 100, so 10x cheaper than FHE. In the same order of magniture as a mul

Comment thread tee/tee_mock.go
Comment on lines +130 to +135
// Always return a 32-byte big-endian integer.
ret := make([]byte, 32)
copy(ret[32-len(plaintext):], plaintext)

return new(big.Int).SetBytes(ret), nil
}

@lovenoble lovenoble May 28, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we can just use big.NewInt(0).SetBytes(plaintext) because it gives us the big-endian integer. In a word, we can remove this whole function.

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.

Okay

@KentaMori115 KentaMori115 requested a review from lovenoble May 29, 2024 04:14
Comment thread fhevm/fhelib.go
requiredGasFunction: getCiphertextRequiredGas,
runFunction: getCiphertextRun,
},
// TEE operations

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 #31, there has been a refactor to move tee operations into teelib.go. Your new function should go there.

Comment on lines +241 to +246
func newTestEVMEnvironmentWithEthCall() *MockEVMEnvironment {
mockEVM := newTestEVMEnvironment()
mockEVM.ethCall = true
return mockEVM
}

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.

Not sure it's super worth it to create a separate function in a separate file just for one instance.

I would rather add the line mockEVM.ethCall = true inside tee_crypto_test.go

Comment thread fhevm/params.go
Comment on lines +313 to +318
TeeReencrypt: map[tfhe.FheUintType]uint64{
tfhe.FheBool: 1000,
tfhe.FheUint4: 1000,
tfhe.FheUint8: 1000,
tfhe.FheUint16: 1100,
tfhe.FheUint32: 1200,

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.

Agreed. Maybe we can do 100, so 10x cheaper than FHE. In the same order of magniture as a mul

Comment thread fhevm/tee_crypto.go
return nil, err
}

// TODO: decide if `res.Signature` should be verified here

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.

What is this comment about?

Comment thread fhevm/tee_crypto_test.go
environment.depth = depth
addr := common.Address{}
readOnly := false
ct, err := importTeePlaintextToEVM(environment, depth, tc.expected, tc.typ)

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.

The test doesn't use any pubkey. What is it testing exactly here?

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